[GRASS-SVN] r34431 - grass/branches/develbranch_6/general/g.mlist
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Nov 21 15:38:25 EST 2008
Author: neteler
Date: 2008-11-21 15:38:25 -0500 (Fri, 21 Nov 2008)
New Revision: 34431
Modified:
grass/branches/develbranch_6/general/g.mlist/main.c
Log:
glynn: Add exclude= option (modified merge from trunk, #34406)
Modified: grass/branches/develbranch_6/general/g.mlist/main.c
===================================================================
--- grass/branches/develbranch_6/general/g.mlist/main.c 2008-11-21 16:07:50 UTC (rev 34430)
+++ grass/branches/develbranch_6/general/g.mlist/main.c 2008-11-21 20:38:25 UTC (rev 34431)
@@ -29,9 +29,9 @@
static int any;
-static void do_list(const struct list *,
- const char *, const char *, const char *,
- int, int, int);
+static void make_list(const struct list *,
+ const char *, const char *,
+ int, int, int);
static int parse(const char *);
static int ls_filter(const char *, void *);
@@ -42,6 +42,7 @@
{
struct Option *type;
struct Option *pattern;
+ struct Option *exclude;
struct Option *separator;
struct Option *mapset;
} opt;
@@ -55,8 +56,8 @@
struct Flag *full;
} flag;
int i, n, all, num_types;
- char *pattern = NULL, separator[2], *buf;
- regex_t regex;
+ char *pattern = NULL, *exclude = NULL, separator[2], *buf;
+ regex_t regex, regex_ex;
G_gisinit(argv[0]);
@@ -93,9 +94,15 @@
opt.pattern->type = TYPE_STRING;
opt.pattern->required = NO;
opt.pattern->multiple = NO;
- opt.pattern->answer = "*";
opt.pattern->description = _("Map name search pattern (default: all)");
+ opt.exclude = G_define_option();
+ opt.exclude->key = "exclude";
+ opt.exclude->type = TYPE_STRING;
+ opt.exclude->required = NO;
+ opt.exclude->multiple = NO;
+ opt.exclude->description = _("Map name exclusion pattern (default: none)");
+
opt.separator = G_define_option();
opt.separator->key = "separator";
opt.separator->type = TYPE_STRING;
@@ -147,15 +154,28 @@
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 (opt.pattern->answer) {
+ if (flag.regex->answer || flag.extended->answer)
+ pattern = G_store(opt.pattern->answer);
+ else
+ pattern = wc2regex(opt.pattern->answer);
- if (regcomp(®ex, 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, ®ex);
+ if (regcomp(®ex, 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, ®ex);
+ }
+ if (opt.exclude->answer) {
+ if (flag.regex->answer || flag.extended->answer)
+ exclude = G_store(opt.exclude->answer);
+ else
+ exclude = wc2regex(opt.exclude->answer);
+
+ if (regcomp(®ex_ex, exclude, (flag.regex->answer ? 0 : REG_EXTENDED) | REG_NOSUB))
+ G_fatal_error(_("Unable to compile regular expression %s"), exclude);
+ G_set_ls_exclude_filter(ls_filter, ®ex_ex);
+ }
+
if (strcmp(opt.separator->answer, "newline") == 0)
separator[0] = '\n';
else if (strcmp(opt.separator->answer, "comma") == 0)
@@ -204,25 +224,30 @@
}
}
else
- do_list(&list[n], pattern, opt.mapset->answer, separator,
- flag.pretty->answer, flag.type->answer,
- flag.mapset->answer);
+ make_list(&list[n], opt.mapset->answer, separator,
+ flag.pretty->answer, flag.type->answer,
+ flag.mapset->answer);
}
if (!flag.pretty->answer && any)
fprintf(stdout, "\n");
- if (!flag.regex->answer)
+ if (pattern) {
G_free(pattern);
+ regfree(®ex);
+ }
- regfree(®ex);
+ if (exclude) {
+ G_free(exclude);
+ regfree(®ex_ex);
+ }
exit(EXIT_SUCCESS);
}
-static void do_list(
+static void make_list(
const struct list *elem,
- const char *pattern, const char *mapset, const char *separator,
+ const char *mapset, const char *separator,
int pretty, int add_type, int add_mapset)
{
char path[GPATH_MAX];
@@ -240,8 +265,8 @@
if (!mapset || !*mapset) {
int n;
for (n = 0; mapset = G__mapset_name(n), mapset; n++)
- do_list(elem, pattern, mapset, separator,
- pretty, add_type, add_mapset);
+ make_list(elem, mapset, separator,
+ pretty, add_type, add_mapset);
return;
}
More information about the grass-commit
mailing list