xref: /original-bsd/bin/csh/char.h (revision ac773626)
1 /*-
2  * Copyright (c) 1980, 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)char.h	5.9 (Berkeley) 05/27/93
8  */
9 
10 #include <ctype.h>
11 
12 extern unsigned short _cmap[];
13 
14 #ifndef NLS
15 extern unsigned char _cmap_lower[], _cmap_upper[];
16 
17 #endif
18 
19 #define	_QF	0x0001		/* '" (Forward quotes) */
20 #define	_QB	0x0002		/* ` (Backquote) */
21 #define	_SP	0x0004		/* space and tab */
22 #define	_NL	0x0008		/* \n */
23 #define	_META	0x0010		/* lex meta characters, sp #'`";&<>()|\t\n */
24 #define	_GLOB	0x0020		/* glob characters, *?{[` */
25 #define	_ESC	0x0040		/* \ */
26 #define	_DOL	0x0080		/* $ */
27 #define	_DIG  	0x0100		/* 0-9 */
28 #define	_LET  	0x0200		/* a-z, A-Z, _ */
29 #define	_UP   	0x0400		/* A-Z */
30 #define	_LOW  	0x0800		/* a-z */
31 #define	_XD 	0x1000		/* 0-9, a-f, A-F */
32 #define	_CMD	0x2000		/* lex end of command chars, ;&(|` */
33 #define _CTR	0x4000		/* control */
34 
35 #define cmap(c, bits)	\
36 	(((c) & QUOTE) ? 0 : (_cmap[(unsigned char)(c)] & (bits)))
37 
38 #define isglob(c)	cmap(c, _GLOB)
39 #define isspc(c)	cmap(c, _SP)
40 #define ismeta(c)	cmap(c, _META)
41 #define iscmdmeta(c)	cmap(c, _CMD)
42 #define letter(c)	(((c) & QUOTE) ? 0 : \
43 			 (isalpha((unsigned char) (c)) || (c) == '_'))
44 #define alnum(c)	(((c) & QUOTE) ? 0 : \
45 		         (isalnum((unsigned char) (c)) || (c) == '_'))
46 #ifdef NLS
47 #define Isspace(c)	(((c) & QUOTE) ? 0 : isspace((unsigned char) (c)))
48 #define Isdigit(c)	(((c) & QUOTE) ? 0 : isdigit((unsigned char) (c)))
49 #define Isalpha(c)	(((c) & QUOTE) ? 0 : isalpha((unsigned char) (c)))
50 #define Islower(c)	(((c) & QUOTE) ? 0 : islower((unsigned char) (c)))
51 #define Isupper(c)	(((c) & QUOTE) ? 0 : isupper((unsigned char) (c)))
52 #define Tolower(c) 	(((c) & QUOTE) ? 0 : tolower((unsigned char) (c)))
53 #define Toupper(c) 	(((c) & QUOTE) ? 0 : toupper((unsigned char) (c)))
54 #define Isxdigit(c)	(((c) & QUOTE) ? 0 : isxdigit((unsigned char) (c)))
55 #define Isalnum(c)	(((c) & QUOTE) ? 0 : isalnum((unsigned char) (c)))
56 #define Iscntrl(c) 	(((c) & QUOTE) ? 0 : iscntrl((unsigned char) (c)))
57 #define Isprint(c) 	(((c) & QUOTE) ? 0 : isprint((unsigned char) (c)))
58 #else
59 #define Isspace(c)	cmap(c, _SP|_NL)
60 #define Isdigit(c)	cmap(c, _DIG)
61 #define Isalpha(c)	(cmap(c,_LET) && !(((c) & META) && AsciiOnly))
62 #define Islower(c)	(cmap(c,_LOW) && !(((c) & META) && AsciiOnly))
63 #define Isupper(c)	(cmap(c, _UP) && !(((c) & META) && AsciiOnly))
64 #define Tolower(c)  (_cmap_lower[(unsigned char)(c)])
65 #define Toupper(c)  (_cmap_upper[(unsigned char)(c)])
66 #define Isxdigit(c)	cmap(c, _XD)
67 #define Isalnum(c)	(cmap(c, _DIG|_LET) && !(((c) & META) && AsciiOnly))
68 #define Iscntrl(c)  (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
69 #define Isprint(c)  (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
70 #endif
71