module_synopsis.sh 13 KB

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