]> diplodocus.org Git - nmh/blob - sbr/smatch.c
Another pass at cleaning up (some of) the manpages.
[nmh] / sbr / smatch.c
1
2 /*
3 * smatch.c -- match a switch (option)
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 int
14 smatch(char *string, struct swit *swp)
15 {
16 char *sp, *tcp;
17 int firstone, len;
18 struct swit *tp;
19
20 firstone = UNKWNSW;
21
22 if (!string)
23 return firstone;
24 len = strlen(string);
25
26 for (tp = swp; tp->sw; tp++) {
27 tcp = tp->sw;
28 if (len < abs(tp->minchars))
29 continue; /* no match */
30 for (sp = string; *sp == *tcp++;) {
31 if (*sp++ == '\0')
32 return tp->swret; /* exact match */
33 }
34 if (*sp) {
35 if (*sp != ' ')
36 continue; /* no match */
37 if (*--tcp == '\0')
38 return tp->swret; /* exact match */
39 }
40 if (firstone == UNKWNSW)
41 firstone = tp->swret;
42 else
43 firstone = AMBIGSW;
44 }
45
46 return (firstone);
47 }