File: print_sw.c

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (57 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* print_sw.c -- print switches
 *
 * This code is Copyright (c) 2002, by the authors of nmh.  See the
 * COPYRIGHT file in the root directory of the nmh distribution for
 * complete copyright information.
 */

#include "h/mh.h"
#include "sbr/utils.h"
#include "print_sw.h"


void
print_sw (const char *substr, const struct swit *swp, char *prefix, FILE *fp)
{
    int len;
    bool optno;
    int i;
    char *cp, *cp1, *sp;
    char buf[128];

    len = strlen(substr);
    for (; swp->sw; swp++) {
	/* null matches all strings */
	if (!*substr || (has_prefix(swp->sw, substr) && len >= swp->minchars)) {
	    optno = false;
	    /* next switch */
	    if ((sp = (&swp[1])->sw)) {
		if (!*substr && sp[0] == 'n' && sp[1] == 'o' &&
			strcmp (&sp[2], swp->sw) == 0 && (
			((&swp[1])->minchars == 0 && swp->minchars == 0) ||
			((&swp[1])->minchars == (swp->minchars) + 2)))
		    optno = true;
	    }

	    if (swp->minchars > 0) {
		cp = buf;
		*cp++ = '(';
		if (optno) {
		    strcpy (cp, "[no]");
		    cp += strlen (cp);
		}
		for (cp1 = swp->sw, i = 0; i < swp->minchars; i++)
		    *cp++ = *cp1++;
		*cp++ = ')';
		while ((*cp++ = *cp1++));
		fprintf (fp, "  %s%s\n", prefix, buf);
	    } else {
		if (!swp->minchars)
		    fprintf(fp, optno ? "  %s[no]%s\n" : "  %s%s\n",
                            prefix, swp->sw);
	    }
	    if (optno)
		swp++;	/* skip -noswitch */
	}
    }
}