xref: /csrg-svn/usr.bin/tn3270/api/astosc.c (revision 34888)
131890Sminshall /*
233820Sbostic  * Copyright (c) 1988 Regents of the University of California.
333820Sbostic  * All rights reserved.
431890Sminshall  *
533820Sbostic  * Redistribution and use in source and binary forms are permitted
6*34888Sbostic  * provided that the above copyright notice and this paragraph are
7*34888Sbostic  * duplicated in all such forms and that any documentation,
8*34888Sbostic  * advertising materials, and other materials related to such
9*34888Sbostic  * distribution and use acknowledge that the software was developed
10*34888Sbostic  * by the University of California, Berkeley.  The name of the
11*34888Sbostic  * University may not be used to endorse or promote products derived
12*34888Sbostic  * from this software without specific prior written permission.
13*34888Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34888Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34888Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1631890Sminshall  */
1731890Sminshall 
18*34888Sbostic #ifndef lint
19*34888Sbostic static char sccsid[] = "@(#)astosc.c	3.3 (Berkeley) 06/29/88";
20*34888Sbostic #endif /* not lint */
21*34888Sbostic 
2231245Sminshall #include <ctype.h>
2331245Sminshall 
2431245Sminshall #include "../general/general.h"
2531245Sminshall 
2631245Sminshall #include "../ctlr/function.h"
2731245Sminshall 
2831240Sminshall #include "astosc.h"
2931240Sminshall 
3031240Sminshall struct astosc astosc[256] = {
3131240Sminshall #include "astosc.out"
3231240Sminshall };
3331240Sminshall 
3431245Sminshall /* compare two strings, ignoring case */
3531240Sminshall 
3631245Sminshall static
3731245Sminshall ustrcmp(string1, string2)
3831245Sminshall register char *string1;
3931245Sminshall register char *string2;
4031245Sminshall {
4131245Sminshall     register int c1, c2;
4231245Sminshall 
4331245Sminshall     while ((c1 = (unsigned char) *string1++) != 0) {
4431245Sminshall 	if (isupper(c1)) {
4531245Sminshall 	    c1 = tolower(c1);
4631245Sminshall 	}
4731245Sminshall 	if (isupper(c2 = (unsigned char) *string2++)) {
4831245Sminshall 	    c2 = tolower(c2);
4931245Sminshall 	}
5031245Sminshall 	if (c1 < c2) {
5131245Sminshall 	    return(-1);
5231245Sminshall 	} else if (c1 > c2) {
5331245Sminshall 	    return(1);
5431245Sminshall 	}
5531245Sminshall     }
5631245Sminshall     if (*string2) {
5731245Sminshall 	return(-1);
5831245Sminshall     } else {
5931245Sminshall 	return(0);
6031245Sminshall     }
6131245Sminshall }
6231245Sminshall 
6331245Sminshall 
6431240Sminshall /*
6531240Sminshall  * This routine takes a string and returns an integer.  It may return
6631606Sminshall  * -1 if there is no other integer which corresponds to the
6731606Sminshall  * string.  -1 implies an error.
6831240Sminshall  */
6931240Sminshall 
7031240Sminshall int
7131240Sminshall ascii_to_index(string)
7231240Sminshall register char *string;
7331240Sminshall {
7431240Sminshall     register struct astosc *this;
7531240Sminshall 
7631240Sminshall     for (this = astosc; this <= &astosc[highestof(astosc)]; this++) {
7731800Sminshall 	if ((this->name != 0) && (ustrcmp(this->name, string) == 0)) {
7831240Sminshall 	    return this-astosc;
7931240Sminshall 	}
8031240Sminshall     }
8131606Sminshall     return -1;
8231240Sminshall }
83