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