فهرست منبع

d.colorlist: fix separator handling
(merge r63192-3 from trunk)


git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@63197 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 10 سال پیش
والد
کامیت
4f0bdf6f9c
1فایلهای تغییر یافته به همراه16 افزوده شده و 13 حذف شده
  1. 16 13
      display/d.colorlist/main.c

+ 16 - 13
display/d.colorlist/main.c

@@ -25,7 +25,7 @@ int main(int argc, char **argv)
 {
     struct Option *sep;
     struct GModule *module;
-    char *colorlist;
+    char *colorlist, *sep_str;
     int i;
 
     /* Initialize the GIS calls */
@@ -34,27 +34,30 @@ int main(int argc, char **argv)
     module = G_define_module();
     G_add_keyword(_("display"));
     G_add_keyword(_("settings"));
+    G_add_keyword(_("colors"));
     module->description =
-	"Output a list of all available display colors with a configurable "
-	"separator (default is comma).";
+	_("Outputs a list of all available display colors.");
 
     /* set up option */
     sep = G_define_standard_option(G_OPT_F_SEP);
-    sep->key = "separator";
-    sep->description = "Character for separation of list items";
-
+    sep->answer = "comma";
+    
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+    sep_str = G_option_to_separator(sep);
+    
     colorlist = G_store(D_COLOR_LIST);
 
     /* if separator is different from ",", escape this character */
-    if (strcmp(sep->answer, ",") != 0 && strlen(sep->answer) > 0) {
-	for (i = 0; colorlist[i] != '\0'; i++)
-	    if (colorlist[i] == ',')
-		colorlist[i] = (char)sep->answer[0];
+    for (i = 0; colorlist[i] != '\0'; i++) {
+        if (colorlist[i] == ',') {
+            fprintf(stdout, "%s", sep_str);
+            continue;
+        }
+        fprintf(stdout, "%c", colorlist[i]);
     }
-
-    fprintf(stdout, "%s\n", colorlist);
-    return 0;
+    fprintf(stdout, "\n");
+    
+    exit(EXIT_SUCCESS);
 }