]> diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/subs/smatch.c
Update XOAUTH2 documentation.
[nmh] / docs / historical / mh-nov-1983 / subs / smatch.c
1 #include "mh.h"
2
3 /* switch match, or any unambiguous abbreviation */
4 /* exact match always wins, even if shares same root */
5 /* returns subscript in zero-terminated tbl[] of strings */
6 /* returns -1 if no match, -2 if ambiguous */
7
8 #define abs(i) (i < 0 ? -i : i)
9
10 smatch(string, swp)
11 char *string;
12 struct swit *swp;
13 {
14 register char *sp, *tcp;
15 struct swit *tp;
16 int firstone, stringlen;
17
18 firstone = -1;
19
20 for (stringlen = strlen(string), tp = swp; tcp = tp->sw; tp++) {
21 if(stringlen < abs(tp->minchars)) continue; /* no match */
22 for (sp = string; *sp == *tcp++; ) {
23 if (*sp++ == 0) return(tp-swp); /* exact match */
24 }
25 if (*sp != 0) {
26 if (*sp != ' ') continue; /* no match */
27 if (*--tcp == 0) return(tp-swp); /* exact match */
28 }
29 if (firstone == -1) firstone = tp-swp; /* possible match */
30 else firstone = -2; /* ambiguous */
31 }
32
33 return (firstone);
34 }