xref: /titanic_41/usr/src/cmd/sgs/m4/common/m4.h (revision b3697b90e692e3e5d859fb77d285d4c056d99eda)
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 #ifndef	_M4_H
30 #define	_M4_H
31 
32 #include	<ctype.h>
33 #include	<stdio.h>
34 #include	<stdlib.h>
35 #include	<string.h>
36 #include	<locale.h>
37 #include	<limits.h>
38 
39 #include	<wchar.h>
40 #include	<wctype.h>
41 
42 #define	EOS	((wchar_t)0)
43 #define	MAXSYM	5
44 #define	PUSH	1
45 #define	NOPUSH	0
46 #define	OK	0
47 #define	NOT_OK	1
48 
49 /* Used in m4.c and m4ext.c */
50 #define	DEF_HSHSIZE	199	/* default hash table size (prime). */
51 #define	DEF_BUFSIZE	4096	/* default pushback & arg text buffers size */
52 #define	DEF_STKSIZE	100	/* default call stack size */
53 #define	DEF_TOKSIZE	512	/* default token buffer size */
54 
55 #define	BUILTIN		0x40000000
56 #define	INVALID_CHAR	0x80000000
57 #define	builtin(x)	((x) | BUILTIN)
58 #define	builtin_idx(x)	((x) & (wchar_t)~BUILTIN)
59 #define	is_builtin(x)	((x) != WEOF && ((x) & BUILTIN))
60 
61 /*
62  * Since we have expanded char to wchar_t, large vaule(has BUILTIN set)
63  * can be given to the ctype macros. First check BUILTIN, and return
64  * FALSE if it was set. EOF/WEOF will be in this case.
65  */
66 #define	is_alpha(x)	(!is_builtin(x) && \
67 				(wide ? iswalpha(x) : isalpha(x)))
68 #define	is_alnum(x)	(!is_builtin(x) && \
69 				(wide ? iswalnum(x) : isalnum(x)))
70 #define	is_space(x)	(!is_builtin(x) && \
71 				(wide ? iswspace(x) : isspace(x)))
72 #define	is_digit(x)	(!is_builtin(x) && iswascii(x) && isdigit(x))
73 
74 
75 struct bs {
76 	void	(*bfunc)(wchar_t **, int);
77 	wchar_t	*bname;
78 };
79 
80 struct	call {
81 	wchar_t	**argp;
82 	int	plev;
83 };
84 
85 struct	nlist {
86 	wchar_t	*name;
87 	wchar_t	*def;
88 	char	tflag;
89 	struct	nlist *next;
90 };
91 
92 struct Wrap {
93 	wchar_t *wrapstr;
94 	struct Wrap *nxt;
95 };
96 
97 typedef struct {
98 	unsigned char buffer[MB_LEN_MAX + 1];
99 	char nbytes;
100 } ibuf_t;
101 
102 extern FILE	*cf;
103 extern FILE	*ifile[];
104 extern FILE	*ofile[];
105 extern FILE	*xfopen(char *, char *);
106 extern wchar_t	**Ap;
107 extern wchar_t	**argstk;
108 extern wchar_t	*astklm;
109 extern void	*xmalloc(size_t);
110 extern char	*fname[];
111 extern wchar_t	*ibuf;
112 extern wchar_t	*ibuflm;
113 extern wchar_t	*ip;
114 extern wchar_t	*ipflr;
115 extern wchar_t	*ipstk[10];
116 extern wchar_t	*obuf;
117 extern wchar_t	*obuflm;
118 extern wchar_t	*op;
119 extern char	*procnam;
120 extern char	*tempfile;
121 extern wchar_t	*token;
122 extern wchar_t	*toklm;
123 extern wchar_t	C;
124 extern wchar_t	getchr();
125 extern wchar_t	lcom[];
126 extern wchar_t	lquote[];
127 extern wchar_t	nullstr[];
128 extern wchar_t	rcom[];
129 extern wchar_t	rquote[];
130 extern int	bufsize;
131 extern int	fline[];
132 extern int	hshsize;
133 extern unsigned int	hshval;
134 extern int	ifx;
135 extern int	nflag;
136 extern int	ofx;
137 extern int	sflag;
138 extern int	stksize;
139 extern int	sysrval;
140 extern int	toksize;
141 extern int	trace;
142 extern int	exitstat;
143 extern long	ctol(wchar_t *);
144 extern struct bs	barray[];
145 extern struct call	*Cp;
146 extern struct call	*callst;
147 extern struct nlist	**hshtab;
148 extern void	install();
149 extern struct nlist	*lookup();
150 extern struct Wrap	*wrapstart;
151 extern int	wide;
152 extern ibuf_t	ibuffer[];
153 
154 extern void setfname(char *);
155 extern void pbstr(wchar_t *);
156 extern void pbnum(long);
157 extern void pbnbr(long, int, int);
158 extern void undiv(int, int);
159 extern void delexit(int, int);
160 extern void error(char *);
161 extern int min(int, int);
162 extern void putbak(wchar_t);
163 extern void stkchr(wchar_t);
164 extern void error2(char *, int);
165 
166 extern wchar_t *wstrdup(wchar_t *);
167 extern int wstoi(wchar_t *);
168 extern char *wstr2str(wchar_t *, int);
169 extern wchar_t *str2wstr(char *, int);
170 
171 extern void dodef(wchar_t **, int);
172 extern void doundef(wchar_t **, int);
173 extern int undef(wchar_t *);
174 
175 /*
176  * macros for performance reason.
177  */
178 #define	putbak(c)	\
179 	if (ip < ibuflm)	\
180 		*ip++ = (c);	\
181 	else	\
182 		error2(gettext("pushed back more than %d chars"), bufsize)
183 
184 #define	stkchr(c)	\
185 	if (op < obuflm)	\
186 		*op++ = (c);	\
187 	else	\
188 		error2(gettext("more than %d chars of argument text"), bufsize)
189 
190 #endif	/* _M4_H */
191