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