4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2014 Gary Mills
24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1988 AT&T */
29 /* All Rights Reserved */
31 /* Copyright 1976, Bell Telephone Laboratories, Inc. */
39 static wchar_t L_INITIAL
[] = {'I', 'N', 'I', 'T', 'I', 'A', 'L', 0};
40 static void get1core(void);
41 static void free1core(void);
42 static void get2core(void);
43 static void free2core(void);
44 static void get3core(void);
46 static void free3core(void);
50 main(int argc
, char **argv
)
56 Boolean eoption
= 0, woption
= 0;
60 (void) setlocale(LC_ALL
, "");
62 while ((c
= getopt(argc
, argv
, "dyctvnewVQ:Y:")) != EOF
) {
64 while ((c
= getopt(argc
, argv
, "ctvnewVQ:Y:")) != EOF
) {
76 (void) fprintf(stderr
, "lex: %s %s\n",
77 (const char *)SGU_PKG
,
78 (const char *)SGU_REL
);
82 if (*v_stmp
!= 'y' && *v_stmp
!= 'n')
84 "lex: -Q should be followed by [y/n]");
87 apath
= (char *)malloc(strlen(optarg
) +
88 sizeof ("/nceucform") + 1);
90 error("No available memory "
91 "for directory name.");
93 apath
= strcpy(apath
, optarg
);
120 (void) fprintf(stderr
,
121 "Usage: lex [-ewctvnV] [-Y directory] "
122 "[-Q(y/n)] [file]\n");
126 if (woption
&& eoption
) {
128 "You may not specify both -w and -e simultaneously.");
130 no_input
= argc
- optind
;
132 /* XCU4: recognize "-" file operand for stdin */
133 if (strcmp(argv
[optind
], "-") == 0)
136 fin
= fopen(argv
[optind
], "r");
139 "Can't open input file -- %s", argv
[optind
]);
144 /* may be gotten: def, subs, sname, schar, ccl, dchar */
147 /* may be gotten: name, left, right, nullstr, parent */
150 scopy(L_INITIAL
, sp
);
152 sp
+= slength(L_INITIAL
) + 1;
155 /* XCU4: %x exclusive start */
160 * Set ZCH and ncg to their default values
161 * as they may be needed to handle %t directive.
163 ZCH
= ncg
= NCH
; /* ncg behaves as constant in this mode. */
166 /* may be disposed of: def, subs, dchar */
168 exit(1); /* error return code */
175 "Too complex rules -- requires too many char groups.");
178 repbycgid(); /* Call this even in ASCII compat. mode. */
182 * tmpstat, foll, positions, gotof, nexts,
183 * nchar, state, atable, sfall, cpackflg
203 (void) printf("Print %d states:\n", stnum
+ 1);
204 for (i
= 0; i
<= stnum
; i
++)
209 * may be disposed of:
210 * positions, tmpstat, foll, state, name,
211 * left, right, parent, ccl, schar, sname
212 * maybe get: verify, advance, stoff
218 * may be disposed of:
219 * verify, advance, stoff, nexts, nchar,
220 * gotof, atable, ccpackflg, sfall
229 error("Ratfor is not supported by -w or -e option.");
233 ypath
= ratfor
? RATNAME
: CNAME
;
236 ypath
= strcat(apath
, strrchr(ypath
, '/'));
237 fother
= fopen(ypath
, "r");
239 error("Lex driver missing, file %s", ypath
);
240 while ((i
= getc(fother
)) != EOF
)
241 (void) putc((char)i
, fout
);
242 (void) fclose(fother
);
247 (void) fclose(stdout
);
248 (void) fclose(stderr
);
249 return (0); /* success return code */
255 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
256 ccptr
= ccl
= (CHR
*)myalloc(CCLSIZE
, sizeof (*ccl
));
257 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
258 pcptr
= pchar
= (CHR
*)myalloc(pchlen
, sizeof (*pchar
));
259 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
260 def
= (CHR
**)myalloc(DEFSIZE
, sizeof (*def
));
261 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
262 subs
= (CHR
**)myalloc(DEFSIZE
, sizeof (*subs
));
263 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
264 dp
= dchar
= (CHR
*)myalloc(DEFCHAR
, sizeof (*dchar
));
265 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
266 sname
= (CHR
**)myalloc(STARTSIZE
, sizeof (*sname
));
267 /* XCU4: exclusive start array */
268 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
269 exclusive
= (int *)myalloc(STARTSIZE
, sizeof (*exclusive
));
270 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
271 sp
= schar
= (CHR
*)myalloc(STARTCHAR
, sizeof (*schar
));
272 if (ccl
== 0 || def
== 0 ||
273 pchar
== 0 || subs
== 0 || dchar
== 0 ||
274 sname
== 0 || exclusive
== 0 || schar
== 0)
275 error("Too little core to begin");
290 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
291 gotof
= (int *)myalloc(nstates
, sizeof (*gotof
));
292 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
293 nexts
= (int *)myalloc(ntrans
, sizeof (*nexts
));
294 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
295 nchar
= (CHR
*)myalloc(ntrans
, sizeof (*nchar
));
296 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
297 state
= (int **)myalloc(nstates
, sizeof (*state
));
298 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
299 atable
= (int *)myalloc(nstates
, sizeof (*atable
));
300 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
301 sfall
= (int *)myalloc(nstates
, sizeof (*sfall
));
302 cpackflg
= (Boolean
*)myalloc(nstates
, sizeof (*cpackflg
));
303 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
304 tmpstat
= (CHR
*)myalloc(tptr
+1, sizeof (*tmpstat
));
305 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
306 foll
= (int **)myalloc(tptr
+1, sizeof (*foll
));
307 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
308 nxtpos
= positions
= (int *)myalloc(maxpos
, sizeof (*positions
));
309 if (tmpstat
== 0 || foll
== 0 || positions
== 0 ||
310 gotof
== 0 || nexts
== 0 || nchar
== 0 ||
311 state
== 0 || atable
== 0 || sfall
== 0 || cpackflg
== 0)
312 error("Too little core for state generation");
313 for (i
= 0; i
<= tptr
; i
++)
330 /* XCU4: exclusive start array */
339 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
340 verify
= (int *)myalloc(outsize
, sizeof (*verify
));
341 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
342 advance
= (int *)myalloc(outsize
, sizeof (*advance
));
343 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
344 stoff
= (int *)myalloc(stnum
+2, sizeof (*stoff
));
345 if (verify
== 0 || advance
== 0 || stoff
== 0)
346 error("Too little core for final packing");
366 myalloc(int a
, int b
)
371 warning("calloc returns a 0");
378 (void) fprintf(stderr
,
379 "\"%s\":line %d: Error: %s\n", sargv
[optind
], yyline
, s
);