[GRASS-SVN] r38609 - grass/branches/develbranch_6/vector/v.db.select

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 3 16:10:15 EDT 2009


Author: martinl
Date: 2009-08-03 16:10:15 -0400 (Mon, 03 Aug 2009)
New Revision: 38609

Modified:
   grass/branches/develbranch_6/vector/v.db.select/main.c
Log:
v.db.select: output to file (trac #710, patch by mlennert)
	     (merge from trunk, r38606)


Modified: grass/branches/develbranch_6/vector/v.db.select/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.db.select/main.c	2009-08-03 20:01:33 UTC (rev 38608)
+++ grass/branches/develbranch_6/vector/v.db.select/main.c	2009-08-03 20:10:15 UTC (rev 38609)
@@ -7,7 +7,7 @@
  *               
  * PURPOSE:      Print vector attributes
  *               
- * COPYRIGHT:    (C) 2005-2007 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2005-2009 by the GRASS Development Team
  *
  *               This program is free software under the 
  *               GNU General Public License (>=v2). 
@@ -15,22 +15,23 @@
  *               for details.
  *
  **************************************************************/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <math.h>
+
 #include <grass/glocale.h>
 #include <grass/gis.h>
 #include <grass/Vect.h>
 #include <grass/dbmi.h>
 
-
 int main(int argc, char **argv)
 {
     struct GModule *module;
     struct Option *map_opt, *field_opt, *fs_opt, *vs_opt, *nv_opt, *col_opt,
-	*where_opt;
+	*where_opt, *file_opt;
     struct Flag *c_flag, *v_flag, *r_flag;
     dbDriver *driver;
     dbString sql, value_string;
@@ -76,6 +77,12 @@
     nv_opt->description = _("Null value indicator");
     nv_opt->guisection = _("Format");
 
+    file_opt = G_define_standard_option(G_OPT_F_OUTPUT); 
+    file_opt->key = "file";
+    file_opt->required = NO; 
+    file_opt->description = 
+	_("Name for output file (if omitted or \"-\" output to stdout)"); 
+    
     r_flag = G_define_flag();
     r_flag->key = 'r';
     r_flag->description =
@@ -99,6 +106,12 @@
     /* set input vector map name and mapset */
     field = atoi(field_opt->answer);
 
+    if (file_opt->answer && strcmp(file_opt->answer, "-") != 0) { 
+	if (NULL == freopen(file_opt->answer, "w", stdout)) { 
+	    G_fatal_error(_("Unable to open file <%s> for writing"), file_opt->answer); 
+	} 
+    } 
+    
     if (r_flag->answer) {
 	min_box = (BOUND_BOX *) G_malloc(sizeof(BOUND_BOX));
 	G_zero((void *)min_box, sizeof(BOUND_BOX));



More information about the grass-commit mailing list