main.c revision 672986541be54a7a471bb088e60780c37e371d7e
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CDDL HEADER START
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * The contents of this file are subject to the terms of the
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Common Development and Distribution License (the "License").
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * You may not use this file except in compliance with the License.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * or http://www.opensolaris.org/os/licensing.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * See the License for the specific language governing permissions
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * and limitations under the License.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * When distributing Covered Code, include this CDDL HEADER in each
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * If applicable, add the following below this CDDL HEADER, with the
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * fields enclosed by brackets "[]" replaced with your own identifying
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * information: Portions Copyright [yyyy] [name of copyright owner]
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * CDDL HEADER END
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley/*
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * Use is subject to license terms.
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley/* Copyright (c) 1988 AT&T */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley/* All Rights Reserved */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley/* Copyright 1976, Bell Telephone Laboratories, Inc. */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#pragma ident "%Z%%M% %I% %E% SMI"
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#include <string.h>
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#include "once.h"
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#include "sgs.h"
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#include <locale.h>
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#include <limits.h>
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic wchar_t L_INITIAL[] = {'I', 'N', 'I', 'T', 'I', 'A', 'L', 0};
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void get1core(void);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void free1core(void);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void get2core(void);
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halleystatic void free2core(void);
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halleystatic void get3core(void);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#ifdef DEBUG
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void free3core(void);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#endif
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halleyint
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halleymain(int argc, char **argv)
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley{
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley int i;
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley int c;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence char *path = NULL;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff Boolean eoption = 0, woption = 0;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff sargv = argv;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff sargc = argc;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff setlocale(LC_ALL, "");
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#ifdef DEBUG
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff while ((c = getopt(argc, argv, "dyctvnewVQ:Y:")) != EOF) {
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#else
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff while ((c = getopt(argc, argv, "ctvnewVQ:Y:")) != EOF) {
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#endif
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff switch (c) {
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#ifdef DEBUG
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence case 'd':
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff debug++;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff break;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff case 'y':
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff yydebug = TRUE;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff break;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#endif
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 'V':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley (void) fprintf(stderr, "lex: %s %s\n",
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley (const char *)SGU_PKG,
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley (const char *)SGU_REL);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley break;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 'Q':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley v_stmp = optarg;
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley if (*v_stmp != 'y' && *v_stmp != 'n')
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley error(
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley "lex: -Q should be followed by [y/n]");
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff break;
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley case 'Y':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley path = (char *)malloc(strlen(optarg) +
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley sizeof ("/nceucform") + 1);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley path = strcpy(path, optarg);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley break;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 'c':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley ratfor = FALSE;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley break;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 't':
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff fout = stdout;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley break;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 'v':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley report = 1;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley break;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 'n':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley report = 0;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley break;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 'w':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley case 'W':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley woption = 1;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley handleeuc = 1;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley widecio = 1;
7aacbd685b2107670e4179689abec9cb82d972abBob Halley break;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence case 'e':
fcdd365bbf062559cff1c0e4a5a88fa329aa7fceBrian Wellington case 'E':
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley eoption = 1;
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff handleeuc = 1;
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff widecio = 0;
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff break;
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff default:
0b3427d15cc6711f263447d81a0d47a35d2c037eDavid Lawrence (void) fprintf(stderr,
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff "Usage: lex [-ewctvnVY] [-Q(y/n)] [file]\n");
7aacbd685b2107670e4179689abec9cb82d972abBob Halley exit(1);
7aacbd685b2107670e4179689abec9cb82d972abBob Halley }
3df43dad430973e273bc55b304c6d5965390db06Michael Graff }
3df43dad430973e273bc55b304c6d5965390db06Michael Graff if (woption && eoption) {
3df43dad430973e273bc55b304c6d5965390db06Michael Graff error(
3df43dad430973e273bc55b304c6d5965390db06Michael Graff "You may not specify both -w and -e simultaneously.");
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence }
3df43dad430973e273bc55b304c6d5965390db06Michael Graff no_input = argc - optind;
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff if (no_input) {
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff /* XCU4: recognize "-" file operand for stdin */
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff if (strcmp(argv[optind], "-") == 0)
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff fin = stdin;
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff else {
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff fin = fopen(argv[optind], "r");
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff if (fin == NULL)
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff error(
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence "Can't open input file -- %s", argv[optind]);
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff }
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence } else
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence fin = stdin;
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence /* may be gotten: def, subs, sname, schar, ccl, dchar */
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence (void) gch();
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence /* may be gotten: name, left, right, nullstr, parent */
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence get1core();
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff scopy(L_INITIAL, sp);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence sname[0] = sp;
07a9b8b58802575e1ec29a3c8b00e5fae1a94008Michael Graff sp += slength(L_INITIAL) + 1;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence sname[1] = 0;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence /* XCU4: %x exclusive start */
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence exclusive[0] = 0;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley if (!handleeuc) {
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley /*
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * Set ZCH and ncg to their default values
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * as they may be needed to handle %t directive.
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley ZCH = ncg = NCH; /* ncg behaves as constant in this mode. */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley }
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff /* may be disposed of: def, subs, dchar */
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff if (yyparse())
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley exit(1); /* error return code */
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff if (handleeuc) {
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff ncg = ncgidtbl * 2;
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff ZCH = ncg;
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff if (ncg >= MAXNCG)
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff error(
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff "Too complex rules -- requires too many char groups.");
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff sortcgidtbl();
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff }
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff repbycgid(); /* Call this even in ASCII compat. mode. */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley /*
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * maybe get:
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * tmpstat, foll, positions, gotof, nexts,
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff * nchar, state, atable, sfall, cpackflg
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff */
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence free1core();
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff get2core();
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff ptail();
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff mkmatch();
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#ifdef DEBUG
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff if (debug)
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff pccl();
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#endif
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff sect = ENDSECTION;
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff if (tptr > 0)
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff cfoll(tptr-1);
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#ifdef DEBUG
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff if (debug)
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff pfoll();
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff#endif
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff cgoto();
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#ifdef DEBUG
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff if (debug) {
84d79ecd505cc880d01a73a2bf47541eaa53fcbcMichael Graff (void) printf("Print %d states:\n", stnum + 1);
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff for (i = 0; i <= stnum; i++)
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff stprt(i);
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff }
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff#endif
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff /*
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff * may be disposed of:
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff * positions, tmpstat, foll, state, name,
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff * left, right, parent, ccl, schar, sname
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff * maybe get: verify, advance, stoff
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff */
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff free2core();
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff get3core();
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff layout();
441a57f959ae5e08b3008e067898d11d5ab71e0bMichael Graff /*
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * may be disposed of:
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley * verify, advance, stoff, nexts, nchar,
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence * gotof, atable, ccpackflg, sfall
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#ifdef DEBUG
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free3core();
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#endif
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley if (handleeuc) {
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley if (ratfor)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley error("Ratfor is not supported by -w or -e option.");
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley path = EUCNAME;
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley }
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley else
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff path = ratfor ? RATNAME : CNAME;
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley fother = fopen(path, "r");
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley if (fother == NULL)
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley error("Lex driver missing, file %s", path);
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley while ((i = getc(fother)) != EOF)
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley (void) putc((char)i, fout);
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley (void) fclose(fother);
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley (void) fclose(fout);
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley if (report == 1)
005df5aba5181dc57b0e84eae72929f009b6b8fdBob Halley statistics();
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence (void) fclose(stdout);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley (void) fclose(stderr);
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff return (0); /* success return code */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley}
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleyget1core(void)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley{
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley ccptr = ccl = (CHR *)myalloc(CCLSIZE, sizeof (*ccl));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley pcptr = pchar = (CHR *)myalloc(pchlen, sizeof (*pchar));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley def = (CHR **)myalloc(DEFSIZE, sizeof (*def));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley subs = (CHR **)myalloc(DEFSIZE, sizeof (*subs));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley dp = dchar = (CHR *)myalloc(DEFCHAR, sizeof (*dchar));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley sname = (CHR **)myalloc(STARTSIZE, sizeof (*sname));
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff /* XCU4: exclusive start array */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley exclusive = (int *)myalloc(STARTSIZE, sizeof (*exclusive));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley sp = schar = (CHR *)myalloc(STARTCHAR, sizeof (*schar));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley if (ccl == 0 || def == 0 ||
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley pchar == 0 || subs == 0 || dchar == 0 ||
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley sname == 0 || exclusive == 0 || schar == 0)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley error("Too little core to begin");
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley}
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleyfree1core(void)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley{
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff free(def);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(subs);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(dchar);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley}
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleyget2core(void)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley{
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley int i;
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley gotof = (int *)myalloc(nstates, sizeof (*gotof));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley nexts = (int *)myalloc(ntrans, sizeof (*nexts));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley nchar = (CHR *)myalloc(ntrans, sizeof (*nchar));
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff state = (int **)myalloc(nstates, sizeof (*state));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley atable = (int *)myalloc(nstates, sizeof (*atable));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley sfall = (int *)myalloc(nstates, sizeof (*sfall));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley cpackflg = (Boolean *)myalloc(nstates, sizeof (*cpackflg));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley tmpstat = (CHR *)myalloc(tptr+1, sizeof (*tmpstat));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley foll = (int **)myalloc(tptr+1, sizeof (*foll));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley nxtpos = positions = (int *)myalloc(maxpos, sizeof (*positions));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley if (tmpstat == 0 || foll == 0 || positions == 0 ||
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley gotof == 0 || nexts == 0 || nchar == 0 ||
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley state == 0 || atable == 0 || sfall == 0 || cpackflg == 0)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley error("Too little core for state generation");
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley for (i = 0; i <= tptr; i++)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley foll[i] = 0;
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff}
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleyfree2core(void)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley{
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(positions);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(tmpstat);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(foll);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(name);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(left);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(right);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(parent);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(nullstr);
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff free(state);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(sname);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley /* XCU4: exclusive start array */
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(exclusive);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(schar);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(ccl);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley}
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleyget3core(void)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley{
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley verify = (int *)myalloc(outsize, sizeof (*verify));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley advance = (int *)myalloc(outsize, sizeof (*advance));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley stoff = (int *)myalloc(stnum+2, sizeof (*stoff));
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley if (verify == 0 || advance == 0 || stoff == 0)
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff error("Too little core for final packing");
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley}
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#ifdef DEBUG
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleystatic void
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleyfree3core(void)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley{
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(advance);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(verify);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(stoff);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(gotof);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(nexts);
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff free(nchar);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(atable);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(sfall);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley free(cpackflg);
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley}
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley#endif
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley
928da6e9e3f2e58666a59ba53d87f3e82486734eBob HalleyBYTE *
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halleymyalloc(int a, int b)
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley{
928da6e9e3f2e58666a59ba53d87f3e82486734eBob Halley BYTE *i;
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley i = calloc(a, b);
35a8d16d614cda6fec64c989c1a5ee0f3f16fb08Michael Graff if (i == 0)
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley warning("calloc returns a 0");
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley return (i);
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley}
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halleyvoid
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halleyyyerror(char *s)
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley{
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley (void) fprintf(stderr,
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley "\"%s\":line %d: Error: %s\n", sargv[optind], yyline, s);
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley}
cada82f4ffbbccf373e4483e67082e0d916d10c4Bob Halley