[GRASS-SVN] r34913 - grass/branches/develbranch_6/general/g.gisenv

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Dec 16 09:33:27 EST 2008


Author: martinl
Date: 2008-12-16 09:33:27 -0500 (Tue, 16 Dec 2008)
New Revision: 34913

Modified:
   grass/branches/develbranch_6/general/g.gisenv/main.c
Log:
g.gisenv: -s/n flags added (merge from trunk)


Modified: grass/branches/develbranch_6/general/g.gisenv/main.c
===================================================================
--- grass/branches/develbranch_6/general/g.gisenv/main.c	2008-12-16 14:21:41 UTC (rev 34912)
+++ grass/branches/develbranch_6/general/g.gisenv/main.c	2008-12-16 14:33:27 UTC (rev 34913)
@@ -25,9 +25,10 @@
 int main(int argc, char *argv[])
 {
     int n, store;
-    int tty;
-    char *name, *value, *ptr;
+    const char *name, *value;
+    char *ptr;
     struct Option *get, *set, *store_opt;
+    struct Flag *flag_s, *flag_n;
     struct GModule *module;
 
     G_set_program_name(argv[0]);
@@ -60,15 +61,34 @@
     store_opt->description = _("Where GRASS variable is stored");
     store_opt->required = NO;
 
+    flag_s = G_define_flag();
+    flag_s->key = 's';
+    flag_s->description = _("Use shell syntax (for \"eval\")");
+
+    flag_n = G_define_flag();
+    flag_n->key = 'n';
+    flag_n->description = _("Don't use shell syntax");
+
     if (argc > 1 && G_parser(argc, argv) < 0)
 	exit(EXIT_FAILURE);
 
+    if (flag_s->answer && flag_n->answer)
+	G_fatal_error(_("-s and -n are mutually exclusive"));
+
     /* Print or optionally set environment variables */
     if (!get->answer && !set->answer) {
-	tty = isatty(1);
 	for (n = 0; (name = G__env_name(n)); n++) {
+	    int quote;
+
+	    if (flag_s->answer)
+		quote = 1;
+	    else if (flag_n->answer)
+		quote = 0;
+	    else
+		quote = !isatty(fileno(stdout));
+
 	    if ((value = G__getenv(name))) {
-		if (tty)
+		if (!quote)
 		    fprintf(stdout, "%s=%s\n", name, value);
 		else
 		    fprintf(stdout, "%s='%s';\n", name, value);



More information about the grass-commit mailing list