[GRASS-SVN] r61534 - in grass/branches/releasebranch_7_0: . vector/v.distance

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 5 12:45:28 PDT 2014


Author: neteler
Date: 2014-08-05 12:45:28 -0700 (Tue, 05 Aug 2014)
New Revision: 61534

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/vector/v.distance/local_proto.h
   grass/branches/releasebranch_7_0/vector/v.distance/main.c
   grass/branches/releasebranch_7_0/vector/v.distance/print.c
Log:
v.distance: Added separator= for -p (trunk, r60986)


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Added: svn:mergeinfo
   + /grass/trunk:60986

Modified: grass/branches/releasebranch_7_0/vector/v.distance/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.distance/local_proto.h	2014-08-05 18:48:33 UTC (rev 61533)
+++ grass/branches/releasebranch_7_0/vector/v.distance/local_proto.h	2014-08-05 19:45:28 UTC (rev 61534)
@@ -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/branches/releasebranch_7_0/vector/v.distance/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.distance/main.c	2014-08-05 18:48:33 UTC (rev 61533)
+++ grass/branches/releasebranch_7_0/vector/v.distance/main.c	2014-08-05 19:45:28 UTC (rev 61534)
@@ -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);
     Vect_open_old2(&From, opt.from->answer, G_mapset(), opt.from_field->answer);
@@ -1244,10 +1251,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");
@@ -1357,14 +1364,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");
 		}
@@ -1372,8 +1379,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/branches/releasebranch_7_0/vector/v.distance/print.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.distance/print.c	2014-08-05 18:48:33 UTC (rev 61533)
+++ grass/branches/releasebranch_7_0/vector/v.distance/print.c	2014-08-05 19:45:28 UTC (rev 61534)
@@ -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