xref: /csrg-svn/usr.bin/tn3270/api/astosc.c (revision 31890)
1*31890Sminshall /*
2*31890Sminshall  *	Copyright (c) 1984-1987 by the Regents of the
3*31890Sminshall  *	University of California and by Gregory Glenn Minshall.
4*31890Sminshall  *
5*31890Sminshall  *	Permission to use, copy, modify, and distribute these
6*31890Sminshall  *	programs and their documentation for any purpose and
7*31890Sminshall  *	without fee is hereby granted, provided that this
8*31890Sminshall  *	copyright and permission appear on all copies and
9*31890Sminshall  *	supporting documentation, the name of the Regents of
10*31890Sminshall  *	the University of California not be used in advertising
11*31890Sminshall  *	or publicity pertaining to distribution of the programs
12*31890Sminshall  *	without specific prior permission, and notice be given in
13*31890Sminshall  *	supporting documentation that copying and distribution is
14*31890Sminshall  *	by permission of the Regents of the University of California
15*31890Sminshall  *	and by Gregory Glenn Minshall.  Neither the Regents of the
16*31890Sminshall  *	University of California nor Gregory Glenn Minshall make
17*31890Sminshall  *	representations about the suitability of this software
18*31890Sminshall  *	for any purpose.  It is provided "as is" without
19*31890Sminshall  *	express or implied warranty.
20*31890Sminshall  */
21*31890Sminshall 
22*31890Sminshall #ifndef lint
23*31890Sminshall static char sccsid[] = "@(#)astosc.c	1.5 (Berkeley) 07/17/87";
24*31890Sminshall #endif	/* not lint */
25*31890Sminshall 
2631245Sminshall #include <ctype.h>
2731245Sminshall 
2831245Sminshall #include "../general/general.h"
2931245Sminshall 
3031245Sminshall #include "../ctlr/function.h"
3131245Sminshall 
3231240Sminshall #include "astosc.h"
3331240Sminshall 
3431240Sminshall struct astosc astosc[256] = {
3531240Sminshall #include "astosc.out"
3631240Sminshall };
3731240Sminshall 
3831245Sminshall /* compare two strings, ignoring case */
3931240Sminshall 
4031245Sminshall static
4131245Sminshall ustrcmp(string1, string2)
4231245Sminshall register char *string1;
4331245Sminshall register char *string2;
4431245Sminshall {
4531245Sminshall     register int c1, c2;
4631245Sminshall 
4731245Sminshall     while ((c1 = (unsigned char) *string1++) != 0) {
4831245Sminshall 	if (isupper(c1)) {
4931245Sminshall 	    c1 = tolower(c1);
5031245Sminshall 	}
5131245Sminshall 	if (isupper(c2 = (unsigned char) *string2++)) {
5231245Sminshall 	    c2 = tolower(c2);
5331245Sminshall 	}
5431245Sminshall 	if (c1 < c2) {
5531245Sminshall 	    return(-1);
5631245Sminshall 	} else if (c1 > c2) {
5731245Sminshall 	    return(1);
5831245Sminshall 	}
5931245Sminshall     }
6031245Sminshall     if (*string2) {
6131245Sminshall 	return(-1);
6231245Sminshall     } else {
6331245Sminshall 	return(0);
6431245Sminshall     }
6531245Sminshall }
6631245Sminshall 
6731245Sminshall 
6831240Sminshall /*
6931240Sminshall  * This routine takes a string and returns an integer.  It may return
7031606Sminshall  * -1 if there is no other integer which corresponds to the
7131606Sminshall  * string.  -1 implies an error.
7231240Sminshall  */
7331240Sminshall 
7431240Sminshall int
7531240Sminshall ascii_to_index(string)
7631240Sminshall register char *string;
7731240Sminshall {
7831240Sminshall     register struct astosc *this;
7931240Sminshall 
8031240Sminshall     for (this = astosc; this <= &astosc[highestof(astosc)]; this++) {
8131800Sminshall 	if ((this->name != 0) && (ustrcmp(this->name, string) == 0)) {
8231240Sminshall 	    return this-astosc;
8331240Sminshall 	}
8431240Sminshall     }
8531606Sminshall     return -1;
8631240Sminshall }
87