[GRASS-SVN] r31868 - in grass/trunk/scripts: g.mlist g.mremove

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 28 04:23:07 EDT 2008


Author: hcho
Date: 2008-06-28 04:23:07 -0400 (Sat, 28 Jun 2008)
New Revision: 31868

Removed:
   grass/trunk/scripts/g.mlist/README
Modified:
   grass/trunk/scripts/g.mlist/description.html
   grass/trunk/scripts/g.mlist/g.mlist
   grass/trunk/scripts/g.mremove/description.html
   grass/trunk/scripts/g.mremove/g.mremove
Log:
- Removed an obsolete file.
- Fixed the bug that swallows *mapset* file names.
- Fixed "wildcards1|wildcards2".
- g.mlist now uses sed instead of grep (10~30 times faster!).
- POSIX Basic Regular Expressions should continue to work because previous
  versions of g.mlist also supported only basic regular expressions (not grep
  -E).


Deleted: grass/trunk/scripts/g.mlist/README
===================================================================
--- grass/trunk/scripts/g.mlist/README	2008-06-28 03:58:11 UTC (rev 31867)
+++ grass/trunk/scripts/g.mlist/README	2008-06-28 08:23:07 UTC (rev 31868)
@@ -1,34 +0,0 @@
-g.mlist prints out only mapnames with separator, if any, without garbage 
-outputs. In addition, map search is also available.
-
-	g.mlist [type=datatype] [map=mapname] [mapset=mapsetname]
-		[sep=separator]
-
-
-examples)
-wildcards:
-	g.mlist type=vect "r*"
-		lists all vector maps starting with letter "r"
-
-regular expressions:
-	g.mlist -r type=rast '^soils'
-		prints out all soils map with "soils" in their name
-
-	g.mlist -r map='^tmp$'
-		prints out "tmp" if "tmp" raster map exists.
-
-	g.mlist -r map='^tmp[0-9]$' type=vect
-
-		tmp0
-		tmp5
-		tmp6
-
-		prints out "tmp0" ~ "tmp9" if corresponding vector map exists.
-
-	g.mlist -r map='^tmp[0-9]$' type=vect sep=,
-
-		tmp0,tmp5,tmp6
-
-		with separator ','.
-		This may be useful for other programs' parameter input.
-

Modified: grass/trunk/scripts/g.mlist/description.html
===================================================================
--- grass/trunk/scripts/g.mlist/description.html	2008-06-28 03:58:11 UTC (rev 31867)
+++ grass/trunk/scripts/g.mlist/description.html	2008-06-28 08:23:07 UTC (rev 31868)
@@ -1,8 +1,8 @@
 <H2>DESCRIPTION</H2>
 
 <EM>g.mlist</EM> is an extended version of 
-<EM><a href="g.list.html">g.list</a></EM> which
-provides regular-expression and wildcard support.
+<EM><A HREF="g.list.html">g.list</A></EM> which
+provides support for POSIX Basic Regular Expressions and wildcards.
 <EM>g.mlist</EM> will only print map names and an optional separator,
 without extraneous output. In addition, map search is also available.
 
@@ -47,7 +47,7 @@
 <TT>g.mlist -r type=vect sep=, pattern='^tmp[0-9]$'</TT>
 <P>
 This may be useful for other programs' parameter input 
-(e.g. <EM><a href="r.series.html">r.series</a></EM>).
+(e.g. <EM><A HREF="r.series.html">r.series</A></EM>).
 
 <H2>SEE ALSO</H2>
 
@@ -57,4 +57,4 @@
 
 <H2>AUTHOR</H2>
 Huidae Cho
-<p><i>Last changed: $Date$</i>
+<P><I>Last changed: $Date$</I>

Modified: grass/trunk/scripts/g.mlist/g.mlist
===================================================================
--- grass/trunk/scripts/g.mlist/g.mlist	2008-06-28 03:58:11 UTC (rev 31867)
+++ grass/trunk/scripts/g.mlist/g.mlist	2008-06-28 08:23:07 UTC (rev 31868)
@@ -4,7 +4,7 @@
 #
 # MODULE:	g.mlist
 # AUTHOR(S):	Huidae Cho - grass4u at gmail.com
-# PURPOSE:	applied regular expression and wildcard to g.list
+# PURPOSE:	Lists data files using basic regular expressions and wildcards
 # COPYRIGHT:	(C) 2000 by the GRASS Development Team
 #
 #		This program is free software under the GNU General Public
@@ -14,16 +14,16 @@
 #############################################################################
 
 #%Module
-#%  description: Apply regular expressions and wildcards to g.list
-#%  keywords: general, map management 
+#%  description: Lists data files using basic regular expressions and wildcards.
+#%  keywords: general, map management
 #%End
 #%flag
 #%  key: r
-#%  description: Use regular expression instead of wildcard
+#%  description: Use basic regular expressions instead of wildcards
 #%end
 #%flag
 #%  key: m
-#%  description: Print mapset name
+#%  description: Print mapset names
 #%end
 #%option
 #% key: type
@@ -66,19 +66,20 @@
 	MAPSET=""
     fi
 
-    LC_ALL=C g.list type="$type" mapset="$mapset" \
-	| grep -vE '^-+$|files available' \
-	| grep -vi "mapset" \
-	| sed 's/  */\
-/g' \
-	| grep . \
-	| grep -- "$search" \
-	| sort \
-	| sed -e "s/$/$MAPSET/"
+    LC_ALL=C g.list type="$type" mapset="$mapset" |
+    sed '
+	/^--*$/d;
+	/files available/d;
+	/^$/d;
+	s/  */\
+/g;' |
+    sed "
+	/$search/!d;
+	s/$/$MAPSET/;"
 }
 
 
