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