source: trunk/third/nmh/sbr/smatch.c @ 12455

Revision 12455, 784 bytes checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12454, which included commits to RCS files with non-trunk default branches.
RevLine 
[12454]1
2/*
3 * smatch.c -- match a switch (option)
4 *
5 * $Id: smatch.c,v 1.1.1.1 1999-02-07 18:14:10 danw Exp $
6 */
7
8#include <h/mh.h>
9
10
11int
12smatch(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}
Note: See TracBrowser for help on using the repository browser.