1*35184Smarc /*
2*35184Smarc 
3*35184Smarc  *      Copyright (c) 1984, 1985, 1986 AT&T
4*35184Smarc  *      All Rights Reserved
5*35184Smarc 
6*35184Smarc  *      THIS IS UNPUBLISHED PROPRIETARY SOURCE
7*35184Smarc  *      CODE OF AT&T.
8*35184Smarc  *      The copyright notice above does not
9*35184Smarc  *      evidence any actual or intended
10*35184Smarc  *      publication of such source code.
11*35184Smarc 
12*35184Smarc  */
13*35184Smarc /* @(#)chkid.c	1.1 */
14*35184Smarc 
15*35184Smarc /*
16*35184Smarc  *   CHKID.C
17*35184Smarc  *
18*35184Smarc  *   Programmer:  D. G. Korn
19*35184Smarc  *
20*35184Smarc  *        Owner:  D. A. Lambeth
21*35184Smarc  *
22*35184Smarc  *         Date:  April 17, 1980
23*35184Smarc  *
24*35184Smarc  *
25*35184Smarc  *
26*35184Smarc  *   CHKID (NAME)
27*35184Smarc  *
28*35184Smarc  *        Verify the validity of NAME as a namid, and return its
29*35184Smarc  *        hash value.
30*35184Smarc  *
31*35184Smarc  *
32*35184Smarc  *
33*35184Smarc  *   See Also:  gettree(III)
34*35184Smarc  */
35*35184Smarc 
36*35184Smarc #ifdef KSHELL
37*35184Smarc #include       "shtype.h"
38*35184Smarc #else
39*35184Smarc #include       <ctype.h>
40*35184Smarc #endif	/* KSHELL */
41*35184Smarc 
42*35184Smarc #define BITSPBYTE     8
43*35184Smarc #define BITSPWORD     8*sizeof(unsigned)
44*35184Smarc 
45*35184Smarc /*
46*35184Smarc  *   CHKID (NAME)
47*35184Smarc  *
48*35184Smarc  *        char *NAME;
49*35184Smarc  *
50*35184Smarc  *   Check the validity of NAME as a namid, and return its hash value.
51*35184Smarc  *
52*35184Smarc  *   NAME should begin with a printable character, and should
53*35184Smarc  *   contain only alphanumerics.  If NAME does not meet these
54*35184Smarc  *   requirements, '0' is returned.
55*35184Smarc  *   The characters *, [, $ and ` cannot be used.
56*35184Smarc  */
57*35184Smarc 
chkid(name)58*35184Smarc unsigned chkid(name)
59*35184Smarc char *name;
60*35184Smarc {
61*35184Smarc 	register char *cp = name;
62*35184Smarc 	register unsigned i;
63*35184Smarc 	register unsigned c = *cp;
64*35184Smarc 	if(!isprint(c))
65*35184Smarc 		return(0);
66*35184Smarc 	if(expchar(c))
67*35184Smarc 		return(0);
68*35184Smarc 	i = c;
69*35184Smarc 	while(c= *++cp)
70*35184Smarc 	{
71*35184Smarc #ifdef KSHELL
72*35184Smarc 		if(!isalnum(c))
73*35184Smarc #else
74*35184Smarc 		if ((!isalnum (c)) && (c != '_'))
75*35184Smarc #endif	/* KSHELL */
76*35184Smarc 			return(0);
77*35184Smarc 		i = ((i<<1)|(i>>(BITSPWORD-1))) ^ c;
78*35184Smarc 	}
79*35184Smarc 	return (i | (1 << (BITSPWORD - 1)));
80*35184Smarc }
81*35184Smarc 
82