[GRASS-SVN] r38633 - in grass/trunk/vector: v.in.dxf v.vol.rst

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 7 11:30:43 EDT 2009


Author: mmetz
Date: 2009-08-07 11:30:43 -0400 (Fri, 07 Aug 2009)
New Revision: 38633

Modified:
   grass/trunk/vector/v.in.dxf/global.h
   grass/trunk/vector/v.in.dxf/main.c
   grass/trunk/vector/v.in.dxf/read_dxf.c
   grass/trunk/vector/v.vol.rst/user1.c
   grass/trunk/vector/v.vol.rst/user3.c
Log:
LFS-safe v.in.dxf and v.vol.rst

Modified: grass/trunk/vector/v.in.dxf/global.h
===================================================================
--- grass/trunk/vector/v.in.dxf/global.h	2009-08-07 15:26:24 UTC (rev 38632)
+++ grass/trunk/vector/v.in.dxf/global.h	2009-08-07 15:30:43 UTC (rev 38633)
@@ -1,7 +1,9 @@
 #ifndef _GLOBAL_H_
 #define _GLOBAL_H_
 
+#include <grass/config.h>
 #include <stdio.h>
+#include <sys/types.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
 #include <grass/vector.h>
@@ -11,7 +13,8 @@
     char *name;
     FILE *fp;
     /* for G_percent() */
-    unsigned long size, pos;
+    off_t size, pos;
+    int curr_pos;
     int percent;
 };
 

Modified: grass/trunk/vector/v.in.dxf/main.c
===================================================================
--- grass/trunk/vector/v.in.dxf/main.c	2009-08-07 15:26:24 UTC (rev 38632)
+++ grass/trunk/vector/v.in.dxf/main.c	2009-08-07 15:30:43 UTC (rev 38633)
@@ -36,7 +36,7 @@
 int main(int argc, char *argv[])
 {
     struct dxf_file *dxf;
-    struct Map_info *Map;
+    struct Map_info Map;
     char *output;
     int ret;
 
@@ -144,39 +144,36 @@
 	output = opt.output->answer;
 
 	/* create vector map */
-	Map = (struct Map_info *)G_malloc(sizeof(struct Map_info));
-	if (Vect_open_new(Map, output, 1) < 0)
+	if (Vect_open_new(&Map, output, 1) < 0)
 	    G_fatal_error(_("Unable to create vector map <%s>"), output);
 
-	Vect_set_map_name(Map, output);
+	Vect_set_map_name(&Map, output);
 
-	Vect_hist_command(Map);
+	Vect_hist_command(&Map);
     }
 
     /* import */
-    ret = dxf_to_vect(dxf, Map);
+    ret = dxf_to_vect(dxf, &Map);
 
     dxf_close(dxf);
 
     if (flag_list)
 	init_list();
     else {
-	Vect_close(Map);
+	Vect_close(&Map);
 
 	if (ret) {
-	    if (Vect_open_old(Map, output, G_mapset())) {
+	    if (Vect_open_old(&Map, output, G_mapset())) {
 		if (!flag_topo)
-		    if (!Vect_build(Map))
+		    if (!Vect_build(&Map))
 			G_warning(_("Building topology failed"));
-		Vect_close(Map);
+		Vect_close(&Map);
 	    }
 	}
 	else {
 	    Vect_delete(output);
 	    G_fatal_error(_("Failed to import DXF file!"));
 	}
-
-	G_free(Map);
     }
 
     G_done_msg(" ");

Modified: grass/trunk/vector/v.in.dxf/read_dxf.c
===================================================================
--- grass/trunk/vector/v.in.dxf/read_dxf.c	2009-08-07 15:26:24 UTC (rev 38632)
+++ grass/trunk/vector/v.in.dxf/read_dxf.c	2009-08-07 15:30:43 UTC (rev 38633)
@@ -1,3 +1,4 @@
+#include <grass/config.h>
 #include <stdlib.h>
 #include <string.h>
 #include "global.h"
@@ -16,8 +17,8 @@
 	return NULL;
 
     /* get the file size */
-    fseek(dxf->fp, 0L, SEEK_END);
-    dxf->size = ftell(dxf->fp);
+    G_fseek(dxf->fp, 0L, SEEK_END);
+    dxf->size = G_ftell(dxf->fp);
     rewind(dxf->fp);
 
     dxf->pos = 0;
@@ -30,7 +31,7 @@
 	dxf->percent = 2;
 
     /* initialize G_percent() */
-    G_percent(0, dxf->size, dxf->percent);
+    G_percent(0, 100, dxf->percent);
 
     return dxf;
 }
