Don't remove the draft on SIGQUIT to allow debugging
[mmh] / sbr / smatch.c
1 /*
2 ** smatch.c -- match a switch (option)
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 int
13 smatch(char *string, struct swit *swp)
14 {
15         char *sp, *tcp;
16         int firstone, len;
17         struct swit *tp;
18
19         firstone = UNKWNSW;
20
21         if (!string)
22                 return firstone;
23         len = strlen(string);
24
25         for (tp = swp; tp->sw; tp++) {
26                 tcp = tp->sw;
27                 if (len < abs(tp->minchars))
28                         continue;  /* no match */
29                 for (sp = string; *sp == *tcp++;) {
30                         if (*sp++ == '\0')
31                                 return (tp - swp);  /* exact match */
32                 }
33                 if (*sp) {
34                         if (*sp != ' ')
35                                 continue;  /* no match */
36                         if (*--tcp == '\0')
37                                 return (tp - swp);  /* exact match */
38                 }
39                 if (firstone == UNKWNSW)
40                         firstone = tp - swp;
41                 else
42                         firstone = AMBIGSW;
43         }
44
45         return (firstone);
46 }