[GRASS-SVN] r61840 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 8 15:00:43 PDT 2014
Author: glynn
Date: 2014-09-08 15:00:42 -0700 (Mon, 08 Sep 2014)
New Revision: 61840
Modified:
grass/trunk/lib/gis/find_file.c
Log:
When searching the mapset search path, find the first map,
not the first map with the requested element
Modified: grass/trunk/lib/gis/find_file.c
===================================================================
--- grass/trunk/lib/gis/find_file.c 2014-09-08 06:10:28 UTC (rev 61839)
+++ grass/trunk/lib/gis/find_file.c 2014-09-08 22:00:42 UTC (rev 61840)
@@ -18,6 +18,40 @@
#include <grass/gis.h>
#include <grass/glocale.h>
+static const char *find_element(int misc, const char *dir, const char *element)
+{
+ static const char *cell_elements[] = {
+ "cellhd",
+ "cell",
+ "cats",
+ "colr",
+ "hist",
+ "cell_misc",
+ "fcell",
+ "g3dcell",
+ NULL
+ };
+ static const char *dig_elements[] = {
+ "dig",
+ "dig_att",
+ "dig_plus",
+ "dig_cats",
+ "dig_misc",
+ "reg",
+ NULL
+ };
+ const char *search = misc ? dir : element;
+ int i;
+
+ for (i = 1; cell_elements[i]; i++)
+ if (strcmp(search, cell_elements[i]) == 0)
+ return cell_elements[0];
+ for (i = 1; dig_elements[i]; i++)
+ if (strcmp(search, dig_elements[i]) == 0)
+ return dig_elements[0];
+ return element;
+}
+
static const char *find_file(int misc, const char *dir,
const char *element, const char *name,
const char *mapset)
@@ -66,28 +100,35 @@
if (pmapset == NULL || *pmapset == 0) {
int cnt = 0;
const char *pselmapset = NULL;
+ const char *pelement = find_element(misc, dir, element);
for (n = 0; (pmapset = G_get_mapset_name(n)); n++) {
- if (misc)
- G_file_name_misc(path, dir, element, pname, pmapset);
+ if (misc && element == pelement)
+ G_file_name_misc(path, dir, pelement, pname, pmapset);
else
- G_file_name(path, element, pname, pmapset);
+ G_file_name(path, pelement, pname, pmapset);
if (access(path, 0) == 0) {
if (!pselmapset)
pselmapset = pmapset;
- else
+ else if (element == pelement)
G_warning(_("'%s/%s' was found in more mapsets (also found in <%s>)"),
element, pname, pmapset);
cnt++;
}
}
if (cnt > 0) {
- /* If the same name exists in more mapsets and print a warning */
- if (cnt > 1)
- G_warning(_("Using <%s@%s>"),
- pname, pselmapset);
+ if (misc)
+ G_file_name_misc(path, dir, element, pname, pmapset);
+ else
+ G_file_name(path, element, name, pmapset);
+ if (access(path, 0) == 0) {
+ /* If the same name exists in more mapsets and print a warning */
+ if (cnt > 1 && element == pelement)
+ G_warning(_("Using <%s@%s>"),
+ pname, pselmapset);
- return G_store(pselmapset);
+ return G_store(pselmapset);
+ }
}
}
/*
More information about the grass-commit
mailing list