|
@@ -1,7 +1,7 @@
|
|
|
|
|
|
/****************************************************************************
|
|
/****************************************************************************
|
|
*
|
|
*
|
|
- * MODULE: g.mremove
|
|
|
|
|
|
+ * MODULE: g.remove
|
|
*
|
|
*
|
|
* AUTHOR(S): Huidae Cho <grass4u gmail.com>
|
|
* AUTHOR(S): Huidae Cho <grass4u gmail.com>
|
|
*
|
|
*
|
|
@@ -9,13 +9,12 @@
|
|
* CERL (original contributor),
|
|
* CERL (original contributor),
|
|
* Radim Blazek <radim.blazek gmail.com>,
|
|
* Radim Blazek <radim.blazek gmail.com>,
|
|
* Cedric Shock <cedricgrass shockfamily.net>,
|
|
* Cedric Shock <cedricgrass shockfamily.net>,
|
|
- * Huidae Cho <grass4u gmail.com>,
|
|
|
|
* Glynn Clements <glynn gclements.plus.com>,
|
|
* Glynn Clements <glynn gclements.plus.com>,
|
|
* Jachym Cepicky <jachym les-ejk.cz>,
|
|
* Jachym Cepicky <jachym les-ejk.cz>,
|
|
* Markus Neteler <neteler itc.it>,
|
|
* Markus Neteler <neteler itc.it>,
|
|
* Martin Landa <landa.martin gmail.com>
|
|
* Martin Landa <landa.martin gmail.com>
|
|
*
|
|
*
|
|
- * PURPOSE: lets users remove GRASS database files
|
|
|
|
|
|
+ * PURPOSE: Lets users remove GRASS database files
|
|
*
|
|
*
|
|
* COPYRIGHT: (C) 1999-2014 by the GRASS Development Team
|
|
* COPYRIGHT: (C) 1999-2014 by the GRASS Development Team
|
|
*
|
|
*
|
|
@@ -32,6 +31,8 @@
|
|
#include <grass/manage.h>
|
|
#include <grass/manage.h>
|
|
#include <grass/glocale.h>
|
|
#include <grass/glocale.h>
|
|
|
|
|
|
|
|
+/* construct_pattern.c */
|
|
|
|
+char *construct_pattern(char **);
|
|
/* check_reclass.c */
|
|
/* check_reclass.c */
|
|
int check_reclass(const char *, const char *, int);
|
|
int check_reclass(const char *, const char *, int);
|
|
|
|
|
|
@@ -43,6 +44,8 @@ int main(int argc, char *argv[])
|
|
struct Option *type;
|
|
struct Option *type;
|
|
struct Option *pattern;
|
|
struct Option *pattern;
|
|
struct Option *exclude;
|
|
struct Option *exclude;
|
|
|
|
+ struct Option *names;
|
|
|
|
+ struct Option *ignore;
|
|
} opt;
|
|
} opt;
|
|
struct
|
|
struct
|
|
{
|
|
{
|
|
@@ -51,15 +54,16 @@ int main(int argc, char *argv[])
|
|
struct Flag *force;
|
|
struct Flag *force;
|
|
struct Flag *basemap;
|
|
struct Flag *basemap;
|
|
} flag;
|
|
} flag;
|
|
|
|
+ char *pattern, *exclude;
|
|
const char *mapset;
|
|
const char *mapset;
|
|
int result;
|
|
int result;
|
|
int i, all, num_types, nlist;
|
|
int i, all, num_types, nlist;
|
|
- void *filter, *exclude;
|
|
|
|
|
|
+ void *filter, *exclude_filter;
|
|
|
|
|
|
G_gisinit(argv[0]);
|
|
G_gisinit(argv[0]);
|
|
|
|
|
|
result = EXIT_SUCCESS;
|
|
result = EXIT_SUCCESS;
|
|
-
|
|
|
|
|
|
+
|
|
module = G_define_module();
|
|
module = G_define_module();
|
|
G_add_keyword(_("general"));
|
|
G_add_keyword(_("general"));
|
|
G_add_keyword(_("map management"));
|
|
G_add_keyword(_("map management"));
|
|
@@ -74,30 +78,48 @@ int main(int argc, char *argv[])
|
|
opt.type->multiple = YES;
|
|
opt.type->multiple = YES;
|
|
opt.type->options = M_get_options(TRUE);
|
|
opt.type->options = M_get_options(TRUE);
|
|
opt.type->descriptions = M_get_option_desc(TRUE);
|
|
opt.type->descriptions = M_get_option_desc(TRUE);
|
|
|
|
+ opt.type->guidependency = "pattern,exclude,names,ignore";
|
|
|
|
+
|
|
|
|
+ opt.names = G_define_option();
|
|
|
|
+ opt.names->key = "names";
|
|
|
|
+ opt.names->type = TYPE_STRING;
|
|
|
|
+ opt.names->multiple = YES;
|
|
|
|
+ opt.names->gisprompt = "old,element,element";
|
|
|
|
+ opt.names->description = _("File names separated by a comma");
|
|
|
|
+ opt.names->guisection = _("Names");
|
|
|
|
+
|
|
|
|
+ opt.ignore = G_define_option();
|
|
|
|
+ opt.ignore->key = "ignore";
|
|
|
|
+ opt.ignore->type = TYPE_STRING;
|
|
|
|
+ opt.ignore->multiple = YES;
|
|
|
|
+ opt.ignore->gisprompt = "old,element,element";
|
|
|
|
+ opt.ignore->description =
|
|
|
|
+ _("File names to ignore separated by a comma (default: none)");
|
|
|
|
+ opt.ignore->guisection = _("Names");
|
|
|
|
|
|
opt.pattern = G_define_option();
|
|
opt.pattern = G_define_option();
|
|
opt.pattern->key = "pattern";
|
|
opt.pattern->key = "pattern";
|
|
opt.pattern->type = TYPE_STRING;
|
|
opt.pattern->type = TYPE_STRING;
|
|
- opt.pattern->required = YES;
|
|
|
|
- opt.pattern->description = _("Map name search pattern");
|
|
|
|
|
|
+ opt.pattern->description = _("File name search pattern");
|
|
opt.pattern->guisection = _("Pattern");
|
|
opt.pattern->guisection = _("Pattern");
|
|
|
|
|
|
opt.exclude = G_define_option();
|
|
opt.exclude = G_define_option();
|
|
opt.exclude->key = "exclude";
|
|
opt.exclude->key = "exclude";
|
|
opt.exclude->type = TYPE_STRING;
|
|
opt.exclude->type = TYPE_STRING;
|
|
- opt.exclude->required = NO;
|
|
|
|
- opt.exclude->description = _("Map name exclusion pattern (default: none)");
|
|
|
|
|
|
+ opt.exclude->description = _("File name exclusion pattern (default: none)");
|
|
opt.exclude->guisection = _("Pattern");
|
|
opt.exclude->guisection = _("Pattern");
|
|
|
|
|
|
flag.regex = G_define_flag();
|
|
flag.regex = G_define_flag();
|
|
flag.regex->key = 'r';
|
|
flag.regex->key = 'r';
|
|
flag.regex->description =
|
|
flag.regex->description =
|
|
_("Use basic regular expressions instead of wildcards");
|
|
_("Use basic regular expressions instead of wildcards");
|
|
|
|
+ flag.regex->guisection = _("Pattern");
|
|
|
|
|
|
flag.extended = G_define_flag();
|
|
flag.extended = G_define_flag();
|
|
flag.extended->key = 'e';
|
|
flag.extended->key = 'e';
|
|
flag.extended->description =
|
|
flag.extended->description =
|
|
_("Use extended regular expressions instead of wildcards");
|
|
_("Use extended regular expressions instead of wildcards");
|
|
|
|
+ flag.extended->guisection = _("Pattern");
|
|
|
|
|
|
flag.force = G_define_flag();
|
|
flag.force = G_define_flag();
|
|
flag.force->key = 'f';
|
|
flag.force->key = 'f';
|
|
@@ -107,57 +129,68 @@ int main(int argc, char *argv[])
|
|
flag.basemap = G_define_flag();
|
|
flag.basemap = G_define_flag();
|
|
flag.basemap->key = 'b';
|
|
flag.basemap->key = 'b';
|
|
flag.basemap->description = _("Remove base raster maps");
|
|
flag.basemap->description = _("Remove base raster maps");
|
|
- flag.basemap->guisection = _("Raster");
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ G_option_exclusive(flag.regex, flag.extended, NULL);
|
|
|
|
+ G_option_exclusive(opt.pattern, opt.names, NULL);
|
|
|
|
+ G_option_exclusive(opt.exclude, opt.ignore, NULL);
|
|
|
|
+ G_option_required(opt.pattern, opt.names, NULL);
|
|
|
|
+
|
|
if (G_parser(argc, argv))
|
|
if (G_parser(argc, argv))
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
- if (flag.regex->answer && flag.extended->answer)
|
|
|
|
- G_fatal_error(_("-%c and -%c are mutually exclusive"),
|
|
|
|
- flag.regex->key, flag.extended->key);
|
|
|
|
|
|
+ if (opt.pattern->answer)
|
|
|
|
+ pattern = opt.pattern->answer;
|
|
|
|
+ else
|
|
|
|
+ pattern = construct_pattern(opt.names->answers);
|
|
|
|
+
|
|
|
|
+ if (opt.exclude->answer)
|
|
|
|
+ exclude = opt.exclude->answer;
|
|
|
|
+ else if (opt.ignore->answer)
|
|
|
|
+ exclude = construct_pattern(opt.ignore->answers);
|
|
|
|
+ else
|
|
|
|
+ exclude = NULL;
|
|
|
|
|
|
- if (flag.regex->answer || flag.extended->answer)
|
|
|
|
- filter = G_ls_regex_filter(opt.pattern->answer, 0,
|
|
|
|
- (int)flag.extended->answer);
|
|
|
|
|
|
+ if ((flag.regex->answer || flag.extended->answer) && opt.pattern->answer)
|
|
|
|
+ filter = G_ls_regex_filter(pattern, 0, (int)flag.extended->answer);
|
|
else {
|
|
else {
|
|
/* handle individual map names */
|
|
/* handle individual map names */
|
|
- if (strchr(opt.pattern->answer, ',')) {
|
|
|
|
- char *pattern;
|
|
|
|
|
|
+ if (strchr(pattern, ',')) {
|
|
|
|
+ char *buf;
|
|
|
|
|
|
- pattern = (char *)G_malloc(strlen(opt.pattern->answer) + 3);
|
|
|
|
- sprintf(pattern, "{%s}", opt.pattern->answer);
|
|
|
|
|
|
+ buf = (char *)G_malloc(strlen(pattern) + 3);
|
|
|
|
+ sprintf(buf, "{%s}", pattern);
|
|
|
|
|
|
- filter = G_ls_glob_filter(pattern, 0);
|
|
|
|
|
|
+ filter = G_ls_glob_filter(buf, 0);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- filter = G_ls_glob_filter(opt.pattern->answer, 0);
|
|
|
|
|
|
+ filter = G_ls_glob_filter(pattern, 0);
|
|
}
|
|
}
|
|
if (!filter)
|
|
if (!filter)
|
|
- G_fatal_error(_("Unable to compile pattern <%s>"), opt.pattern->answer);
|
|
|
|
|
|
+ G_fatal_error(_("Unable to compile pattern <%s>"), pattern);
|
|
|
|
|
|
- if (opt.exclude->answer) {
|
|
|
|
- if (flag.regex->answer || flag.extended->answer)
|
|
|
|
- exclude = G_ls_regex_filter(opt.exclude->answer, 1,
|
|
|
|
- (int)flag.extended->answer);
|
|
|
|
|
|
+ if (exclude) {
|
|
|
|
+ if ((flag.regex->answer || flag.extended->answer) &&
|
|
|
|
+ opt.exclude->answer)
|
|
|
|
+ exclude_filter = G_ls_regex_filter(exclude, 1,
|
|
|
|
+ (int)flag.extended->answer);
|
|
else {
|
|
else {
|
|
/* handle individual map names */
|
|
/* handle individual map names */
|
|
- if (strchr(opt.exclude->answer, ',')) {
|
|
|
|
- char *pattern;
|
|
|
|
|
|
+ if (strchr(exclude, ',')) {
|
|
|
|
+ char *buf;
|
|
|
|
|
|
- pattern = (char *)G_malloc(strlen(opt.exclude->answer) + 3);
|
|
|
|
- sprintf(pattern, "{%s}", opt.exclude->answer);
|
|
|
|
|
|
+ buf = (char *)G_malloc(strlen(exclude) + 3);
|
|
|
|
+ sprintf(buf, "{%s}", exclude);
|
|
|
|
|
|
- exclude = G_ls_glob_filter(pattern, 1);
|
|
|
|
|
|
+ exclude_filter = G_ls_glob_filter(buf, 1);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- exclude = G_ls_glob_filter(opt.exclude->answer, 1);
|
|
|
|
|
|
+ exclude_filter = G_ls_glob_filter(exclude, 1);
|
|
}
|
|
}
|
|
- if (!exclude)
|
|
|
|
- G_fatal_error(_("Unable to compile pattern <%s>"),
|
|
|
|
- opt.exclude->answer);
|
|
|
|
|
|
+ if (!exclude_filter)
|
|
|
|
+ G_fatal_error(_("Unable to compile pattern <%s>"), exclude);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- exclude = NULL;
|
|
|
|
|
|
+ exclude_filter = NULL;
|
|
|
|
|
|
if (!flag.force->answer)
|
|
if (!flag.force->answer)
|
|
G_message(_("The following data base element files would be deleted:"));
|
|
G_message(_("The following data base element files would be deleted:"));
|
|
@@ -192,16 +225,16 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
rast = !G_strcasecmp(elem->alias, "rast");
|
|
rast = !G_strcasecmp(elem->alias, "rast");
|
|
files = G__ls(path, &num_files);
|
|
files = G__ls(path, &num_files);
|
|
-
|
|
|
|
|
|
+
|
|
for (j = 0; j < num_files; j++) {
|
|
for (j = 0; j < num_files; j++) {
|
|
if (!flag.force->answer) {
|
|
if (!flag.force->answer) {
|
|
fprintf(stdout, "%s/%s@%s\n", elem->alias, files[j], mapset);
|
|
fprintf(stdout, "%s/%s@%s\n", elem->alias, files[j], mapset);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (rast && check_reclass(files[j], mapset, flag.basemap->answer))
|
|
if (rast && check_reclass(files[j], mapset, flag.basemap->answer))
|
|
continue;
|
|
continue;
|
|
-
|
|
|
|
|
|
+
|
|
if (M_do_remove(n, (char *)files[j]) == 1)
|
|
if (M_do_remove(n, (char *)files[j]) == 1)
|
|
result = EXIT_FAILURE;
|
|
result = EXIT_FAILURE;
|
|
}
|
|
}
|
|
@@ -209,8 +242,8 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
G_free_ls_filter(filter);
|
|
G_free_ls_filter(filter);
|
|
|
|
|
|
- if (exclude)
|
|
|
|
- G_free_ls_filter(exclude);
|
|
|
|
|
|
+ if (exclude_filter)
|
|
|
|
+ G_free_ls_filter(exclude_filter);
|
|
|
|
|
|
if (!flag.force->answer)
|
|
if (!flag.force->answer)
|
|
G_important_message(_("You must use the force flag (-%c) to actually "
|
|
G_important_message(_("You must use the force flag (-%c) to actually "
|