[GRASS-SVN] r36667 - grass/trunk/vector/v.in.dxf

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Apr 10 04:04:58 EDT 2009


Author: hcho
Date: 2009-04-10 04:04:56 -0400 (Fri, 10 Apr 2009)
New Revision: 36667

Modified:
   grass/trunk/vector/v.in.dxf/add_3dface.c
   grass/trunk/vector/v.in.dxf/add_arc.c
   grass/trunk/vector/v.in.dxf/add_circle.c
   grass/trunk/vector/v.in.dxf/add_line.c
   grass/trunk/vector/v.in.dxf/add_lwpolyline.c
   grass/trunk/vector/v.in.dxf/add_point.c
   grass/trunk/vector/v.in.dxf/add_polyline.c
   grass/trunk/vector/v.in.dxf/add_text.c
   grass/trunk/vector/v.in.dxf/dxf_to_vect.c
   grass/trunk/vector/v.in.dxf/global.h
   grass/trunk/vector/v.in.dxf/layer_list.c
   grass/trunk/vector/v.in.dxf/main.c
   grass/trunk/vector/v.in.dxf/make_arc.c
   grass/trunk/vector/v.in.dxf/v.in.dxf.html
   grass/trunk/vector/v.in.dxf/write_vect.c
Log:
Added the "handle" column to store entity handles (Benjamin Ducke).
Lowercase entity type => Uppercase entity type


Modified: grass/trunk/vector/v.in.dxf/add_3dface.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_3dface.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_3dface.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,10 +2,11 @@
 #include <string.h>
 #include "global.h"
 
-int add_3dface(struct dxf_file *dxf, struct Map_info *Map)
+void add_3dface(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int dface_flag = 0;		/* indicates if a edge is invisible */
     int xflag = 0;		/* indicates if a x value has been found */
@@ -13,30 +14,32 @@
     int zflag = 0;		/* indicates if a z value has been found */
     int arr_size = 0;
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
+	case 5:		/* entity handle */
+	    strcpy(handle, dxf_buf);
+	    break;
 	case 8:		/* layer name */
 	    if (!layer_flag && *dxf_buf) {
 		if (flag_list) {
-		    if (!is_layer_in_list(dxf_buf)) {
-			add_layer_to_list(dxf_buf);
-			print_layer(dxf_buf);
-		    }
-		    return 0;
+		    if (!is_layer_in_list(dxf_buf))
+			add_layer_to_list(dxf_buf, 1);
+		    return;
 		}
-		/* skip if layers != NULL && (
+		/* skip if (opt_layers != NULL && (
 		 * (flag_invert == 0 && is_layer_in_list == 0) ||
 		 * (flag_invert == 1 && is_layer_in_list == 1)
 		 * )
 		 */
-		if (layers && flag_invert == is_layer_in_list(dxf_buf))
-		    return 0;
+		if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+		    return;
 		strcpy(layer, dxf_buf);
 		layer_flag = 1;
 	    }
@@ -116,8 +119,8 @@
 	if (xpnts[2] == xpnts[3] && ypnts[2] == ypnts[3] &&
 	    zpnts[2] == zpnts[3])
 	    arr_size--;
-	write_face(Map, layer, arr_size);
+	write_vect(Map, layer, "3DFACE", handle, "", arr_size, GV_FACE);
     }
 
-    return 0;
+    return;
 }

Modified: grass/trunk/vector/v.in.dxf/add_arc.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_arc.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_arc.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,10 +2,11 @@
 #include <string.h>
 #include "global.h"
 
-int add_arc(struct dxf_file *dxf, struct Map_info *Map)
+void add_arc(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int xflag = 0;		/* indicates if a x value has been found */
     int yflag = 0;		/* indicates if a y value has been found */
@@ -20,30 +21,32 @@
     float finish_angle = 0;	/* read in from dxf file */
     int arr_size = 0;
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
+	case 5:		/* entity handle */
+	    strcpy(handle, dxf_buf);
+	    break;
 	case 8:		/* layer name */
 	    if (!layer_flag && *dxf_buf) {
 		if (flag_list) {
-		    if (!is_layer_in_list(dxf_buf)) {
-			add_layer_to_list(dxf_buf);
-			print_layer(dxf_buf);
-		    }
-		    return 0;
+		    if (!is_layer_in_list(dxf_buf))
+			add_layer_to_list(dxf_buf, 1);
+		    return;
 		}
-		/* skip if layers != NULL && (
+		/* skip if (opt_layers != NULL && (
 		 * (flag_invert == 0 && is_layer_in_list == 0) ||
 		 * (flag_invert == 1 && is_layer_in_list == 1)
 		 * )
 		 */
-		if (layers && flag_invert == is_layer_in_list(dxf_buf))
-		    return 0;
+		if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+		    return;
 		strcpy(layer, dxf_buf);
 		layer_flag = 1;
 	    }
@@ -78,8 +81,8 @@
 	arr_size =
 	    make_arc(0, centerx, centery, radius, start_angle, finish_angle,
 		     zcoor);
-	write_line(Map, layer, arr_size);
+	write_vect(Map, layer, "ARC", handle, "", arr_size, GV_LINE);
     }
 
-    return 0;
+    return;
 }

Modified: grass/trunk/vector/v.in.dxf/add_circle.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_circle.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_circle.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,10 +2,11 @@
 #include <string.h>
 #include "global.h"
 
