[GRASS-SVN] r57679 - grass/branches/releasebranch_6_4/general/g.setproj

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Sep 13 22:28:55 PDT 2013


Author: hamish
Date: 2013-09-13 22:28:55 -0700 (Fri, 13 Sep 2013)
New Revision: 57679

Modified:
   grass/branches/releasebranch_6_4/general/g.setproj/main.c
Log:
options to read and reset the location's one line description (merge from devbr6 r56961, wish #2018)

Modified: grass/branches/releasebranch_6_4/general/g.setproj/main.c
===================================================================
--- grass/branches/releasebranch_6_4/general/g.setproj/main.c	2013-09-14 05:17:25 UTC (rev 57678)
+++ grass/branches/releasebranch_6_4/general/g.setproj/main.c	2013-09-14 05:28:55 UTC (rev 57679)
@@ -57,21 +57,24 @@
     int stat;
     char cmnd2[500];
     char proj_out[20], proj_name[50], set_name[20];
-    char path[1024], buffa[1024], buffb[1024], answer[200], answer1[200];
+    char path[GPATH_MAX], buffa[1024], buffb[1024], answer[200], answer1[200];
     char answer2[200], buff[1024];
     char tmp_buff[20], *buf;
 
     struct Key_Value *old_proj_keys, *out_proj_keys, *in_unit_keys;
     double aa, e2;
     double f;
-    FILE *FPROJ;
+    FILE *FPROJ, *fp;
     int exist = 0;
     char spheroid[100];
     int j, k, sph_check;
     struct Cell_head cellhd;
     char datum[100], dat_ellps[100], dat_params[100];
     struct proj_parm *proj_parms;
+    struct Option *set_myname;
+    struct Flag *print_myname;
 
+
     G_gisinit(argv[0]);
 
     module = G_define_module();
@@ -79,15 +82,45 @@
     module->description =
 	_("Interactively reset the location's projection settings.");
 
+    set_myname = G_define_option();
+    set_myname->key = "description";
+    set_myname->key_desc = "\"phrase\"";
+    set_myname->type = TYPE_STRING;
+    set_myname->required = NO;
+    set_myname->description =
+	_("Reset the location's one line description with this text, then exit");
+
+    print_myname = G_define_flag();
+    print_myname->key = 'n';
+    print_myname->description =
+        _("Print the location's one line description and exit");
+
     if (argc > 1 && G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
 
+    if (print_myname->answer) {
+	fprintf(stdout, "%s\n", G_myname());
+	exit(EXIT_SUCCESS);
+    }
+
     if (strcmp(G_mapset(), "PERMANENT") != 0)
 	G_fatal_error(_("You must be in the PERMANENT mapset to run g.setproj"));
 
+    if (set_myname->answer) {
+	fp = G_fopen_new(".", "MYNAME");
+	if (strlen(set_myname->answer) > RECORD_LEN-1)
+	    G_warning(_("Text shortened to first %d characters"), RECORD_LEN-1);
+	strncpy(buffa, set_myname->answer, RECORD_LEN-1);
+	buffa[RECORD_LEN-1] = '\0';
+	G_squeeze(buffa);
+	fputs(buffa, fp);
+	fclose(fp);
+	exit(EXIT_SUCCESS);
+    }
+
 	/***
-         * no longer necessary, table is a static struct 
+	  * no longer necessary, table is a static struct
 	 * init_unit_table();
         ***/
     sprintf(set_name, "PERMANENT");
@@ -246,7 +279,7 @@
     }
     else {
 
-/*****************   GET spheroid  **************************/
+	/*****************   GET spheroid  **************************/
 
 	if (Out_proj != PROJECTION_SP) {	/* some projections have 
 						 * fixed spheroids */
@@ -318,7 +351,7 @@
 		    radius =
 			prompt_num_double(_("Enter radius for the sphere in meters"),
 					  RADIUS_DEF, 1);
-	    }			/* end ask radius */
+	    }	/* end ask radius */
 	}
     }
 
@@ -486,7 +519,7 @@
 		    G_set_key_value(desc->key, tmp_buff, out_proj_keys);
 		}
 	    }
-	}			/* for OPTIONS */
+	}	/* for OPTIONS */
     }
 
     /* create the PROJ_INFO & PROJ_UNITS files, if required */



More information about the grass-commit mailing list