[GRASS-SVN] r32633 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Aug 8 00:35:13 EDT 2008
Author: glynn
Date: 2008-08-08 00:35:12 -0400 (Fri, 08 Aug 2008)
New Revision: 32633
Modified:
grass/trunk/lib/gis/color_read.c
grass/trunk/lib/gis/open.c
grass/trunk/lib/gis/open_misc.c
Log:
Fix handling of qualified map names
Modified: grass/trunk/lib/gis/color_read.c
===================================================================
--- grass/trunk/lib/gis/color_read.c 2008-08-08 00:48:58 UTC (rev 32632)
+++ grass/trunk/lib/gis/color_read.c 2008-08-08 04:35:12 UTC (rev 32633)
@@ -64,7 +64,7 @@
int fp;
char buf[GNAME_MAX];
char *err;
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+ char xname[GNAME_MAX];
struct Range range;
struct FPRange drange;
CELL min, max;
@@ -72,12 +72,11 @@
fp = G_raster_map_is_fp(name, mapset);
G_init_colors(colors);
- if (G__name_is_fully_qualified(name, xname, xmapset)) {
- if (strcmp(xmapset, mapset) != 0)
- return -1;
- name = xname;
- }
+ strcpy(xname, name);
+ mapset = G_find_cell(xname, mapset);
+ name = xname;
+
if (fp)
G_mark_colors_as_fp(colors);
@@ -114,9 +113,8 @@
return 1;
}
- sprintf(buf, _("color support for [%s] in mapset [%s] %s"), name, mapset,
- err);
- G_warning(buf);
+ G_warning(_("color support for [%s] in mapset [%s] %s"), name, mapset,
+ err);
return -1;
}
Modified: grass/trunk/lib/gis/open.c
===================================================================
--- grass/trunk/lib/gis/open.c 2008-08-08 00:48:58 UTC (rev 32632)
+++ grass/trunk/lib/gis/open.c 2008-08-08 04:35:12 UTC (rev 32633)
@@ -15,11 +15,7 @@
#include <grass/config.h>
#include <string.h>
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif
-
-#include <unistd.h>
#include <fcntl.h>
#include <grass/gis.h>
@@ -54,7 +50,7 @@
const char *name, const char *mapset, int mode)
{
char path[GPATH_MAX];
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *dummy;
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
G__check_gisinit();
@@ -62,25 +58,31 @@
/* READ */
if (mode == 0) {
if (G__name_is_fully_qualified(name, xname, xmapset)) {
- if (strcmp(xmapset, mapset) != 0) {
+ if (*mapset && strcmp(xmapset, mapset) != 0) {
G_warning(_("G__open(read): mapset <%s> doesn't match xmapset <%s>"),
mapset, xmapset);
return -1;
}
name = xname;
+ mapset = xmapset;
}
- if ((dummy = G_find_file2(element, name, mapset)) == NULL)
+ else if (!*mapset)
+ mapset = G_find_file2(element, name, mapset);
+
+ if (!mapset)
return -1;
+
G__file_name(path, element, name, mapset);
return open(path, 0);
}
/* WRITE */
if (mode == 1 || mode == 2) {
+ mapset = G_mapset();
if (G__name_is_fully_qualified(name, xname, xmapset)) {
- if (strcmp(xmapset, G_mapset()) != 0) {
+ if (strcmp(xmapset, mapset) != 0) {
G_warning(_("G__open(write): xmapset <%s> != G_mapset() <%s>"),
- xmapset, G_mapset());
+ xmapset, mapset);
return -1;
}
name = xname;
@@ -89,7 +91,8 @@
if (G_legal_filename(name) == -1)
return -1;
- G__file_name(path, element, name, G_mapset());
+ G__file_name(path, element, name, mapset);
+
if (mode == 1 || access(path, 0) != 0) {
G__make_mapset_element(element);
close(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666));
Modified: grass/trunk/lib/gis/open_misc.c
===================================================================
--- grass/trunk/lib/gis/open_misc.c 2008-08-08 00:48:58 UTC (rev 32632)
+++ grass/trunk/lib/gis/open_misc.c 2008-08-08 04:35:12 UTC (rev 32633)
@@ -22,20 +22,18 @@
#include <grass/config.h>
#include <string.h>
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif
+#include <fcntl.h>
#include <grass/gis.h>
-#include <unistd.h>
-#include <fcntl.h>
+#include <grass/glocale.h>
static int G__open_misc(const char *dir,
const char *element,
const char *name, const char *mapset, int mode)
{
char path[GPATH_MAX];
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *dummy;
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
G__check_gisinit();
@@ -43,15 +41,18 @@
/* READ */
if (mode == 0) {
if (G__name_is_fully_qualified(name, xname, xmapset)) {
- if (strcmp(xmapset, mapset) != 0) {
- fprintf(stderr,
- "G__open(r): mapset (%s) doesn't match xmapset (%s)\n",
- mapset, xmapset);
+ if (*mapset && strcmp(xmapset, mapset) != 0) {
+ G_warning(_("G__open_misc(read): mapset <%s> doesn't match xmapset <%s>"),
+ mapset, xmapset);
return -1;
}
name = xname;
+ mapset = xmapset;
}
- if ((dummy = G_find_file2_misc(dir, element, name, mapset)) == NULL)
+ else if (!*mapset)
+ mapset = G_find_file2_misc(dir, element, name, mapset);
+
+ if (!mapset)
return -1;
G__file_name_misc(path, dir, element, name, mapset);
@@ -60,11 +61,11 @@
}
/* WRITE */
if (mode == 1 || mode == 2) {
+ mapset = G_mapset();
if (G__name_is_fully_qualified(name, xname, xmapset)) {
- if (strcmp(xmapset, G_mapset()) != 0) {
- fprintf(stderr,
- "G__open(w): xmapset (%s) != G_mapset() (%s)\n",
- xmapset, G_mapset());
+ if (strcmp(xmapset, mapset) != 0) {
+ G_warning(_("G__open_misc(write): xmapset <%s> != G_mapset() <%s>"),
+ xmapset, mapset);
return -1;
}
name = xname;
@@ -73,7 +74,7 @@
if (G_legal_filename(name) == -1)
return -1;
- G__file_name_misc(path, dir, element, name, G_mapset());
+ G__file_name_misc(path, dir, element, name, mapset);
if (mode == 1 || access(path, 0) != 0) {
G__make_mapset_element_misc(dir, name);
close(creat(path, 0666));
More information about the grass-commit
mailing list