xref: /original-bsd/bin/csh/char.h (revision cde495fc)
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.5 (Berkeley) 04/04/91
8  */
9 
10 extern unsigned short _cmap[];
11 
12 #define	_Q	0x001		/* '" */
13 #define	_Q1	0x002		/* ` */
14 #define	_SP	0x004		/* space and tab */
15 #define	_NL	0x008		/* \n */
16 #define	_META	0x010		/* lex meta characters, sp #'`";&<>()|\t\n */
17 #define	_GLOB	0x020		/* glob characters, *?{[` */
18 #define	_ESC	0x040		/* \ */
19 #define	_DOL	0x080		/* $ */
20 #define	_DIG	0x100		/* 0-9 */
21 #define	_LET	0x200		/* a-z, A-Z, _ */
22 
23 #define	cmap(c, bits)	(_cmap[(unsigned char)(c)] & (bits))
24 
25 #define	isglob(c)	cmap(c, _GLOB)
26 #define	isspace(c)	cmap(c, _SP)
27 #define	isspnl(c)	cmap(c, _SP|_NL)
28 #define	ismeta(c)	cmap(c, _META)
29 #define	digit(c)	cmap(c, _DIG)
30 #define	letter(c)	cmap(c, _LET)
31 #define	alnum(c)	(digit(c) || letter(c))
32 
33 #define	LINELEN		128
34 extern char *linp, linbuf[LINELEN];
35 
36 #define	CSHPUTCHAR { \
37 	if (!(ch&QUOTE) && (ch == 0177 || ch < ' ' && ch != '\t' && \
38 	    ch != '\n')) { \
39 		*linp++ = '^'; \
40 		if (ch == 0177) \
41 			ch = '?'; \
42 		else \
43 			ch |= 'A' - 1; \
44 		if (linp >= &linbuf[sizeof linbuf - 2]) \
45 			flush(); \
46 	} \
47 	ch &= TRIM; \
48 	*linp++ = ch; \
49 	if (ch == '\n' || linp >= &linbuf[sizeof(linbuf) - 2]) \
50 		flush(); \
51 }
52