[GRASS-SVN] r31867 - grass/trunk/scripts/g.mremove

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 27 23:58:11 EDT 2008


Author: hcho
Date: 2008-06-27 23:58:11 -0400 (Fri, 27 Jun 2008)
New Revision: 31867

Modified:
   grass/trunk/scripts/g.mremove/g.mremove
Log:
Simplified (thanks Ivan)

Modified: grass/trunk/scripts/g.mremove/g.mremove
===================================================================
--- grass/trunk/scripts/g.mremove/g.mremove	2008-06-27 23:01:20 UTC (rev 31866)
+++ grass/trunk/scripts/g.mremove/g.mremove	2008-06-28 03:58:11 UTC (rev 31867)
@@ -95,124 +95,59 @@
 fi
 
 if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
-fi   
-     
+    echo "You must be in GRASS GIS to run this program." >&2
+    exit 1
+fi
+
 eval `g.gisenv`
 : ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
 LOCATION=$GISDBASE/$LOCATION_NAME/$MAPSET
 
-program=`basename $0`
-
 g.message "Collecting map names for current mapset <$MAPSET>..."
 
 if [ $GIS_FLAG_R -eq 1 ] ; then
-   regex="-r"
+    regex="-r"
 else
-   regex=""
+    regex=""
 fi
 
 force=$GIS_FLAG_F
 
 if [ $force -eq 1 ] ; then
-   g.message "Forcing ..."
+    g.message "Forcing ..."
 fi
 
-r=$GIS_OPT_RAST
-r3=$GIS_OPT_RAST3D
-v=$GIS_OPT_VECT
-i=$GIS_OPT_ICON
-l=$GIS_OPT_LABEL
-rg=$GIS_OPT_REGION
-g=$GIS_OPT_GROUP
-d=$GIS_OPT_DVIEW
+found=""
 
-if [ -n "$r" ] ; then
-    rast=`g.mlist $regex type=rast sep=, mapset=$MAPSET pattern="$r"`
-fi
+search() {
+    if [ ! "$2" ]; then
+        return
+    fi
+    found="$found"`
+        g.mlist $regex sep=, mapset="$MAPSET" type="$1" pattern="$2" |
+        sed "s,^\(.\), $1=\1,"`
+}
 
-if [ -n "$r3" ] ; then
-    rast3d=`g.mlist $regex type=rast3d sep=, mapset=$MAPSET pattern="$r3"`
-fi
+search rast	"$GIS_OPT_RAST"
+search rast3d	"$GIS_OPT_RAST3D"
+search vect	"$GIS_OPT_VECT"
+search icon	"$GIS_OPT_ICON"
+search labels	"$GIS_OPT_LABEL"
+search region	"$GIS_OPT_REGION"
+search group	"$GIS_OPT_GROUP"
+search 3dview	"$GIS_OPT_DVIEW"
 
-if [ -n "$v" ] ; then
-    vect=`g.mlist $regex type=vect sep=, mapset=$MAPSET pattern="$v"`
-fi
-
-if [ -n "$i" ] ; then
-    icon=`g.mlist $regex type=icon sep=, mapset=$MAPSET pattern="$i"`
-fi
-
-if [ -n "$l" ] ; then
-    labels=`g.mlist $regex type=labels sep=, mapset=$MAPSET pattern="$l"`
-fi
-
-if [ -n "$rg" ] ; then
-    region=`g.mlist $regex type=region sep=, mapset=$MAPSET pattern="$rg"`
-fi
-
-if [ -n "$g" ] ; then
-    group=`g.mlist $regex type=group sep=, mapset=$MAPSET pattern="$g"`
-fi
-
-if [ -n "$d" ] ; then
-    dview=`g.mlist $regex type=3dview sep=, mapset=$MAPSET pattern="$d"`
-fi
-
-found=
-if [ "$rast" ] ; then
-	found=1
-	rast="rast=$rast"
-fi
-
-if [ "$rast3d" ] ; then
-	found=1
-	rast3d="rast3d=$rast3d"
-fi
-
-if [ "$vect" ] ; then
-	found=1
-	vect="vect=$vect"
-fi
-
-if [ "$icon" ] ; then
-	found=1
-	icon="icon=$icon"
-fi
-
-if [ "$labels" ] ; then
-	found=1
-	labels="labels=$labels"
-fi
-
-if [ "$region" ] ; then
-	found=1
-	region="region=$region"
-fi
-
-if [ "$group" ] ; then
-	found=1
-	group="group=$group"
-fi
-
-if [ "$dview" ] ; then
-	found=1
-	dview="3dview=$dview"
-fi
-
 if [ ! "$found" ] ; then
-	g.message -e "No data found."
-	exit 1
+    g.message -e "No data found."
+    exit 1
 fi
 
 if [ $force -eq 0 ] ; then
     g.message "The following files would be deleted:"
-    echo "g.remove $rast $rast3d $vect $icon $labels $region $group $dview"
+    echo "g.remove $found"
     g.message message=""
     g.message "You must use the force flag to actually remove them. Exiting."
     exit 0
 fi
 
-
-exec g.remove $rast $rast3d $vect $icon $labels $region $group $dview
+exec g.remove $found



More information about the grass-commit mailing list