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