]> diplodocus.org Git - nmh/blob - sbr/smatch.c
Just reworded the bit about '%s' being safe not to quote (it's only safe not to
[nmh] / sbr / smatch.c
1
2 /*
3 * smatch.c -- match a switch (option)
4 *
5 * $Id$
6 */
7
8 #include <h/mh.h>
9
10
11 int
12 smatch(char *string, struct swit *swp)
13 {
14 char *sp, *tcp;
15 int firstone, len;
16 struct swit *tp;
17
18 firstone = UNKWNSW;
19
20 if (!string)
21 return firstone;
22 len = strlen(string);
23
24 for (tp = swp; tp->sw; tp++) {
25 tcp = tp->sw;
26 if (len < abs(tp->minchars))
27 continue; /* no match */
28 for (sp = string; *sp == *tcp++;) {
29 if (*sp++ == '\0')
30 return (tp - swp); /* exact match */
31 }
32 if (*sp) {
33 if (*sp != ' ')
34 continue; /* no match */
35 if (*--tcp == '\0')
36 return (tp - swp); /* exact match */
37 }
38 if (firstone == UNKWNSW)
39 firstone = tp - swp;
40 else
41 firstone = AMBIGSW;
42 }
43
44 return (firstone);
45 }