[GRASS-dev] g.mlist list multiple types from all mapsets
Huidae Cho
grass4u at gmail.com
Sun Jun 8 06:05:43 PDT 2014
For our records, I'm attaching a new g.mlist main.c, which supports
multiple mapsets. I removed -p/-f and mapset=* mutual exclusiveness, but it
seems to have a problem with M_do_list when there are a small number of
maps in a previous mapset, but there are many in the current one.
For example, let's say there are only 3 maps in mapset a, but 100 in mapset
b. M_do_list(.., a) would be scrolled up by M_do_list(.., b) because the
pager doesn't pause for mapset a, but does for mapset b. Effectively,
g.mlist mapset=a,b looks as if it only shows maps in mapset b, but
actually, maps in a were displayed, but scrolled up.
The current trunk version doesn't have this problem because M_do_list is
called once and it takes care of all the maps in the current search path at
once.
I think it's little more work to fix it. or just leave g.mlist as is.
On Sun, Jun 8, 2014 at 8:30 AM, Vaclav Petras <wenzeslaus at gmail.com> wrote:
>
>
>
> On Sun, Jun 8, 2014 at 7:10 AM, Huidae Cho <grass4u at gmail.com> wrote:
>
>> Non-existent mapset fixed in r60749.
>>
>> Thanks. I can confirm that it works. Now we need the test for it.
>
> On Fri, Jun 6, 2014 at 12:18 PM, Vaclav Petras <wenzeslaus at gmail.com>
> wrote:
>
>>
>> By the way, is multiple for mapset a planned feature? Or it is too much?
>> Pattern for mapset seems too much for sure.
>>
>
> On Sun, Jun 8, 2014 at 7:10 AM, Huidae Cho <grass4u at gmail.com> wrote:
>
>> Multiple mapsets is not too much, but do we need it?
>>
>
> I don't know. I asked because I just automatically tried that syntax
> because I used `pattern="something,some_*"` syntax recently.
>
>
>> Also, if we implement multiple mapsets, it would be better semantically
>> to change "mapset=.." to "mapset=*" for all mapsets in the current
>> location. Martin, do you mind if I change mapset=.. to mapset=*?
>>
>> I would say that in any case, * fits more with the other options,
> although * is also used also for null values (besides nv and others).
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140608/081b3eed/attachment-0001.html>
-------------- next part --------------
--- main.c 2014-06-08 08:56:48.270462030 -0400
+++ new/main.c 2014-06-08 08:58:37.024455899 -0400
@@ -27,8 +27,8 @@
static int any = 0;
-static void make_list(FILE *, const struct list *, const char *, const char *,
- int, int, int);
+static void make_list(int, int, FILE *, const struct list *, const char *,
+ const char *, int, int);
int main(int argc, char *argv[])
{
@@ -56,6 +56,7 @@
FILE *fp;
const char *mapset;
char *separator;
+ int list_format;
G_gisinit(argv[0]);
@@ -91,6 +92,7 @@
opt.exclude->guisection = _("Pattern");
opt.mapset = G_define_standard_option(G_OPT_M_MAPSET);
+ opt.mapset->multiple = YES;
opt.mapset->label =
_("Name of mapset to list (default: current search path)");
opt.mapset->description = _("'.' for current mapset; '*' for all mapsets in location");
@@ -204,23 +206,6 @@
separator = G_option_to_separator(opt.separator);
fp = G_open_option_file(opt.output);
- if ((mapset = opt.mapset->answer) == NULL)
- mapset = "";
- else if (strcmp(mapset, ".") == 0)
- mapset = G_mapset(); /* current mapset */
- else if (strcmp(mapset, "*") == 0) {
- if (flag.pretty->answer || flag.full->answer)
- G_fatal_error(_("-%c/-%c and %s=%s are mutually exclusive"),
- flag.pretty->key, flag.full->key, opt.mapset->key,
- mapset);
- mapset = NULL; /* all mapsets */
- }
- else if ((i = G__mapset_permissions(mapset)) == -1)
- G_fatal_error(_("Mapset <%s> does not exist"), mapset);
- else if (i == 0)
- G_warning(_("Permission denied for mapset <%s>. "
- "Trying to list files..."), mapset);
-
for (i = 0; opt.type->answers[i]; i++) {
if (strcmp(opt.type->answers[i], "all") == 0)
break;
@@ -234,30 +219,50 @@
num_types = i;
}
+ if (flag.full->answer)
+ list_format = 0;
+ else if (flag.pretty->answer)
+ list_format = 1;
+ else
+ list_format = 2;
+
for (i = 0; i < num_types; i++) {
const struct list *elem;
+ int j;
n = all ? i : M_get_element(opt.type->answers[i]);
-
elem = M_get_list(n);
- if (flag.full->answer) {
- char lister[GPATH_MAX];
-
- sprintf(lister, "%s/etc/lister/%s", G_gisbase(), elem->element[0]);
-
- G_debug(3, "lister CMD: %s", lister);
-
- if (access(lister, X_OK) == 0) /* execute permission? */
- G_spawn(lister, lister, mapset, NULL);
- else
- M_do_list(n, mapset);
+ if (opt.mapset->answers && opt.mapset->answers[0]) {
+ for (j = 0; (mapset = opt.mapset->answers[j]); j++) {
+ if (strcmp(mapset, "*") == 0) {
+ /* all mapsets from current location */
+ int k;
+ char **ms;
+
+ ms = G_get_available_mapsets();
+ for (k = 0; (mapset = ms[k]); k++) {
+ make_list(list_format, n,
+ fp, elem, mapset, separator,
+ flag.type->answer, flag.mapset->answer);
+ }
+ continue;
+ }
+ else if (strcmp(mapset, ".") == 0)
+ mapset = G_mapset();
+
+ make_list(list_format, n,
+ fp, elem, mapset, separator, flag.type->answer,
+ flag.mapset->answer);
+ }
+ }
+ else {
+ /* mapsets from search path only */
+ for (j = 0; (mapset = G_get_mapset_name(j)); j++)
+ make_list(list_format, n,
+ fp, elem, mapset, separator, flag.type->answer,
+ flag.mapset->answer);
}
- else if (flag.pretty->answer)
- M_do_list(n, mapset);
- else
- make_list(fp, elem, mapset, separator, flag.type->answer,
- flag.mapset->answer, mapset && *mapset);
}
if (any)
@@ -274,10 +279,11 @@
exit(EXIT_SUCCESS);
}
-static void make_list(FILE *fp, const struct list *elem, const char *mapset,
- const char *separator, int add_type, int add_mapset,
- int single_mapset)
+static void make_list(int list_format, int n,
+ FILE *fp, const struct list *elem, const char *mapset,
+ const char *separator, int add_type, int add_mapset)
{
+ static int first_mapset = 1;
char path[GPATH_MAX];
const char *element = elem->element[0];
const char *alias = elem->alias;
@@ -285,23 +291,28 @@
int count;
int i;
- if (!mapset) {
- /* all mapsets from current location */
- int n;
- char **ms;
- ms = G_get_available_mapsets();
- for (n = 0; ms[n]; n++) {
- make_list(fp, elem, ms[n], separator, add_type, add_mapset,
- n == 0);
- }
- return;
+ if ((i = G__mapset_permissions(mapset)) == -1)
+ G_fatal_error(_("Mapset <%s> does not exist"), mapset);
+ else if (i == 0)
+ G_warning(_("Permission denied for mapset <%s>. "
+ "Trying to list files..."), mapset);
+
+ if (list_format == 0) {
+ char lister[GPATH_MAX];
+
+ sprintf(lister, "%s/etc/lister/%s", G_gisbase(), elem->element[0]);
+
+ G_debug(3, "lister CMD: %s", lister);
+
+ if (access(lister, X_OK) == 0) /* execute permission? */
+ G_spawn(lister, lister, mapset, NULL);
+ else
+ M_do_list(n, mapset);
+ return;
}
- else if (!*mapset) {
- /* mapsets from search path only */
- int n;
- for (n = 0; mapset = G_get_mapset_name(n), mapset; n++)
- make_list(fp, elem, mapset, separator, add_type, add_mapset,
- n == 0);
+
+ if (list_format == 1) {
+ M_do_list(n, mapset);
return;
}
@@ -334,7 +345,7 @@
fprintf(fp, "%s", name);
- if (!add_mapset && !single_mapset) {
+ if (!add_mapset && !first_mapset) {
const char *mapset2 = G_find_file2(element, name, "");
if (mapset2)
need_mapset = strcmp(mapset, mapset2) != 0;
@@ -349,7 +360,8 @@
G_suppress_warnings(0);
fflush(fp);
-
+
G_free(list);
-}
+ first_mapset = 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: g-mlist-main.c
Type: text/x-csrc
Size: 9948 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140608/081b3eed/attachment-0001.c>
More information about the grass-dev
mailing list