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