Prechádzať zdrojové kódy

d.colorlist: fix separator handling

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@63192 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 10 rokov pred
rodič
commit
cfc312b7e0
1 zmenil súbory, kde vykonal 13 pridanie a 11 odobranie
  1. 13 11
      display/d.colorlist/main.c

+ 13 - 11
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 */
@@ -40,21 +40,23 @@ int main(int argc, char **argv)
 
     /* set up option */
     sep = G_define_standard_option(G_OPT_F_SEP);
-    sep->key = "separator";
-    sep->description = "Character for separation of list items";
-
+    
     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);
 }