]>
Commit | Line | Data |
---|---|---|
3d864fce | 1 | (* Copyright (C) 2015-2022 Free Software Foundation, Inc. *) |
7401123f GM |
2 | (* This file is part of GNU Modula-2. |
3 | ||
4 | GNU Modula-2 is free software; you can redistribute it and/or modify it under | |
5 | the terms of the GNU General Public License as published by the Free | |
6 | Software Foundation; either version 3, or (at your option) any later | |
7 | version. | |
8 | ||
9 | GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY | |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 | for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License along | |
15 | with gm2; see the file COPYING. If not, write to the Free Software | |
16 | Foundation, 51 Franklin Street, Fifth Floor, | |
17 | Boston, MA 02110-1301, USA. *) | |
18 | ||
19 | IMPLEMENTATION MODULE mcOptions ; | |
20 | ||
21 | FROM SArgs IMPORT GetArg, Narg ; | |
22 | FROM mcSearch IMPORT prependSearchPath ; | |
23 | FROM libc IMPORT exit, printf ; | |
24 | FROM mcPrintf IMPORT printf0 ; | |
25 | FROM Debug IMPORT Halt ; | |
26 | FROM StrLib IMPORT StrLen ; | |
27 | FROM decl IMPORT setLangC, setLangCP, setLangM2 ; | |
28 | ||
29 | FROM DynamicStrings IMPORT String, Length, InitString, Mark, Slice, EqualArray, | |
30 | InitStringCharStar, ConCatChar, ConCat, KillString, | |
31 | Dup, string, char ; | |
32 | ||
33 | IMPORT FIO ; | |
34 | IMPORT SFIO ; | |
35 | ||
36 | CONST | |
37 | YEAR = '2021' ; | |
38 | ||
39 | VAR | |
40 | langC, | |
41 | langCPP, | |
42 | langM2, | |
43 | gplHeader, | |
44 | glplHeader, | |
45 | summary, | |
46 | contributed, | |
47 | caseRuntime, | |
48 | arrayRuntime, | |
49 | returnRuntime, | |
50 | gccConfigSystem, | |
51 | ignoreFQ, | |
52 | debugTopological, | |
53 | extendedOpaque, | |
54 | internalDebugging, | |
55 | verbose, | |
56 | quiet : BOOLEAN ; | |
57 | projectContents, | |
58 | summaryContents, | |
59 | contributedContents, | |
60 | hPrefix, | |
61 | outputFile, | |
62 | cppArgs, | |
63 | cppProgram : String ; | |
64 | ||
65 | ||
66 | (* | |
67 | displayVersion - displays the version of the compiler. | |
68 | *) | |
69 | ||
70 | PROCEDURE displayVersion (mustExit: BOOLEAN) ; | |
71 | BEGIN | |
72 | printf0 ('Copyright (C) ' + YEAR + ' Free Software Foundation, Inc.\n') ; | |
73 | printf0 ('License GPLv2: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n') ; | |
74 | printf0 ('This is free software: you are free to change and redistribute it.\n') ; | |
75 | printf0 ('There is NO WARRANTY, to the extent permitted by law.\n') ; | |
76 | IF mustExit | |
77 | THEN | |
78 | exit (0) | |
79 | END | |
80 | END displayVersion ; | |
81 | ||
82 | ||
83 | (* | |
84 | displayHelp - display the mc help summary. | |
85 | *) | |
86 | ||
87 | PROCEDURE displayHelp ; | |
88 | BEGIN | |
89 | printf0 ("usage: mc [--cpp] [-g] [--quiet] [--extended-opaque] [-q] [-v]") ; | |
90 | printf0 (" [--verbose] [--version] [--help] [-h] [-Ipath] [--olang=c]") ; | |
91 | printf0 (" [--olang=c++] [--olang=m2] [--debug-top]") ; | |
92 | printf0 (' [--gpl-header] [--glpl-header] [--summary="foo"]') ; | |
93 | printf0 (' [--contributed="foo"] [--project="foo"]') ; | |
94 | printf0 (" [--h-file-prefix=foo] [--automatic] [-o=foo] filename\n") ; | |
95 | ||
96 | printf0 (" --cpp preprocess through the C preprocessor\n") ; | |
97 | printf0 (" -g emit debugging directives in the output language") ; | |
98 | printf0 (" so that the debugger will refer to the source\n") ; | |
99 | printf0 (" -q --quiet no output unless an error occurs\n") ; | |
100 | printf0 (" -v --verbose display preprocessor if invoked\n") ; | |
101 | printf0 (" --version display version and exit\n") ; | |
102 | printf0 (" -h --help display this help message\n") ; | |
103 | printf0 (" -Ipath set the module search path\n") ; | |
104 | printf0 (" --olang=c generate ansi C output\n") ; | |
105 | printf0 (" --olang=c++ generate ansi C++ output\n") ; | |
106 | printf0 (" --olang=m2 generate PIM4 output\n") ; | |
107 | printf0 (" --extended-opaque parse definition and implementation modules to\n") ; | |
108 | printf0 (" generate full type debugging of opaque types\n") ; | |
109 | printf0 (" --debug-top debug topological data structure resolving (internal)\n") ; | |
110 | printf0 (" --h-file-prefix=foo set the h file prefix to foo\n") ; | |
111 | printf0 (" -o=foo set the output file to foo\n") ; | |
112 | printf0 (" --ignore-fq do not generate fully qualified idents\n") ; | |
113 | printf0 (" --gcc-config-system do not use standard host include files, use gcc config and system instead\n"); | |
114 | printf0 (" --gpl-header generate a GPL3 header comment at the top of the file\n") ; | |
115 | printf0 (" --glpl-header generate a GLPL3 header comment at the top of the file\n") ; | |
116 | printf0 (' --summary="foo" generate a one line summary comment at the top of the file\n') ; | |
117 | printf0 (' --contributed="foo" generate a one line contribution comment near the top of the file\n') ; | |
118 | printf0 (' --project="foo" include the project name within the GPL3 or GLPL3 header\n') ; | |
119 | printf0 (' --automatic generate a comment at the start of the file warning not to edit as it was automatically generated\n') ; | |
120 | printf0 (" filename the source file must be the last option\n") ; | |
121 | exit (0) | |
122 | END displayHelp ; | |
123 | ||
124 | ||
125 | (* | |
126 | commentBegin - issue a start of comment for the appropriate language. | |
127 | *) | |
128 | ||
129 | PROCEDURE commentBegin (f: File) ; | |
130 | BEGIN | |
131 | IF langC OR langCPP | |
132 | THEN | |
133 | FIO.WriteString (f, '/* ') | |
134 | ELSIF langM2 | |
135 | THEN | |
136 | FIO.WriteString (f, '(* ') | |
137 | END | |
138 | END commentBegin ; | |
139 | ||
140 | ||
141 | (* | |
142 | commentEnd - issue an end of comment for the appropriate language. | |
143 | *) | |
144 | ||
145 | PROCEDURE commentEnd (f: File) ; | |
146 | BEGIN | |
147 | IF langC OR langCPP | |
148 | THEN | |
149 | FIO.WriteString (f, ' */') ; FIO.WriteLine (f) | |
150 | ELSIF langM2 | |
151 | THEN | |
152 | FIO.WriteString (f, ' *)') ; FIO.WriteLine (f) | |
153 | END | |
154 | END commentEnd ; | |
155 | ||
156 | ||
157 | (* | |
158 | comment - write a comment to file, f, and also a newline. | |
159 | *) | |
160 | ||
161 | PROCEDURE comment (f: File; a: ARRAY OF CHAR) ; | |
162 | BEGIN | |
163 | FIO.WriteString (f, a) ; FIO.WriteLine (f) | |
164 | END comment ; | |
165 | ||
166 | ||
167 | (* | |
168 | commentS - write a comment to file, f, and also a newline. | |
169 | *) | |
170 | ||
171 | PROCEDURE commentS (f: File; s: String) ; | |
172 | BEGIN | |
173 | s := SFIO.WriteS (f, s) ; FIO.WriteLine (f) | |
174 | END commentS ; | |
175 | ||
176 | ||
177 | (* | |
178 | gplBody - | |
179 | *) | |
180 | ||
181 | PROCEDURE gplBody (f: File) ; | |
182 | BEGIN | |
183 | comment (f, 'Copyright (C) ' + YEAR + ' Free Software Foundation, Inc.') ; | |
184 | IF contributed | |
185 | THEN | |
186 | FIO.WriteString (f, "Contributed by ") ; | |
187 | contributedContents := SFIO.WriteS (f, contributedContents) ; | |
188 | FIO.WriteString (f, ".") ; | |
189 | FIO.WriteLine (f) | |
190 | END ; | |
191 | FIO.WriteLine (f) ; | |
192 | FIO.WriteString (f, "This file is part of ") ; | |
193 | projectContents := SFIO.WriteS (f, projectContents) ; | |
194 | FIO.WriteString (f, ".") ; | |
195 | FIO.WriteLine (f) ; FIO.WriteLine (f) ; | |
196 | projectContents := SFIO.WriteS (f, projectContents) ; | |
197 | comment (f, " is software; you can redistribute it and/or modify") ; | |
198 | comment (f, "it under the terms of the GNU General Public License as published by") ; | |
199 | comment (f, "the Free Software Foundation; either version 3, or (at your option)") ; | |
200 | comment (f, "any later version.") ; | |
201 | FIO.WriteLine (f) ; | |
202 | projectContents := SFIO.WriteS (f, projectContents) ; | |
203 | comment (f, " is distributed in the hope that it will be useful, but") ; | |
204 | comment (f, "WITHOUT ANY WARRANTY; without even the implied warranty of") ; | |
205 | comment (f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU") ; | |
206 | comment (f, "General Public License for more details.") ; | |
207 | FIO.WriteLine (f) ; | |
208 | comment (f, "You should have received a copy of the GNU General Public License") ; | |
209 | FIO.WriteString (f, "along with ") ; | |
210 | projectContents := SFIO.WriteS (f, projectContents) ; | |
211 | comment (f, "; see the file COPYING. If not,") ; | |
212 | FIO.WriteString (f, "see <https://www.gnu.org/licenses/>. ") | |
213 | END gplBody ; | |
214 | ||
215 | ||
216 | (* | |
217 | glplBody - | |
218 | *) | |
219 | ||
220 | PROCEDURE glplBody (f: File) ; | |
221 | BEGIN | |
222 | comment (f, 'Copyright (C) ' + YEAR + ' Free Software Foundation, Inc.') ; | |
223 | IF contributed | |
224 | THEN | |
225 | FIO.WriteString (f, "Contributed by ") ; | |
226 | contributedContents := SFIO.WriteS (f, contributedContents) ; | |
227 | FIO.WriteString (f, ".") ; | |
228 | FIO.WriteLine (f) | |
229 | END ; | |
230 | FIO.WriteLine (f) ; | |
231 | FIO.WriteString (f, "This file is part of ") ; | |
232 | projectContents := SFIO.WriteS (f, projectContents) ; | |
233 | FIO.WriteString (f, ".") ; | |
234 | FIO.WriteLine (f) ; FIO.WriteLine (f) ; | |
235 | ||
236 | projectContents := SFIO.WriteS (f, projectContents) ; | |
237 | comment (f, " is free software; you can redistribute it and/or modify") ; | |
238 | comment (f, "it under the terms of the GNU General Public License as published by") ; | |
239 | comment (f, "the Free Software Foundation; either version 3, or (at your option)") ; | |
240 | comment (f, "any later version.") ; | |
241 | FIO.WriteLine (f) ; | |
242 | ||
243 | projectContents := SFIO.WriteS (f, projectContents) ; | |
244 | comment (f, " is software; you can redistribute it and/or modify") ; | |
245 | comment (f, "it under the terms of the GNU Lesser General Public License") ; | |
246 | comment (f, "as published by the Free Software Foundation; either version 3,") ; | |
247 | comment (f, "or (at your option) any later version.") ; | |
248 | FIO.WriteLine (f) ; | |
249 | ||
250 | projectContents := SFIO.WriteS (f, projectContents) ; | |
251 | comment (f, " is distributed in the hope that it will be useful, but") ; | |
252 | comment (f, "WITHOUT ANY WARRANTY; without even the implied warranty of") ; | |
253 | comment (f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU") ; | |
254 | comment (f, "General Public License for more details.") ; | |
255 | FIO.WriteLine (f) ; | |
256 | ||
257 | comment (f, "You should have received a copy of the GNU General Public License") ; | |
258 | FIO.WriteString (f, "along with ") ; | |
259 | projectContents := SFIO.WriteS (f, projectContents) ; | |
260 | comment (f, "; see the file COPYING3. If not see") ; | |
261 | comment (f, "<http://www.gnu.org/licenses/>.") ; | |
262 | ||
263 | FIO.WriteLine (f) ; | |
264 | comment (f, "You should have received a copy of the GNU Lesser General Public License") ; | |
265 | FIO.WriteString (f, "along with ") ; | |
266 | projectContents := SFIO.WriteS (f, projectContents) ; | |
267 | comment (f, "; see the file COPYING. If not,") ; | |
268 | FIO.WriteString (f, "see <https://www.gnu.org/licenses/>. ") | |
269 | END glplBody ; | |
270 | ||
271 | ||
272 | (* | |
273 | issueGPL - writes out the summary, GPL/LGPL and/or contributed as a single comment. | |
274 | *) | |
275 | ||
276 | PROCEDURE issueGPL (f: File) ; | |
277 | BEGIN | |
278 | IF summary OR contributed OR gplHeader OR glplHeader | |
279 | THEN | |
280 | commentBegin (f) ; | |
281 | IF summary | |
282 | THEN | |
283 | commentS (f, summaryContents) ; | |
284 | FIO.WriteLine (f) | |
285 | END ; | |
286 | IF gplHeader | |
287 | THEN | |
288 | gplBody (f) | |
289 | END ; | |
290 | IF glplHeader | |
291 | THEN | |
292 | glplBody (f) | |
293 | END ; | |
294 | commentEnd (f) ; | |
295 | FIO.WriteLine (f) | |
296 | END | |
297 | END issueGPL ; | |
298 | ||
299 | ||
300 | (* | |
301 | writeGPLheader - writes out the GPL or the LGPL as a comment. | |
302 | *) | |
303 | ||
304 | PROCEDURE writeGPLheader (f: File) ; | |
305 | BEGIN | |
306 | issueGPL (f) | |
307 | END writeGPLheader ; | |
308 | ||
309 | ||
310 | (* | |
311 | getCppCommandLine - returns the Cpp command line and all arguments. | |
312 | *) | |
313 | ||
314 | PROCEDURE getCppCommandLine () : String ; | |
315 | VAR | |
316 | s: String ; | |
317 | BEGIN | |
318 | IF EqualArray (cppProgram, '') | |
319 | THEN | |
320 | RETURN NIL | |
321 | ELSE | |
322 | s := Dup (cppProgram) ; | |
323 | s := ConCat (ConCatChar(s, ' '), cppArgs) ; | |
324 | IF getQuiet () | |
325 | THEN | |
326 | s := ConCat (ConCatChar(s, ' '), Mark (InitString ('-quiet'))) | |
327 | END ; | |
328 | RETURN s | |
329 | END | |
330 | END getCppCommandLine ; | |
331 | ||
332 | ||
333 | (* | |
334 | setOutputFile - sets the output filename to output. | |
335 | *) | |
336 | ||
337 | PROCEDURE setOutputFile (output: String) ; | |
338 | BEGIN | |
339 | outputFile := output | |
340 | END setOutputFile ; | |
341 | ||
342 | ||
343 | (* | |
344 | getOutputFile - sets the output filename to output. | |
345 | *) | |
346 | ||
347 | PROCEDURE getOutputFile () : String ; | |
348 | BEGIN | |
349 | RETURN outputFile | |
350 | END getOutputFile ; | |
351 | ||
352 | ||
353 | (* | |
354 | setQuiet - sets the quiet flag to, value. | |
355 | *) | |
356 | ||
357 | PROCEDURE setQuiet (value: BOOLEAN) ; | |
358 | BEGIN | |
359 | quiet := value | |
360 | END setQuiet ; | |
361 | ||
362 | ||
363 | (* | |
364 | getQuiet - return the value of quiet. | |
365 | *) | |
366 | ||
367 | PROCEDURE getQuiet () : BOOLEAN ; | |
368 | BEGIN | |
369 | RETURN quiet | |
370 | END getQuiet ; | |
371 | ||
372 | ||
373 | (* | |
374 | setVerbose - sets the verbose flag to, value. | |
375 | *) | |
376 | ||
377 | PROCEDURE setVerbose (value: BOOLEAN) ; | |
378 | BEGIN | |
379 | verbose := value | |
380 | END setVerbose ; | |
381 | ||
382 | ||
383 | (* | |
384 | getVerbose - return the value of verbose. | |
385 | *) | |
386 | ||
387 | PROCEDURE getVerbose () : BOOLEAN ; | |
388 | BEGIN | |
389 | RETURN verbose | |
390 | END getVerbose ; | |
391 | ||
392 | ||
393 | (* | |
394 | setExtendedOpaque - set extendedOpaque to value. | |
395 | *) | |
396 | ||
397 | PROCEDURE setExtendedOpaque (value: BOOLEAN) ; | |
398 | BEGIN | |
399 | extendedOpaque := value | |
400 | END setExtendedOpaque ; | |
401 | ||
402 | ||
403 | (* | |
404 | getExtendedOpaque - return the extendedOpaque value. | |
405 | *) | |
406 | ||
407 | PROCEDURE getExtendedOpaque () : BOOLEAN ; | |
408 | BEGIN | |
409 | RETURN extendedOpaque | |
410 | END getExtendedOpaque ; | |
411 | ||
412 | ||
413 | (* | |
414 | setSearchPath - set the search path for the module sources. | |
415 | *) | |
416 | ||
417 | PROCEDURE setSearchPath (arg: String) ; | |
418 | BEGIN | |
419 | prependSearchPath (arg) | |
420 | END setSearchPath ; | |
421 | ||
422 | ||
423 | (* | |
424 | setInternalDebugging - turn on/off internal debugging. | |
425 | *) | |
426 | ||
427 | PROCEDURE setInternalDebugging (value: BOOLEAN) ; | |
428 | BEGIN | |
429 | internalDebugging := value | |
430 | END setInternalDebugging ; | |
431 | ||
432 | ||
433 | (* | |
434 | getInternalDebugging - return the value of internalDebugging. | |
435 | *) | |
436 | ||
437 | PROCEDURE getInternalDebugging () : BOOLEAN ; | |
438 | BEGIN | |
439 | RETURN internalDebugging | |
440 | END getInternalDebugging ; | |
441 | ||
442 | ||
443 | (* | |
444 | setDebugTopological - sets the flag debugTopological to value. | |
445 | *) | |
446 | ||
447 | PROCEDURE setDebugTopological (value: BOOLEAN) ; | |
448 | BEGIN | |
449 | debugTopological := value | |
450 | END setDebugTopological ; | |
451 | ||
452 | ||
453 | (* | |
454 | getDebugTopological - returns the flag value of the command | |
455 | line option --debug-top. | |
456 | *) | |
457 | ||
458 | PROCEDURE getDebugTopological () : BOOLEAN ; | |
459 | BEGIN | |
460 | RETURN debugTopological | |
461 | END getDebugTopological ; | |
462 | ||
463 | ||
464 | (* | |
465 | setHPrefix - saves the H file prefix. | |
466 | *) | |
467 | ||
468 | PROCEDURE setHPrefix (s: String) ; | |
469 | BEGIN | |
470 | hPrefix := s | |
471 | END setHPrefix ; | |
472 | ||
473 | ||
474 | (* | |
475 | getHPrefix - saves the H file prefix. | |
476 | *) | |
477 | ||
478 | PROCEDURE getHPrefix () : String ; | |
479 | BEGIN | |
480 | RETURN hPrefix | |
481 | END getHPrefix ; | |
482 | ||
483 | ||
484 | (* | |
485 | setIgnoreFQ - sets the ignorefq flag. | |
486 | *) | |
487 | ||
488 | PROCEDURE setIgnoreFQ (value: BOOLEAN) ; | |
489 | BEGIN | |
490 | ignoreFQ := value | |
491 | END setIgnoreFQ ; | |
492 | ||
493 | ||
494 | (* | |
495 | getIgnoreFQ - returns the ignorefq flag. | |
496 | *) | |
497 | ||
498 | PROCEDURE getIgnoreFQ () : BOOLEAN ; | |
499 | BEGIN | |
500 | RETURN ignoreFQ | |
501 | END getIgnoreFQ ; | |
502 | ||
503 | ||
504 | (* | |
505 | getGccConfigSystem - return the value of the gccConfigSystem flag. | |
506 | *) | |
507 | ||
508 | PROCEDURE getGccConfigSystem () : BOOLEAN ; | |
509 | BEGIN | |
510 | RETURN gccConfigSystem | |
511 | END getGccConfigSystem ; | |
512 | ||
513 | ||
514 | (* | |
515 | optionIs - returns TRUE if the first len (right) characters | |
516 | match left. | |
517 | *) | |
518 | ||
519 | PROCEDURE optionIs (left: ARRAY OF CHAR; right: String) : BOOLEAN ; | |
520 | VAR | |
521 | s: String ; | |
522 | BEGIN | |
523 | IF Length (right) = StrLen (left) | |
524 | THEN | |
525 | RETURN EqualArray (right, left) | |
526 | ELSIF Length (right) > StrLen (left) | |
527 | THEN | |
528 | s := Mark (Slice (right, 0, StrLen (left))) ; | |
529 | RETURN EqualArray (s, left) | |
530 | ELSE | |
531 | RETURN FALSE | |
532 | END | |
533 | END optionIs ; | |
534 | ||
535 | ||
536 | (* | |
537 | setLang - set the appropriate output language. | |
538 | *) | |
539 | ||
540 | PROCEDURE setLang (arg: String) ; | |
541 | BEGIN | |
542 | (* must check the longest distinctive string first. *) | |
543 | IF optionIs ("c++", arg) | |
544 | THEN | |
545 | setLangCP ; | |
546 | langCPP := TRUE | |
547 | ELSIF optionIs ("c", arg) | |
548 | THEN | |
549 | setLangC ; | |
550 | langC := TRUE | |
551 | ELSIF optionIs ("m2", arg) | |
552 | THEN | |
553 | setLangM2 ; | |
554 | langM2 := TRUE | |
555 | ELSE | |
556 | displayHelp | |
557 | END | |
558 | END setLang ; | |
559 | ||
560 | ||
561 | (* | |
562 | handleOption - | |
563 | *) | |
564 | ||
565 | PROCEDURE handleOption (arg: String) ; | |
566 | BEGIN | |
567 | IF optionIs ("--quiet", arg) OR optionIs ("-q", arg) | |
568 | THEN | |
569 | setQuiet (TRUE) | |
570 | ELSIF optionIs ("--verbose", arg) OR optionIs ("-v", arg) | |
571 | THEN | |
572 | setVerbose (TRUE) | |
573 | ELSIF optionIs ("--version", arg) | |
574 | THEN | |
575 | displayVersion (TRUE) | |
576 | ELSIF optionIs ("--olang=", arg) | |
577 | THEN | |
578 | setLang (Slice (arg, 8, 0)) | |
579 | ELSIF optionIs ("-I", arg) | |
580 | THEN | |
581 | setSearchPath (Slice (arg, 2, 0)) | |
582 | ELSIF optionIs ("--help", arg) OR optionIs ("-h", arg) | |
583 | THEN | |
584 | displayHelp | |
585 | ELSIF optionIs ("--cpp", arg) | |
586 | THEN | |
587 | cppProgram := InitString ('cpp') | |
588 | ELSIF optionIs ("-o=", arg) | |
589 | THEN | |
590 | setOutputFile (Slice (arg, 3, 0)) | |
591 | ELSIF optionIs ("--extended-opaque", arg) | |
592 | THEN | |
593 | setExtendedOpaque (TRUE) | |
594 | ELSIF optionIs ("--debug-top", arg) | |
595 | THEN | |
596 | setDebugTopological (TRUE) | |
597 | ELSIF optionIs ("--h-file-prefix=", arg) | |
598 | THEN | |
599 | setHPrefix (Slice (arg, 16, 0)) | |
600 | ELSIF optionIs ("--ignore-fq", arg) | |
601 | THEN | |
602 | setIgnoreFQ (TRUE) | |
603 | ELSIF optionIs ("--gpl-header", arg) | |
604 | THEN | |
605 | gplHeader := TRUE | |
606 | ELSIF optionIs ("--glpl-header", arg) | |
607 | THEN | |
608 | glplHeader := TRUE | |
609 | ELSIF optionIs ('--summary="', arg) | |
610 | THEN | |
611 | summary := TRUE ; | |
612 | summaryContents := Slice (arg, 11, -1) | |
613 | ELSIF optionIs ('--contributed="', arg) | |
614 | THEN | |
615 | contributed := TRUE ; | |
616 | contributedContents := Slice (arg, 13, -1) | |
617 | ELSIF optionIs ('--project="', arg) | |
618 | THEN | |
619 | projectContents := Slice (arg, 10, -1) | |
620 | ELSIF optionIs ('--gcc-config-system', arg) | |
621 | THEN | |
622 | gccConfigSystem := TRUE | |
623 | END | |
624 | END handleOption ; | |
625 | ||
626 | ||
627 | (* | |
628 | handleOptions - iterates over all options setting appropriate | |
629 | values and returns the single source file | |
630 | if found at the end of the arguments. | |
631 | *) | |
632 | ||
633 | PROCEDURE handleOptions () : String ; | |
634 | VAR | |
635 | i : CARDINAL ; | |
636 | arg: String ; | |
637 | BEGIN | |
638 | i := 1 ; | |
639 | WHILE GetArg (arg, i) DO | |
640 | IF Length (arg) > 0 | |
641 | THEN | |
642 | IF char (arg, 0)='-' | |
643 | THEN | |
644 | handleOption (arg) | |
645 | ELSE | |
646 | IF NOT summary | |
647 | THEN | |
648 | summaryContents := ConCatChar (ConCat (InitString ('automatically created by mc from '), | |
649 | arg), '.') ; | |
650 | summary := FALSE | |
651 | END ; | |
652 | RETURN arg | |
653 | END | |
654 | END ; | |
655 | INC (i) | |
656 | END ; | |
657 | RETURN NIL | |
658 | END handleOptions ; | |
659 | ||
660 | ||
661 | BEGIN | |
662 | langC := TRUE ; | |
663 | langCPP := FALSE ; | |
664 | langM2 := FALSE ; | |
665 | gplHeader := FALSE ; | |
666 | glplHeader := FALSE ; | |
667 | summary := FALSE ; | |
668 | contributed := FALSE ; | |
669 | caseRuntime := FALSE ; | |
670 | arrayRuntime := FALSE ; | |
671 | returnRuntime := FALSE ; | |
672 | internalDebugging := FALSE ; | |
673 | quiet := FALSE ; | |
674 | verbose := FALSE ; | |
675 | extendedOpaque := FALSE ; | |
676 | debugTopological := FALSE ; | |
677 | ignoreFQ := FALSE ; | |
678 | gccConfigSystem := FALSE ; | |
679 | hPrefix := InitString ('') ; | |
680 | cppArgs := InitString ('') ; | |
681 | cppProgram := InitString ('') ; | |
682 | outputFile := InitString ('-') ; | |
683 | summaryContents := InitString ('') ; | |
684 | contributedContents := InitString ('') ; | |
685 | projectContents := InitString ('GNU Modula-2') | |
686 | END mcOptions. |