Print this page
2926 lex ignores -Y
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/lex/common/main.c
+++ new/usr/src/cmd/sgs/lex/common/main.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 + * Copyright (c) 2014 Gary Mills
23 + *
22 24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 25 * Use is subject to license terms.
24 26 */
25 27
26 28 /* Copyright (c) 1988 AT&T */
27 29 /* All Rights Reserved */
28 30
29 31 /* Copyright 1976, Bell Telephone Laboratories, Inc. */
30 32
31 -#pragma ident "%Z%%M% %I% %E% SMI"
32 -
33 33 #include <string.h>
34 34 #include "once.h"
35 35 #include "sgs.h"
36 36 #include <locale.h>
37 37 #include <limits.h>
38 38
39 39 static wchar_t L_INITIAL[] = {'I', 'N', 'I', 'T', 'I', 'A', 'L', 0};
40 40 static void get1core(void);
41 41 static void free1core(void);
42 42 static void get2core(void);
43 43 static void free2core(void);
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
44 44 static void get3core(void);
45 45 #ifdef DEBUG
46 46 static void free3core(void);
47 47 #endif
48 48
49 49 int
50 50 main(int argc, char **argv)
51 51 {
52 52 int i;
53 53 int c;
54 - char *path = NULL;
54 + char *apath = NULL;
55 + char *ypath;
55 56 Boolean eoption = 0, woption = 0;
56 57
57 58 sargv = argv;
58 59 sargc = argc;
59 60 (void) setlocale(LC_ALL, "");
60 61 #ifdef DEBUG
61 62 while ((c = getopt(argc, argv, "dyctvnewVQ:Y:")) != EOF) {
62 63 #else
63 64 while ((c = getopt(argc, argv, "ctvnewVQ:Y:")) != EOF) {
64 65 #endif
65 66 switch (c) {
66 67 #ifdef DEBUG
67 68 case 'd':
68 69 debug++;
69 70 break;
70 71 case 'y':
71 72 yydebug = TRUE;
72 73 break;
73 74 #endif
74 75 case 'V':
75 76 (void) fprintf(stderr, "lex: %s %s\n",
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
76 77 (const char *)SGU_PKG,
77 78 (const char *)SGU_REL);
78 79 break;
79 80 case 'Q':
80 81 v_stmp = optarg;
81 82 if (*v_stmp != 'y' && *v_stmp != 'n')
82 83 error(
83 84 "lex: -Q should be followed by [y/n]");
84 85 break;
85 86 case 'Y':
86 - path = (char *)malloc(strlen(optarg) +
87 + apath = (char *)malloc(strlen(optarg) +
87 88 sizeof ("/nceucform") + 1);
88 - path = strcpy(path, optarg);
89 + if (apath == NULL)
90 + error("No available memory "
91 + "for directory name.");
92 + else
93 + apath = strcpy(apath, optarg);
89 94 break;
90 95 case 'c':
91 96 ratfor = FALSE;
92 97 break;
93 98 case 't':
94 99 fout = stdout;
95 100 break;
96 101 case 'v':
97 102 report = 1;
98 103 break;
99 104 case 'n':
100 105 report = 0;
101 106 break;
102 107 case 'w':
103 108 case 'W':
104 109 woption = 1;
105 110 handleeuc = 1;
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
106 111 widecio = 1;
107 112 break;
108 113 case 'e':
109 114 case 'E':
110 115 eoption = 1;
111 116 handleeuc = 1;
112 117 widecio = 0;
113 118 break;
114 119 default:
115 120 (void) fprintf(stderr,
116 - "Usage: lex [-ewctvnVY] [-Q(y/n)] [file]\n");
121 + "Usage: lex [-ewctvnV] [-Y directory] "
122 + "[-Q(y/n)] [file]\n");
117 123 exit(1);
118 124 }
119 125 }
120 126 if (woption && eoption) {
121 127 error(
122 128 "You may not specify both -w and -e simultaneously.");
123 129 }
124 130 no_input = argc - optind;
125 131 if (no_input) {
126 132 /* XCU4: recognize "-" file operand for stdin */
127 133 if (strcmp(argv[optind], "-") == 0)
128 134 fin = stdin;
129 135 else {
130 136 fin = fopen(argv[optind], "r");
131 137 if (fin == NULL)
132 138 error(
133 139 "Can't open input file -- %s", argv[optind]);
134 140 }
135 141 } else
136 142 fin = stdin;
137 143
138 144 /* may be gotten: def, subs, sname, schar, ccl, dchar */
139 145 (void) gch();
140 146
141 147 /* may be gotten: name, left, right, nullstr, parent */
142 148 get1core();
143 149
144 150 scopy(L_INITIAL, sp);
145 151 sname[0] = sp;
146 152 sp += slength(L_INITIAL) + 1;
147 153 sname[1] = 0;
148 154
149 155 /* XCU4: %x exclusive start */
150 156 exclusive[0] = 0;
151 157
152 158 if (!handleeuc) {
153 159 /*
154 160 * Set ZCH and ncg to their default values
155 161 * as they may be needed to handle %t directive.
156 162 */
157 163 ZCH = ncg = NCH; /* ncg behaves as constant in this mode. */
158 164 }
159 165
160 166 /* may be disposed of: def, subs, dchar */
161 167 if (yyparse())
162 168 exit(1); /* error return code */
163 169
164 170 if (handleeuc) {
165 171 ncg = ncgidtbl * 2;
166 172 ZCH = ncg;
167 173 if (ncg >= MAXNCG)
168 174 error(
169 175 "Too complex rules -- requires too many char groups.");
170 176 sortcgidtbl();
171 177 }
172 178 repbycgid(); /* Call this even in ASCII compat. mode. */
173 179
174 180 /*
175 181 * maybe get:
176 182 * tmpstat, foll, positions, gotof, nexts,
177 183 * nchar, state, atable, sfall, cpackflg
178 184 */
179 185 free1core();
180 186 get2core();
181 187 ptail();
182 188 mkmatch();
183 189 #ifdef DEBUG
184 190 if (debug)
185 191 pccl();
186 192 #endif
187 193 sect = ENDSECTION;
188 194 if (tptr > 0)
189 195 cfoll(tptr-1);
190 196 #ifdef DEBUG
191 197 if (debug)
192 198 pfoll();
193 199 #endif
194 200 cgoto();
195 201 #ifdef DEBUG
196 202 if (debug) {
197 203 (void) printf("Print %d states:\n", stnum + 1);
198 204 for (i = 0; i <= stnum; i++)
199 205 stprt(i);
200 206 }
201 207 #endif
202 208 /*
203 209 * may be disposed of:
204 210 * positions, tmpstat, foll, state, name,
205 211 * left, right, parent, ccl, schar, sname
206 212 * maybe get: verify, advance, stoff
207 213 */
208 214 free2core();
209 215 get3core();
210 216 layout();
211 217 /*
212 218 * may be disposed of:
213 219 * verify, advance, stoff, nexts, nchar,
↓ open down ↓ |
87 lines elided |
↑ open up ↑ |
214 220 * gotof, atable, ccpackflg, sfall
215 221 */
216 222
217 223 #ifdef DEBUG
218 224 free3core();
219 225 #endif
220 226
221 227 if (handleeuc) {
222 228 if (ratfor)
223 229 error("Ratfor is not supported by -w or -e option.");
224 - path = EUCNAME;
230 + ypath = EUCNAME;
225 231 }
226 232 else
227 - path = ratfor ? RATNAME : CNAME;
233 + ypath = ratfor ? RATNAME : CNAME;
228 234
229 - fother = fopen(path, "r");
235 + if (apath != NULL)
236 + ypath = strcat(apath, strrchr(ypath, '/'));
237 + fother = fopen(ypath, "r");
230 238 if (fother == NULL)
231 - error("Lex driver missing, file %s", path);
239 + error("Lex driver missing, file %s", ypath);
232 240 while ((i = getc(fother)) != EOF)
233 241 (void) putc((char)i, fout);
234 242 (void) fclose(fother);
235 243 (void) fclose(fout);
244 + free(apath);
236 245 if (report == 1)
237 246 statistics();
238 247 (void) fclose(stdout);
239 248 (void) fclose(stderr);
240 249 return (0); /* success return code */
241 250 }
242 251
243 252 static void
244 253 get1core(void)
245 254 {
246 255 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
247 256 ccptr = ccl = (CHR *)myalloc(CCLSIZE, sizeof (*ccl));
248 257 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
249 258 pcptr = pchar = (CHR *)myalloc(pchlen, sizeof (*pchar));
250 259 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
251 260 def = (CHR **)myalloc(DEFSIZE, sizeof (*def));
252 261 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
253 262 subs = (CHR **)myalloc(DEFSIZE, sizeof (*subs));
254 263 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
255 264 dp = dchar = (CHR *)myalloc(DEFCHAR, sizeof (*dchar));
256 265 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
257 266 sname = (CHR **)myalloc(STARTSIZE, sizeof (*sname));
258 267 /* XCU4: exclusive start array */
259 268 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
260 269 exclusive = (int *)myalloc(STARTSIZE, sizeof (*exclusive));
261 270 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
262 271 sp = schar = (CHR *)myalloc(STARTCHAR, sizeof (*schar));
263 272 if (ccl == 0 || def == 0 ||
264 273 pchar == 0 || subs == 0 || dchar == 0 ||
265 274 sname == 0 || exclusive == 0 || schar == 0)
266 275 error("Too little core to begin");
267 276 }
268 277
269 278 static void
270 279 free1core(void)
271 280 {
272 281 free(def);
273 282 free(subs);
274 283 free(dchar);
275 284 }
276 285
277 286 static void
278 287 get2core(void)
279 288 {
280 289 int i;
281 290 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
282 291 gotof = (int *)myalloc(nstates, sizeof (*gotof));
283 292 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
284 293 nexts = (int *)myalloc(ntrans, sizeof (*nexts));
285 294 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
286 295 nchar = (CHR *)myalloc(ntrans, sizeof (*nchar));
287 296 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
288 297 state = (int **)myalloc(nstates, sizeof (*state));
289 298 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
290 299 atable = (int *)myalloc(nstates, sizeof (*atable));
291 300 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
292 301 sfall = (int *)myalloc(nstates, sizeof (*sfall));
293 302 cpackflg = (Boolean *)myalloc(nstates, sizeof (*cpackflg));
294 303 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
295 304 tmpstat = (CHR *)myalloc(tptr+1, sizeof (*tmpstat));
296 305 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
297 306 foll = (int **)myalloc(tptr+1, sizeof (*foll));
298 307 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
299 308 nxtpos = positions = (int *)myalloc(maxpos, sizeof (*positions));
300 309 if (tmpstat == 0 || foll == 0 || positions == 0 ||
301 310 gotof == 0 || nexts == 0 || nchar == 0 ||
302 311 state == 0 || atable == 0 || sfall == 0 || cpackflg == 0)
303 312 error("Too little core for state generation");
304 313 for (i = 0; i <= tptr; i++)
305 314 foll[i] = 0;
306 315 }
307 316
308 317 static void
309 318 free2core(void)
310 319 {
311 320 free(positions);
312 321 free(tmpstat);
313 322 free(foll);
314 323 free(name);
315 324 free(left);
316 325 free(right);
317 326 free(parent);
318 327 free(nullstr);
319 328 free(state);
320 329 free(sname);
321 330 /* XCU4: exclusive start array */
322 331 free(exclusive);
323 332 free(schar);
324 333 free(ccl);
325 334 }
326 335
327 336 static void
328 337 get3core(void)
329 338 {
330 339 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
331 340 verify = (int *)myalloc(outsize, sizeof (*verify));
332 341 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
333 342 advance = (int *)myalloc(outsize, sizeof (*advance));
334 343 /*LINTED: E_BAD_PTR_CAST_ALIGN*/
335 344 stoff = (int *)myalloc(stnum+2, sizeof (*stoff));
336 345 if (verify == 0 || advance == 0 || stoff == 0)
337 346 error("Too little core for final packing");
338 347 }
339 348
340 349 #ifdef DEBUG
341 350 static void
342 351 free3core(void)
343 352 {
344 353 free(advance);
345 354 free(verify);
346 355 free(stoff);
347 356 free(gotof);
348 357 free(nexts);
349 358 free(nchar);
350 359 free(atable);
351 360 free(sfall);
352 361 free(cpackflg);
353 362 }
354 363 #endif
355 364
356 365 BYTE *
357 366 myalloc(int a, int b)
358 367 {
359 368 BYTE *i;
360 369 i = calloc(a, b);
361 370 if (i == 0)
362 371 warning("calloc returns a 0");
363 372 return (i);
364 373 }
365 374
366 375 void
367 376 yyerror(char *s)
368 377 {
369 378 (void) fprintf(stderr,
370 379 "\"%s\":line %d: Error: %s\n", sargv[optind], yyline, s);
371 380 }
↓ open down ↓ |
126 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX