[GRASS-SVN] r46738 - grass/trunk/raster3d/r3.in.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 18 14:56:48 EDT 2011


Author: huhabla
Date: 2011-06-18 11:56:48 -0700 (Sat, 18 Jun 2011)
New Revision: 46738

Modified:
   grass/trunk/raster3d/r3.in.ascii/main.c
Log:
Use  G_getl2() for header parsing.

Modified: grass/trunk/raster3d/r3.in.ascii/main.c
===================================================================
--- grass/trunk/raster3d/r3.in.ascii/main.c	2011-06-18 18:34:02 UTC (rev 46737)
+++ grass/trunk/raster3d/r3.in.ascii/main.c	2011-06-18 18:56:48 UTC (rev 46738)
@@ -16,6 +16,7 @@
  *
  *****************************************************************************/
 #include <stdio.h>
+
 #include <stdlib.h>
 #include <string.h>
 #include <grass/gis.h>
@@ -47,8 +48,6 @@
 static void asciiToG3d(FILE * fp, G3D_Region * region, int convertNull,
                        char *nullValue);
 
-
-
 /*---------------------------------------------------------------------------*/
 
 /* global variables */
@@ -119,14 +118,15 @@
 void readHeaderString(FILE * fp, char *valueString, double *value)
 {
     static char format[100];
+    char line_buff[1024];
 
     /* to avoid buffer overflows we use G_snprintf */
     G_snprintf(format, 100, "%s %%lf", valueString);
-    if (fscanf(fp, format, value) != 1) {
+    G_getl2(line_buff, 1024, fp);
+    if (sscanf(line_buff, format, value) != 1) {
         G_debug(0, "bad value for [%s]", valueString);
         fatalError("readHeaderString: header value invalid");
     }
-    while (fgetc(fp) != '\n');
 }
 
 /*---------------------------------------------------------------------------*/
@@ -136,6 +136,7 @@
     FILE *fp;
     double tmp;
     char buff[1024];
+    char line_buff[1024];
 
     G_debug(3, "openAscii: opens the ascii file and reads the header");
 
@@ -150,16 +151,18 @@
     rowOrder = ROW_ORDER_NORTH_TO_SOUTH;
     depthOrder = DEPTH_ORDER_BOTTOM_TO_TOP;
 
+    /* Read the first line and check for grass version */
+    G_getl2(line_buff, 1024, fp);
+
     /* First check for new ascii format*/
-    if (fscanf(fp, "version: %s", buff) == 1) {
-        while (fgetc(fp) != '\n');
+    if (sscanf(line_buff, "version: %s", buff) == 1) {
         G_message("Found version information: %s\n", buff);
         if (G_strcasecmp(buff, "grass7") == 0) {
 
             /* Parse the row and depth order */
-            if (fscanf(fp, "order:%s", buff) != 1)
+            G_getl2(line_buff, 1024, fp);
+            if (sscanf(line_buff, "order: %s", buff) != 1)
                 fatalError("Unable to parse the row and depth order");
-            while (fgetc(fp) != '\n');
 
             if (G_strcasecmp(buff, "nsbt") == 0) {
                 rowOrder = ROW_ORDER_NORTH_TO_SOUTH;
@@ -185,7 +188,7 @@
             G_fatal_error(_("Unsupported grass version %s"), buff);
         }
     } else {
-        /* Rewind the stream */
+        /* Rewind the stream if no grass version info found */
         rewind(fp);
     }
 
@@ -298,7 +301,6 @@
     G3d_unlockAll(map);
 
     G_percent(1, 1, 1);
-
 }
 
 /*---------------------------------------------------------------------------*/



More information about the grass-commit mailing list