[GRASS-SVN] r60986 - grass/trunk/vector/v.distance

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 26 10:27:14 PDT 2014


Author: hcho
Date: 2014-06-26 10:27:14 -0700 (Thu, 26 Jun 2014)
New Revision: 60986

Modified:
   grass/trunk/vector/v.distance/local_proto.h
   grass/trunk/vector/v.distance/main.c
   grass/trunk/vector/v.distance/print.c
Log:
v.distance: Added separator= for -p

Modified: grass/trunk/vector/v.distance/local_proto.h
===================================================================
--- grass/trunk/vector/v.distance/local_proto.h	2014-06-26 16:36:21 UTC (rev 60985)
+++ grass/trunk/vector/v.distance/local_proto.h	2014-06-26 17:27:14 UTC (rev 60986)
@@ -64,4 +64,4 @@
 	      int geodesic);
 
 /* print.c */
-int print_upload(NEAR *, UPLOAD *, int, dbCatValArray *, dbCatVal *);
+int print_upload(NEAR *, UPLOAD *, int, dbCatValArray *, dbCatVal *, char *);

Modified: grass/trunk/vector/v.distance/main.c
===================================================================
--- grass/trunk/vector/v.distance/main.c	2014-06-26 16:36:21 UTC (rev 60985)
+++ grass/trunk/vector/v.distance/main.c	2014-06-26 17:27:14 UTC (rev 60986)
@@ -44,6 +44,7 @@
 	    *from_field, *to_field;
 	struct Option *out, *max, *min, *table;
 	struct Option *upload, *column, *to_column;
+	struct Option *sep;
     } opt;
     struct {
 	struct Flag *print, *all;
@@ -76,6 +77,7 @@
     struct bound_box fbox, box;
     dbCatValArray cvarr;
     dbColumn *column;
+    char *sep;
 
     do_all = FALSE;
     print_as_matrix = FALSE;
@@ -198,6 +200,9 @@
     opt.table->description =
 	_("Name of table created when the 'distance to all' flag is used");
 
+    opt.sep = G_define_standard_option(G_OPT_F_SEP);
+    opt.sep->label = _("Field separator for printing output to stdout");
+
     flag.print = G_define_flag();
     flag.print->key = 'p';
     flag.print->label =
@@ -286,6 +291,8 @@
     if (Upload[i].upload != END)
 	G_fatal_error(_("Not enough column names"));
 
+    sep = G_option_to_separator(opt.sep);
+
     /* Open 'from' vector */
     Vect_set_open_level(2);
     if (Vect_open_old2(&From, opt.from->answer, G_mapset(), opt.from_field->answer) < 0)
@@ -1249,10 +1256,10 @@
     if (flag.print->answer) {	/* print header */
 	fprintf(stdout, "from_cat");
 	if (do_all)
-	    fprintf(stdout, "|to_cat");
+	    fprintf(stdout, "%sto_cat", sep);
 	i = 0;
 	while (Upload[i].upload != END) {
-	    fprintf(stdout, "|%s", Upload[i].column);
+	    fprintf(stdout, "%s%s", sep, Upload[i].column);
 	    i++;
 	}
 	fprintf(stdout, "\n");
@@ -1362,14 +1369,14 @@
 		    for (j = 0; j < nfrom; j++) {
 			if (j == 0)
 			    fprintf(stdout, " ");
-			fprintf(stdout, "|%d", Near[j].to_cat);
+			fprintf(stdout, "%s%d", sep, Near[j].to_cat);
 		    }
 		    fprintf(stdout, "\n");
 		}
 		if (i % nfrom == 0) {
 		    fprintf(stdout, "%d", Near[i].from_cat);
 		    for (j = 0; j < nfrom; j++) {
-			print_upload(Near, Upload, i + j, &cvarr, catval);
+			print_upload(Near, Upload, i + j, &cvarr, catval, sep);
 		    }
 		    fprintf(stdout, "\n");
 		}
@@ -1377,8 +1384,8 @@
 	    else {
 		fprintf(stdout, "%d", Near[i].from_cat);
 		if (do_all)
-		    fprintf(stdout, "|%d", Near[i].to_cat);
-		print_upload(Near, Upload, i, &cvarr, catval);
+		    fprintf(stdout, "%s%d", sep, Near[i].to_cat);
+		print_upload(Near, Upload, i, &cvarr, catval, sep);
 		fprintf(stdout, "\n");
 	    }
 	}

