xref: /csrg-svn/usr.bin/tn3270/api/astosc.c (revision 33820)
131890Sminshall /*
2*33820Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*33820Sbostic  * All rights reserved.
431890Sminshall  *
5*33820Sbostic  * Redistribution and use in source and binary forms are permitted
6*33820Sbostic  * provided that this notice is preserved and that due credit is given
7*33820Sbostic  * to the University of California at Berkeley. The name of the University
8*33820Sbostic  * may not be used to endorse or promote products derived from this
9*33820Sbostic  * software without specific prior written permission. This software
10*33820Sbostic  * is provided ``as is'' without express or implied warranty.
11*33820Sbostic  *
12*33820Sbostic  *	@(#)astosc.c	3.2 (Berkeley) 03/28/88
1331890Sminshall  */
1431890Sminshall 
1531245Sminshall #include <ctype.h>
1631245Sminshall 
1731245Sminshall #include "../general/general.h"
1831245Sminshall 
1931245Sminshall #include "../ctlr/function.h"
2031245Sminshall 
2131240Sminshall #include "astosc.h"
2231240Sminshall 
2331240Sminshall struct astosc astosc[256] = {
2431240Sminshall #include "astosc.out"
2531240Sminshall };
2631240Sminshall 
2731245Sminshall /* compare two strings, ignoring case */
2831240Sminshall 
2931245Sminshall static
3031245Sminshall ustrcmp(string1, string2)
3131245Sminshall register char *string1;
3231245Sminshall register char *string2;
3331245Sminshall {
3431245Sminshall     register int c1, c2;
3531245Sminshall 
3631245Sminshall     while ((c1 = (unsigned char) *string1++) != 0) {
3731245Sminshall 	if (isupper(c1)) {
3831245Sminshall 	    c1 = tolower(c1);
3931245Sminshall 	}
4031245Sminshall 	if (isupper(c2 = (unsigned char) *string2++)) {
4131245Sminshall 	    c2 = tolower(c2);
4231245Sminshall 	}
4331245Sminshall 	if (c1 < c2) {
4431245Sminshall 	    return(-1);
4531245Sminshall 	} else if (c1 > c2) {
4631245Sminshall 	    return(1);
4731245Sminshall 	}
4831245Sminshall     }
4931245Sminshall     if (*string2) {
5031245Sminshall 	return(-1);
5131245Sminshall     } else {
5231245Sminshall 	return(0);
5331245Sminshall     }
5431245Sminshall }
5531245Sminshall 
5631245Sminshall 
5731240Sminshall /*
5831240Sminshall  * This routine takes a string and returns an integer.  It may return
5931606Sminshall  * -1 if there is no other integer which corresponds to the
6031606Sminshall  * string.  -1 implies an error.
6131240Sminshall  */
6231240Sminshall 
6331240Sminshall int
6431240Sminshall ascii_to_index(string)
6531240Sminshall register char *string;
6631240Sminshall {
6731240Sminshall     register struct astosc *this;
6831240Sminshall 
6931240Sminshall     for (this = astosc; this <= &astosc[highestof(astosc)]; this++) {
7031800Sminshall 	if ((this->name != 0) && (ustrcmp(this->name, string) == 0)) {
7131240Sminshall 	    return this-astosc;
7231240Sminshall 	}
7331240Sminshall     }
7431606Sminshall     return -1;
7531240Sminshall }
76