Browse Source

Fix bugs in reclassed_to handling

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@45681 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 14 years ago
parent
commit
ebc07a8de4
1 changed files with 16 additions and 9 deletions
  1. 16 9
      lib/raster/reclass.c

+ 16 - 9
lib/raster/reclass.c

@@ -122,6 +122,8 @@ int Rast_is_reclassed_to(const char *name, const char *mapset, int *nrmaps,
 	(*rmaps)[i - 1] = NULL;
     }
 
+    fclose(fd);
+
     return i;
 }
 
@@ -261,8 +263,9 @@ int Rast_put_reclass(const char *name, const struct Reclass *reclass)
 {
     FILE *fd;
     long min, max;
-    int i;
-    char buf1[GPATH_MAX], buf2[GNAME_MAX], buf3[GNAME_MAX], *p;
+    int found;
+    char buf1[GPATH_MAX], buf2[GNAME_MAX], *p;
+    char *xname;
 
     switch (reclass->type) {
     case RECLASS_TABLE:
@@ -334,18 +337,22 @@ int Rast_put_reclass(const char *name, const struct Reclass *reclass)
 
     G_fseek(fd, 0L, SEEK_SET);
 
-    sprintf(buf2, "%s@%s\n", name, G_mapset());
-    for (i = 0; !feof(fd) && fgets(buf3, 255, fd);) {
-	if (!(strcmp(buf2, buf3))) {
-	    i = 1;
+    xname = G_fully_qualified_name(name, G_mapset());
+    found = 0;
+    for (;;) {
+	char buf[GNAME_MAX + GMAPSET_MAX];
+	if (!G_getl2(buf, sizeof(buf), fd))
+	    break;
+	if (strcmp(xname, buf) == 0) {
+	    found = 1;
 	    break;
 	}
     }
 
-    if (!i) {
-	fprintf(fd, "%s@%s\n", name, G_mapset());
-    }
+    if (!found)
+	fprintf(fd, "%s\n", xname);
 
+    G_free(xname);
     fclose(fd);
 
     return 1;