]> pd.if.org Git - zpackage/blob - zpm-quote.c
add zpm program to quote strings for sqlite
[zpackage] / zpm-quote.c
1 #include <stdlib.h>
2
3 #include "zpm.h"
4
5 /* for quoting against the shell replace ' with '\'' and surround with
6  * single quotes
7  */
8 int main(int ac, char **av) {
9         size_t n = 0;
10         size_t bufsize = 0;
11         char *buffer = 0;
12         int i;
13
14         for (i=1;i<ac;i++) {
15                 n = zpm_quote(av[i], 0, 0);
16                 if (n+1 > bufsize) {
17                         buffer = realloc(buffer, n+1);
18                         if (buffer) {
19                                 bufsize = n+1;
20                         } else {
21                                 exit(EXIT_FAILURE);
22                         }
23                 }
24                 zpm_quote(av[i], buffer, bufsize);
25                 printf("%s\n", buffer);
26         }
27         return 0;
28 }