[GRASS-SVN] r63581 - grass/trunk/vector/v.in.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 18 00:28:20 PST 2014


Author: mmetz
Date: 2014-12-18 00:28:20 -0800 (Thu, 18 Dec 2014)
New Revision: 63581

Modified:
   grass/trunk/vector/v.in.ascii/local_proto.h
   grass/trunk/vector/v.in.ascii/main.c
   grass/trunk/vector/v.in.ascii/points.c
Log:
v.in.ascii: add text delimiter

Modified: grass/trunk/vector/v.in.ascii/local_proto.h
===================================================================
--- grass/trunk/vector/v.in.ascii/local_proto.h	2014-12-17 15:48:26 UTC (rev 63580)
+++ grass/trunk/vector/v.in.ascii/local_proto.h	2014-12-18 08:28:20 UTC (rev 63581)
@@ -5,10 +5,10 @@
 #include <grass/gis.h>
 #include <grass/dbmi.h>
 
-int points_analyse(FILE *, FILE *, char *, int *, int *, int *, int *, int **,
+int points_analyse(FILE *, FILE *, char *, char *, int *, int *, int *, int *, int **,
 		   int **, int, int, int, int, int, int, int);
 
 int points_to_bin(FILE *, int, struct Map_info *, dbDriver *,
-		  char *, char *, int, int *, int, int, int, int, int);
+		  char *, char *, char *, int, int *, int, int, int, int, int);
 
 #endif /* __LOCAL_PROTO_H__ */

Modified: grass/trunk/vector/v.in.ascii/main.c
===================================================================
--- grass/trunk/vector/v.in.ascii/main.c	2014-12-17 15:48:26 UTC (rev 63580)
+++ grass/trunk/vector/v.in.ascii/main.c	2014-12-18 08:28:20 UTC (rev 63581)
@@ -27,17 +27,36 @@
 
 #define	A_DIR	"dig_ascii"
 
+static char *get_td(const struct Option *option)
+{
+    char* sep;
+
+    if (option->answer == NULL)
+        return NULL;
+
+    if (strcmp(option->answer, "doublequote") == 0)
+        sep = G_store("\"");
+    else if (strcmp(option->answer, "singlequote") == 0)
+        sep = G_store("\'");
+    else
+        sep = G_store(option->answer);
+
+    return sep;
+}
+
+
 int main(int argc, char *argv[])
 {
     FILE *ascii;
     struct GModule *module;
-    struct Option *old, *new, *delim_opt, *columns_opt, *xcol_opt,
-	*ycol_opt, *zcol_opt, *catcol_opt, *format_opt, *skip_opt;
+    struct Option *old, *new, *delim_opt, *tdelim_opt, *columns_opt, 
+	          *xcol_opt, *ycol_opt, *zcol_opt, *catcol_opt,
+		  *format_opt, *skip_opt;
     int xcol, ycol, zcol, catcol, format, skip_lines;
     struct Flag *zcoorf, *t_flag, *e_flag, *noheader_flag, *notopol_flag,
 	*region_flag, *ignore_flag;
     char *table;
-    char *fs;
+    char *fs, *td;
     char *desc;
     int zcoor = WITHOUT_Z, make_table;
 
@@ -78,6 +97,13 @@
     delim_opt = G_define_standard_option(G_OPT_F_SEP);
     delim_opt->guisection = _("Input format");
     
+    tdelim_opt = G_define_standard_option(G_OPT_F_SEP);
+    tdelim_opt->key = "text";
+    tdelim_opt->label = "text delimiter";
+    tdelim_opt->answer = "doublequote";
+    tdelim_opt->description = _("Special characters: doublequote, singlequote");
+    tdelim_opt->guisection = _("Input format");
+
     skip_opt = G_define_option();
     skip_opt->key = "skip";
     skip_opt->type = TYPE_INTEGER;
@@ -210,6 +236,7 @@
 
     ascii = G_open_option_file(old);
     fs = G_option_to_separator(delim_opt);
+    td = get_td(tdelim_opt);
 
     /* check dimension */
     if (zcoorf->answer) {
@@ -245,7 +272,7 @@
 	}
 	unlink(tmp);
 
-	points_analyse(ascii, tmpascii, fs, &rowlen, &ncols, &minncols,
+	points_analyse(ascii, tmpascii, fs, td, &rowlen, &ncols, &minncols,
 		       &nrows, &coltype, &collen, skip_lines, xcol, ycol,
 		       zcol, catcol, region_flag->answer, ignore_flag->answer);
 
@@ -258,7 +285,7 @@
 	   G_message(_("Number of columns: %d"), ncols);
         }
 
-       G_message(_("Number of rows: %d"), nrows);
+        G_message(_("Number of rows: %d"), nrows);
         
 	/* check column numbers */
 	if (xcol >= minncols) {
@@ -501,7 +528,7 @@
 	    table = NULL;
 	}
 
-	points_to_bin(tmpascii, rowlen, &Map, driver, table, fs, nrows,
+	points_to_bin(tmpascii, rowlen, &Map, driver, table, fs, td, nrows,
 		      coltype2, xcol, ycol, zcol, catcol, skip_lines);
 
 	if (driver) {

Modified: grass/trunk/vector/v.in.ascii/points.c
===================================================================
--- grass/trunk/vector/v.in.ascii/points.c	2014-12-17 15:48:26 UTC (rev 63580)
+++ grass/trunk/vector/v.in.ascii/points.c	2014-12-18 08:28:20 UTC (rev 63581)
@@ -51,7 +51,7 @@
  * column_length: column lengths (string only)
  */
 
-int points_analyse(FILE * ascii_in, FILE * ascii, char *fs,
+int points_analyse(FILE * ascii_in, FILE * ascii, char *fs, char *td,
 		   int *rowlength, int *ncolumns, int *minncolumns,
 		   int *nrows, int **column_type, int **column_length,
 		   int skip_lines, int xcol, int ycol, int zcol, int catcol, 
@@ -118,7 +118,7 @@
 	/* no G_chop() as first/last column may be empty fs=tab value */
 	G_debug(3, "row %d : %d chars", row, (int)strlen(buf));
 
-	tokens = G_tokenize(buf, fs);
+	tokens = G_tokenize2(buf, fs, td);
 	ntokens = G_number_of_tokens(tokens);
 	if (ntokens == 0) {
 	    continue;
@@ -313,8 +313,8 @@
  * Note: column types (both in header or coldef) must be supported by driver
  */
 int points_to_bin(FILE * ascii, int rowlen, struct Map_info *Map,
-		  dbDriver * driver, char *table, char *fs, int nrows,
-		  int *coltype, int xcol, int ycol, int zcol,
+		  dbDriver * driver, char *table, char *fs, char *td,
+		  int nrows, int *coltype, int xcol, int ycol, int zcol,
 		  int catcol, int skip_lines)
 {
     char *buf, buf2[4000];
@@ -367,7 +367,7 @@
 
 	G_debug(4, "row: %s", buf);
 
-	tokens = G_tokenize(buf, fs);
+	tokens = G_tokenize2(buf, fs, td);
 	ntokens = G_number_of_tokens(tokens);
 
 	G_chop(tokens[xcol]);



More information about the grass-commit mailing list