xref: /minix3/usr.bin/m4/extern.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
12e8d1edaSArun Thomas /*	$OpenBSD: extern.h,v 1.49 2009/10/14 17:19:47 sthen Exp $	*/
2*0a6a1f1dSLionel Sambuc /*	$NetBSD: extern.h,v 1.17 2015/01/29 03:27:06 christos Exp $	*/
32e8d1edaSArun Thomas 
42e8d1edaSArun Thomas /*-
52e8d1edaSArun Thomas  * Copyright (c) 1991, 1993
62e8d1edaSArun Thomas  *	The Regents of the University of California.  All rights reserved.
72e8d1edaSArun Thomas  *
82e8d1edaSArun Thomas  * This code is derived from software contributed to Berkeley by
92e8d1edaSArun Thomas  * Ozan Yigit at York University.
102e8d1edaSArun Thomas  *
112e8d1edaSArun Thomas  * Redistribution and use in source and binary forms, with or without
122e8d1edaSArun Thomas  * modification, are permitted provided that the following conditions
132e8d1edaSArun Thomas  * are met:
142e8d1edaSArun Thomas  * 1. Redistributions of source code must retain the above copyright
152e8d1edaSArun Thomas  *    notice, this list of conditions and the following disclaimer.
162e8d1edaSArun Thomas  * 2. Redistributions in binary form must reproduce the above copyright
172e8d1edaSArun Thomas  *    notice, this list of conditions and the following disclaimer in the
182e8d1edaSArun Thomas  *    documentation and/or other materials provided with the distribution.
192e8d1edaSArun Thomas  * 3. Neither the name of the University nor the names of its contributors
202e8d1edaSArun Thomas  *    may be used to endorse or promote products derived from this software
212e8d1edaSArun Thomas  *    without specific prior written permission.
222e8d1edaSArun Thomas  *
232e8d1edaSArun Thomas  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
242e8d1edaSArun Thomas  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
252e8d1edaSArun Thomas  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
262e8d1edaSArun Thomas  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
272e8d1edaSArun Thomas  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
282e8d1edaSArun Thomas  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
292e8d1edaSArun Thomas  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
302e8d1edaSArun Thomas  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
312e8d1edaSArun Thomas  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
322e8d1edaSArun Thomas  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
332e8d1edaSArun Thomas  * SUCH DAMAGE.
342e8d1edaSArun Thomas  *
352e8d1edaSArun Thomas  *	@(#)extern.h	8.1 (Berkeley) 6/6/93
362e8d1edaSArun Thomas  */
372e8d1edaSArun Thomas 
382e8d1edaSArun Thomas /* eval.c */
392e8d1edaSArun Thomas extern void	eval(const char *[], int, int, int);
402e8d1edaSArun Thomas extern void	dodefine(const char *, const char *);
412e8d1edaSArun Thomas extern unsigned long expansion_id;
422e8d1edaSArun Thomas 
432e8d1edaSArun Thomas /* expr.c */
442e8d1edaSArun Thomas extern int	expr(const char *);
452e8d1edaSArun Thomas 
462e8d1edaSArun Thomas /* gnum4.c */
472e8d1edaSArun Thomas extern void 	addtoincludepath(const char *);
482e8d1edaSArun Thomas extern struct input_file *fopen_trypath(struct input_file *, const char *);
492e8d1edaSArun Thomas extern void doindir(const char *[], int);
502e8d1edaSArun Thomas extern void dobuiltin(const char *[], int);
512e8d1edaSArun Thomas extern void dopatsubst(const char *[], int);
522e8d1edaSArun Thomas extern void doregexp(const char *[], int);
532e8d1edaSArun Thomas 
542e8d1edaSArun Thomas extern void doprintlineno(struct input_file *);
552e8d1edaSArun Thomas extern void doprintfilename(struct input_file *);
562e8d1edaSArun Thomas 
572e8d1edaSArun Thomas extern void doesyscmd(const char *);
582e8d1edaSArun Thomas extern void getdivfile(const char *);
592e8d1edaSArun Thomas extern void doformat(const char *[], int);
602e8d1edaSArun Thomas 
612e8d1edaSArun Thomas 
622e8d1edaSArun Thomas /* look.c */
632e8d1edaSArun Thomas 
642e8d1edaSArun Thomas #define FLAG_UNTRACED 0
652e8d1edaSArun Thomas #define FLAG_TRACED 1
662e8d1edaSArun Thomas #define FLAG_NO_TRACE 2
672e8d1edaSArun Thomas 
682e8d1edaSArun Thomas extern void	init_macros(void);
692e8d1edaSArun Thomas extern ndptr	lookup(const char *);
702e8d1edaSArun Thomas extern void mark_traced(const char *, int);
712e8d1edaSArun Thomas extern struct ohash macros;
722e8d1edaSArun Thomas 
732e8d1edaSArun Thomas extern struct macro_definition *lookup_macro_definition(const char *);
742e8d1edaSArun Thomas extern void 	macro_define(const char *, const char *);
752e8d1edaSArun Thomas extern void 	macro_pushdef(const char *, const char *);
762e8d1edaSArun Thomas extern void 	macro_popdef(const char *);
772e8d1edaSArun Thomas extern void 	macro_undefine(const char *);
782e8d1edaSArun Thomas extern void 	setup_builtin(const char *, unsigned int);
792e8d1edaSArun Thomas extern void 	macro_for_all(void (*)(const char *, struct macro_definition *));
802e8d1edaSArun Thomas #define macro_getdef(p) 	((p)->d)
812e8d1edaSArun Thomas #define macro_name(p)		((p)->name)
822e8d1edaSArun Thomas #define macro_builtin_type(p)	((p)->builtin_type)
832e8d1edaSArun Thomas #define is_traced(p) ((p)->trace_flags == FLAG_NO_TRACE ? (trace_flags & TRACE_ALL) : (p)->trace_flags)
842e8d1edaSArun Thomas 
852e8d1edaSArun Thomas extern ndptr macro_getbuiltin(const char *);
862e8d1edaSArun Thomas 
872e8d1edaSArun Thomas /* main.c */
882e8d1edaSArun Thomas extern void outputstr(const char *);
892e8d1edaSArun Thomas extern void do_emit_synchline(void);
902e8d1edaSArun Thomas #define emit_synchline() do { if (synch_lines) do_emit_synchline(); } while(0)
912e8d1edaSArun Thomas 
922e8d1edaSArun Thomas /* misc.c */
932e8d1edaSArun Thomas extern void	chrsave(int);
942e8d1edaSArun Thomas extern char 	*compute_prevep(void);
952e8d1edaSArun Thomas extern void	getdiv(int);
962e8d1edaSArun Thomas extern ptrdiff_t indx(const char *, const char *);
972e8d1edaSArun Thomas extern void 	initspaces(void);
982e8d1edaSArun Thomas extern void	killdiv(void);
992e8d1edaSArun Thomas extern void	pbnum(int);
1002e8d1edaSArun Thomas extern void	pbnumbase(int, int, int);
1012e8d1edaSArun Thomas extern void	pbunsigned(unsigned long);
1022e8d1edaSArun Thomas extern void	pbstr(const char *);
1032e8d1edaSArun Thomas extern void	pushback(int);
10471c7dcb9SLionel Sambuc extern void	*xalloc(size_t, const char *fmt, ...) __printflike(2, 3);
10571c7dcb9SLionel Sambuc extern void	*xrealloc(void *, size_t, const char *fmt, ...)
10671c7dcb9SLionel Sambuc     __printflike(3, 4);
1072e8d1edaSArun Thomas extern char	*xstrdup(const char *);
1082e8d1edaSArun Thomas extern void	resizedivs(int);
1092e8d1edaSArun Thomas extern size_t	buffer_mark(void);
1102e8d1edaSArun Thomas extern void	dump_buffer(FILE *, size_t);
11171c7dcb9SLionel Sambuc extern void	__dead m4errx(int, const char *, ...) __printflike(2, 3);
1122e8d1edaSArun Thomas 
1132e8d1edaSArun Thomas extern int 	obtain_char(struct input_file *);
1142e8d1edaSArun Thomas extern void	set_input(struct input_file *, FILE *, const char *);
1152e8d1edaSArun Thomas extern void	release_input(struct input_file *);
1162e8d1edaSArun Thomas 
1172e8d1edaSArun Thomas /* speeded-up versions of chrsave/pushback */
1182e8d1edaSArun Thomas #define PUSHBACK(c)				\
1192e8d1edaSArun Thomas 	do {					\
1202e8d1edaSArun Thomas 		if (bp >= endpbb)		\
1212e8d1edaSArun Thomas 			enlarge_bufspace();	\
1222e8d1edaSArun Thomas 		*bp++ = (c);			\
1232e8d1edaSArun Thomas 	} while(0)
1242e8d1edaSArun Thomas 
1252e8d1edaSArun Thomas #define CHRSAVE(c)				\
1262e8d1edaSArun Thomas 	do {					\
1272e8d1edaSArun Thomas 		if (ep >= endest)		\
1282e8d1edaSArun Thomas 			enlarge_strspace();	\
1292e8d1edaSArun Thomas 		*ep++ = (c);			\
1302e8d1edaSArun Thomas 	} while(0)
1312e8d1edaSArun Thomas 
1322e8d1edaSArun Thomas /* and corresponding exposure for local symbols */
1332e8d1edaSArun Thomas extern void enlarge_bufspace(void);
1342e8d1edaSArun Thomas extern void enlarge_strspace(void);
1352e8d1edaSArun Thomas extern unsigned char *endpbb;
1362e8d1edaSArun Thomas extern char *endest;
1372e8d1edaSArun Thomas 
1382e8d1edaSArun Thomas /* trace.c */
1392e8d1edaSArun Thomas extern unsigned int trace_flags;
1402e8d1edaSArun Thomas #define TRACE_ALL	512
1412e8d1edaSArun Thomas extern void trace_file(const char *);
1422e8d1edaSArun Thomas extern size_t trace(const char **, int, struct input_file *);
1432e8d1edaSArun Thomas extern void finish_trace(size_t);
1442e8d1edaSArun Thomas extern void set_trace_flags(const char *);
1452e8d1edaSArun Thomas extern FILE *traceout;
1462e8d1edaSArun Thomas 
1472e8d1edaSArun Thomas extern ndptr hashtab[];		/* hash table for macros etc. */
1482e8d1edaSArun Thomas extern stae *mstack;		/* stack of m4 machine */
1492e8d1edaSArun Thomas extern char *sstack;		/* shadow stack, for string space extension */
1502e8d1edaSArun Thomas extern FILE *active;		/* active output file pointer */
1512e8d1edaSArun Thomas extern struct input_file infile[];/* input file stack (0=stdin) */
1522e8d1edaSArun Thomas extern FILE **outfile;		/* diversion array(0=bitbucket) */
1532e8d1edaSArun Thomas extern int maxout;		/* maximum number of diversions */
1542e8d1edaSArun Thomas extern int fp; 			/* m4 call frame pointer */
1552e8d1edaSArun Thomas extern int ilevel;		/* input file stack pointer */
1562e8d1edaSArun Thomas extern int oindex;		/* diversion index. */
1572e8d1edaSArun Thomas extern int sp;			/* current m4 stack pointer */
1582e8d1edaSArun Thomas extern unsigned char *bp;	/* first available character */
1592e8d1edaSArun Thomas extern unsigned char *buf;	/* push-back buffer */
1602e8d1edaSArun Thomas extern unsigned char *bufbase;	/* buffer base for this ilevel */
1612e8d1edaSArun Thomas extern unsigned char *bbase[];	/* buffer base per ilevel */
1622e8d1edaSArun Thomas extern char ecommt[MAXCCHARS+1];/* end character for comment */
1632e8d1edaSArun Thomas extern char *ep;		/* first free char in strspace */
1642e8d1edaSArun Thomas extern char lquote[MAXCCHARS+1];/* left quote character (`) */
1652e8d1edaSArun Thomas extern char **m4wraps;		/* m4wrap string default. */
1662e8d1edaSArun Thomas extern int maxwraps;		/* size of m4wraps array */
1672e8d1edaSArun Thomas extern int wrapindex;		/* current index in m4wraps */
1682e8d1edaSArun Thomas 
1692e8d1edaSArun Thomas extern const char *null;	/* as it says.. just a null. */
1702e8d1edaSArun Thomas extern char rquote[MAXCCHARS+1];/* right quote character (') */
1712e8d1edaSArun Thomas extern char scommt[MAXCCHARS+1];/* start character for comment */
1722e8d1edaSArun Thomas extern int  synch_lines;	/* line synchronisation directives */
1732e8d1edaSArun Thomas 
1742e8d1edaSArun Thomas extern int mimic_gnu;		/* behaves like gnu-m4 */
1752e8d1edaSArun Thomas extern int prefix_builtins;	/* prefix builtin macros with m4_ */
176