1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

printf: fix %(pattern)q documentation in 'printf --man'

%(pattern)q is equivalent to %P. It's also equivalent to %#P, but
since the alternative format specifier '#' does nothing for %P,
%P and %#P are the same and documenting #%P is just confusing.

Thanks to @stephane-chazelas for the report.

src/cmd/ksh93/bltins/print.c:
- In the printmap struct, document %P as equivalent of %(pattern)q.
- Sort it alphabetically.
- Do not pointlessly repeat the string "Equivalent to". Instead,
  let the discipline function infof() insert it for each entry.
  (This is the function used to dynamically insert the equivalents
  documentation into the --man output at the \fextra\f tag in
  sh_optprintf[] in data/builtins.c.)

Resolves: https://github.com/ksh93/ksh/issues/338
This commit is contained in:
Martijn Dekker 2021-11-18 17:35:09 +01:00
parent 0b0d0094b9
commit fb8308243c

View file

@ -71,16 +71,16 @@ struct printmap
size_t size;
char *name;
char map[3];
const char *description;
const char *equivalent;
};
const struct printmap Pmap[] =
static const struct printmap Pmap[] =
{
3, "csv", "q+", "Equivalent to %#q",
4, "html", "H", "Equivalent to %H",
3, "ere", "R", "Equivalent to %R",
7, "pattern","P", "Equivalent to %#P",
3, "url", "H+", "Equivalent to %#H",
3, "csv", "q+", "%#q",
3, "ere", "R", "%R",
4, "html", "H", "%H",
7, "pattern","P", "%P",
3, "url", "H+", "%#H",
0, 0, 0,
};
@ -159,9 +159,7 @@ static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp)
const struct printmap *pm;
char c='%';
for(pm=Pmap;pm->size>0;pm++)
{
sfprintf(sp, "[+%c(%s)q?%s.]",c,pm->name,pm->description);
}
sfprintf(sp, "[+%c(%s)q?Equivalent to %s.]",c,pm->name,pm->equivalent);
return(1);
}
@ -260,7 +258,6 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
nflag++;
if(*argv && strcmp(*argv,"-n")==0)
{
nflag++;
argv++;
}
@ -425,7 +422,6 @@ static char strformat(char *s)
#if SHOPT_MULTIBYTE && defined(FMT_EXP_WIDE)
int w;
#endif
b = t = s;
for (;;)
{
@ -471,7 +467,6 @@ static char strformat(char *s)
}
}
static char *genformat(char *format)
{
register char *fp;
@ -706,7 +701,6 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
Shell_t *shp = pp->sh;
register char* argp = *pp->nextarg;
char *w,*s;
if(fe->n_str>0 && (format=='T'||format=='Q') && varname(fe->t_str,fe->n_str) && (!argp || varname(argp,-1)))
{
if(argp)