xref: /illumos-gate/usr/src/cmd/csh/sh.char.h (revision 1b863af9bc9a5c76ed773e129889fc19dbf9e41c)
1 /*
2  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved.  The Berkeley Software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 /*
16  * Macros to classify characters.
17  */
18 
19 #ifdef MBCHAR
20 #include <wchar.h>
21 #include <wctype.h>
22 #define	isauxspZ	(!isascii(Z)&&!(Z&QUOTE)&&iswspace(Z))
23 #define	isauxsp(c) 	(Z=((unsigned)(c)), isauxspZ)
24 /* Regocnizes non-ASCII space characters. */
25 #else
26 #include <ctype.h>
27 /* macros of macros to reduce further #ifdef MBCHAR later. Please be patient!*/
28 #define	iswdigit(c)	isdigit(c)
29 #define	iswalpha(c)	isalpha(c)
30 #define	isphonogram(c)	0
31 #define	isideogram(c)	0
32 #define	isauxsp(c) 	0
33 #define	isauxspZ 	0
34 #endif
35 extern unsigned short _cmap[];/* Defined in sh.char.c */
36 extern unsigned int Z; 	/* A place to save macro arg to avoid side-effect!*/
37 
38 #define _Q	0x01		/* '" */
39 #define _Q1	0x02		/* ` */
40 #define _SP	0x04		/* space and tab */
41 #define _NL	0x08		/* \n */
42 #define _META	0x10		/* lex meta characters, sp #'`";&<>()|\t\n */
43 #define _GLOB	0x20		/* glob characters, *?{[` */
44 #define _ESC	0x40		/* \ */
45 #define _DOL	0x80		/* $ */
46 #define _DIG    0x100		/* 0-9 */
47 #define _LET    0x200		/* a-z, A-Z, _ 	NO LONGER OF REAL USE. */
48 
49 
50 #define quoted(c)     ((unsigned)(c) & QUOTE)
51 
52 #define	cmapZ(bits)	(isascii(Z)?(_cmap[Z] & (bits)):0)
53 #define cmap(c, bits)	(Z=((unsigned)(c)), cmapZ(bits))
54 
55 #define isglob(c)	cmap(c, _GLOB)
56 #define ismeta(c)	cmap(c, _META)
57 #define digit(c)	cmap(c, _DIG)
58 #define issp(c)		(Z=((unsigned)(c)), cmapZ( _SP)||isauxspZ)
59 /*WAS isspace(c)*/
60 #define isspnl(c)	(Z=((unsigned)(c)), cmapZ( _SP|_NL)||isauxspZ)
61 #define letter(c)	\
62 	(Z=((unsigned)(c)), !quoted(Z)&&(iswalpha(Z)||((Z)=='_')\
63 	||isphonogram(Z)||isideogram(Z)))
64 #define alnum(c)	\
65 	(Z=((unsigned)(c)), !quoted(Z)&&(iswalpha(Z)||((Z)=='_')\
66 	||iswdigit(Z)||isphonogram(Z)||isideogram(Z)))
67