* man/mhbuild.man: wrapped one appearance of "Content-Disposition"
[mmh] / sbr / smatch.c
1
2 /*
3  * smatch.c -- match a switch (option)
4  *
5  * $Id$
6  *
7  * This code is Copyright (c) 2002, by the authors of nmh.  See the
8  * COPYRIGHT file in the root directory of the nmh distribution for
9  * complete copyright information.
10  */
11
12 #include <h/mh.h>
13
14
15 int
16 smatch(char *string, struct swit *swp)
17 {
18     char *sp, *tcp;
19     int firstone, len;
20     struct swit *tp;
21
22     firstone = UNKWNSW;
23
24     if (!string)
25         return firstone;
26     len = strlen(string);
27
28     for (tp = swp; tp->sw; tp++) {
29         tcp = tp->sw;
30         if (len < abs(tp->minchars))
31             continue;                   /* no match */
32         for (sp = string; *sp == *tcp++;) {
33             if (*sp++ == '\0')
34                 return (tp - swp);      /* exact match */
35         }
36         if (*sp) {
37             if (*sp != ' ')
38                 continue;               /* no match */
39             if (*--tcp == '\0')
40                 return (tp - swp);      /* exact match */
41         }
42         if (firstone == UNKWNSW)
43             firstone = tp - swp;
44         else
45             firstone = AMBIGSW;
46     }
47
48     return (firstone);
49 }