-int add_circle(struct dxf_file *dxf, struct Map_info *Map)
+void add_circle(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int xflag = 0;		/* indicates if a x value has been found */
     int yflag = 0;		/* indicates if a y value has been found */
@@ -16,30 +17,32 @@
     double zcoor = 0;		/* read in from dxf file */
     int arr_size = 0;
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
+	case 5:		/* entity handle */
+	    strcpy(handle, dxf_buf);
+	    break;
 	case 8:		/* layer name */
 	    if (!layer_flag && *dxf_buf) {
 		if (flag_list) {
-		    if (!is_layer_in_list(dxf_buf)) {
-			add_layer_to_list(dxf_buf);
-			print_layer(dxf_buf);
-		    }
-		    return 0;
+		    if (!is_layer_in_list(dxf_buf))
+			add_layer_to_list(dxf_buf, 1);
+		    return;
 		}
-		/* skip if layers != NULL && (
+		/* skip if (opt_layers != NULL && (
 		 * (flag_invert == 0 && is_layer_in_list == 0) ||
 		 * (flag_invert == 1 && is_layer_in_list == 1)
 		 * )
 		 */
-		if (layers && flag_invert == is_layer_in_list(dxf_buf))
-		    return 0;
+		if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+		    return;
 		strcpy(layer, dxf_buf);
 		layer_flag = 1;
 	    }
@@ -64,8 +67,8 @@
 
     if (xflag && yflag && rflag) {
 	arr_size = make_arc(0, centerx, centery, radius, 0.0, 360.0, zcoor);
-	write_line(Map, layer, arr_size);
+	write_vect(Map, layer, "CIRCLE", handle, "", arr_size, GV_LINE);
     }
 
-    return 0;
+    return;
 }

Modified: grass/trunk/vector/v.in.dxf/add_line.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_line.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_line.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,40 +2,43 @@
 #include <string.h>
 #include "global.h"
 
-int add_line(struct dxf_file *dxf, struct Map_info *Map)
+void add_line(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int xflag = 0;		/* indicates if a x value has been found */
     int yflag = 0;		/* indicates if a y value has been found */
     int zflag = 0;		/* indicates if a z value has been found */
     int arr_size = 0;
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
+	case 5:		/* entity handle */
+	    strcpy(handle, dxf_buf);
+	    break;
 	case 8:		/* layer name */
 	    if (!layer_flag && *dxf_buf) {
 		if (flag_list) {
-		    if (!is_layer_in_list(dxf_buf)) {
-			add_layer_to_list(dxf_buf);
-			print_layer(dxf_buf);
-		    }
-		    return 0;
+		    if (!is_layer_in_list(dxf_buf))
+			add_layer_to_list(dxf_buf, 1);
+		    return;
 		}
-		/* skip if layers != NULL && (
+		/* skip if (opt_layers != NULL && (
 		 * (flag_invert == 0 && is_layer_in_list == 0) ||
 		 * (flag_invert == 1 && is_layer_in_list == 1)
 		 * )
 		 */
-		if (layers && flag_invert == is_layer_in_list(dxf_buf))
-		    return 0;
+		if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+		    return;
 		strcpy(layer, dxf_buf);
 		layer_flag = 1;
 	    }
@@ -76,7 +79,7 @@
     }
 
     if (arr_size == 2)	/* have both start and stop */
-	write_line(Map, layer, arr_size);
+	write_vect(Map, layer, "LINE", handle, "", arr_size, GV_LINE);
 
-    return 0;
+    return;
 }

Modified: grass/trunk/vector/v.in.dxf/add_lwpolyline.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_lwpolyline.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_lwpolyline.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,10 +2,11 @@
 #include <string.h>
 #include "global.h"
 
-int add_lwpolyline(struct dxf_file *dxf, struct Map_info *Map)
+void add_lwpolyline(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int polyline_flag = 0;	/* indicates the type of polyline */
     int xflag = 0;		/* indicates if a x value has been found */
@@ -16,31 +17,33 @@
     double bulge = 0.0;		/* for arc curves */
     double prev_bulge = 0.0;	/* for arc curves */
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     zpnts[0] = 0.0;
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
+	case 5:		/* entity handle */
+	    strcpy(handle, dxf_buf);
+	    break;
 	case 8:		/* layer name */
 	    if (!layer_flag && *dxf_buf) {
 		if (flag_list) {
-		    if (!is_layer_in_list(dxf_buf)) {
-			add_layer_to_list(dxf_buf);
-			print_layer(dxf_buf);
-		    }
-		    return 0;
+		    if (!is_layer_in_list(dxf_buf))
+			add_layer_to_list(dxf_buf, 1);
+		    return;
 		}
-		/* skip if layers != NULL && (
+		/* skip if (opt_layers != NULL && (
 		 * (flag_invert == 0 && is_layer_in_list == 0) ||
 		 * (flag_invert == 1 && is_layer_in_list == 1)
 		 * )
 		 */
-		if (layers && flag_invert == is_layer_in_list(dxf_buf))
-		    return 0;
+		if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+		    return;
 		strcpy(layer, dxf_buf);
 		layer_flag = 1;
 	    }
@@ -88,11 +91,11 @@
 	    zpnts[arr_size] = zpnts[0];
 
 	    /* arr_size incremented to be consistent with polyline_flag != 1 */
-	    if (arr_size >= ARR_MAX - 1) {
-		ARR_MAX += ARR_INCR;
-		xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
-		ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
-		zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
+	    if (arr_size >= arr_max - 1) {
+		arr_max += ARR_INCR;
+		xpnts = (double *)G_realloc(xpnts, arr_max * sizeof(double));
+		ypnts = (double *)G_realloc(ypnts, arr_max * sizeof(double));
+		zpnts = (double *)G_realloc(zpnts, arr_max * sizeof(double));
 	    }
 	    arr_size++;
 	}
@@ -105,7 +108,7 @@
 	    zpnts[i] = 0.0;
     }
 
