]> git.lyx.org Git - wiki-uploads.git/blob - make-lfun-list.sh
1aea9a7d38ce9f67f2424e3abbfccc3d8f0fdb6c
[wiki-uploads.git] / make-lfun-list.sh
1 #!/bin/bash
2 #
3 # Christian Riddertrom 2003-11-124
4 #
5 S0=`basename $0`
6 if [[ "$1" == "" || "$1" == "-h" || "$1" == "--help" ]]; then
7     cat <<EOF
8 Fcn:    Extract list of lfuns from a .C-file
9 Options:
10         -q      Be more quiet
11         -v      Be more verbose
12         -d      Debug script
13         -n      Don't actually do anything
14         -r rev  Use wget to retrieve release 'rev' from CVS web-interface
15         --normal        Extract 'normal' functions
16         --no-normal     Skip extracting 'normal' functions
17         --only-normal   Only extract 'normal' functions
18         --fonts, --no-fonts and --only-fonts  are similar to the above.
19         --accents, --no-accents and --only-accents are similar to the above.
20         --wiki-output   Produce output in PmWiki-format
21         --wiki-page     Produce a complete wiki-page (-r is required, and
22                         no other options work)
23 Examples:
24 # Extract 'normal' lfuns from release 1.3.3 (downloads file from the web)
25         $S0 -r lyx-1_3_3
26 # Same thing, but using the latest (VCS) version
27         $S0 -r HEAD
28
29 Note: The output is normally the string for the user-command, followed
30 by a TAB and possibly a help string (for release lyx-1_3_3). However, if
31 the option '--wiki-output' is given, then a resulting line looks like this:
32 ||<user-command><TABs>||<help-text><TABs>||
33
34 To create a wiki page, use this sequence:
35         $S0 -r lyx-1_3_3 --wiki-page > LyxFunctionList1-3-3.pmwiki
36
37 EOF
38     exit 0
39 fi
40
41 Version=1.0
42 [[ "$1" == --version ]] && { printf "%s\n" "$Version"; exit 0; }
43
44 # Use: Verbose [vLevel] formatString [arguments]
45
46 # Execute 'printf formatString [arguments]' if $Verbosity >= $vLevel,
47 # where the default value of $vLevel is 1, and the default is assumed if
48 # the length of the first argument is not one.
49 # Ex:   Verbose 3 "Only printed if verbosity(%d) >= 3" "$Verbosity"
50 # Ex:   Verbose "Only printed if verbosity >= 1"
51 #
52 Verbosity=0                     # Default is Verbosity=0, i.e. no messages
53 function Verbose() {
54     if ((${#1} == 1)); then vLevel=$1; shift; else vLevel=1; fi
55     if (($Verbosity >= $vLevel)); then printf "$1\n" "${@:2}"; fi;
56 }
57
58 function Log() {
59     printf "$1\n" "${@:2}"
60 }
61
62 #
63 # Set default values for variables
64 #
65 DO=1;
66 DO_NORMAL=1;
67 DO_FONTS=0;
68 DO_ACCENTS=0;
69 quiet=0;
70 args=( )
71 dir0=~lyx/www/pmwiki            # pmwiki/-directory
72 lyxDir=~lyx/www/sourcedoc
73 fileName=LyXAction.C
74 srcDir=src
75 sedFile=`dirname $0`/make-lfun-list.sed
76 sedFileWiki=`dirname $0`/make-lfun-wiki.sed
77 baseURI=http://www.lyx.org/cgi-bin/viewcvs.cgi/lyx-devel
78 USE_WGET=0;
79 rev=HEAD;
80 outputWiki=0;
81 tmpResult=/tmp/lfuns.$$.tmp
82
83 # Parse arguments
84 while [[ "$1" != "" ]]; do
85     case "$1" in
86         "-q") quiet=1;;
87         "-v") let ++Verbosity;;
88         "-d") set -v;;
89         "+n") DO=1;;
90         "-n") DO=0;;
91         -r)             USE_WGET=1; rev=$2; shift;;
92         --normal)       DO_NORMAL=1;;
93         --fonts)                     DO_FONTS=1;;
94         --accents)                               DO_ACCENTS=1;;
95         --no-normal)    DO_NORMAL=0;;
96         --no-fonts)                  DO_FONTS=0;;
97         --no-accents)                            DO_ACCENTS=0;;
98         --only-normal)  DO_NORMAL=1; DO_FONTS=0; DO_ACCENTS=0;;
99         --only-fonts)   DO_NORMAL=0; DO_FONTS=1; DO_ACCENTS=0;;
100         --only-accents) DO_NORMAL=0; DO_FONTS=0; DO_ACCENTS=1;;
101         --wiki-output)  outputWiki=1;;
102         --wiki-page)    outputPage=1;;
103     esac
104     shift;
105 done
106
107 if(($outputPage)); then
108     cat <<EOF
109 !!!List of LyxFunctions in release $rev
110
111 The lists of [=LFUNs=] below were derived from from releaes $rev of [[LyxSrc:LyXAction.C?rev=lyx-1_3_3&content-type=text/vnd.viewcvs-markup src/LyXAction.C]]. 
112 Some of the commands below take arguments and others don't.
113 Feel free to add comments about what an LFUN does.
114
115 [[#various]]Various [=LFUNs=], sorted alphabetically:
116 EOF
117
118     $0 -r $rev --wiki-output
119     cat <<EOF
120
121 [[#font]][=LFUNs=] related to font commands:
122 EOF
123     $0 -r $rev --wiki-output --only-fonts
124     cat <<EOF
125
126 [[#accent]]Accent [=LFUNs=]:[[<<]]
127 Try for instance, @@M-x accent acute a@@ &mdash; which should give you the letter a with an ''acute'' above it. If you don't give an argument ('@@a@@' in the example), the command will be applied to the next letter you type.
128 EOF
129     $0 -r $rev --wiki-output --only-accents
130     exit
131 fi;
132
133 Verbose "Processing options now finished."
134 if(($outputWiki)); then
135     Verbose "Redirecting output to %s" "$tmpResult"
136     exec 6>&1
137     exec > $tmpResult
138 fi;
139
140 if(($USE_WGET)); then
141     file=/tmp/$fileName-$rev-$$.C
142     wget -q -O $file "$baseURI/$srcDir/$fileName?rev=$rev"
143 else
144     file=$lyxDir/$srcDir/$fileName
145 fi;
146
147 function ExtractEnums() {
148     (($DO)) && sed -f $sedFile $file | sort
149 }
150
151
152 if (($DO && $DO_NORMAL)); then
153     ExtractEnums | grep -v '^\(font\|accent\)-'
154 fi;
155
156 if (($DO && $DO_FONTS)); then
157     ExtractEnums | grep '^\(font-\)'
158 fi;
159
160 if (($DO && $DO_ACCENTS)); then
161     ExtractEnums | grep '^\(accent-\)'
162 fi;
163
164 if(($outputWiki)); then
165     exec 1>&6 6>&-              # Restore stdout and close file.desc.6
166
167     printf "||%-30s||%-28s||%s||\n" \
168         "'''Command string'''" "'''Help text'''" "'''Comment'''"
169     while read command helpText; do
170         printf "||%-30s||%-28s||\n" "$command" "$helpText"
171     done < $tmpResult
172     rm $tmpResult
173 fi;
174
175 Verbose "Done."
176 if(($USE_WGET)); then
177     rm -f $file
178 fi;