]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/smatch.c
Always check that mktemp()/mktemp2() succeeds before trying to
[nmh] / docs / historical / mh-6.8.5 / sbr / smatch.c
1 /* smatch.c - match a switch */
2 #ifndef lint
3 static char ident[] = "@(#)$Id: smatch.c,v 1.5 1992/12/15 00:20:22 jromine Exp $";
4 #endif /* lint */
5
6 #include "../h/mh.h"
7
8 #ifndef abs
9 #define abs(i) (i < 0 ? -i : i)
10 #endif
11
12 smatch(string, swp)
13 register char *string;
14 register struct swit *swp;
15 {
16 register char *sp,
17 *tcp;
18 struct swit *tp;
19 int firstone,
20 stringlen;
21
22 firstone = UNKWNSW;
23
24 if (string == 0)
25 return firstone;
26
27 for (stringlen = strlen (string), tp = swp; tcp = tp -> sw; tp++) {
28 if (stringlen < abs (tp -> minchars))
29 continue; /* no match */
30 for (sp = string; *sp == *tcp++;) {
31 if (*sp++ == 0)
32 return (tp - swp);/* exact match */
33 }
34 if (*sp != 0) {
35 if (*sp != ' ')
36 continue; /* no match */
37 if (*--tcp == 0)
38 return (tp - swp);/* exact match */
39 }
40 if (firstone == UNKWNSW)
41 firstone = tp - swp;
42 else
43 firstone = AMBIGSW;
44 }
45
46 return (firstone);
47 }