[GRASS-SVN] r33305 - in grass/trunk/general: g.mlist g.mremove

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Sep 6 13:31:46 EDT 2008


Author: glynn
Date: 2008-09-06 13:31:46 -0400 (Sat, 06 Sep 2008)
New Revision: 33305

Modified:
   grass/trunk/general/g.mlist/main.c
   grass/trunk/general/g.mremove/main.c
Log:
Use basic REs by default; add -e for extended REs


Modified: grass/trunk/general/g.mlist/main.c
===================================================================
--- grass/trunk/general/g.mlist/main.c	2008-09-06 17:23:43 UTC (rev 33304)
+++ grass/trunk/general/g.mlist/main.c	2008-09-06 17:31:46 UTC (rev 33305)
@@ -48,6 +48,7 @@
     struct
     {
 	struct Flag *regex;
+	struct Flag *extended;
 	struct Flag *type;
 	struct Flag *mapset;
 	struct Flag *pretty;
@@ -115,6 +116,11 @@
     flag.regex = G_define_flag();
     flag.regex->key = 'r';
     flag.regex->description =
+	_("Use basic regular expressions instead of wildcards");
+
+    flag.extended = G_define_flag();
+    flag.extended->key = 'e';
+    flag.extended->description =
 	_("Use extended regular expressions instead of wildcards");
 
     flag.type = G_define_flag();
@@ -138,12 +144,15 @@
 
     G_free(buf);
 
-    if (flag.regex->answer)
+    if (flag.regex->answer && flag.extended->answer)
+	G_fatal_error(_("-r and -e are mutually exclusive"));
+
+    if (flag.regex->answer || flag.extended->answer)
 	pattern = opt.pattern->answer;
     else
 	pattern = wc2regex(opt.pattern->answer);
 
-    if (regcomp(&regex, pattern, REG_EXTENDED | REG_NOSUB))
+    if (regcomp(&regex, pattern, (flag.regex->answer ? 0 : REG_EXTENDED) | REG_NOSUB))
 	G_fatal_error(_("Unable to compile regular expression %s"), pattern);
     G_set_ls_filter(ls_filter, &regex);
 

Modified: grass/trunk/general/g.mremove/main.c
===================================================================
--- grass/trunk/general/g.mremove/main.c	2008-09-06 17:23:43 UTC (rev 33304)
+++ grass/trunk/general/g.mremove/main.c	2008-09-06 17:31:46 UTC (rev 33305)
@@ -42,6 +42,7 @@
     struct
     {
 	struct Flag *regex;
+	struct Flag *extended;
 	struct Flag *force;
 	struct Flag *basemap;
     } flag;
@@ -62,6 +63,11 @@
     flag.regex = G_define_flag();
     flag.regex->key = 'r';
     flag.regex->description =
+	_("Use basic regular expressions instead of wildcards");
+
+    flag.extended = G_define_flag();
+    flag.extended->key = 'e';
+    flag.extended->description =
 	_("Use extended regular expressions instead of wildcards");
 
     flag.force = G_define_flag();
@@ -94,6 +100,9 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+    if (flag.regex->answer && flag.extended->answer)
+	G_fatal_error(_("-r and -e are mutually exclusive"));
+
     for (n = 0; n < nlist; n++) {
 	o = opt[n];
 	G_free((char *)o->gisprompt);
@@ -110,13 +119,14 @@
 		continue;
 	    rast = !G_strcasecmp(list[n].alias, "rast");
 	    for (i = 0; (name = opt[n]->answers[i]); i++) {
-		if (!flag.regex->answer)
+		if (!flag.regex->answer && !flag.extended->answer)
 		    name = wc2regex(name);
-		if (regcomp(&regex, name, REG_EXTENDED | REG_NOSUB))
+		if (regcomp(&regex, name,
+			    (flag.regex->answer ? 0 : REG_EXTENDED) | REG_NOSUB))
 		    G_fatal_error(_
 				  ("Unable to compile regular expression %s"),
 				  name);
-		if (!flag.regex->answer)
+		if (!flag.regex->answer && !flag.extended->answer)
 		    G_free(name);
 
 		G_set_ls_filter(ls_filter, &regex);



More information about the grass-commit mailing list