1/*	$OpenBSD: extern.h,v 1.55 2017/06/15 13:48:42 bcallah Exp $	*/
2/*	$NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $	*/
3
4/*-
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Copyright (c) 1991, 1993
8 *	The Regents of the University of California.  All rights reserved.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * Ozan Yigit at York University.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 *    may be used to endorse or promote products derived from this software
23 *    without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38/* eval.c */
39extern void	eval(const char *[], int, int, int);
40extern void	dodefine(const char *, const char *);
41extern unsigned long expansion_id;
42
43/* expr.c */
44extern int	expr(const char *);
45
46/* gnum4.c */
47extern void	addtoincludepath(const char *);
48extern struct input_file *fopen_trypath(struct input_file *, const char *);
49extern void doindir(const char *[], int);
50extern void dobuiltin(const char *[], int);
51extern void dopatsubst(const char *[], int);
52extern void doregexp(const char *[], int);
53
54extern void doprintlineno(struct input_file *);
55extern void doprintfilename(struct input_file *);
56
57extern void doesyscmd(const char *);
58extern void getdivfile(const char *);
59extern void doformat(const char *[], int);
60
61extern void m4_warnx(const char *, ...);
62
63/* look.c */
64
65#define FLAG_UNTRACED 0
66#define FLAG_TRACED 1
67#define FLAG_NO_TRACE 2
68
69extern void	init_macros(void);
70extern ndptr	lookup(const char *);
71extern void mark_traced(const char *, int);
72extern struct ohash macros;
73
74extern struct macro_definition *lookup_macro_definition(const char *);
75extern void	macro_define(const char *, const char *);
76extern void	macro_pushdef(const char *, const char *);
77extern void	macro_popdef(const char *);
78extern void	macro_undefine(const char *);
79extern void	setup_builtin(const char *, unsigned int);
80extern void	macro_for_all(void (*)(const char *, struct macro_definition *));
81#define macro_getdef(p)		((p)->d)
82#define macro_name(p)		((p)->name)
83#define macro_builtin_type(p)	((p)->builtin_type)
84#define is_traced(p) ((p)->trace_flags == FLAG_NO_TRACE ? (trace_flags & TRACE_ALL) : (p)->trace_flags)
85
86extern ndptr macro_getbuiltin(const char *);
87
88/* main.c */
89extern void outputstr(const char *);
90extern void do_emit_synchline(void);
91extern int exit_code;
92#define emit_synchline() do { if (synch_lines) do_emit_synchline(); } while(0)
93
94/* misc.c */
95extern void	chrsave(int);
96extern char	*compute_prevep(void);
97extern void	getdiv(int);
98extern ptrdiff_t indx(const char *, const char *);
99extern void	initspaces(void);
100extern void	killdiv(void);
101extern void	onintr(int);
102extern void	pbnum(int);
103extern void	pbnumbase(int, int, int);
104extern void	pbunsigned(unsigned long);
105extern void	pbstr(const char *);
106extern void	pushback(int);
107extern void	*xalloc(size_t, const char *, ...) __printf0like(2, 3);
108extern void	*xcalloc(size_t, size_t, const char *, ...) __printf0like(3, 4);
109extern void	*xrealloc(void *, size_t, const char *, ...) __printf0like(3, 4);
110extern void	*xreallocarray(void *, size_t, size_t, const char *, ...) __printf0like(4, 5);
111extern char	*xstrdup(const char *);
112extern void	usage(void);
113extern void	resizedivs(int);
114extern size_t	buffer_mark(void);
115extern void	dump_buffer(FILE *, size_t);
116extern void	m4errx(int, const char *, ...) __dead2 __printf0like(2, 3);
117
118extern int	obtain_char(struct input_file *);
119extern void	set_input(struct input_file *, FILE *, const char *);
120extern void	release_input(struct input_file *);
121
122/* speeded-up versions of chrsave/pushback */
123#define PUSHBACK(c)				\
124	do {					\
125		if (bp >= endpbb)		\
126			enlarge_bufspace();	\
127		*bp++ = (c);			\
128	} while(0)
129
130#define CHRSAVE(c)				\
131	do {					\
132		if (ep >= endest)		\
133			enlarge_strspace();	\
134		*ep++ = (c);			\
135	} while(0)
136
137/* and corresponding exposure for local symbols */
138extern void enlarge_bufspace(void);
139extern void enlarge_strspace(void);
140extern unsigned char *endpbb;
141extern char *endest;
142
143/* trace.c */
144extern unsigned int trace_flags;
145#define TRACE_ALL	512
146extern void trace_file(const char *);
147extern size_t trace(const char **, int, struct input_file *);
148extern void finish_trace(size_t);
149extern void set_trace_flags(const char *);
150extern FILE *traceout;
151
152extern stae *mstack;		/* stack of m4 machine */
153extern char *sstack;		/* shadow stack, for string space extension */
154extern FILE *active;		/* active output file pointer */
155extern struct input_file infile[];/* input file stack (0=stdin) */
156extern FILE **outfile;		/* diversion array(0=bitbucket) */
157extern int maxout;		/* maximum number of diversions */
158extern int fp;			/* m4 call frame pointer */
159extern int ilevel;		/* input file stack pointer */
160extern int oindex;		/* diversion index. */
161extern int sp;			/* current m4 stack pointer */
162extern unsigned char *bp;	/* first available character */
163extern unsigned char *buf;	/* push-back buffer */
164extern unsigned char *bufbase;	/* buffer base for this ilevel */
165extern unsigned char *bbase[];	/* buffer base per ilevel */
166extern char ecommt[MAXCCHARS+1];/* end character for comment */
167extern char *ep;		/* first free char in strspace */
168extern char lquote[MAXCCHARS+1];/* left quote character (`) */
169extern char **m4wraps;		/* m4wrap string default. */
170extern int maxwraps;		/* size of m4wraps array */
171extern int wrapindex;		/* current index in m4wraps */
172
173extern const char *null;	/* as it says.. just a null. */
174extern char rquote[MAXCCHARS+1];/* right quote character (') */
175extern char scommt[MAXCCHARS+1];/* start character for comment */
176extern int  synch_lines;	/* line synchronisation directives */
177
178extern int mimic_gnu;		/* behaves like gnu-m4 */
179extern int prefix_builtins;	/* prefix builtin macros with m4_ */
180extern int error_warns;		/* make warnings cause exit_code = 1 */
181extern int fatal_warns;		/* make warnings fatal */
182