Commit | Line | Data |
---|---|---|
992de934 | 1 | /* |
f6e43951 KB |
2 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | |
992de934 | 4 | * |
f6e43951 | 5 | * Redistribution and use in source and binary forms are permitted |
b36fc510 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
992de934 GM |
16 | */ |
17 | ||
b36fc510 | 18 | #ifndef lint |
d43d1075 | 19 | static char sccsid[] = "@(#)astosc.c 4.1 (Berkeley) %G%"; |
b36fc510 KB |
20 | #endif /* not lint */ |
21 | ||
addfa672 GM |
22 | #include <ctype.h> |
23 | ||
24 | #include "../general/general.h" | |
d382747c GM |
25 | |
26 | #include "../ctlr/function.h" | |
27 | ||
addfa672 | 28 | #include "astosc.h" |
addfa672 | 29 | |
d382747c GM |
30 | struct astosc astosc[256] = { |
31 | #include "astosc.out" | |
32 | }; | |
33 | ||
addfa672 GM |
34 | /* compare two strings, ignoring case */ |
35 | ||
36 | static | |
37 | ustrcmp(string1, string2) | |
38 | register char *string1; | |
39 | register char *string2; | |
40 | { | |
41 | register int c1, c2; | |
42 | ||
43 | while ((c1 = (unsigned char) *string1++) != 0) { | |
44 | if (isupper(c1)) { | |
45 | c1 = tolower(c1); | |
46 | } | |
47 | if (isupper(c2 = (unsigned char) *string2++)) { | |
48 | c2 = tolower(c2); | |
49 | } | |
50 | if (c1 < c2) { | |
51 | return(-1); | |
52 | } else if (c1 > c2) { | |
53 | return(1); | |
54 | } | |
55 | } | |
56 | if (*string2) { | |
57 | return(-1); | |
58 | } else { | |
59 | return(0); | |
60 | } | |
61 | } | |
62 | ||
d382747c GM |
63 | |
64 | /* | |
65 | * This routine takes a string and returns an integer. It may return | |
61e81f6b GM |
66 | * -1 if there is no other integer which corresponds to the |
67 | * string. -1 implies an error. | |
d382747c GM |
68 | */ |
69 | ||
70 | int | |
71 | ascii_to_index(string) | |
72 | register char *string; | |
73 | { | |
74 | register struct astosc *this; | |
75 | ||
76 | for (this = astosc; this <= &astosc[highestof(astosc)]; this++) { | |
bc1c5b66 | 77 | if ((this->name != 0) && (ustrcmp(this->name, string) == 0)) { |
d382747c GM |
78 | return this-astosc; |
79 | } | |
80 | } | |
61e81f6b | 81 | return -1; |
d382747c | 82 | } |