-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
module_synopsis.sh
executable file
·510 lines (408 loc) · 12.8 KB
/
module_synopsis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
#!/bin/sh
############################################################################
#
# TOOL: module_synopsis.sh
# AUTHOR: M. Hamish Bowman, Dept. Marine Science, Otago Univeristy,
# New Zealand
# PURPOSE: Runs through GRASS modules and creates a synopsis list of
# module names and descriptions.
# COPYRIGHT: (c) 2007 Hamish Bowman, and the GRASS Development Team
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
#############################################################################
#
# PDF output requires the Palatino font.
# Run this script from the tools/ directory in the souce code.
# (TeX needs to be able to find grasslogo_vector.pdf)
#
if [ -z "$GISBASE" ] ; then
echo "You must be in GRASS GIS to run this program." 1>&2
exit 1
fi
for FILE in txt tex ; do
if [ -e "$GISBASE/etc/module_synopsis.$FILE" ] ; then
# echo "ERROR: module_synopsis.$FILE already exists" 1>&2
# exit 1
#blank it
g.message -w "Overwriting \"\$GISBASE/etc/module_synopsis.$FILE\""
\rm "$GISBASE/etc/module_synopsis.$FILE"
fi
done
for FILE in html pdf ; do
if [ -e "$GISBASE/docs/$FILE/module_synopsis.$FILE" ] ; then
# echo "ERROR: module_synopsis.$FILE already exists" 1>&2
# exit 1
#blank it
g.message -w "Overwriting \"\$GISBASE/docs/$FILE/module_synopsis.$FILE\""
\rm "$GISBASE/docs/$FILE/module_synopsis.$FILE"
fi
done
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
g.message -e "Unable to create temporary files"
exit 1
fi
g.message "Generating module synopsis (writing to \$GISBASE/etc/) ..."
SYNOP="$GISBASE/etc/module_synopsis.txt"
OLDDIR="`pwd`"
cd "$GISBASE"
### generate menu hierarchy
#### fixme: no longer exists
MDPY="$GISBASE/etc/wxpython/gui_modules/menudata.py"
# python menudata.py commands
# python menudata.py tree
# python menudata.py strings
python "$MDPY" commands | sed -e 's/ | /|/' -e 's/[ -].*|/|/' \
| sort -u > "$TMP.menu_hierarchy"
# for running with GRASS 6.4 after generating with GRASS 6.5.
#\cp "$TMP.menu_hierarchy" "$GISBASE/etc/gui/menu_hierarchy.txt"
#\cp "$GISBASE/etc/gui/menu_hierarchy.txt" "$TMP.menu_hierarchy"
### given a module name return where it is in the menu tree
find_menu_hierarchy()
{
MODL=$1
# unwrap wrapper scripts
if [ "$MODL" = "g.gui" ] ; then
MODL="g.change.gui.py"
elif [ "$MODL" = "v.type" ] ; then
MODL="v.type_wrapper.py"
fi
PLACEMENT=`grep "^$MODL|" "$TMP.menu_hierarchy" | cut -f2 -d'|' | head -n 1`
# combine some modules which are listed twice
if [ "$MODL" = "g.region" ] ; then
PLACEMENT=`echo "$PLACEMENT" | sed -e 's/Display/Set or Display/'`
elif [ "$MODL" = "r.reclass" ] || [ "$MODL" = "v.reclass" ] ; then
PLACEMENT=`echo "$PLACEMENT" | sed -e 's/Reclassify.*$/Reclassify/'`
fi
echo "$PLACEMENT"
}
### execute the loop for all modules
for DIR in bin scripts ; do
cd $DIR
for MODULE in ?\.* db.* r3.* ; do
unset label
unset desc
# echo "[$MODULE]"
case "$MODULE" in
g.parser | "r3.*" | g.module_to_skip)
continue
;;
esac
eval `$MODULE --interface-description | head -n 5 | tail -n 1 | \
tr '"' "'" | sed -e 's/^[ \t]./desc="/' -e 's/$/"/' -e 's/[^\."]"$/&./'`
if [ -z "$label" ] && [ -z "$desc" ] ; then
continue
fi
MODULE_MENU_LOC=`find_menu_hierarchy "$MODULE"`
BUFF=""
if [ -z "$label" ] ; then
BUFF="$MODULE: $desc"
else
BUFF="$MODULE: $label"
fi
if [ -n "$MODULE_MENU_LOC" ] ; then
BUFF="$BUFF {$MODULE_MENU_LOC}"
fi
if [ -n "$BUFF" ] ; then
#echo "$BUFF"
echo "$BUFF" >> "$TMP"
fi
done
cd ..
done
# ps.map doesn't jive with the above loop.
for MODULE in ps.map ; do
unset label
unset desc
eval `$MODULE --interface-description | head -n 5 | tail -n 1 | \
tr '"' "'" | sed -e 's/^[ \t]./desc="/' -e 's/$/"/' -e 's/[^\."]"$/&./'`
if [ -z "$label" ] && [ -z "$desc" ] ; then
continue
fi
MODULE_MENU_LOC=`find_menu_hierarchy "$MODULE"`
BUFF=""
if [ -z "$label" ] ; then
BUFF="$MODULE: $desc"
else
BUFF="$MODULE: $label"
fi
if [ -n "$MODULE_MENU_LOC" ] ; then
BUFF="$BUFF {$MODULE_MENU_LOC}"
fi
if [ -n "$BUFF" ] ; then
#echo "$BUFF"
echo "$BUFF" >> "$TMP"
fi
done
# these don't use the parser at all.
cat << EOF >> "$TMP"
g.parser: Full parser support for GRASS scripts.
photo.2image: Marks fiducial or reseau points on an image to be ortho-rectified and then computes the image-to-photo coordinate transformation parameters.
photo.2target: Create control points on an image to be ortho-rectified.
photo.camera: Creates or modifies entries in a camera reference file.
photo.elev: Selects target elevation model for ortho-rectification.
photo.init: Creates or modifies entries in a camera initial exposure station file for imagery group referenced by a sub-block.
photo.rectify: Rectifies an image by using the image to photo coordinate transformation matrix created by photo.2image and the rectification parameters created by photo.2target.
photo.target: Selects target location and mapset for ortho-rectification.
EOF
## with --dictionary-order db.* ends up in the middle of the d.* cmds
#sort --dictionary-order "$TMP" > "$SYNOP"
sort "$TMP" > "$SYNOP"
\rm -f "$TMP"
cp "$SYNOP" "${TMP}.txt"
####### create HTML source #######
# poor cousin to full_index.html from tools/build_html_index.sh
# todo $MODULE.html links
g.message "Generating HTML (writing to \$GISBASE/docs/html/) ..."
#### write header
cat << EOF > "${TMP}.html"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>`g.version | cut -f1 -d'('` Command list</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="grassdocs.css" type="text/css">
</head>
<body bgcolor="white">
<img src="grass_logo.png" alt="_\|/_ GRASS logo">
<hr class="header">
<!-- prettier:
<BR><BR><BR><BR>
<center>
<img src="../../images/grasslogo.gif" alt="_\|/_ GRASS logo">
<BR><BR>
<hr width="450" align=center size=6 noshade>
-->
<center>
<H1>`g.version | cut -f1 -d'('` Command list</H1>
<h3>`date "+%e %B %Y"`</h3>
</center>
<BR><BR><BR>
<!--
<i><font size="-1" color="#778877">
Menu position follows description if applicable.</font></i>
<BR><BR>
-->
<!--
# so it works from $WEB/gdp/grassmanuals/
# untested:
sed -i -e 's+\(a href="\)\([^#\.h]\)+\1../../grass64/manuals/html64_user/\2+'
-->
<h4>Command types:</h4>
<ul>
<li> d.* - <a href="#d">display commands</a>
<li> db.* - <a href="#db">database</a> commands
<li> g.* - <a href="#g">general</a> commands
<li> i.* - <a href="#i">imagery</a> commands
<li> m.* - <a href="#m">miscellanous</a> commands
<li> ps.* - <a href="#ps">PostScript</a> commands
<li> r.* - <a href="#r">raster</a> commands
<li> r3.* - <a href="#r3">raster3D</a> commands
<li> v.* - <a href="#v">vector</a> commands
<li> <a href="wxGUI.html">wxGUI</a> - GUI frontend (wxPython)
<li> <a href="nviz.html">NVIZ</a> - <i>n</i>-dimensional visualization suite
EOF
#### fill in module entries
for SECTION in d db g i m ps r r3 v ; do
SEC_TYPE="commands"
case $SECTION in
d)
SEC_NAME="Display" ;;
db)
SEC_NAME="Database management" ;;
g)
SEC_NAME="General GIS management" ;;
i)
SEC_NAME="Imagery" ;;
m)
SEC_NAME="Miscellaneous"
SEC_TYPE="tools" ;;
ps)
SEC_NAME="PostScript" ;;
r)
SEC_NAME="Raster" ;;
r3)
SEC_NAME="Raster 3D" ;;
v)
SEC_NAME="Vector" ;;
esac
cat << EOF >> "${TMP}.html"
</ul>
<BR>
<a name="$SECTION"></a>
<H3>$SEC_NAME $SEC_TYPE:</H3>
<ul>
EOF
grep "^${SECTION}\." "${TMP}.txt" | \
sed -e 's/: /| /' -e 's/^.*|/<li> <a href="&.html">&<\/a>:/' \
-e 's/|.html">/.html">/' -e 's+|</a>:+</a>:+' \
-e 's/&/\&/g' \
-e 's+ {+\n <BR><font size="-2" color="#778877"><i>+' \
-e 's+}+</i></font>+' \
-e 's+ > + \→ +g' >> "${TMP}.html"
if [ "$SECTION" = "i" ] ; then
# include imagery photo subsection
cat << EOF >> "${TMP}.html"
</ul>
<h4>Imagery photo.* commands:</h4>
<ul>
EOF
grep "^photo\." "${TMP}.txt" | \
sed -e 's/: /| /' -e 's/^.*|/<li> <a href="&.html">&<\/a>:/' \
-e 's/|.html">/.html">/' -e 's+|</a>:+</a>:+' \
-e 's/&/\&/g' \
-e 's+ {+\n <BR><font size="-2" color="#778877"><i>+' \
-e 's+}+</i></font>+' \
-e 's+ > + \→ +g' >> "${TMP}.html"
fi
done
#### save footer
cat << EOF >> "${TMP}.html"
</ul>
<hr class="header">
<p>
<a href="index.html">Help Index</a><br>
© 2007-2010 <a href="http://grass.osgeo.org">GRASS Development Team</a>
</p>
</BODY>
</HTML>
EOF
\mv "${TMP}.html" "$GISBASE/docs/html/module_synopsis.html"
####### create LaTeX source #######
g.message "Generating LaTeX source (writing to \$GISBASE/etc/) ..."
#### write header
cat << EOF > "${TMP}.tex"
%% Adapted from LyX 1.3 LaTeX export. (c) 2009 The GRASS Development Team
\documentclass[a4paper]{article}
\usepackage{palatino}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{a4wide}
\usepackage{graphicx}
\usepackage{color}
\definecolor{DarkSeaGreen3}{rgb}{0.412,0.545,0.412}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\newenvironment{lyxlist}[1]
{\begin{list}{}
{\settowidth{\labelwidth}{#1}
\setlength{\leftmargin}{\labelwidth}
\addtolength{\leftmargin}{\labelsep}
\renewcommand{\makelabel}[1]{##1\hfil}}}
{\end{list}}
%% last language is the default
\usepackage[german, english]{babel}
\makeatother
\begin{document}
\begin{center}\includegraphics[%
width=0.3\textwidth]{grasslogo_vector.pdf}\end{center}
\begin{center}{\huge `g.version | cut -f1 -d'('` Command list}\end{center}{\huge \par}
\begin{center}{\large `date "+%e %B %Y"`}\end{center}{\large \par}
\bigskip{}
\section*{Command types:}
\begin{lyxlist}{00.00.0000}
\item [d.{*}]display commands
\item [db.{*}]database commands
\item [g.{*}]general commands
\item [i.{*}]imagery commands
\item [m.{*}]miscellanous commands
\item [ps.{*}]postscript commands
\item [r.{*}]raster commands
\item [r3.{*}]raster3D commands
\item [v.{*}]vector commands
\item [wxGUI]GUI frontend (wxPython)
\item [NVIZ]$n$-dimensional visualization suite
EOF
#### fill in module entries
for SECTION in d db g i m ps r r3 v ; do
SEC_TYPE="commands"
case $SECTION in
d)
SEC_NAME="Display" ;;
db)
SEC_NAME="Database management" ;;
g)
SEC_NAME="General GIS management" ;;
i)
SEC_NAME="Imagery" ;;
m)
SEC_NAME="Miscellaneous"
SEC_TYPE="tools" ;;
ps)
SEC_NAME="PostScript" ;;
r)
SEC_NAME="Raster" ;;
r3)
SEC_NAME="Raster 3D" ;;
v)
SEC_NAME="Vector" ;;
esac
cat << EOF >> "${TMP}.tex"
\end{lyxlist}
\smallskip{}
\section*{$SEC_NAME $SEC_TYPE:}
\begin{lyxlist}{00.00.0000}
EOF
grep "^${SECTION}\." "${TMP}.txt" | \
sed -e 's/^/\\item [/' -e 's/: /]/' \
-e 's+ {+ \\\\\n$+' -e 's/}$/$/' \
-e 's+ > +\\,\\triangleright\\,|+g' \
-e 's/\*/{*}/g' -e 's/_/\\_/g' -e 's/&/\\\&/g' \
| awk '/^\$/ { STR=$0; \
gsub(" ", "\\: ", STR); \
gsub(/\|/, " ", STR); \
sub(/^/, " \\textcolor{DarkSeaGreen3}{\\footnotesize ", STR); \
sub(/$/, "}", STR); \
print STR \
} ;
/^\\/ {print}' >> "${TMP}.tex"
if [ "$SECTION" = "i" ] ; then
# include imagery photo subsection
cat << EOF >> "${TMP}.tex"
\end{lyxlist}
\subsubsection*{Imagery photo.{*} commands:}
\begin{lyxlist}{00.00.0000}
EOF
grep "^photo\." "${TMP}.txt" | \
sed -e 's/^/\\item [/' -e 's/: /]/' >> "${TMP}.tex"
fi
done
#### save footer
cat << EOF >> "${TMP}.tex"
\end{lyxlist}
\end{document}
EOF
\mv "${TMP}.tex" "$GISBASE/etc/module_synopsis.tex"
\rm -f "${TMP}.txt"
##### FIXME
# post generation tidy-up
# - sort order isn't ideal. try 'sort -n'??
# fix: *.univar.sh, r.surf.idw2, v.to.rast3, r.out.ppm3, others..
#####
g.message "Converting LaTeX to PDF (writing to \$GISBASE/docs/pdf/) ..."
for PGM in pdflatex ; do
if [ ! -x `which $PGM` ] ; then
g.message -e "pdflatex needed for this PDF conversion."
g.message "Done."
exit 1
fi
done
TMPDIR="`dirname "$TMP"`"
cp "$OLDDIR/../man/grasslogo_vector.pdf" "$TMPDIR"
cd "$TMPDIR"
#once working nicely make it quieter
#pdflatex --interaction batchmode "$GISBASE/etc/module_synopsis.tex"
pdflatex "$GISBASE/etc/module_synopsis.tex"
\rm -f module_synopsis.dvi module_synopsis.ps \
module_synopsis_2.ps grasslogo_vector.pdf
if [ ! -d "$GISBASE/docs/pdf" ] ; then
mkdir "$GISBASE/docs/pdf"
fi
\mv module_synopsis.pdf "$GISBASE/docs/pdf/"
# Convert to pretty two-up version:
# Open PDF in Acrobat, print-to-file as postscript, then run:
# a2ps module_list.ps -o module_list_2up.ps
# ps2pdf13 module_list_2up.ps
g.message "Done."