summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sgs/m4/common/m4.h
blob: 279448732eea3702228532070142e96b79edd8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*	Copyright (c) 1988 AT&T	*/
/*	  All Rights Reserved  	*/


/*
 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
 */

/*
 * Copyright (c) 2011 Gary Mills
 */

#ifndef	_M4_H
#define	_M4_H

#include	<ctype.h>
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<errno.h>
#include	<locale.h>
#include	<limits.h>

#include	<wchar.h>
#include	<wctype.h>

#define	EOS	((wchar_t)0)
#define	MAXSYM	5
#define	PUSH	1
#define	NOPUSH	0
#define	OK	0
#define	NOT_OK	1

/* Used in m4.c and m4ext.c */
#define	DEF_HSHSIZE	199	/* default hash table size (prime). */
#define	DEF_BUFSIZE	4096	/* default pushback & arg text buffers size */
#define	DEF_STKSIZE	100	/* default call stack size */
#define	DEF_TOKSIZE	512	/* default token buffer size */

#define	BUILTIN		0x40000000
#define	INVALID_CHAR	0x80000000
#define	builtin(x)	((x) | BUILTIN)
#define	builtin_idx(x)	((x) & (wchar_t)~BUILTIN)
#define	is_builtin(x)	((x) != WEOF && ((x) & BUILTIN))

/*
 * Since we have expanded char to wchar_t, large vaule(has BUILTIN set)
 * can be given to the ctype macros. First check BUILTIN, and return
 * FALSE if it was set. EOF/WEOF will be in this case.
 */
#define	is_alpha(x)	(!is_builtin(x) && \
				(wide ? iswalpha(x) : isalpha(x)))
#define	is_alnum(x)	(!is_builtin(x) && \
				(wide ? iswalnum(x) : isalnum(x)))
#define	is_space(x)	(!is_builtin(x) && \
				(wide ? iswspace(x) : isspace(x)))
#define	is_digit(x)	(!is_builtin(x) && iswascii(x) && isdigit(x))


struct bs {
	void	(*bfunc)(wchar_t **, int);
	wchar_t	*bname;
};

struct	call {
	wchar_t	**argp;
	int	plev;
};

struct	nlist {
	wchar_t	*name;
	wchar_t	*def;
	char	tflag;
	struct	nlist *next;
};

struct Wrap {
	wchar_t *wrapstr;
	struct Wrap *nxt;
};

typedef struct {
	unsigned char buffer[MB_LEN_MAX + 1];
	char nbytes;
} ibuf_t;

extern FILE	*cf;
extern FILE	*ifile[];
extern FILE	*ofile[];
extern FILE	*xfopen(char *, char *);
extern wchar_t	**Ap;
extern wchar_t	**argstk;
extern wchar_t	*astklm;
extern void	*xmalloc(size_t);
extern char	*fname[];
extern wchar_t	*ibuf;
extern wchar_t	*ibuflm;
extern wchar_t	*ip;
extern wchar_t	*ipflr;
extern wchar_t	*ipstk[10];
extern wchar_t	*obuf;
extern wchar_t	*obuflm;
extern wchar_t	*op;
extern char	*procnam;
extern char	*tempfile;
extern wchar_t	*token;
extern wchar_t	*toklm;
extern wchar_t	C;
extern wchar_t	getchr();
extern wchar_t	lcom[];
extern wchar_t	lquote[];
extern wchar_t	nullstr[];
extern wchar_t	rcom[];
extern wchar_t	rquote[];
extern int	bufsize;
extern int	fline[];
extern int	hshsize;
extern unsigned int	hshval;
extern int	ifx;
extern int	nflag;
extern int	ofx;
extern int	sflag;
extern int	stksize;
extern int	sysrval;
extern int	toksize;
extern int	trace;
extern int	exitstat;
extern long	ctol(wchar_t *);
extern struct bs	barray[];
extern struct call	*Cp;
extern struct call	*callst;
extern struct nlist	**hshtab;
extern void	install();
extern struct nlist	*lookup();
extern struct Wrap	*wrapstart;
extern int	wide;
extern ibuf_t	ibuffer[];

extern void setfname(char *);
extern void pbstr(wchar_t *);
extern void pbnum(long);
extern void pbnbr(long, int, int);
extern void undiv(int, int);
extern void delexit(int, int);
extern void error(char *);
extern int min(int, int);
extern void putbak(wchar_t);
extern void stkchr(wchar_t);
extern void errorf(char *, char *);
extern void error2(char *, int);

extern wchar_t *wstrdup(wchar_t *);
extern int wstoi(wchar_t *);
extern char *wstr2str(wchar_t *, int);
extern wchar_t *str2wstr(char *, int);

extern void dodef(wchar_t **, int);
extern void doundef(wchar_t **, int);
extern int undef(wchar_t *);

/*
 * macros for performance reason.
 */
#define	putbak(c)	\
	if (ip < ibuflm)	\
		*ip++ = (c);	\
	else	\
		error2(gettext("pushed back more than %d chars"), bufsize)

#define	stkchr(c)	\
	if (op < obuflm)	\
		*op++ = (c);	\
	else	\
		error2(gettext("more than %d chars of argument text"), bufsize)

#endif	/* _M4_H */