[GRASS-SVN] r40331 - grass/branches/develbranch_6/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 8 23:04:57 EST 2010


Author: hamish
Date: 2010-01-08 23:04:57 -0500 (Fri, 08 Jan 2010)
New Revision: 40331

Modified:
   grass/branches/develbranch_6/lib/vector/Vlib/field.c
Log:
deal with spaces in pathnames better (trac #809)

Modified: grass/branches/develbranch_6/lib/vector/Vlib/field.c
===================================================================
--- grass/branches/develbranch_6/lib/vector/Vlib/field.c	2010-01-09 03:41:20 UTC (rev 40330)
+++ grass/branches/develbranch_6/lib/vector/Vlib/field.c	2010-01-09 04:04:57 UTC (rev 40331)
@@ -430,7 +430,6 @@
  */
 int Vect_read_dblinks(struct Map_info *Map)
 {
-    int ndef;
     FILE *fd;
     char file[1024], buf[2001];
     char tab[1024], col[1024], db[1024], drv[1024], fldstr[1024], *fldname;
@@ -438,6 +437,8 @@
     char *c;
     int row, rule;
     struct dblinks *dbl;
+    char **tokens;
+    int ntok, i;
 
     G_debug(1, "Vect_read_dblinks(): map = %s, mapset = %s", Map->name,
 	    Map->mapset);
@@ -630,14 +631,32 @@
 
 	if (strlen(buf) == 0)
 	    continue;
+ 
+	tokens = G_tokenize(buf, " ");
+	ntok = G_number_of_tokens(tokens);
 
-	ndef = sscanf(buf, "%s %s %s %s %s", fldstr, tab, col, db, drv);
-
-	if (ndef < 2 || (ndef < 5 && rule < 1)) {
+	if (ntok < 2 || (ntok < 5 && rule < 1)) {
 	    G_warning(_("Error in rule on row %d in %s"), row, file);
 	    continue;
 	}
 
+	strcpy(fldstr, tokens[0]);
+	strcpy(tab, tokens[1]);
+	if (ntok > 2) {
+	    strcpy(col, tokens[2]);
+	    if (ntok > 3) {
+		strcpy(db, tokens[3]);
+		/* allow for spaces in path names */
+		for (i=4; i < ntok-1; i++) {
+		    strcat(db, " ");
+		    strcat(db, tokens[i]);
+		}
+
+		strcpy(drv, tokens[ntok-1]);
+	    }
+	}
+	G_free_tokens(tokens);
+
 	/* get field and field name */
 	fldname = strchr(fldstr, '/');
 	if (fldname != NULL) {	/* field has name */



More information about the grass-commit mailing list