2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
10 /* switch match, or any unambiguous abbreviation */
11 /* exact match always wins, even if shares same root */
12 /* returns subscript in zero-terminated tbl[] of strings */
13 /* returns -1 if no match, -2 if ambiguous */
15 #define abs(i) (i < 0 ? -i : i)
21 register char *sp
, *tcp
;
23 int firstone
, stringlen
;
27 for (stringlen
= strlen(string
), tp
= swp
; tcp
= tp
->sw
; tp
++) {
28 if(stringlen
< abs(tp
->minchars
)) continue; /* no match */
29 for (sp
= string
; *sp
== *tcp
++; ) {
30 if (*sp
++ == 0) return(tp
-swp
); /* exact match */
33 if (*sp
!= ' ') continue; /* no match */
34 if (*--tcp
== 0) return(tp
-swp
); /* exact match */
36 if (firstone
== -1) firstone
= tp
-swp
; /* possible match */
37 else firstone
= -2; /* ambiguous */