- zpm_quote(av[i], buffer, bufsize);
- printf("%s\n", buffer);
+
+ if (addquotes) {
+ *d++ = ch;
+ }
+ *d = 0;
+ }
+
+ return q;
+}
+
+int main(int ac, char **av) {
+ char *quoted;
+ int i;
+ int ch = '\'';
+ int opt, shellmode = 0, addquotes = 0, ident = 0;
+ char *repl = "''";
+
+ while ((opt = getopt(ac, av, "sqi")) != -1) {
+ switch (opt) {
+ case 's': shellmode = 1; break;
+ case 'q': addquotes = 1; break;
+ case 'i': ident = 1; break;
+ default:
+ exit(EXIT_FAILURE);
+ break;
+ }
+ }
+ int argn = optind;
+
+ if (shellmode) {
+ repl = "'\\''";
+ } else if (ident) {
+ ch = '"';
+ repl = "\"\"";
+ }
+
+ for (i=argn;i<ac;i++) {
+ quoted = quote(av[i], ch, repl, addquotes);
+ printf("%s\n", quoted);