-    write_line(Map, layer, arr_size);
+    write_vect(Map, layer, "LWPOLYLINE", handle, "", arr_size, GV_LINE);
 
-    return 0;
+    return;
 }

Modified: grass/trunk/vector/v.in.dxf/add_point.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_point.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_point.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,39 +2,42 @@
 #include <string.h>
 #include "global.h"
 
-int add_point(struct dxf_file *dxf, struct Map_info *Map)
+void add_point(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int xflag = 0;		/* indicates if a x value has been found */
     int yflag = 0;		/* indicates if a y value has been found */
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     zpnts[0] = 0.0;
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
+	case 5:		/* entity handle */
+	    strcpy(handle, dxf_buf);
+	    break;
 	case 8:		/* layer name */
 	    if (!layer_flag && *dxf_buf) {
 		if (flag_list) {
-		    if (!is_layer_in_list(dxf_buf)) {
-			add_layer_to_list(dxf_buf);
-			print_layer(dxf_buf);
-		    }
-		    return 0;
+		    if (!is_layer_in_list(dxf_buf))
+			add_layer_to_list(dxf_buf, 1);
+		    return;
 		}
-		/* skip if layers != NULL && (
+		/* skip if (opt_layers != NULL && (
 		 * (flag_invert == 0 && is_layer_in_list == 0) ||
 		 * (flag_invert == 1 && is_layer_in_list == 1)
 		 * )
 		 */
-		if (layers && flag_invert == is_layer_in_list(dxf_buf))
-		    return 0;
+		if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+		    return;
 		strcpy(layer, dxf_buf);
 		layer_flag = 1;
 	    }
@@ -61,8 +64,8 @@
 	 * ypnts[1] = ypnts[0];
 	 * zpnts[1] = zpnts[0];
 	 */
-	write_point(Map, layer);
+        write_vect(Map, layer, "POINT", handle, "", 1, GV_POINT);
     }
 
-    return 0;
+    return;
 }

Modified: grass/trunk/vector/v.in.dxf/add_polyline.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_polyline.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_polyline.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,12 +2,13 @@
 #include <string.h>
 #include "global.h"
 
-static void write_pnts(struct Map_info *, char *, int, int, int);
+static void write_pnts(struct Map_info *, char *, char *, int, int, int);
 
