module_synopsis.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. #### fixme: no longer exists
  53. MDPY="$GISBASE/etc/wxpython/gui_modules/menudata.py"
  54. # python menudata.py commands
  55. # python menudata.py tree
  56. # python menudata.py strings
  57. python "$MDPY" commands | sed -e 's/ | /|/' -e 's/[ -].*|/|/' \
  58. | sort -u > "$TMP.menu_hierarchy"
  59. # for running with GRASS 6.4 after generating with GRASS 6.5.
  60. #\cp "$TMP.menu_hierarchy" "$GISBASE/etc/gui/menu_hierarchy.txt"
  61. #\cp "$GISBASE/etc/gui/menu_hierarchy.txt" "$TMP.menu_hierarchy"
  62. ### given a module name return where it is in the menu tree
  63. find_menu_hierarchy()
  64. {
  65. MODL=$1
  66. # unwrap wrapper scripts
  67. if [ "$MODL" = "g.gui" ] ; then
  68. MODL="g.change.gui.py"
  69. elif [ "$MODL" = "v.type" ] ; then
  70. MODL="v.type_wrapper.py"
  71. fi
  72. PLACEMENT=`grep "^$MODL|" "$TMP.menu_hierarchy" | cut -f2 -d'|' | head -n 1`
  73. # combine some modules which are listed twice
  74. if [ "$MODL" = "g.region" ] ; then
  75. PLACEMENT=`echo "$PLACEMENT" | sed -e 's/Display/Set or Display/'`
  76. elif [ "$MODL" = "r.reclass" ] || [ "$MODL" = "v.reclass" ] ; then
  77. PLACEMENT=`echo "$PLACEMENT" | sed -e 's/Reclassify.*$/Reclassify/'`
  78. fi
  79. echo "$PLACEMENT"
  80. }
  81. ### execute the loop for all modules
  82. for DIR in bin scripts ; do
  83. cd $DIR
  84. for MODULE in ?\.* db.* r3.* ; do
  85. unset label
  86. unset desc
  87. # echo "[$MODULE]"
  88. case "$MODULE" in
  89. g.parser | "r3.*" | g.module_to_skip)
  90. continue
  91. ;;
  92. esac
  93. eval `$MODULE --interface-description | head -n 5 | tail -n 1 | \
  94. tr '"' "'" | sed -e 's/^[ \t]./desc="/' -e 's/$/"/' -e 's/[^\."]"$/&./'`
  95. if [ -z "$label" ] && [ -z "$desc" ] ; then
  96. continue
  97. fi
  98. MODULE_MENU_LOC=`find_menu_hierarchy "$MODULE"`
  99. BUFF=""
  100. if [ -z "$label" ] ; then
  101. BUFF="$MODULE: $desc"
  102. else
  103. BUFF="$MODULE: $label"
  104. fi
  105. if [ -n "$MODULE_MENU_LOC" ] ; then
  106. BUFF="$BUFF {$MODULE_MENU_LOC}"
  107. fi
  108. if [ -n "$BUFF" ] ; then
  109. #echo "$BUFF"
  110. echo "$BUFF" >> "$TMP"
  111. fi
  112. done
  113. cd ..
  114. done
  115. # ps.map doesn't jive with the above loop.
  116. for MODULE in ps.map ; do
  117. unset label
  118. unset desc
  119. eval `$MODULE --interface-description | head -n 5 | tail -n 1 | \
  120. tr '"' "'" | sed -e 's/^[ \t]./desc="/' -e 's/$/"/' -e 's/[^\."]"$/&./'`
  121. if [ -z "$label" ] && [ -z "$desc" ] ; then
  122. continue
  123. fi
  124. MODULE_MENU_LOC=`find_menu_hierarchy "$MODULE"`
  125. BUFF=""
  126. if [ -z "$label" ] ; then
  127. BUFF="$MODULE: $desc"
  128. else
  129. BUFF="$MODULE: $label"
  130. fi
  131. if [ -n "$MODULE_MENU_LOC" ] ; then
  132. BUFF="$BUFF {$MODULE_MENU_LOC}"
  133. fi
  134. if [ -n "$BUFF" ] ; then
  135. #echo "$BUFF"
  136. echo "$BUFF" >> "$TMP"
  137. fi
  138. done
  139. # these don't use the parser at all.
  140. cat << EOF >> "$TMP"
  141. g.parser: Full parser support for GRASS scripts.
  142. photo.2image: Marks fiducial or reseau points on an image to be ortho-rectified and then computes the image-to-photo coordinate transformation parameters.
  143. photo.2target: Create control points on an image to be ortho-rectified.
  144. photo.camera: Creates or modifies entries in a camera reference file.
  145. photo.elev: Selects target elevation model for ortho-rectification.
  146. photo.init: Creates or modifies entries in a camera initial exposure station file for imagery group referenced by a sub-block.
  147. 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.
  148. photo.target: Selects target location and mapset for ortho-rectification.
  149. EOF
  150. ## with --dictionary-order db.* ends up in the middle of the d.* cmds
  151. #sort --dictionary-order "$TMP" > "$SYNOP"
  152. sort "$TMP" > "$SYNOP"
  153. \rm -f "$TMP"
  154. cp "$SYNOP" "${TMP}.txt"
  155. ####### create HTML source #######
  156. # poor cousin to full_index.html from tools/build_html_index.sh
  157. # todo $MODULE.html links
  158. g.message "Generating HTML (writing to \$GISBASE/docs/html/) ..."
  159. #### write header
  160. cat << EOF > "${TMP}.html"
  161. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  162. <html>
  163. <head>
  164. <title>`g.version | cut -f1 -d'('` Command list</title>
  165. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  166. <link rel="stylesheet" href="grassdocs.css" type="text/css">
  167. </head>
  168. <body bgcolor="white">
  169. <img src="grass_logo.png" alt="_\|/_ GRASS logo">
  170. <hr class="header">
  171. <!-- prettier:
  172. <BR><BR><BR><BR>
  173. <center>
  174. <img src="../../images/grasslogo.gif" alt="_\|/_ GRASS logo">
  175. <BR><BR>
  176. <hr width="450" align=center size=6 noshade>
  177. -->
  178. <center>
  179. <H1>`g.version | cut -f1 -d'('` Command list</H1>
  180. <h3>`date "+%e %B %Y"`</h3>
  181. </center>
  182. <BR><BR><BR>
  183. <!--
  184. <i><font size="-1" color="#778877">
  185. Menu position follows description if applicable.</font></i>
  186. <BR><BR>
  187. -->
  188. <!--
  189. # so it works from $WEB/gdp/grassmanuals/
  190. # untested:
  191. sed -i -e 's+\(a href="\)\([^#\.h]\)+\1../../grass64/manuals/html64_user/\2+'
  192. -->
  193. <h4>Command types:</h4>
  194. <ul>
  195. <li> d.* - <a href="#d">display commands</a>
  196. <li> db.* - <a href="#db">database</a> commands
  197. <li> g.* - <a href="#g">general</a> commands
  198. <li> i.* - <a href="#i">imagery</a> commands
  199. <li> m.* - <a href="#m">miscellanous</a> commands
  200. <li> ps.* - <a href="#ps">PostScript</a> commands
  201. <li> r.* - <a href="#r">raster</a> commands
  202. <li> r3.* - <a href="#r3">raster3D</a> commands
  203. <li> v.* - <a href="#v">vector</a> commands
  204. <li> <a href="wxGUI.html">wxGUI</a> - GUI frontend (wxPython)
  205. <li> <a href="nviz.html">NVIZ</a> - <i>n</i>-dimensional visualization suite
  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 class="header">
  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. EOF
  318. #### fill in module entries
  319. for SECTION in d db g i m ps r r3 v ; do
  320. SEC_TYPE="commands"
  321. case $SECTION in
  322. d)
  323. SEC_NAME="Display" ;;
  324. db)
  325. SEC_NAME="Database management" ;;
  326. g)
  327. SEC_NAME="General GIS management" ;;
  328. i)
  329. SEC_NAME="Imagery" ;;
  330. m)
  331. SEC_NAME="Miscellaneous"
  332. SEC_TYPE="tools" ;;
  333. ps)
  334. SEC_NAME="PostScript" ;;
  335. r)
  336. SEC_NAME="Raster" ;;
  337. r3)
  338. SEC_NAME="Raster 3D" ;;
  339. v)
  340. SEC_NAME="Vector" ;;
  341. esac
  342. cat << EOF >> "${TMP}.tex"
  343. \end{lyxlist}
  344. \smallskip{}
  345. \section*{$SEC_NAME $SEC_TYPE:}
  346. \begin{lyxlist}{00.00.0000}
  347. EOF
  348. grep "^${SECTION}\." "${TMP}.txt" | \
  349. sed -e 's/^/\\item [/' -e 's/: /]/' \
  350. -e 's+ {+ \\\\\n$+' -e 's/}$/$/' \
  351. -e 's+ > +\\,\\triangleright\\,|+g' \
  352. -e 's/\*/{*}/g' -e 's/_/\\_/g' -e 's/&/\\\&/g' \
  353. | awk '/^\$/ { STR=$0; \
  354. gsub(" ", "\\: ", STR); \
  355. gsub(/\|/, " ", STR); \
  356. sub(/^/, " \\textcolor{DarkSeaGreen3}{\\footnotesize ", STR); \
  357. sub(/$/, "}", STR); \
  358. print STR \
  359. } ;
  360. /^\\/ {print}' >> "${TMP}.tex"
  361. if [ "$SECTION" = "i" ] ; then
  362. # include imagery photo subsection
  363. cat << EOF >> "${TMP}.tex"
  364. \end{lyxlist}
  365. \subsubsection*{Imagery photo.{*} commands:}
  366. \begin{lyxlist}{00.00.0000}
  367. EOF
  368. grep "^photo\." "${TMP}.txt" | \
  369. sed -e 's/^/\\item [/' -e 's/: /]/' >> "${TMP}.tex"
  370. fi
  371. done
  372. #### save footer
  373. cat << EOF >> "${TMP}.tex"
  374. \end{lyxlist}
  375. \end{document}
  376. EOF
  377. \mv "${TMP}.tex" "$GISBASE/etc/module_synopsis.tex"
  378. \rm -f "${TMP}.txt"
  379. ##### FIXME
  380. # post generation tidy-up
  381. # - sort order isn't ideal. try 'sort -n'??
  382. # fix: *.univar.sh, r.surf.idw2, v.to.rast3, r.out.ppm3, others..
  383. #####
  384. g.message "Converting LaTeX to PDF (writing to \$GISBASE/docs/pdf/) ..."
  385. for PGM in pdflatex ; do
  386. if [ ! -x `which $PGM` ] ; then
  387. g.message -e "pdflatex needed for this PDF conversion."
  388. g.message "Done."
  389. exit 1
  390. fi
  391. done
  392. TMPDIR="`dirname "$TMP"`"
  393. cp "$OLDDIR/../man/grasslogo_vector.pdf" "$TMPDIR"
  394. cd "$TMPDIR"
  395. #once working nicely make it quieter
  396. #pdflatex --interaction batchmode "$GISBASE/etc/module_synopsis.tex"
  397. pdflatex "$GISBASE/etc/module_synopsis.tex"
  398. \rm -f module_synopsis.dvi module_synopsis.ps \
  399. module_synopsis_2.ps grasslogo_vector.pdf
  400. if [ ! -d "$GISBASE/docs/pdf" ] ; then
  401. mkdir "$GISBASE/docs/pdf"
  402. fi
  403. \mv module_synopsis.pdf "$GISBASE/docs/pdf/"
  404. # Convert to pretty two-up version:
  405. # Open PDF in Acrobat, print-to-file as postscript, then run:
  406. # a2ps module_list.ps -o module_list_2up.ps
  407. # ps2pdf13 module_list_2up.ps
  408. g.message "Done."