@@ -83,10 +84,12 @@
 static char *dxf_fgets(char *buf, int size, struct dxf_file *dxf)
 {
     char *p;
+    double perc;
 
     if ((p = fgets(buf, size, dxf->fp))) {
 	dxf->pos += strlen(p);
-	G_percent(dxf->pos, dxf->size, dxf->percent);
+	perc = 1.0 * dxf->pos / dxf->size;
+	G_percent((int) (perc * 100.0), 100, dxf->percent);
 	G_squeeze(buf);
     }
 

Modified: grass/trunk/vector/v.vol.rst/user1.c
===================================================================
--- grass/trunk/vector/v.vol.rst/user1.c	2009-08-07 15:26:24 UTC (rev 38632)
+++ grass/trunk/vector/v.vol.rst/user1.c	2009-08-07 15:30:43 UTC (rev 38633)
@@ -26,8 +26,10 @@
  *
  *****************************************************************************/
 
+#include <grass/config.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/types.h>
 #include <math.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
@@ -403,10 +405,9 @@
 
 	for (i = 0; i < nsizr; i++) {
 	    /* seek to the right row */
-	    if (fseek
-		(Tmp_fd_cell, (long)((nsizr - 1 - i) * nsizc * sizeof(FCELL)),
-		 0) == -1)
-		G_fatal_error("cannot fseek to the right spot");
+	    G_fseek
+		(Tmp_fd_cell, (off_t)((nsizr - 1 - i) * nsizc * sizeof(FCELL)),
+		 0);
 	    fread(cell, sizeof(FCELL), nsizc, Tmp_fd_cell);
 	    Rast_put_f_row(fdcout, cell);
 	}

Modified: grass/trunk/vector/v.vol.rst/user3.c
===================================================================
--- grass/trunk/vector/v.vol.rst/user3.c	2009-08-07 15:26:24 UTC (rev 38632)
+++ grass/trunk/vector/v.vol.rst/user3.c	2009-08-07 15:30:43 UTC (rev 38633)
@@ -25,9 +25,10 @@
  *              for details.
  *
  *****************************************************************************/
-
+#include <grass/config.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/types.h>
 #include <math.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -242,7 +243,7 @@
     int POINT();
     int ind, ind1;
     static int first_time_z = 1;
-    int offset, offset1, offset2;
+    off_t offset, offset1, offset2;
     int bmask = 1;
     static FCELL *cell = NULL;
 
@@ -566,9 +567,7 @@
 		offset2 = offset + ind;	/* rows*cols offset */
 
 		if ((cellinp != NULL) && (cellout != NULL) && (i == ngstl)) {
-		    if (fseek(Tmp_fd_cell, (long)(ind * sizeof(FCELL)), 0) ==
-			-1)
-			return 0;
+		    G_fseek(Tmp_fd_cell, (off_t)(ind * sizeof(FCELL)), 0);
 		    if (!
 			(fwrite
 			 (zero_array_cell + ind1, sizeof(FCELL),
@@ -577,9 +576,7 @@
 			    ("Not enough disk space--cannot write files");
 		}
 		if (outz != NULL) {
-		    if (fseek(Tmp_fd_z, (long)(offset2 * sizeof(float)), 0) ==
-			-1)
-			return 0;
+		    G_fseek(Tmp_fd_z, (off_t)(offset2 * sizeof(float)), 0);
 		    if (!
 			(fwrite
 			 (zero_array1 + ind1, sizeof(float), nszc - ngstc + 1,
@@ -588,9 +585,7 @@
 			    ("Not enough disk space--cannot write files");
 		}
 		if (gradient != NULL) {
-		    if (fseek(Tmp_fd_dx, (long)(offset2 * sizeof(float)), 0)
-			== -1)
-			return 0;
+		    G_fseek(Tmp_fd_dx, (off_t)(offset2 * sizeof(float)), 0);
 		    if (!
 			(fwrite
 			 (zero_array2 + ind1, sizeof(float), nszc - ngstc + 1,
@@ -599,9 +594,7 @@
 			    ("Not enough disk space--cannot write files");
 		}
 		if (aspect1 != NULL) {
-		    if (fseek(Tmp_fd_dy, (long)(offset2 * sizeof(float)), 0)
-			== -1)
-			return 0;
+		    G_fseek(Tmp_fd_dy, (off_t)(offset2 * sizeof(float)), 0);
 		    if (!
 			(fwrite
 			 (zero_array3 + ind1, sizeof(float), nszc - ngstc + 1,
@@ -610,9 +603,7 @@
 			    ("Not enough disk space--cannot write files");
 		}
 		if (aspect2 != NULL) {
-		    if (fseek(Tmp_fd_dz, (long)(offset2 * sizeof(float)), 0)
-			== -1)
-			return 0;
+		    G_fseek(Tmp_fd_dz, (off_t)(offset2 * sizeof(float)), 0);
 		    if (!
 			(fwrite
 			 (zero_array4 + ind1, sizeof(float), nszc - ngstc + 1,
@@ -621,9 +612,7 @@
 			    ("Not enough disk space--cannot write files");
 		}
 		if (ncurv != NULL) {
-		    if (fseek(Tmp_fd_xx, (long)(offset2 * sizeof(float)), 0)
-			== -1)
-			return 0;
+		    G_fseek(Tmp_fd_xx, (off_t)(offset2 * sizeof(float)), 0);
 		    if (!
 			(fwrite
 			 (zero_array5 + ind1, sizeof(float), nszc - ngstc + 1,
@@ -632,9 +621,7 @@
 			    ("Not enough disk space--cannot write files");
 		}
 		if (gcurv != NULL) {
-		    if (fseek(Tmp_fd_yy, (long)(offset2 * sizeof(float)), 0)
-			== -1)
-			return 0;
+		    G_fseek(Tmp_fd_yy, (off_t)(offset2 * sizeof(float)), 0);
 		    if (!
 			(fwrite
 			 (zero_array6 + ind1, sizeof(float), nszc - ngstc + 1,
@@ -643,9 +630,7 @@
 			    ("Not enough disk space--cannot write files");
 		}
 		if (mcurv != NULL) {
-		    if (fseek(Tmp_fd_xy, (long)(offset2 * sizeof(float)), 0)
-			== -1)
-			return 0;
+		    G_fseek(Tmp_fd_xy, (off_t)(offset2 * sizeof(float)), 0);
 		    if (!
 			(fwrite
 			 (zero_array7 + ind1, sizeof(float), nszc - ngstc + 1,



More information about the grass-commit mailing list