]> diplodocus.org Git - nmh/blob - sbr/print_sw.c
Improve fmttest output
[nmh] / sbr / print_sw.c
1 /* print_sw.c -- print switches
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include "h/mh.h"
9 #include "ssequal.h"
10 #include "print_sw.h"
11
12
13 void
14 print_sw (const char *substr, const struct swit *swp, char *prefix, FILE *fp)
15 {
16 int len;
17 bool optno;
18 int i;
19 char *cp, *cp1, *sp;
20 char buf[128];
21
22 len = strlen(substr);
23 for (; swp->sw; swp++) {
24 /* null matches all strings */
25 if (!*substr || (ssequal (substr, swp->sw) && len >= swp->minchars)) {
26 optno = false;
27 /* next switch */
28 if ((sp = (&swp[1])->sw)) {
29 if (!*substr && sp[0] == 'n' && sp[1] == 'o' &&
30 strcmp (&sp[2], swp->sw) == 0 && (
31 ((&swp[1])->minchars == 0 && swp->minchars == 0) ||
32 ((&swp[1])->minchars == (swp->minchars) + 2)))
33 optno = true;
34 }
35
36 if (swp->minchars > 0) {
37 cp = buf;
38 *cp++ = '(';
39 if (optno) {
40 strcpy (cp, "[no]");
41 cp += strlen (cp);
42 }
43 for (cp1 = swp->sw, i = 0; i < swp->minchars; i++)
44 *cp++ = *cp1++;
45 *cp++ = ')';
46 while ((*cp++ = *cp1++));
47 fprintf (fp, " %s%s\n", prefix, buf);
48 } else {
49 if (!swp->minchars)
50 fprintf(fp, optno ? " %s[no]%s\n" : " %s%s\n",
51 prefix, swp->sw);
52 }
53 if (optno)
54 swp++; /* skip -noswitch */
55 }
56 }
57 }