#!/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"
xganim - raster map slideshow viewer
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"