[GRASS-SVN] r46633 - grass/branches/releasebranch_6_4/lib/symbol

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 9 04:08:12 EDT 2011


Author: neteler
Date: 2011-06-09 01:08:12 -0700 (Thu, 09 Jun 2011)
New Revision: 46633

Modified:
   grass/branches/releasebranch_6_4/lib/symbol/read.c
Log:
skip empty and comment lines (backport r38852); use G_getl2() instead of fgets() (backport r38841)

Modified: grass/branches/releasebranch_6_4/lib/symbol/read.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/symbol/read.c	2011-06-09 08:01:11 UTC (rev 46632)
+++ grass/branches/releasebranch_6_4/lib/symbol/read.c	2011-06-09 08:08:12 UTC (rev 46633)
@@ -193,8 +193,13 @@
 
     G_debug(5, "    read_coor()");
 
-    while (fgets(buf, 500, fp) != NULL) {
+    while (G_getl2(buf, 500, fp) != 0) {
 	G_chop(buf);
+
+	/* skip empty and comment lines */
+	if ((buf[0] == '#') || (buf[0] == '\0'))
+	    continue;
+
 	get_key_data(buf);
 
 	if (strcmp(key, "END") == 0) {
@@ -216,7 +221,7 @@
 {
     fclose(fp);
     G_free(s);			/* TODO: free all */
-    G_warning("%s", msg);
+    G_warning(msg);
     return NULL;
 }
 
@@ -231,7 +236,7 @@
 {
     int i, j, k, l;
     FILE *fp;
-    char group[500], name[500], buf[2001], temp_buf[2001];
+    char group[500], name[500], buf[2001];
     char *ms, *c;
     double x, y, x2, y2, rad, ang1, ang2;
     int r, g, b;
@@ -285,9 +290,14 @@
     current = OBJ_NONE;		/* no part */
 
     /* read file */
-    while (fgets(buf, 2000, fp) != NULL) {
+    while (G_getl2(buf, 2000, fp) != 0) {
 	G_chop(buf);
-	G_debug(3, "  BUF: %s", buf);
+	G_debug(3, "  BUF: [%s]", buf);
+
+	/* skip empty and comment lines */
+	if ((buf[0] == '#') || (buf[0] == '\0'))
+	    continue;
+
 	get_key_data(buf);
 
 	if (strcmp(key, "VERSION") == 0) {
@@ -342,8 +352,8 @@
 		sscanf(data, "%lf %lf %lf %lf %lf %c", &x, &y, &rad, &ang1,
 		       &ang2, &clock);
 	    if (ret < 5) {
-		sprintf(temp_buf, "Incorrect arc definition: '%s'", buf);
-		return (err(fp, symb, temp_buf));
+		sprintf(buf, "Incorrect arc definition: '%s'", buf);
+		return (err(fp, symb, buf));
 	    }
 	    if (ret == 6 && (clock == 'c' || clock == 'C'))
 		i = 1;
@@ -426,8 +436,8 @@
 	    }
 	}
 	else {
-	    sprintf(temp_buf, "Unknown keyword in symbol: '%s'", buf);
-	    return (err(fp, symb, temp_buf));
+	    sprintf(buf, "Unknown keyword in symbol: '%s'", buf);
+	    return (err(fp, symb, buf));
 	    break;
 	}
     }



More information about the grass-commit mailing list