2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
28
29 /* Copyright 1976, Bell Telephone Laboratories, Inc. */
30
31 #pragma ident "%Z%%M% %I% %E% SMI"
32
33 #include <string.h>
34 #include "once.h"
35 #include "sgs.h"
36 #include <locale.h>
37 #include <limits.h>
38
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);
45 #ifdef DEBUG
46 static void free3core(void);
47 #endif
48
49 int
50 main(int argc, char **argv)
51 {
52 int i;
53 int c;
54 char *path = NULL;
55 Boolean eoption = 0, woption = 0;
56
57 sargv = argv;
58 sargc = argc;
59 (void) setlocale(LC_ALL, "");
60 #ifdef DEBUG
61 while ((c = getopt(argc, argv, "dyctvnewVQ:Y:")) != EOF) {
62 #else
63 while ((c = getopt(argc, argv, "ctvnewVQ:Y:")) != EOF) {
64 #endif
65 switch (c) {
66 #ifdef DEBUG
67 case 'd':
68 debug++;
69 break;
70 case 'y':
71 yydebug = TRUE;
72 break;
73 #endif
74 case 'V':
75 (void) fprintf(stderr, "lex: %s %s\n",
76 (const char *)SGU_PKG,
77 (const char *)SGU_REL);
78 break;
79 case 'Q':
80 v_stmp = optarg;
81 if (*v_stmp != 'y' && *v_stmp != 'n')
82 error(
83 "lex: -Q should be followed by [y/n]");
84 break;
85 case 'Y':
86 path = (char *)malloc(strlen(optarg) +
87 sizeof ("/nceucform") + 1);
88 path = strcpy(path, optarg);
89 break;
90 case 'c':
91 ratfor = FALSE;
92 break;
93 case 't':
94 fout = stdout;
95 break;
96 case 'v':
97 report = 1;
98 break;
99 case 'n':
100 report = 0;
101 break;
102 case 'w':
103 case 'W':
104 woption = 1;
105 handleeuc = 1;
106 widecio = 1;
107 break;
108 case 'e':
109 case 'E':
110 eoption = 1;
111 handleeuc = 1;
112 widecio = 0;
113 break;
114 default:
115 (void) fprintf(stderr,
116 "Usage: lex [-ewctvnVY] [-Q(y/n)] [file]\n");
117 exit(1);
118 }
119 }
120 if (woption && eoption) {
121 error(
122 "You may not specify both -w and -e simultaneously.");
123 }
124 no_input = argc - optind;
125 if (no_input) {
126 /* XCU4: recognize "-" file operand for stdin */
127 if (strcmp(argv[optind], "-") == 0)
128 fin = stdin;
129 else {
130 fin = fopen(argv[optind], "r");
131 if (fin == NULL)
132 error(
133 "Can't open input file -- %s", argv[optind]);
134 }
135 } else
136 fin = stdin;
204 * positions, tmpstat, foll, state, name,
205 * left, right, parent, ccl, schar, sname
206 * maybe get: verify, advance, stoff
207 */
208 free2core();
209 get3core();
210 layout();
211 /*
212 * may be disposed of:
213 * verify, advance, stoff, nexts, nchar,
214 * gotof, atable, ccpackflg, sfall
215 */
216
217 #ifdef DEBUG
218 free3core();
219 #endif
220
221 if (handleeuc) {
222 if (ratfor)
223 error("Ratfor is not supported by -w or -e option.");
224 path = EUCNAME;
225 }
226 else
227 path = ratfor ? RATNAME : CNAME;
228
229 fother = fopen(path, "r");
230 if (fother == NULL)
231 error("Lex driver missing, file %s", path);
232 while ((i = getc(fother)) != EOF)
233 (void) putc((char)i, fout);
234 (void) fclose(fother);
235 (void) fclose(fout);
236 if (report == 1)
237 statistics();
238 (void) fclose(stdout);
239 (void) fclose(stderr);
240 return (0); /* success return code */
241 }
242
243 static void
244 get1core(void)
245 {
246 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
247 ccptr = ccl = (CHR *)myalloc(CCLSIZE, sizeof (*ccl));
248 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
249 pcptr = pchar = (CHR *)myalloc(pchlen, sizeof (*pchar));
250 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
251 def = (CHR **)myalloc(DEFSIZE, sizeof (*def));
252 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
253 subs = (CHR **)myalloc(DEFSIZE, sizeof (*subs));
254 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
255 dp = dchar = (CHR *)myalloc(DEFCHAR, sizeof (*dchar));
|
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2014 Gary Mills
23 *
24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1988 AT&T */
29 /* All Rights Reserved */
30
31 /* Copyright 1976, Bell Telephone Laboratories, Inc. */
32
33 #include <string.h>
34 #include "once.h"
35 #include "sgs.h"
36 #include <locale.h>
37 #include <limits.h>
38
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);
45 #ifdef DEBUG
46 static void free3core(void);
47 #endif
48
49 int
50 main(int argc, char **argv)
51 {
52 int i;
53 int c;
54 char *apath = NULL;
55 char *ypath;
56 Boolean eoption = 0, woption = 0;
57
58 sargv = argv;
59 sargc = argc;
60 (void) setlocale(LC_ALL, "");
61 #ifdef DEBUG
62 while ((c = getopt(argc, argv, "dyctvnewVQ:Y:")) != EOF) {
63 #else
64 while ((c = getopt(argc, argv, "ctvnewVQ:Y:")) != EOF) {
65 #endif
66 switch (c) {
67 #ifdef DEBUG
68 case 'd':
69 debug++;
70 break;
71 case 'y':
72 yydebug = TRUE;
73 break;
74 #endif
75 case 'V':
76 (void) fprintf(stderr, "lex: %s %s\n",
77 (const char *)SGU_PKG,
78 (const char *)SGU_REL);
79 break;
80 case 'Q':
81 v_stmp = optarg;
82 if (*v_stmp != 'y' && *v_stmp != 'n')
83 error(
84 "lex: -Q should be followed by [y/n]");
85 break;
86 case 'Y':
87 apath = (char *)malloc(strlen(optarg) +
88 sizeof ("/nceucform") + 1);
89 if (apath == NULL)
90 error("No available memory "
91 "for directory name.");
92 else
93 apath = strcpy(apath, optarg);
94 break;
95 case 'c':
96 ratfor = FALSE;
97 break;
98 case 't':
99 fout = stdout;
100 break;
101 case 'v':
102 report = 1;
103 break;
104 case 'n':
105 report = 0;
106 break;
107 case 'w':
108 case 'W':
109 woption = 1;
110 handleeuc = 1;
111 widecio = 1;
112 break;
113 case 'e':
114 case 'E':
115 eoption = 1;
116 handleeuc = 1;
117 widecio = 0;
118 break;
119 default:
120 (void) fprintf(stderr,
121 "Usage: lex [-ewctvnV] [-Y directory] "
122 "[-Q(y/n)] [file]\n");
123 exit(1);
124 }
125 }
126 if (woption && eoption) {
127 error(
128 "You may not specify both -w and -e simultaneously.");
129 }
130 no_input = argc - optind;
131 if (no_input) {
132 /* XCU4: recognize "-" file operand for stdin */
133 if (strcmp(argv[optind], "-") == 0)
134 fin = stdin;
135 else {
136 fin = fopen(argv[optind], "r");
137 if (fin == NULL)
138 error(
139 "Can't open input file -- %s", argv[optind]);
140 }
141 } else
142 fin = stdin;
210 * positions, tmpstat, foll, state, name,
211 * left, right, parent, ccl, schar, sname
212 * maybe get: verify, advance, stoff
213 */
214 free2core();
215 get3core();
216 layout();
217 /*
218 * may be disposed of:
219 * verify, advance, stoff, nexts, nchar,
220 * gotof, atable, ccpackflg, sfall
221 */
222
223 #ifdef DEBUG
224 free3core();
225 #endif
226
227 if (handleeuc) {
228 if (ratfor)
229 error("Ratfor is not supported by -w or -e option.");
230 ypath = EUCNAME;
231 }
232 else
233 ypath = ratfor ? RATNAME : CNAME;
234
235 if (apath != NULL)
236 ypath = strcat(apath, strrchr(ypath, '/'));
237 fother = fopen(ypath, "r");
238 if (fother == NULL)
239 error("Lex driver missing, file %s", ypath);
240 while ((i = getc(fother)) != EOF)
241 (void) putc((char)i, fout);
242 (void) fclose(fother);
243 (void) fclose(fout);
244 free(apath);
245 if (report == 1)
246 statistics();
247 (void) fclose(stdout);
248 (void) fclose(stderr);
249 return (0); /* success return code */
250 }
251
252 static void
253 get1core(void)
254 {
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));
|