Doug McIlroy wrote in <201912271608.xbrg84jr128...@tahoe.cs.dartmouth.edu>:
 |The description of sprintf in the man page pic(1) does not
 |reveal that only a few format codes are permitted.
 |
 |Eric Raymond's "Making Pictures With GNU PIC" says only
 |%,%e,%f,%g are  permitted. But what does a bare % mean?
 |
 |In fact pic rejects a bare %. However it does accept
 |%%, which is supposed to print a single %. Pic,
 |however prints %%.
 |
 |So I believe we have
 |1. An incompleteness in pic(1)
 |2. An error in "Making Pictures With GNU PIC"
 |3. An error in pic itself

Should be handled by

  diff --git a/doc/pic.ms b/doc/pic.ms
  index da95de80..89ba9f37 100644
  --- a/doc/pic.ms
  +++ b/doc/pic.ms
  @@ -1652,7 +1652,8 @@ GNU \fBgpic\fP also documents a one-argument form or 
rand,
   version.
   .PP
   The function \fBsprintf()\fP behaves like a C \fIsprintf\/\fP(3)
  -function that only takes %, %e, %f, and %g format strings.
  +function that only takes the format strings %e, %E, %f, %g and %G,
  +as well as %% for printing a raw percent character.
   .
   .
   .NH 1
  diff --git a/man/pre-pic.1.in b/man/pre-pic.1.in
  index aae228a4..4edfe548 100644
  --- a/man/pre-pic.1.in
  +++ b/man/pre-pic.1.in
  @@ -795,6 +795,11 @@ this will produce the arguments formatted according to
   which should be a string as described in
   .BR printf (3)
   appropriate for the number of arguments supplied.
  +Only the flags
  +.B #-+ 0123456789.,
  +and the formats
  +.B eEfgG%
  +are supported.
   .
   .LP
   The thickness of the lines used to draw objects is controlled by the
  diff --git a/src/pre-pic/pic.y b/src/pre-pic/pic.y
  index c6e4c0f5..e107b7c9 100644
  --- a/src/pre-pic/pic.y
  +++ b/src/pre-pic/pic.y
  @@ -1889,6 +1889,11 @@ char *do_sprintf(const char *form, const double *v, 
int nv)
     string one_format;
     while (*form) {
       if (*form == '%') {
  +      if(form[1] == '%'){
  +        result += '%';
  +        form += 2;
  +        continue;
  +      }
         one_format += *form++;
         for (; *form != '\0' && su_cs_find_c("#-+ 0123456789.", *form) != NIL;
             form++)

in my GPLv2 tree, or as attached for groff v1.22.4.
(I have only compile-tested v1.22.4, and my tree is not at all
ready yet.)

 |Doug
 --End of <201912271608.xbrg84jr128...@tahoe.cs.dartmouth.edu>

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
diff --git a/doc/pic.ms b/doc/pic.ms
index 6d581ba..a0a77c7 100644
--- a/doc/pic.ms
+++ b/doc/pic.ms
@@ -1722,7 +1722,8 @@ GNU \fBgpic\fP also documents a one-argument form or rand,
 version.
 .PP
 The function \fBsprintf()\fP behaves like a C \fIsprintf\/\fP(3)
-function that only takes %, %e, %f, and %g format strings.
+function that only takes the format strings %e, %E, %f, %g and %G,
+as well as %% for printing a raw percent character.
 .
 .
 .NH 1
diff --git a/src/preproc/pic/pic.1.man b/src/preproc/pic/pic.1.man
index 847bbe3..85af1e7 100644
--- a/src/preproc/pic/pic.1.man
+++ b/src/preproc/pic/pic.1.man
@@ -906,6 +906,11 @@ this will produce the arguments formatted according to
 which should be a string as described in
 .BR printf (3)
 appropriate for the number of arguments supplied.
+Only the flags
+.B #-+ 0123456789.,
+and the formats
+.B eEfgG%
+are supported.
 .
 .
 .LP
diff --git a/src/preproc/pic/pic.ypp b/src/preproc/pic/pic.ypp
index 6afa2ab..2e5562e 100644
--- a/src/preproc/pic/pic.ypp
+++ b/src/preproc/pic/pic.ypp
@@ -1895,6 +1895,11 @@ char *do_sprintf(const char *form, const double *v, int nv)
   string one_format;
   while (*form) {
     if (*form == '%') {
+      if(form[1] == '%'){
+        result += '%';
+        form += 2;
+        continue;
+      }
       one_format += *form++;
       for (; *form != '\0' && strchr("#-+ 0123456789.", *form) != 0; form++)
 	one_format += *form;

Reply via email to