]>
diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/subs/smatch.c
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 */
8 #define abs(i) (i < 0 ? -i : i)
14 register char *sp
, *tcp
;
16 int firstone
, stringlen
;
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 */
26 if (*sp
!= ' ') continue; /* no match */
27 if (*--tcp
== 0) return(tp
-swp
); /* exact match */
29 if (firstone
== -1) firstone
= tp
-swp
; /* possible match */
30 else firstone
= -2; /* ambiguous */