On Thu, 9 Jun 2022, Valery Ushakov wrote:

Uhm, you cite "setvar" in your example, but the patch affects handling
of the "font" command, it seems.


You're right--my mistake. Both `setvar' and `font' need quoting.

Can't we just fix the font name in wsfont/bold16x32.h to be
Boldface-16x32? :) Avoids confusion in wsfontload -l output too.


Yes! I would prefer that.

So I'd rather we avoid it altogether and rewrite the loop to consume
all the arguments first, then use the

   set -- "$@" ...

idiom to construct the command line, something along the lines of:

   set -- "$@" ${enc:+ "-e" "$enc"}
   set -- "$@" ${name:+ "-N" "$name"}
   set -- "$@" ${file:+ "-f" "$file"}
   $DOIT "$cmd" "$@"


Yes, cleaner this way.

PS: would be nice to have a version of echo that shqoute(3) its
arguments to use for DOIT too.


This, below, do? (I did the same with printf(1)--"%q", but I was just
chucking away fieldwidth and precesion there, so echo it is.):

---START---
diff -urN bin/echo.orig/echo.c bin/echo/echo.c
--- bin/echo.orig/echo.c        2021-11-16 22:47:05.474277074 +0000
+++ bin/echo/echo.c     2022-06-09 20:36:13.806784976 +0000
@@ -47,29 +47,56 @@
 #include <stdlib.h>
 #include <string.h>

+static char *
+qstr(char *s)
+{
+       char* qs;
+       size_t n;
+
+       if ((n = shquote(s, NULL, 0)) == (size_t)-1)
+               return NULL;
+       n += 1;
+       if ((qs = malloc(n)) == NULL)
+               return NULL;
+       (void)shquote(s, qs, n);
+       return qs;
+}
+
 /* ARGSUSED */
 int
 main(int argc, char *argv[])
 {
-       bool nflag;
+       bool nflag, qflag;
+       int rc = EXIT_FAILURE;

        setprogname(argv[0]);
        (void)setlocale(LC_ALL, "");

+       nflag = qflag = false;
        /* This utility may NOT do getopt(3) option parsing. */
-       nflag = *++argv != NULL && strcmp(*argv, "-n") == 0;
+       if (*++argv != NULL) {
+               nflag = strcmp(*argv, "-n") == 0;
+               qflag = strcmp(*argv, "-q") == 0;
+               if (qflag) nflag = true;        /* -q implies -n */
+       }
        if (nflag)
                ++argv;

        while (*argv != NULL) {
-               (void)printf("%s", *argv);
+               if (qflag) {
+                       char *qs = qstr(*argv);
+                       if (qs == NULL)
+                               err(rc, "quote error");
+                       (void)printf("%s", qs);
+                       free(qs);
+               } else
+                       (void)printf("%s", *argv);
                if (*++argv != NULL)
                        (void)putchar(' ');
        }
        if (!nflag)
                (void)putchar('\n');
-       (void)fflush(stdout);
-       if (ferror(stdout) != 0)
-               err(1, "write error");
-       return 0;
+       if (fflush(stdout))
+               err(rc, "write error");
+       return EXIT_SUCCESS;
 }
---END---

Man pages, tests to come if OK.

-RVP

Reply via email to