-if test "$GISBASE" = ""; then
+if [ "$GISBASE" = "" ] ; then
     echo "You must be in GRASS GIS to run this program." >&2
     exit 1
 fi
@@ -96,47 +97,35 @@
 sep="$GIS_OPT_SEP"
 search="$GIS_OPT_PATTERN"
 
-#list all datatypes
-types=`echo $type | sed 's/,/ /g'`
-for itype in $types
-do
-  if [ "$itype" = "all" ] ; then
-      type="rast,rast3d,oldvect,vect,asciivect,icon,labels,sites,region,region3d,group,3dview"
-  fi
-done 
-
-if [ -z "$sep" ] ; then
-#    echo using "\n" as separator
-    sep=""
+# list all datatypes
+if echo $type | grep -qE '(^|,)all(,|$)'; then
+    type="rast,rast3d,oldvect,vect,asciivect,icon,labels,sites,region,region3d,group,3dview"
 fi
 
-
 if [ $GIS_FLAG_R -ne 1 ] ; then
-#    echo wildcard
-    search="^`echo \"$search\" | sed 's/\./\\\\./g; s/?/./g; s/*/.*/g; s/|/$|^/g'`$"
-#else
-#    echo regex, as is
+    # wildcard
+    search="^`echo \"$search\" | sed 's/\./\\\\./g; s/?/./g; s/*/.*/g; s/|/$\\\\|^/g'`$"
 fi
+#echo $search
 
 start=""
 if [ -z "$mapset" ] ; then
-#    echo using current mapset
+    # using current mapset
     mapsets=`g.mapsets -p`
 else
-    mapsets=`echo $mapset | sed 's/,/ /g'`
+    mapsets=`echo $mapset | tr , ' '`
 fi
 
 for mapset in $mapsets
 do
     do_list
-done | (
-	    if [ "$sep" != "" ] ; then
-		tr '\n' "$sep" | sed 's/.$//'
-		echo ""
-	    else
-		cat
-	    fi
-	)
+done | sort | (
+    if [ "$sep" != "" ] ; then
+	tr '\n' "$sep" | sed 's/.$/\
+/'
+    else
+	cat
+    fi
+)
 
 exit 0
-

Modified: grass/trunk/scripts/g.mremove/description.html
===================================================================
--- grass/trunk/scripts/g.mremove/description.html	2008-06-28 03:58:11 UTC (rev 31867)
+++ grass/trunk/scripts/g.mremove/description.html	2008-06-28 08:23:07 UTC (rev 31868)
@@ -1,6 +1,8 @@
 <h2>DESCRIPTION</h2>
 
-<em>g.mremove</em> applies regular expressions and wildcards to <em>g.remove</em>.
+<em>g.mremove</em> is an extended version of
+<em><a href="g.remove.html">g.remove</a></em> which
+provides support for POSIX Basic Regular Expressions and wildcards.
 If the <b>-f</b> force flag is not given then nothing is removed, instead
 a functional <em>g.remove</em> command string is printed to <tt>stdout</tt>
 as a preview of the action to be taken.
@@ -15,12 +17,13 @@
 
 <h2>SEE ALSO</h2>
 
-<em><a HREF="g.remove.html">g.remove</a></em><br>
+<em><a HREF="g.remove.html">g.remove</a></em>
+<p>
+<a href="http://en.wikipedia.org/wiki/Regular_expression">Regular expression</a> (from Wikipedia, the free encyclopedia)
 
 <h2>AUTHOR</h2>
 
-Huidae Cho <br>
+Huidae Cho<br>
 grass4u at gmail.com
 
-<p>
-<i>Last changed: $Date$</i>
+<p><i>Last changed: $Date$</i>

Modified: grass/trunk/scripts/g.mremove/g.mremove
===================================================================
--- grass/trunk/scripts/g.mremove/g.mremove	2008-06-28 03:58:11 UTC (rev 31867)
+++ grass/trunk/scripts/g.mremove/g.mremove	2008-06-28 08:23:07 UTC (rev 31868)
@@ -6,7 +6,7 @@
 #
 # MODULE:	g.mremove
 # AUTHOR(S):	Huidae Cho - grass4u at gmail.com
-# PURPOSE:	applied wildcard to g.remove
+# PURPOSE:	Removes data files using basic regular expressions and wildcards
 # COPYRIGHT:	(C) 2000 by the GRASS Development Team
 #
 #		This program is free software under the GNU General Public
@@ -17,13 +17,13 @@
 
 
 #%Module
-#%  description: Apply regular expressions and wildcards to g.remove
+#%  description: Removes data files using basic regular expressions and wildcards.
 #%  keywords: general, map management
 #%End
 
 #%flag
 #%  key: r
-#%  description: Use regular expression instead of wildcard
+#%  description: Use basic regular expressions instead of wildcards
 #%end
 
 #%flag
@@ -121,11 +121,11 @@
 
 search() {
     if [ ! "$2" ]; then
-        return
+	return
     fi
     found="$found"`
-        g.mlist $regex sep=, mapset="$MAPSET" type="$1" pattern="$2" |
-        sed "s,^\(.\), $1=\1,"`
+	g.mlist $regex sep=, mapset="$MAPSET" type="$1" pattern="$2" |
+	sed "s,^\(.\), $1=\1,"`
 }
 
 search rast	"$GIS_OPT_RAST"



More information about the grass-commit mailing list