Modified: grass/trunk/vector/v.distance/print.c
===================================================================
--- grass/trunk/vector/v.distance/print.c	2014-06-26 16:36:21 UTC (rev 60985)
+++ grass/trunk/vector/v.distance/print.c	2014-06-26 17:27:14 UTC (rev 60986)
@@ -4,70 +4,70 @@
    print out upload values 
  */
 int print_upload(NEAR * Near, UPLOAD * Upload, int i,
-		 dbCatValArray * cvarr, dbCatVal * catval)
+		 dbCatValArray * cvarr, dbCatVal * catval, char *sep)
 {
     int j;
 
     j = 0;
     while (Upload[j].upload != END) {
 	if (Near[i].count == 0) {	/* no nearest found */
-	    fprintf(stdout, "|null");
+	    fprintf(stdout, "%snull", sep);
 	}
 	else {
 	    switch (Upload[j].upload) {
 	    case CAT:
 		if (Near[i].to_cat >= 0)
-		    fprintf(stdout, "|%d", Near[i].to_cat);
+		    fprintf(stdout, "%s%d", sep, Near[i].to_cat);
 		else
-		    fprintf(stdout, "|null");
+		    fprintf(stdout, "%snull", sep);
 		break;
 	    case DIST:
-		fprintf(stdout, "|%.17g", Near[i].dist);
+		fprintf(stdout, "%s%.17g", sep, Near[i].dist);
 		break;
 	    case FROM_X:
-		fprintf(stdout, "|%.17g", Near[i].from_x);
+		fprintf(stdout, "%s%.17g", sep, Near[i].from_x);
 		break;
 	    case FROM_Y:
-		fprintf(stdout, "|%.17g", Near[i].from_y);
+		fprintf(stdout, "%s%.17g", sep, Near[i].from_y);
 		break;
 	    case TO_X:
-		fprintf(stdout, "|%.17g", Near[i].to_x);
+		fprintf(stdout, "%s%.17g", sep, Near[i].to_x);
 		break;
 	    case TO_Y:
-		fprintf(stdout, "|%.17g", Near[i].to_y);
+		fprintf(stdout, "%s%.17g", sep, Near[i].to_y);
 		break;
 	    case FROM_ALONG:
-		fprintf(stdout, "|%.17g", Near[i].from_along);
+		fprintf(stdout, "%s%.17g", sep, Near[i].from_along);
 		break;
 	    case TO_ALONG:
-		fprintf(stdout, "|%.17g", Near[i].to_along);
+		fprintf(stdout, "%s%.17g", sep, Near[i].to_along);
 		break;
 	    case TO_ANGLE:
-		fprintf(stdout, "|%f", Near[i].to_angle);
+		fprintf(stdout, "%s%f", sep, Near[i].to_angle);
 		break;
 	    case TO_ATTR:
 		if (catval) {
 		    switch (cvarr->ctype) {
 		    case DB_C_TYPE_INT:
-			fprintf(stdout, "|%d", catval->val.i);
+			fprintf(stdout, "%s%d", sep, catval->val.i);
 			break;
 
 		    case DB_C_TYPE_DOUBLE:
-			fprintf(stdout, "|%.17g", catval->val.d);
+			fprintf(stdout, "%s%.17g", sep, catval->val.d);
 			break;
 
 		    case DB_C_TYPE_STRING:
-			fprintf(stdout, "|%s", db_get_string(catval->val.s));
+			fprintf(stdout, "%s%s", sep, db_get_string(catval->val.s));
 			break;
 
 		    case DB_C_TYPE_DATETIME:
 			/* TODO: formating datetime */
-			fprintf(stdout, "|");
+			fprintf(stdout, "%s", sep);
 			break;
 		    }
 		}
 		else {
-		    fprintf(stdout, "|null");
+		    fprintf(stdout, "%snull", sep);
 		}
 		break;
 	    }



More information about the grass-commit mailing list