]> pd.if.org Git - zpackage/commitdiff
add option to quote multiple values at once
authorNathan Wagner <nw@hydaspes.if.org>
Wed, 5 Dec 2018 16:42:30 +0000 (16:42 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Wed, 5 Dec 2018 16:42:30 +0000 (16:42 +0000)
zpm-quote.c

index 1aea24b4dbb0811a769b0e37f9c0b1ea005459be..d0006e391a9beeade7a49e6dc4567dbe9c74dacb 100644 (file)
@@ -65,12 +65,15 @@ int main(int ac, char **av) {
        int ch = '\'';
        int opt, shellmode = 0, addquotes = 0, ident = 0;
        char *repl = "''";
+       int count = 0;
+       char *separator = "\n";
 
-       while ((opt = getopt(ac, av, "sqi")) != -1) {
+       while ((opt = getopt(ac, av, "sqid:")) != -1) {
                switch (opt) {
                        case 's': shellmode = 1; break;
                        case 'q': addquotes = 1; break;
                        case 'i': ident = 1; break;
+                       case 'd': separator = optarg; break;
                        default:
                                  exit(EXIT_FAILURE);
                                  break;
@@ -85,10 +88,13 @@ int main(int ac, char **av) {
                repl = "\"\"";
        }
 
+       count = 0;
        for (i=argn;i<ac;i++) {
                quoted = quote(av[i], ch, repl, addquotes);
-               printf("%s\n", quoted);
+               printf("%s%s", count > 0 ? separator : "", quoted);
                free(quoted);
+               count++;
        }
+       printf("\n");
        return 0;
 }