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