xref: /illumos-gate/usr/src/cmd/sgs/lex/common/main.c (revision 7ab03f88)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
567298654Sdamico  * Common Development and Distribution License (the "License").
667298654Sdamico  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*7ab03f88SGary Mills  * Copyright (c) 2014 Gary Mills
23*7ab03f88SGary Mills  *
241dd08564Sab  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
297c478bd9Sstevel@tonic-gate /* All Rights Reserved */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /* Copyright 1976, Bell Telephone Laboratories, Inc. */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate #include "once.h"
357c478bd9Sstevel@tonic-gate #include "sgs.h"
367c478bd9Sstevel@tonic-gate #include <locale.h>
377c478bd9Sstevel@tonic-gate #include <limits.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate static wchar_t  L_INITIAL[] = {'I', 'N', 'I', 'T', 'I', 'A', 'L', 0};
407c478bd9Sstevel@tonic-gate static void get1core(void);
417c478bd9Sstevel@tonic-gate static void free1core(void);
427c478bd9Sstevel@tonic-gate static void get2core(void);
437c478bd9Sstevel@tonic-gate static void free2core(void);
447c478bd9Sstevel@tonic-gate static void get3core(void);
457c478bd9Sstevel@tonic-gate #ifdef DEBUG
467c478bd9Sstevel@tonic-gate static void free3core(void);
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)507c478bd9Sstevel@tonic-gate main(int argc, char **argv)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	int i;
537c478bd9Sstevel@tonic-gate 	int c;
54*7ab03f88SGary Mills 	char *apath = NULL;
55*7ab03f88SGary Mills 	char *ypath;
567c478bd9Sstevel@tonic-gate 	Boolean eoption = 0, woption = 0;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	sargv = argv;
597c478bd9Sstevel@tonic-gate 	sargc = argc;
601dd08564Sab 	(void) setlocale(LC_ALL, "");
617c478bd9Sstevel@tonic-gate #ifdef DEBUG
627c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "dyctvnewVQ:Y:")) != EOF) {
637c478bd9Sstevel@tonic-gate #else
647c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "ctvnewVQ:Y:")) != EOF) {
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate 		switch (c) {
677c478bd9Sstevel@tonic-gate #ifdef DEBUG
687c478bd9Sstevel@tonic-gate 			case 'd':
697c478bd9Sstevel@tonic-gate 				debug++;
707c478bd9Sstevel@tonic-gate 				break;
717c478bd9Sstevel@tonic-gate 			case 'y':
727c478bd9Sstevel@tonic-gate 				yydebug = TRUE;
737c478bd9Sstevel@tonic-gate 				break;
747c478bd9Sstevel@tonic-gate #endif
757c478bd9Sstevel@tonic-gate 			case 'V':
767c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "lex: %s %s\n",
777c478bd9Sstevel@tonic-gate 				    (const char *)SGU_PKG,
787c478bd9Sstevel@tonic-gate 				    (const char *)SGU_REL);
797c478bd9Sstevel@tonic-gate 				break;
807c478bd9Sstevel@tonic-gate 			case 'Q':
817c478bd9Sstevel@tonic-gate 				v_stmp = optarg;
827c478bd9Sstevel@tonic-gate 				if (*v_stmp != 'y' && *v_stmp != 'n')
837c478bd9Sstevel@tonic-gate 					error(
847c478bd9Sstevel@tonic-gate 					"lex: -Q should be followed by [y/n]");
857c478bd9Sstevel@tonic-gate 				break;
867c478bd9Sstevel@tonic-gate 			case 'Y':
87*7ab03f88SGary Mills 				apath = (char *)malloc(strlen(optarg) +
887c478bd9Sstevel@tonic-gate 				    sizeof ("/nceucform") + 1);
89*7ab03f88SGary Mills 				if (apath == NULL)
90*7ab03f88SGary Mills 					error("No available memory "
91*7ab03f88SGary Mills 					    "for directory name.");
92*7ab03f88SGary Mills 				else
93*7ab03f88SGary Mills 					apath = strcpy(apath, optarg);
947c478bd9Sstevel@tonic-gate 				break;
957c478bd9Sstevel@tonic-gate 			case 'c':
967c478bd9Sstevel@tonic-gate 				ratfor = FALSE;
977c478bd9Sstevel@tonic-gate 				break;
987c478bd9Sstevel@tonic-gate 			case 't':
997c478bd9Sstevel@tonic-gate 				fout = stdout;
1007c478bd9Sstevel@tonic-gate 				break;
1017c478bd9Sstevel@tonic-gate 			case 'v':
1027c478bd9Sstevel@tonic-gate 				report = 1;
1037c478bd9Sstevel@tonic-gate 				break;
1047c478bd9Sstevel@tonic-gate 			case 'n':
1057c478bd9Sstevel@tonic-gate 				report = 0;
1067c478bd9Sstevel@tonic-gate 				break;
1077c478bd9Sstevel@tonic-gate 			case 'w':
1087c478bd9Sstevel@tonic-gate 			case 'W':
1097c478bd9Sstevel@tonic-gate 				woption = 1;
1107c478bd9Sstevel@tonic-gate 				handleeuc = 1;
1117c478bd9Sstevel@tonic-gate 				widecio = 1;
1127c478bd9Sstevel@tonic-gate 				break;
1137c478bd9Sstevel@tonic-gate 			case 'e':
1147c478bd9Sstevel@tonic-gate 			case 'E':
1157c478bd9Sstevel@tonic-gate 				eoption = 1;
1167c478bd9Sstevel@tonic-gate 				handleeuc = 1;
1177c478bd9Sstevel@tonic-gate 				widecio = 0;
1187c478bd9Sstevel@tonic-gate 				break;
1197c478bd9Sstevel@tonic-gate 			default:
1207c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
121*7ab03f88SGary Mills 				"Usage: lex [-ewctvnV] [-Y directory] "
122*7ab03f88SGary Mills 				"[-Q(y/n)] [file]\n");
1237c478bd9Sstevel@tonic-gate 				exit(1);
1247c478bd9Sstevel@tonic-gate 		}
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 	if (woption && eoption) {
1277c478bd9Sstevel@tonic-gate 		error(
1287c478bd9Sstevel@tonic-gate 		"You may not specify both -w and -e simultaneously.");
1297c478bd9Sstevel@tonic-gate 	}
1307c478bd9Sstevel@tonic-gate 	no_input = argc - optind;
1317c478bd9Sstevel@tonic-gate 	if (no_input) {
1327c478bd9Sstevel@tonic-gate 		/* XCU4: recognize "-" file operand for stdin */
1337c478bd9Sstevel@tonic-gate 		if (strcmp(argv[optind], "-") == 0)
1347c478bd9Sstevel@tonic-gate 			fin = stdin;
1357c478bd9Sstevel@tonic-gate 		else {
1367c478bd9Sstevel@tonic-gate 			fin = fopen(argv[optind], "r");
1377c478bd9Sstevel@tonic-gate 			if (fin == NULL)
1387c478bd9Sstevel@tonic-gate 				error(
1397c478bd9Sstevel@tonic-gate 				"Can't open input file -- %s", argv[optind]);
1407c478bd9Sstevel@tonic-gate 		}
1417c478bd9Sstevel@tonic-gate 	} else
1427c478bd9Sstevel@tonic-gate 		fin = stdin;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	/* may be gotten: def, subs, sname, schar, ccl, dchar */
1457c478bd9Sstevel@tonic-gate 	(void) gch();
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	/* may be gotten: name, left, right, nullstr, parent */
1487c478bd9Sstevel@tonic-gate 	get1core();
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	scopy(L_INITIAL, sp);
1517c478bd9Sstevel@tonic-gate 	sname[0] = sp;
1527c478bd9Sstevel@tonic-gate 	sp += slength(L_INITIAL) + 1;
1537c478bd9Sstevel@tonic-gate 	sname[1] = 0;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	/* XCU4: %x exclusive start */
1567c478bd9Sstevel@tonic-gate 	exclusive[0] = 0;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	if (!handleeuc) {
1597c478bd9Sstevel@tonic-gate 		/*
1607c478bd9Sstevel@tonic-gate 		 * Set ZCH and ncg to their default values
1617c478bd9Sstevel@tonic-gate 		 * as they may be needed to handle %t directive.
1627c478bd9Sstevel@tonic-gate 		 */
1637c478bd9Sstevel@tonic-gate 		ZCH = ncg = NCH; /* ncg behaves as constant in this mode. */
1647c478bd9Sstevel@tonic-gate 	}
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* may be disposed of: def, subs, dchar */
1677c478bd9Sstevel@tonic-gate 	if (yyparse())
1687c478bd9Sstevel@tonic-gate 		exit(1);	/* error return code */
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	if (handleeuc) {
1717c478bd9Sstevel@tonic-gate 		ncg = ncgidtbl * 2;
1727c478bd9Sstevel@tonic-gate 		ZCH = ncg;
1737c478bd9Sstevel@tonic-gate 		if (ncg >= MAXNCG)
1747c478bd9Sstevel@tonic-gate 			error(
1757c478bd9Sstevel@tonic-gate 			"Too complex rules -- requires too many char groups.");
1767c478bd9Sstevel@tonic-gate 		sortcgidtbl();
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 	repbycgid(); /* Call this even in ASCII compat. mode. */
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	/*
1817c478bd9Sstevel@tonic-gate 	 * maybe get:
1827c478bd9Sstevel@tonic-gate 	 *		tmpstat, foll, positions, gotof, nexts,
1837c478bd9Sstevel@tonic-gate 	 *		nchar, state, atable, sfall, cpackflg
1847c478bd9Sstevel@tonic-gate 	 */
1857c478bd9Sstevel@tonic-gate 	free1core();
1867c478bd9Sstevel@tonic-gate 	get2core();
1877c478bd9Sstevel@tonic-gate 	ptail();
1887c478bd9Sstevel@tonic-gate 	mkmatch();
1897c478bd9Sstevel@tonic-gate #ifdef DEBUG
1907c478bd9Sstevel@tonic-gate 	if (debug)
1917c478bd9Sstevel@tonic-gate 		pccl();
1927c478bd9Sstevel@tonic-gate #endif
1937c478bd9Sstevel@tonic-gate 	sect  = ENDSECTION;
1947c478bd9Sstevel@tonic-gate 	if (tptr > 0)
1957c478bd9Sstevel@tonic-gate 		cfoll(tptr-1);
1967c478bd9Sstevel@tonic-gate #ifdef DEBUG
1977c478bd9Sstevel@tonic-gate 	if (debug)
1987c478bd9Sstevel@tonic-gate 		pfoll();
1997c478bd9Sstevel@tonic-gate #endif
2007c478bd9Sstevel@tonic-gate 	cgoto();
2017c478bd9Sstevel@tonic-gate #ifdef DEBUG
2027c478bd9Sstevel@tonic-gate 	if (debug) {
2037c478bd9Sstevel@tonic-gate 		(void) printf("Print %d states:\n", stnum + 1);
2047c478bd9Sstevel@tonic-gate 		for (i = 0; i <= stnum; i++)
2057c478bd9Sstevel@tonic-gate 			stprt(i);
2067c478bd9Sstevel@tonic-gate 	}
2077c478bd9Sstevel@tonic-gate #endif
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * may be disposed of:
2107c478bd9Sstevel@tonic-gate 	 *		positions, tmpstat, foll, state, name,
2117c478bd9Sstevel@tonic-gate 	 *		left, right, parent, ccl, schar, sname
2127c478bd9Sstevel@tonic-gate 	 * maybe get:	 verify, advance, stoff
2137c478bd9Sstevel@tonic-gate 	 */
2147c478bd9Sstevel@tonic-gate 	free2core();
2157c478bd9Sstevel@tonic-gate 	get3core();
2167c478bd9Sstevel@tonic-gate 	layout();
2177c478bd9Sstevel@tonic-gate 	/*
2187c478bd9Sstevel@tonic-gate 	 * may be disposed of:
2197c478bd9Sstevel@tonic-gate 	 *		verify, advance, stoff, nexts, nchar,
2207c478bd9Sstevel@tonic-gate 	 *		gotof, atable, ccpackflg, sfall
2217c478bd9Sstevel@tonic-gate 	 */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #ifdef DEBUG
2247c478bd9Sstevel@tonic-gate 	free3core();
2257c478bd9Sstevel@tonic-gate #endif
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	if (handleeuc) {
2287c478bd9Sstevel@tonic-gate 		if (ratfor)
2297c478bd9Sstevel@tonic-gate 			error("Ratfor is not supported by -w or -e option.");
230*7ab03f88SGary Mills 		ypath = EUCNAME;
2317c478bd9Sstevel@tonic-gate 	}
2327c478bd9Sstevel@tonic-gate 	else
233*7ab03f88SGary Mills 		ypath = ratfor ? RATNAME : CNAME;
2347c478bd9Sstevel@tonic-gate 
235*7ab03f88SGary Mills 	if (apath != NULL)
236*7ab03f88SGary Mills 		ypath = strcat(apath, strrchr(ypath, '/'));
237*7ab03f88SGary Mills 	fother = fopen(ypath, "r");
2387c478bd9Sstevel@tonic-gate 	if (fother == NULL)
239*7ab03f88SGary Mills 		error("Lex driver missing, file %s", ypath);
2407c478bd9Sstevel@tonic-gate 	while ((i = getc(fother)) != EOF)
2417c478bd9Sstevel@tonic-gate 		(void) putc((char)i, fout);
2427c478bd9Sstevel@tonic-gate 	(void) fclose(fother);
2437c478bd9Sstevel@tonic-gate 	(void) fclose(fout);
244*7ab03f88SGary Mills 	free(apath);
2457c478bd9Sstevel@tonic-gate 	if (report == 1)
2467c478bd9Sstevel@tonic-gate 		statistics();
2477c478bd9Sstevel@tonic-gate 	(void) fclose(stdout);
2487c478bd9Sstevel@tonic-gate 	(void) fclose(stderr);
2497c478bd9Sstevel@tonic-gate 	return (0);	/* success return code */
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate static void
2537c478bd9Sstevel@tonic-gate get1core(void)
2547c478bd9Sstevel@tonic-gate {
2551dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2567c478bd9Sstevel@tonic-gate 	ccptr =	ccl = (CHR *)myalloc(CCLSIZE, sizeof (*ccl));
2571dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2587c478bd9Sstevel@tonic-gate 	pcptr = pchar = (CHR *)myalloc(pchlen, sizeof (*pchar));
2591dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2607c478bd9Sstevel@tonic-gate 	def = (CHR **)myalloc(DEFSIZE, sizeof (*def));
2611dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2627c478bd9Sstevel@tonic-gate 	subs = (CHR **)myalloc(DEFSIZE, sizeof (*subs));
2631dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2647c478bd9Sstevel@tonic-gate 	dp = dchar = (CHR *)myalloc(DEFCHAR, sizeof (*dchar));
2651dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2667c478bd9Sstevel@tonic-gate 	sname = (CHR **)myalloc(STARTSIZE, sizeof (*sname));
2677c478bd9Sstevel@tonic-gate 	/* XCU4: exclusive start array */
2681dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2697c478bd9Sstevel@tonic-gate 	exclusive = (int *)myalloc(STARTSIZE, sizeof (*exclusive));
2701dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2717c478bd9Sstevel@tonic-gate 	sp = schar = (CHR *)myalloc(STARTCHAR, sizeof (*schar));
2727c478bd9Sstevel@tonic-gate 	if (ccl == 0 || def == 0 ||
2737c478bd9Sstevel@tonic-gate 	    pchar == 0 || subs == 0 || dchar == 0 ||
2747c478bd9Sstevel@tonic-gate 	    sname == 0 || exclusive == 0 || schar == 0)
2757c478bd9Sstevel@tonic-gate 		error("Too little core to begin");
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate static void
2797c478bd9Sstevel@tonic-gate free1core(void)
2807c478bd9Sstevel@tonic-gate {
2817c478bd9Sstevel@tonic-gate 	free(def);
2827c478bd9Sstevel@tonic-gate 	free(subs);
2837c478bd9Sstevel@tonic-gate 	free(dchar);
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate static void
2877c478bd9Sstevel@tonic-gate get2core(void)
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate 	int i;
2901dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2917c478bd9Sstevel@tonic-gate 	gotof = (int *)myalloc(nstates, sizeof (*gotof));
2921dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2937c478bd9Sstevel@tonic-gate 	nexts = (int *)myalloc(ntrans, sizeof (*nexts));
2941dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2957c478bd9Sstevel@tonic-gate 	nchar = (CHR *)myalloc(ntrans, sizeof (*nchar));
2961dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2977c478bd9Sstevel@tonic-gate 	state = (int **)myalloc(nstates, sizeof (*state));
2981dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
2997c478bd9Sstevel@tonic-gate 	atable = (int *)myalloc(nstates, sizeof (*atable));
3001dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3017c478bd9Sstevel@tonic-gate 	sfall = (int *)myalloc(nstates, sizeof (*sfall));
3027c478bd9Sstevel@tonic-gate 	cpackflg = (Boolean *)myalloc(nstates, sizeof (*cpackflg));
3031dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3047c478bd9Sstevel@tonic-gate 	tmpstat = (CHR *)myalloc(tptr+1, sizeof (*tmpstat));
3051dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3067c478bd9Sstevel@tonic-gate 	foll = (int **)myalloc(tptr+1, sizeof (*foll));
3071dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3087c478bd9Sstevel@tonic-gate 	nxtpos = positions = (int *)myalloc(maxpos, sizeof (*positions));
3097c478bd9Sstevel@tonic-gate 	if (tmpstat == 0 || foll == 0 || positions == 0 ||
3107c478bd9Sstevel@tonic-gate 	    gotof == 0 || nexts == 0 || nchar == 0 ||
3117c478bd9Sstevel@tonic-gate 	    state == 0 || atable == 0 || sfall == 0 || cpackflg == 0)
3127c478bd9Sstevel@tonic-gate 		error("Too little core for state generation");
3137c478bd9Sstevel@tonic-gate 	for (i = 0; i <= tptr; i++)
3147c478bd9Sstevel@tonic-gate 		foll[i] = 0;
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate static void
3187c478bd9Sstevel@tonic-gate free2core(void)
3197c478bd9Sstevel@tonic-gate {
3207c478bd9Sstevel@tonic-gate 	free(positions);
3217c478bd9Sstevel@tonic-gate 	free(tmpstat);
3227c478bd9Sstevel@tonic-gate 	free(foll);
3237c478bd9Sstevel@tonic-gate 	free(name);
3247c478bd9Sstevel@tonic-gate 	free(left);
3257c478bd9Sstevel@tonic-gate 	free(right);
3267c478bd9Sstevel@tonic-gate 	free(parent);
3277c478bd9Sstevel@tonic-gate 	free(nullstr);
3287c478bd9Sstevel@tonic-gate 	free(state);
3297c478bd9Sstevel@tonic-gate 	free(sname);
3307c478bd9Sstevel@tonic-gate 	/* XCU4: exclusive start array */
3317c478bd9Sstevel@tonic-gate 	free(exclusive);
3327c478bd9Sstevel@tonic-gate 	free(schar);
3337c478bd9Sstevel@tonic-gate 	free(ccl);
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate static void
3377c478bd9Sstevel@tonic-gate get3core(void)
3387c478bd9Sstevel@tonic-gate {
3391dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3407c478bd9Sstevel@tonic-gate 	verify = (int *)myalloc(outsize, sizeof (*verify));
3411dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3427c478bd9Sstevel@tonic-gate 	advance = (int *)myalloc(outsize, sizeof (*advance));
3431dd08564Sab 	/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3447c478bd9Sstevel@tonic-gate 	stoff = (int *)myalloc(stnum+2, sizeof (*stoff));
3457c478bd9Sstevel@tonic-gate 	if (verify == 0 || advance == 0 || stoff == 0)
3467c478bd9Sstevel@tonic-gate 		error("Too little core for final packing");
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate #ifdef DEBUG
3507c478bd9Sstevel@tonic-gate static void
3517c478bd9Sstevel@tonic-gate free3core(void)
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate 	free(advance);
3547c478bd9Sstevel@tonic-gate 	free(verify);
3557c478bd9Sstevel@tonic-gate 	free(stoff);
3567c478bd9Sstevel@tonic-gate 	free(gotof);
3577c478bd9Sstevel@tonic-gate 	free(nexts);
3587c478bd9Sstevel@tonic-gate 	free(nchar);
3597c478bd9Sstevel@tonic-gate 	free(atable);
3607c478bd9Sstevel@tonic-gate 	free(sfall);
3617c478bd9Sstevel@tonic-gate 	free(cpackflg);
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate #endif
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate BYTE *
3667c478bd9Sstevel@tonic-gate myalloc(int a, int b)
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate 	BYTE *i;
3697c478bd9Sstevel@tonic-gate 	i = calloc(a,  b);
3707c478bd9Sstevel@tonic-gate 	if (i == 0)
3717c478bd9Sstevel@tonic-gate 		warning("calloc returns a 0");
3727c478bd9Sstevel@tonic-gate 	return (i);
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate void
3767c478bd9Sstevel@tonic-gate yyerror(char *s)
3777c478bd9Sstevel@tonic-gate {
3787c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
37967298654Sdamico 	    "\"%s\":line %d: Error: %s\n", sargv[optind], yyline, s);
3807c478bd9Sstevel@tonic-gate }
381