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