|
|
1.1 root 1: /* smatch.c - match a switch */
2:
3: #include "../h/mh.h"
4:
5:
6: #define abs(i) (i < 0 ? -i : i)
7:
8:
9: smatch(string, swp)
10: register char *string;
11: register struct swit *swp;
12: {
13: register char *sp,
14: *tcp;
15: struct swit *tp;
16: int firstone,
17: stringlen;
18:
19: firstone = UNKWNSW;
20:
21: if (string == 0)
22: return firstone;
23:
24: for (stringlen = strlen (string), tp = swp; tcp = tp -> sw; tp++) {
25: if (stringlen < abs (tp -> minchars))
26: continue; /* no match */
27: for (sp = string; *sp == *tcp++;) {
28: if (*sp++ == 0)
29: return (tp - swp);/* exact match */
30: }
31: if (*sp != 0) {
32: if (*sp != ' ')
33: continue; /* no match */
34: if (*--tcp == 0)
35: return (tp - swp);/* exact match */
36: }
37: if (firstone == UNKWNSW)
38: firstone = tp - swp;
39: else
40: firstone = AMBIGSW;
41: }
42:
43: return (firstone);
44: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.