xref: /titanic_44/usr/src/cmd/sgs/m4/common/m4.h (revision 4eaa471005973e11a6110b69fe990530b3b95a38)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include	<ctype.h>
34 #include	<stdio.h>
35 #include	<stdlib.h>
36 #include	<string.h>
37 #include	<locale.h>
38 #include	<limits.h>
39 
40 #include	<wchar.h>
41 #include	<wctype.h>
42 
43 #define	EOS	((wchar_t)0)
44 #define	MAXSYM	5
45 #define	PUSH	1
46 #define	NOPUSH	0
47 #define	OK	0
48 #define	NOT_OK	1
49 
50 #define	BUILTIN		0x40000000
51 #define	INVALID_CHAR	0x80000000
52 #define	builtin(x)	((x) | BUILTIN)
53 #define	builtin_idx(x)	((x) & (wchar_t)~BUILTIN)
54 #define	is_builtin(x)	((x) != WEOF && ((x) & BUILTIN))
55 
56 /*
57  * Since we have expanded char to wchar_t, large vaule(has BUILTIN set)
58  * can be given to the ctype macros. First check BUILTIN, and return
59  * FALSE if it was set. EOF/WEOF will be in this case.
60  */
61 #define	is_alpha(x)	(!is_builtin(x) && \
62 				(wide ? iswalpha(x) : isalpha(x)))
63 #define	is_alnum(x)	(!is_builtin(x) && \
64 				(wide ? iswalnum(x) : isalnum(x)))
65 #define	is_space(x)	(!is_builtin(x) && \
66 				(wide ? iswspace(x) : isspace(x)))
67 #define	is_digit(x)	(!is_builtin(x) && iswascii(x) && isdigit(x))
68 
69 
70 struct bs {
71 	void	(*bfunc)(wchar_t **, int);
72 	wchar_t	*bname;
73 };
74 
75 struct	call {
76 	wchar_t	**argp;
77 	int	plev;
78 };
79 
80 struct	nlist {
81 	wchar_t	*name;
82 	wchar_t	*def;
83 	char	tflag;
84 	struct	nlist *next;
85 };
86 
87 struct Wrap {
88 	wchar_t *wrapstr;
89 	struct Wrap *nxt;
90 };
91 
92 typedef struct {
93 	unsigned char buffer[MB_LEN_MAX + 1];
94 	char nbytes;
95 } ibuf_t;
96 
97 extern FILE	*cf;
98 extern FILE	*ifile[];
99 extern FILE	*ofile[];
100 extern FILE	*xfopen(char *, char *);
101 extern wchar_t	**Ap;
102 extern wchar_t	**argstk;
103 extern wchar_t	*astklm;
104 extern void	*xmalloc(size_t);
105 extern char	*fname[];
106 extern wchar_t	*ibuf;
107 extern wchar_t	*ibuflm;
108 extern wchar_t	*ip;
109 extern wchar_t	*ipflr;
110 extern wchar_t	*ipstk[10];
111 extern wchar_t	*obuf;
112 extern wchar_t	*obuflm;
113 extern wchar_t	*op;
114 extern char	*procnam;
115 extern char	*tempfile;
116 extern wchar_t	*token;
117 extern wchar_t	*toklm;
118 extern wchar_t	C;
119 extern wchar_t	getchr();
120 extern wchar_t	lcom[];
121 extern wchar_t	lquote[];
122 extern wchar_t	nullstr[];
123 extern wchar_t	rcom[];
124 extern wchar_t	rquote[];
125 extern int	bufsize;
126 extern int	fline[];
127 extern int	hshsize;
128 extern unsigned int	hshval;
129 extern int	ifx;
130 extern int	nflag;
131 extern int	ofx;
132 extern int	sflag;
133 extern int	stksize;
134 extern int	sysrval;
135 extern int	toksize;
136 extern int	trace;
137 extern int	exitstat;
138 extern long	ctol(wchar_t *);
139 extern struct bs	barray[];
140 extern struct call	*Cp;
141 extern struct call	*callst;
142 extern struct nlist	**hshtab;
143 extern void	install();
144 extern struct nlist	*lookup();
145 extern struct Wrap	*wrapstart;
146 extern int	wide;
147 extern ibuf_t	ibuffer[];
148 
149 extern void setfname(char *);
150 extern void pbstr(wchar_t *);
151 extern void pbnum(long);
152 extern void pbnbr(long, int, int);
153 extern void undiv(int, int);
154 extern void delexit(int, int);
155 extern void error(char *);
156 extern int min(int, int);
157 extern void putbak(wchar_t);
158 extern void stkchr(wchar_t);
159 extern void error2(char *, int);
160 
161 extern wchar_t *wstrdup(wchar_t *);
162 extern int wstoi(wchar_t *);
163 extern char *wstr2str(wchar_t *, int);
164 extern wchar_t *str2wstr(char *, int);
165 
166 extern void dodef(wchar_t **, int);
167 extern void doundef(wchar_t **, int);
168 extern int undef(wchar_t *);
169 
170 /*
171  * macros for performance reason.
172  */
173 #define	putbak(c)	\
174 	if (ip < ibuflm)	\
175 		*ip++ = (c);	\
176 	else	\
177 		error2(gettext("pushed back more than %d chars"), bufsize)
178 
179 #define	stkchr(c)	\
180 	if (op < obuflm)	\
181 		*op++ = (c);	\
182 	else	\
183 		error2(gettext("more than %d chars of argument text"), bufsize)
184