xref: /onnv-gate/usr/src/cmd/sgs/m4/common/m4ext.c (revision 12955:1e73c8f5a88b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*12955Srich.burridge@oracle.com  * Common Development and Distribution License (the "License").
6*12955Srich.burridge@oracle.com  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
220Sstevel@tonic-gate /*	  All Rights Reserved  	*/
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
26*12955Srich.burridge@oracle.com  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include	"m4.h"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /* storage params */
33*12955Srich.burridge@oracle.com int	hshsize 	= DEF_HSHSIZE;	/* hash table size (prime) */
34*12955Srich.burridge@oracle.com int	bufsize 	= DEF_BUFSIZE;	/* pushback & arg text buffers */
35*12955Srich.burridge@oracle.com int	stksize 	= DEF_STKSIZE;	/* call stack */
36*12955Srich.burridge@oracle.com int	toksize 	= DEF_TOKSIZE;	/* biggest word ([a-z_][a-z0-9_]*) */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /* pushback buffer */
400Sstevel@tonic-gate wchar_t	*ibuf;				/* buffer */
410Sstevel@tonic-gate wchar_t	*ibuflm;			/* highest buffer addr */
420Sstevel@tonic-gate wchar_t	*ip;				/* current position */
430Sstevel@tonic-gate wchar_t	*ipflr;				/* buffer floor */
440Sstevel@tonic-gate wchar_t 	*ipstk[10];			/* stack for "ipflr"s */
450Sstevel@tonic-gate 
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /* arg collection buffer */
480Sstevel@tonic-gate wchar_t	*obuf;				/* buffer */
490Sstevel@tonic-gate wchar_t	*obuflm;			/* high address */
500Sstevel@tonic-gate wchar_t	*op;				/* current position */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /* call stack */
540Sstevel@tonic-gate struct call	*callst;		/* stack */
550Sstevel@tonic-gate struct call	*Cp 	= NULL;		/* position */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /* token storage */
590Sstevel@tonic-gate wchar_t	*token;				/* buffer */
600Sstevel@tonic-gate wchar_t	*toklm;				/* high addr */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /* file name and current line storage for line sync and diagnostics */
640Sstevel@tonic-gate char	*fname[11];			/* file name ptr stack */
650Sstevel@tonic-gate int	fline[10];			/* current line nbr stack */
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /* input file stuff for "include"s */
690Sstevel@tonic-gate FILE	*ifile[10] 	= {stdin};	/* stack */
700Sstevel@tonic-gate int	ifx;				/* stack index */
710Sstevel@tonic-gate ibuf_t	ibuffer[11];			/* input buffer */
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /* stuff for output diversions */
740Sstevel@tonic-gate FILE	*cf 	= stdout;		/* current output file */
750Sstevel@tonic-gate FILE	*ofile[11] 	= {stdout};	/* output file stack */
760Sstevel@tonic-gate int	ofx;				/* stack index */
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /* comment markers */
800Sstevel@tonic-gate wchar_t	lcom[MAXSYM+1] 	= L"#";
810Sstevel@tonic-gate wchar_t	rcom[MAXSYM+1] 	= L"\n";
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 
840Sstevel@tonic-gate /* quote markers */
850Sstevel@tonic-gate wchar_t	lquote[MAXSYM+1]  = L"`";
860Sstevel@tonic-gate wchar_t	rquote[MAXSYM+1]  = L"\'";
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /* argument ptr stack */
900Sstevel@tonic-gate wchar_t	**argstk;
910Sstevel@tonic-gate wchar_t	*astklm;			/* high address */
920Sstevel@tonic-gate wchar_t	**Ap;				/* current position */
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /* symbol table */
960Sstevel@tonic-gate struct nlist	**hshtab;		/* hash table */
970Sstevel@tonic-gate unsigned int	hshval;			/* last hash val */
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate /* misc */
1010Sstevel@tonic-gate char	*procnam;			/* argv[0] */
1020Sstevel@tonic-gate char	*tempfile;			/* used for diversion files */
1030Sstevel@tonic-gate struct	Wrap *wrapstart = NULL;	/* first entry in of list of "m4wrap" strings */
1040Sstevel@tonic-gate wchar_t	nullstr[] 	= {0};
1050Sstevel@tonic-gate int	nflag 	= 1;			/* name flag, used for line sync code */
1060Sstevel@tonic-gate int	sflag;				/* line sync flag */
1070Sstevel@tonic-gate int	sysrval;			/* return val from syscmd */
1080Sstevel@tonic-gate int	trace;				/* global trace flag */
1090Sstevel@tonic-gate int	exitstat = OK;			/* global exit status */
1100Sstevel@tonic-gate int	wide;				/* multi-byte locale */
111