-int add_polyline(struct dxf_file *dxf, struct Map_info *Map)
+void add_polyline(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int polyline_flag = 0;	/* indicates the type of polyline */
     int warn_flag66 = 1;	/* indicates if error message printed once */
@@ -31,12 +32,13 @@
     double *mesh_ypnts = NULL;
     double *mesh_zpnts = NULL;
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
 	case 66:		/* vertices follow flag */
@@ -79,7 +81,7 @@
     /* loop until SEQEND in the dxf file */
     while (strcmp(dxf_buf, "SEQEND") != 0) {
 	if (feof(dxf->fp))	/* EOF */
-	    return -1;
+	    return;
 
 	if (strcmp(dxf_buf, "VERTEX") == 0) {
 	    vertex_idx++;
@@ -88,27 +90,27 @@
 	    zflag = 0;
 	    while ((code = dxf_get_code(dxf)) != 0) {
 		if (code == -2)	/* EOF */
-		    return -1;
+		    return;
 
 		switch (code) {
+		case 5:		/* entity handle */
+		    strcpy(handle, dxf_buf);
+		    break;
 		case 8:	/* layer name */
 		    /* if no layer previously assigned */
 		    if (!layer_flag && *dxf_buf) {
 			if (flag_list) {
-			    if (!is_layer_in_list(dxf_buf)) {
-				add_layer_to_list(dxf_buf);
-				print_layer(dxf_buf);
-			    }
-			    return 0;
+			    if (!is_layer_in_list(dxf_buf))
+				add_layer_to_list(dxf_buf, 1);
+			    return;
 			}
-			/* skip if layers != NULL && (
+			/* skip if (opt_layers != NULL && (
 			 * (flag_invert == 0 && is_layer_in_list == 0) ||
 			 * (flag_invert == 1 && is_layer_in_list == 1)
 			 * )
 			 */
-			if (layers &&
-			    flag_invert == is_layer_in_list(dxf_buf))
-			    return 0;
+			if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+			    return;
 			strcpy(layer, dxf_buf);
 			layer_flag = 1;
 		    }
@@ -199,14 +201,10 @@
 			    ypnts[arr_size] = ypnts[0];
 			    zpnts[arr_size] = zpnts[0];
 			    arr_size++;
-			    if (flag_frame) {
-				set_entity("POLYFACE FRAME");
-				write_line(Map, layer, arr_size);
-			    }
-			    else {
-				set_entity("POLYFACE");
-				write_face(Map, layer, arr_size);
-			    }
+			    if (flag_frame)
+				write_vect(Map, layer, "POLYFACE FRAME", handle, "", arr_size, GV_LINE);
+			    else
+				write_vect(Map, layer, "POLYFACE", handle, "", arr_size, GV_FACE);
 			    arr_size = 0;
 			}
 			mesh_pnts = 0;
@@ -236,13 +234,13 @@
 	G_free(mesh_zpnts);
     }
     else
-	write_pnts(Map, layer, polyline_flag, zflag, arr_size);
+	write_pnts(Map, layer, handle, polyline_flag, zflag, arr_size);
 
-    return 0;
+    return;
 }
 
-static void write_pnts(struct Map_info *Map, char *layer, int polyline_flag,
-		       int zflag, int arr_size)
+static void write_pnts(struct Map_info *Map, char *layer, char *handle,
+		int polyline_flag, int zflag, int arr_size)
 {
     /* done reading vertices */
     if (polyline_flag & 1) {	/* only dealing with polyline_flag = 1 */
@@ -255,11 +253,11 @@
 	    zpnts[arr_size] = zpnts[0];
 
 	    /* arr_size incremented to be consistent with polyline_flag != 1 */
-	    if (arr_size >= ARR_MAX - 1) {
-		ARR_MAX += ARR_INCR;
-		xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
-		ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
-		zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
+	    if (arr_size >= arr_max - 1) {
+		arr_max += ARR_INCR;
+		xpnts = (double *)G_realloc(xpnts, arr_max * sizeof(double));
+		ypnts = (double *)G_realloc(ypnts, arr_max * sizeof(double));
+		zpnts = (double *)G_realloc(zpnts, arr_max * sizeof(double));
 	    }
 	    arr_size++;
 	}
@@ -272,7 +270,7 @@
 	    zpnts[i] = 0.0;
     }
 
-    write_line(Map, layer, arr_size);
+    write_vect(Map, layer, "POLYLINE", handle, "", arr_size, GV_LINE);
 
     return;
 }

Modified: grass/trunk/vector/v.in.dxf/add_text.c
===================================================================
--- grass/trunk/vector/v.in.dxf/add_text.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/add_text.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -2,10 +2,11 @@
 #include <string.h>
 #include "global.h"
 
-int add_text(struct dxf_file *dxf, struct Map_info *Map)
+void add_text(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
-    char layer[DXF_BUF_SIZE];
+    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
+    char layer[DXF_BUF_SIZE];	/* layer name */
     int layer_flag = 0;		/* indicates if a layer name has been found */
     int xflag = 0;		/* indicates if a x value has been found */
     int yflag = 0;		/* indicates if a y value has been found */
@@ -14,35 +15,37 @@
     char label[DXF_BUF_SIZE];	/* read in from dxf file */
     int label_len = 0;
 
+    handle[0] = 0;
     strcpy(layer, UNIDENTIFIED_LAYER);
 
     zpnts[0] = 0.0;
     /* read in lines and process information until a 0 is read in */
     while ((code = dxf_get_code(dxf)) != 0) {
 	if (code == -2)
-	    return -1;
+	    return;
 
 	switch (code) {
 	case 1:		/* label value */
 	    label_len = strlen(dxf_buf);
 	    strcpy(label, dxf_buf);
 	    break;
+	case 5:		/* entity handle */
+	    strcpy(handle, dxf_buf);
+	    break;
 	case 8:		/* layer name */
 	    if (!layer_flag && *dxf_buf) {
 		if (flag_list) {
-		    if (!is_layer_in_list(dxf_buf)) {
-			add_layer_to_list(dxf_buf);
-			print_layer(dxf_buf);
-		    }
-		    return 0;
+		    if (!is_layer_in_list(dxf_buf))
+			add_layer_to_list(dxf_buf, 1);
+		    return;
 		}
-		/* skip if layers != NULL && (
+		/* skip if (opt_layers != NULL && (
 		 * (flag_invert == 0 && is_layer_in_list == 0) ||
 		 * (flag_invert == 1 && is_layer_in_list == 1)
 		 * )
 		 */
-		if (layers && flag_invert == is_layer_in_list(dxf_buf))
-		    return 0;
+		if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
+		    return;
 		strcpy(layer, dxf_buf);
 		layer_flag = 1;
 	    }
@@ -78,7 +81,7 @@
     }
 
     if (label_len == 0)
-	return -2;
+	return;
 
     if (xflag && yflag) {
 	/* TODO */
@@ -110,10 +113,10 @@
 	ypnts[3] = ypnts[0] + (length * sin(theta));
 	zpnts[3] = zpnts[0];
 
-	write_line(Map, layer, 5);
+        write_vect(Map, layer, "TEXT", handle, "", 5, GV_LINE);
 #endif
-	write_text(Map, layer, label);
+        write_vect(Map, layer, "TEXT", handle, label, 1, GV_POINT);
     }
 
-    return 0;
+    return;
 }

Modified: grass/trunk/vector/v.in.dxf/dxf_to_vect.c
===================================================================
--- grass/trunk/vector/v.in.dxf/dxf_to_vect.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/dxf_to_vect.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -12,6 +12,7 @@
 
 static BOUND_BOX ext, dxf_ext;
 
+/* returns 1 on success, otherwise 0 */
 int dxf_to_vect(struct dxf_file *dxf, struct Map_info *Map)
 {
     int code;
@@ -22,7 +23,7 @@
 	code = dxf_get_code(dxf);
 	while (code != 0) {
 	    if (code == -2)	/* EOF */
-		return -1;
+		return 0;
 
 	    /* only looking for header groups (code == 9) */
 	    if (code != 9)
@@ -33,7 +34,7 @@
 		 * or a 0 is read in */
 		while ((code = dxf_get_code(dxf)) != 9 && code != 0) {
 		    if (code == -2)	/* EOF */
-			return -1;
+			return 0;
 
 		    switch (code) {
 		    case 10:
@@ -58,7 +59,7 @@
 		 * or a 0 is read in */
 		while ((code = dxf_get_code(dxf)) != 9 && code != 0) {
 		    if (code == -2)	/* EOF */
-			return -1;
+			return 0;
 
 		    switch (code) {
 		    case 10:
@@ -80,7 +81,7 @@
 	    else {
 		while ((code = dxf_get_code(dxf)) != 9 && code != 0) {
 		    if (code == -2)	/* EOF */
-			return -1;
+			return 0;
 		}
 	    }
 
@@ -91,20 +92,18 @@
     else
 	code = dxf_get_code(dxf);
 
-    ARR_MAX = ARR_INCR;
+    arr_max = ARR_INCR;
     ext.E = ext.N = ext.T = DBL_MIN;
     ext.W = ext.S = ext.B = DBL_MAX;
 
-    xpnts = (double *)G_malloc(ARR_MAX * sizeof(double));
-    ypnts = (double *)G_malloc(ARR_MAX * sizeof(double));
-    zpnts = (double *)G_malloc(ARR_MAX * sizeof(double));
+    xpnts = (double *)G_malloc(arr_max * sizeof(double));
+    ypnts = (double *)G_malloc(arr_max * sizeof(double));
+    zpnts = (double *)G_malloc(arr_max * sizeof(double));
 
     if (!flag_list)
 	Points = Vect_new_line_struct();
 
     while (!feof(dxf->fp)) {
-	set_entity(dxf_buf);
-
 	/* avoid TEXT having object names: '0' should be followed by objects */
 	if (code != 0)
 	    code = dxf_get_code(dxf);
@@ -141,11 +140,14 @@
     G_free(ypnts);
     G_free(zpnts);
 
-    if (!flag_list) {
-	Vect_destroy_line_struct(Points);
-	write_done(Map);
-	if (found_layers)
-	    make_head(Map);
+    if (flag_list)
+	return 1;
+
+    Vect_destroy_line_struct(Points);
+
+    if (write_done(Map)) {
+	make_head(Map);
+	return 1;
     }
 
     return 0;
@@ -169,15 +171,6 @@
     return 0;
 }
 
-void set_entity(char *str)
-{
-    strcpy(entity, str);
-    for (str = entity; *str; str++)
-	*str = tolower(*str);
-
-    return;
-}
-
 static void make_head(struct Map_info *Map)
 {
     char *organization;

Modified: grass/trunk/vector/v.in.dxf/global.h
===================================================================
--- grass/trunk/vector/v.in.dxf/global.h	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/global.h	2009-04-10 08:04:56 UTC (rev 36667)
@@ -19,25 +19,28 @@
 #define ARR_INCR 256
 #define DXF_BUF_SIZE 256
 
-extern int flag_list, flag_extent, flag_table, flag_topo, flag_invert,
+#ifdef _MAIN_C_
+#define GLOBAL
+#else
+#define GLOBAL extern
+#endif
+
+GLOBAL int flag_list, flag_extent, flag_table, flag_topo, flag_invert,
     flag_one_layer, flag_frame;
-extern int num_layers, found_layers;
-extern char **layers;
-extern char dxf_buf[DXF_BUF_SIZE], entity[DXF_BUF_SIZE];
-extern int ARR_MAX;
-extern double *xpnts, *ypnts, *zpnts;
-extern struct line_pnts *Points;
+GLOBAL char **opt_layers;
+GLOBAL char dxf_buf[DXF_BUF_SIZE];
+GLOBAL int arr_max;
+GLOBAL double *xpnts, *ypnts, *zpnts;
+GLOBAL struct line_pnts *Points;
 
 /* dxf_to_vect.c */
 int dxf_to_vect(struct dxf_file *, struct Map_info *);
 int check_ext(double, double, double);
-void set_entity(char *);
 
 /* layer_list.c */
-void add_layer_to_list(char *);
-int is_layer_in_list(char *);
+void add_layer_to_list(const char *, int);
+int is_layer_in_list(const char *);
 void init_list(void);
-void print_layer(const char *);
 
 /* read_dxf.c */
 struct dxf_file *dxf_open(char *);
@@ -52,35 +55,31 @@
 int make_arc_from_polyline(int, double, double);
 
 /* add_point.c */
-int add_point(struct dxf_file *, struct Map_info *);
+void add_point(struct dxf_file *, struct Map_info *);
 
 /* add_line.c */
-int add_line(struct dxf_file *, struct Map_info *);
+void add_line(struct dxf_file *, struct Map_info *);
 
 /* add_lwpolyline.c */
-int add_lwpolyline(struct dxf_file *, struct Map_info *);
+void add_lwpolyline(struct dxf_file *, struct Map_info *);
 
 /* add_polyline.c */
-int add_polyline(struct dxf_file *, struct Map_info *);
+void add_polyline(struct dxf_file *, struct Map_info *);
 
 /* add_3dface.c */
-int add_3dface(struct dxf_file *, struct Map_info *);
+void add_3dface(struct dxf_file *, struct Map_info *);
 
 /* add_arc.c */
-int add_arc(struct dxf_file *, struct Map_info *);
+void add_arc(struct dxf_file *, struct Map_info *);
 
 /* add_circle.c */
-int add_circle(struct dxf_file *, struct Map_info *);
+void add_circle(struct dxf_file *, struct Map_info *);
 
 /* add_text.c */
-int add_text(struct dxf_file *, struct Map_info *);
+void add_text(struct dxf_file *, struct Map_info *);
 
 /* write_vect.c */
-#define write_point(a, b) write_vect(a, b, entity, "", 1, GV_POINT)
-#define write_line(a, b, c) write_vect(a, b, entity, "", c, GV_LINE)
-#define write_face(a, b, c) write_vect(a, b, entity, "", c, GV_FACE)
-#define write_text(a, b, c) write_vect(a, b, entity, c, 1, GV_POINT)
-void write_vect(struct Map_info *, char *, char *, char *, int, int);
-void write_done(struct Map_info *);
+void write_vect(struct Map_info *, char *, char *, char *, char *, int, int);
+int write_done(struct Map_info *);
 
 #endif

Modified: grass/trunk/vector/v.in.dxf/layer_list.c
===================================================================
--- grass/trunk/vector/v.in.dxf/layer_list.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/layer_list.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -1,33 +1,36 @@
 #include <string.h>
 #include "global.h"
 
-void add_layer_to_list(char *layer)
-{
-    /* capital column names are a pain in SQL */
-    G_str_to_lower(layer);
+static int num_layers = 0;
+static char **layers = NULL;
 
+void add_layer_to_list(const char *layer, int print)
+{
     if (is_layer_in_list(layer))
 	return;
 
     layers = (char **)G_realloc(layers, (num_layers + 2) * sizeof(char *));
-    layers[num_layers++] = G_store(layer);
+    layers[num_layers] = G_store(layer);
+    G_str_to_lower(layers[num_layers]);
+    if (print) {
+        fprintf(stdout, _("Layer %d: %s\n"), num_layers+1, layers[num_layers]);
+        fflush(stdout);
+    }
+    num_layers++;
     layers[num_layers] = NULL;
 
     return;
 }
 
-int is_layer_in_list(char *layer)
+int is_layer_in_list(const char *layer)
 {
     char **p;
 
-    /* capital column names are a pain in SQL */
-    G_str_to_lower(layer);
-
     if (!layers)
 	return 0;
 
     p = layers;
-    while (*p && strcmp(layer, *p) != 0)
+    while (*p && G_strcasecmp(layer, *p) != 0)
 	p++;
 
     return *p != NULL;
@@ -51,12 +54,3 @@
 
     return;
 }
-
-void print_layer(const char *layer_name)
-{
-    fprintf(stdout, _("Layer %d: %s\n"), num_layers,
-	    layer_name);
-    fflush(stdout);
-    
-    return;
-}

Modified: grass/trunk/vector/v.in.dxf/main.c
===================================================================
--- grass/trunk/vector/v.in.dxf/main.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/main.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -15,34 +15,30 @@
  *               Rewrite for GRASS 6:
  *               Huidae Cho <grass4u gmail.com>
  *
+ *               Enhancements:
+ *               Benjamin Ducke <benjamin.ducke at oadigital.net>
+ *
  * PURPOSE:      Import DXF file
  *
- * COPYRIGHT:    (C) 1999-2006 by the GRASS Development Team
+ * COPYRIGHT:    (C) 1999-2009 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
  *               License (>=v2). Read the file COPYING that comes with GRASS
  *               for details.
  */
 
+#define _MAIN_C_
 #include <stdlib.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
 #include "global.h"
 
-int flag_list, flag_extent, flag_table, flag_topo, flag_invert,
-    flag_one_layer, flag_frame;
-int num_layers, found_layers;
-char **layers;
-char dxf_buf[DXF_BUF_SIZE], entity[DXF_BUF_SIZE];
-int ARR_MAX;
-double *xpnts, *ypnts, *zpnts;
-struct line_pnts *Points;
-
 int main(int argc, char *argv[])
 {
     struct dxf_file *dxf;
     struct Map_info *Map;
-    char *output = NULL;
+    char *output;
+    int ret;
 
     struct GModule *module;
     struct
@@ -112,7 +108,7 @@
     opt.layers->type = TYPE_STRING;
     opt.layers->required = NO;
     opt.layers->multiple = YES;
-    opt.layers->description = _("List of layers to import");
+    opt.layers->description = _("List of layers to import (default: all)");
     opt.layers->guisection = _("DXF layers");
 
     if (G_parser(argc, argv))
@@ -124,22 +120,27 @@
     flag_invert = flag.invert->answer;
     flag_one_layer = flag.one_layer->answer;
     flag_frame = flag.frame->answer;
+    opt_layers = opt.layers->answers;
 
+    if (flag_invert && !opt_layers)
+        G_fatal_error(_("Please specify list of layers to exclude"));
+
     /* open DXF file */
     if (!(dxf = dxf_open(opt.input->answer)))
 	G_fatal_error(_("Unable to open DXF file <%s>"), opt.input->answer);
 
-    if (flag_list) {
-	num_layers = 0;
-	layers = NULL;
-	Map = NULL;
+    if (flag_list)
 	G_verbose_message(_("Layer number: layer name / GRASS compliant name"));
-    }
     else {
-	output = G_store(opt.output->answer);
+	int i;
 
-	layers = opt.layers->answers;
+	if (opt_layers){
+	    for(i=0; opt_layers[i]; i++)
+		add_layer_to_list(opt_layers[i], 0);
+	}
 
+	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)
@@ -151,7 +152,7 @@
     }
 
     /* import */
-    dxf_to_vect(dxf, Map);
+    ret = dxf_to_vect(dxf, Map);
 
     dxf_close(dxf);
 
@@ -160,7 +161,7 @@
     else {
 	Vect_close(Map);
 
-	if (found_layers) {
+	if (ret) {
 	    if (Vect_open_old(Map, output, G_mapset())) {
 		if (!flag_topo)
 		    if (!Vect_build(Map))
@@ -173,7 +174,6 @@
 	    G_fatal_error(_("Failed to import DXF file!"));
 	}
 
-	G_free(output);
 	G_free(Map);
     }
 

Modified: grass/trunk/vector/v.in.dxf/make_arc.c
===================================================================
--- grass/trunk/vector/v.in.dxf/make_arc.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/make_arc.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -32,11 +32,11 @@
 	    ypnts[arr_size] = radius * sin(alpha) + centery;
 	    zpnts[arr_size] = zcoor;
 	    theta -= RSTEP;
-	    if (arr_size == ARR_MAX) {
-		ARR_MAX += ARR_INCR;
-		xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
-		ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
-		zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
+	    if (arr_size == arr_max) {
+		arr_max += ARR_INCR;
+		xpnts = (double *)G_realloc(xpnts, arr_max * sizeof(double));
+		ypnts = (double *)G_realloc(ypnts, arr_max * sizeof(double));
+		zpnts = (double *)G_realloc(zpnts, arr_max * sizeof(double));
 	    }
 	    arr_size++;
 	}
@@ -49,11 +49,11 @@
 	    ypnts[arr_size] = radius * sin(alpha) + centery;
 	    zpnts[arr_size] = zcoor;
 	    theta += RSTEP;
-	    if (arr_size == ARR_MAX) {
-		ARR_MAX += ARR_INCR;
-		xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
-		ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
-		zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
+	    if (arr_size == arr_max) {
+		arr_max += ARR_INCR;
+		xpnts = (double *)G_realloc(xpnts, arr_max * sizeof(double));
+		ypnts = (double *)G_realloc(ypnts, arr_max * sizeof(double));
+		zpnts = (double *)G_realloc(zpnts, arr_max * sizeof(double));
 	    }
 	    arr_size++;
 	}
@@ -63,11 +63,11 @@
     xpnts[arr_size] = radius * cos(alpha) + centerx;
     ypnts[arr_size] = radius * sin(alpha) + centery;
     zpnts[arr_size] = zcoor;
-    if (arr_size == ARR_MAX) {
-	ARR_MAX += ARR_INCR;
-	xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
-	ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
-	zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
+    if (arr_size == arr_max) {
+	arr_max += ARR_INCR;
+	xpnts = (double *)G_realloc(xpnts, arr_max * sizeof(double));
+	ypnts = (double *)G_realloc(ypnts, arr_max * sizeof(double));
+	zpnts = (double *)G_realloc(zpnts, arr_max * sizeof(double));
     }
     arr_size++;
 
@@ -88,11 +88,11 @@
 	arc_tan = (-1.0) * prev_bulge;
 
     if (arc_tan == 0.0) {	/* straight line segment */
-	if (arr_size >= ARR_MAX - 1) {
-	    ARR_MAX += ARR_INCR;
-	    xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
-	    ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
-	    zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
+	if (arr_size >= arr_max - 1) {
+	    arr_max += ARR_INCR;
+	    xpnts = (double *)G_realloc(xpnts, arr_max * sizeof(double));
+	    ypnts = (double *)G_realloc(ypnts, arr_max * sizeof(double));
+	    zpnts = (double *)G_realloc(zpnts, arr_max * sizeof(double));
 	}
 	arr_size++;
     }
@@ -161,11 +161,11 @@
 	    arc_arr_size = make_arc(arr_size, cent_x, cent_y,
 				    rad, ang1, ang2, zpnts[0]);
 	arr_size += arc_arr_size;
-	while (arr_size >= ARR_MAX) {
-	    ARR_MAX += ARR_INCR;
-	    xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
-	    ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
-	    zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
+	while (arr_size >= arr_max) {
+	    arr_max += ARR_INCR;
+	    xpnts = (double *)G_realloc(xpnts, arr_max * sizeof(double));
+	    ypnts = (double *)G_realloc(ypnts, arr_max * sizeof(double));
+	    zpnts = (double *)G_realloc(zpnts, arr_max * sizeof(double));
 	}
     }				/* arc */
 

Modified: grass/trunk/vector/v.in.dxf/v.in.dxf.html
===================================================================
--- grass/trunk/vector/v.in.dxf/v.in.dxf.html	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/v.in.dxf.html	2009-04-10 08:04:56 UTC (rev 36667)
@@ -1,6 +1,7 @@
 <h2>DESCRIPTION</h2>
 
-Standard DXF is imported. The following graphical objects are supported:
+Converts DXF format CAD files to GRASS vector format. The following graphical
+objects (DXF entities) are supported:
 
 <ul>
 <li>GRASS point type:</li>
@@ -23,13 +24,25 @@
  </ul></li>
 </ul>
 
-Capital column names are changed to lowercase characters as for easier
-SQL usage (lowercase column names avoid the need to quote them if the
-attribute table is stored in a SQL DBMS such as PostgreSQL).
+Table and column names are changed to lowercase characters for easier SQL usage
+(lowercase table/column names avoid the need to quote them if the attribute
+table is stored in a SQL DBMS such as PostgreSQL).<p>
 
+The "layer" column will contain the name(s) of the DXF input layer(s). The DXF
+entity type string will be stored in the "entity" column as uppercase.<p>
+
+The "handle" column can be used to store small bits of data associated with any
+entity in the DXF file (i.e., entity handle or unique object identifiers in the
+layer). The entity handle is a "text string of up to 16 hexadecimal digits",
+which is a 64-bit integer (currently not supported by GRASS database drivers).
+For text type entities, the text value will be stored in the "label" column of
+the GRASS vector output map. Neither the "handle" nor "label" column is
+mandatory.
+
 <H2>REFERENCES</H2>
 
-<a href="http://en.wikipedia.org/wiki/AutoCAD_DXF">AutoCad DXF</a> (from Wikipedia, the free encyclopedia)
+<a href="http://en.wikipedia.org/wiki/AutoCAD_DXF">AutoCad DXF</a> (from Wikipedia, the free encyclopedia)<br>
+<a href="http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12272454&linkID=10809853">DXF References</a> (Autodesk-supplied documentation)
 
 <H2>SEE ALSO</H2>
 
@@ -43,6 +56,7 @@
 Revised by Dave Gerdes, 12/1989<BR>
 US Army Construction Engineering Research Lab
 <P>
-Updated for GRASS 6 and 3D support. Huidae Cho, 3/2006
+Updated for GRASS 6 and 3D support. Huidae Cho, 3/2006<BR>
+With minor additions by Benjamin Ducke (Oxford Archaeology), 4/2009
 
 <P><I>Last changed: $Date$</I>

Modified: grass/trunk/vector/v.in.dxf/write_vect.c
===================================================================
--- grass/trunk/vector/v.in.dxf/write_vect.c	2009-04-10 02:35:24 UTC (rev 36666)
+++ grass/trunk/vector/v.in.dxf/write_vect.c	2009-04-10 08:04:56 UTC (rev 36667)
@@ -11,8 +11,8 @@
 static dbString sql, str;
 static char buf[1000];
 
-void write_vect(struct Map_info *Map, char *layer, char *entity, char *label,
-		int arr_size, int type)
+void write_vect(struct Map_info *Map, char *layer, char *entity, char *handle,
+		char *label, int arr_size, int type)
 {
     struct line_cats *Cats;
     int i, field, cat;
@@ -30,6 +30,7 @@
 	sprintf(buf, "insert into %s (%s"
 		", layer"
 		", entity"
+		", handle"
 		", label" ") values (%d, '", Fi[i]->table, Fi[i]->key, cat);
 
 	if (layer) {
@@ -46,6 +47,17 @@
 	}
 	strcat(buf, "', '");
 
+	if (handle) {
+	    if (strlen(handle) > 16) {
+		    G_warning(_("Entity handle truncated to 16 characters."));
+		    handle[16] = 0;
+	    }
+	    db_set_string(&str, handle);
+	    db_double_quote_string(&str);
+	    strcat(buf, db_get_string(&str));
+	}
+	strcat(buf, "', '");
+
 	if (label) {
 	    db_set_string(&str, label);
 	    db_double_quote_string(&str);
@@ -71,13 +83,13 @@
     return;
 }
 
-void write_done(struct Map_info *Map)
+int write_done(struct Map_info *Map)
 {
     int i;
 
-    if (!(found_layers = (num_fields > 0))) {
+    if (!num_fields) {
 	G_warning(_("No DXF layers found!"));
-	return;
+	return 0;
     }
 
     if (!flag_table) {
@@ -116,7 +128,7 @@
 	driver = NULL;
     }
 
-    return;
+    return 1;
 }
 
 static int get_field_cat(struct Map_info *Map, char *layer, int *field,
@@ -211,6 +223,7 @@
     sprintf(buf, "create table %s (cat integer"
 	    ", layer varchar(%d)"
 	    ", entity varchar(%d)"
+	    ", handle varchar(16)"
 	    ", label varchar(%d)"
 	    ")", Fi[i]->table, DXF_BUF_SIZE, DXF_BUF_SIZE, DXF_BUF_SIZE);
     db_set_string(&sql, buf);



More information about the grass-commit mailing list