Commit | Line | Data |
---|---|---|
992de934 GM |
1 | /* |
2 | * Copyright (c) 1984-1987 by the Regents of the | |
3 | * University of California and by Gregory Glenn Minshall. | |
4 | * | |
5 | * Permission to use, copy, modify, and distribute these | |
6 | * programs and their documentation for any purpose and | |
7 | * without fee is hereby granted, provided that this | |
8 | * copyright and permission appear on all copies and | |
9 | * supporting documentation, the name of the Regents of | |
10 | * the University of California not be used in advertising | |
11 | * or publicity pertaining to distribution of the programs | |
12 | * without specific prior permission, and notice be given in | |
13 | * supporting documentation that copying and distribution is | |
14 | * by permission of the Regents of the University of California | |
15 | * and by Gregory Glenn Minshall. Neither the Regents of the | |
16 | * University of California nor Gregory Glenn Minshall make | |
17 | * representations about the suitability of this software | |
18 | * for any purpose. It is provided "as is" without | |
19 | * express or implied warranty. | |
20 | */ | |
21 | ||
22 | #ifndef lint | |
c578271f | 23 | static char sccsid[] = "@(#)astosc.c 3.1 (Berkeley) %G%"; |
992de934 GM |
24 | #endif /* not lint */ |
25 | ||
addfa672 GM |
26 | #include <ctype.h> |
27 | ||
28 | #include "../general/general.h" | |
d382747c GM |
29 | |
30 | #include "../ctlr/function.h" | |
31 | ||
addfa672 | 32 | #include "astosc.h" |
addfa672 | 33 | |
d382747c GM |
34 | struct astosc astosc[256] = { |
35 | #include "astosc.out" | |
36 | }; | |
37 | ||
addfa672 GM |
38 | /* compare two strings, ignoring case */ |
39 | ||
40 | static | |
41 | ustrcmp(string1, string2) | |
42 | register char *string1; | |
43 | register char *string2; | |
44 | { | |
45 | register int c1, c2; | |
46 | ||
47 | while ((c1 = (unsigned char) *string1++) != 0) { | |
48 | if (isupper(c1)) { | |
49 | c1 = tolower(c1); | |
50 | } | |
51 | if (isupper(c2 = (unsigned char) *string2++)) { | |
52 | c2 = tolower(c2); | |
53 | } | |
54 | if (c1 < c2) { | |
55 | return(-1); | |
56 | } else if (c1 > c2) { | |
57 | return(1); | |
58 | } | |
59 | } | |
60 | if (*string2) { | |
61 | return(-1); | |
62 | } else { | |
63 | return(0); | |
64 | } | |
65 | } | |
66 | ||
d382747c GM |
67 | |
68 | /* | |
69 | * This routine takes a string and returns an integer. It may return | |
61e81f6b GM |
70 | * -1 if there is no other integer which corresponds to the |
71 | * string. -1 implies an error. | |
d382747c GM |
72 | */ |
73 | ||
74 | int | |
75 | ascii_to_index(string) | |
76 | register char *string; | |
77 | { | |
78 | register struct astosc *this; | |
79 | ||
80 | for (this = astosc; this <= &astosc[highestof(astosc)]; this++) { | |
bc1c5b66 | 81 | if ((this->name != 0) && (ustrcmp(this->name, string) == 0)) { |
d382747c GM |
82 | return this-astosc; |
83 | } | |
84 | } | |
61e81f6b | 85 | return -1; |
d382747c | 86 | } |