xref: /original-bsd/usr.bin/tn3270/api/astosc.c (revision 16bc4816)
1 /*-
2  * Copyright (c) 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)astosc.c	4.2 (Berkeley) 04/26/91";
10 #endif /* not lint */
11 
12 #include <ctype.h>
13 
14 #include "../general/general.h"
15 
16 #include "../ctlr/function.h"
17 
18 #include "astosc.h"
19 
20 struct astosc astosc[256] = {
21 #include "astosc.out"
22 };
23 
24 /* compare two strings, ignoring case */
25 
26 static
27 ustrcmp(string1, string2)
28 register char *string1;
29 register char *string2;
30 {
31     register int c1, c2;
32 
33     while ((c1 = (unsigned char) *string1++) != 0) {
34 	if (isupper(c1)) {
35 	    c1 = tolower(c1);
36 	}
37 	if (isupper(c2 = (unsigned char) *string2++)) {
38 	    c2 = tolower(c2);
39 	}
40 	if (c1 < c2) {
41 	    return(-1);
42 	} else if (c1 > c2) {
43 	    return(1);
44 	}
45     }
46     if (*string2) {
47 	return(-1);
48     } else {
49 	return(0);
50     }
51 }
52 
53 
54 /*
55  * This routine takes a string and returns an integer.  It may return
56  * -1 if there is no other integer which corresponds to the
57  * string.  -1 implies an error.
58  */
59 
60 int
61 ascii_to_index(string)
62 register char *string;
63 {
64     register struct astosc *this;
65 
66     for (this = astosc; this <= &astosc[highestof(astosc)]; this++) {
67 	if ((this->name != 0) && (ustrcmp(this->name, string) == 0)) {
68 	    return this-astosc;
69 	}
70     }
71     return -1;
72 }
73