]> gcc.gnu.org Git - gcc.git/blame - gcc/m2/mc/mcOptions.mod
Year date changes for Modula-2 source tree.
[gcc.git] / gcc / m2 / mc / mcOptions.mod
CommitLineData
3d864fce 1(* Copyright (C) 2015-2022 Free Software Foundation, Inc. *)
7401123f
GM
2(* This file is part of GNU Modula-2.
3
4GNU Modula-2 is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 3, or (at your option) any later
7version.
8
9GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License along
15with gm2; see the file COPYING. If not, write to the Free Software
16Foundation, 51 Franklin Street, Fifth Floor,
17Boston, MA 02110-1301, USA. *)
18
19IMPLEMENTATION MODULE mcOptions ;
20
21FROM SArgs IMPORT GetArg, Narg ;
22FROM mcSearch IMPORT prependSearchPath ;
23FROM libc IMPORT exit, printf ;
24FROM mcPrintf IMPORT printf0 ;
25FROM Debug IMPORT Halt ;
26FROM StrLib IMPORT StrLen ;
27FROM decl IMPORT setLangC, setLangCP, setLangM2 ;
28
29FROM DynamicStrings IMPORT String, Length, InitString, Mark, Slice, EqualArray,
30 InitStringCharStar, ConCatChar, ConCat, KillString,
31 Dup, string, char ;
32
33IMPORT FIO ;
34IMPORT SFIO ;
35
36CONST
37 YEAR = '2021' ;
38
39VAR
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
70PROCEDURE displayVersion (mustExit: BOOLEAN) ;
71BEGIN
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
80END displayVersion ;
81
82
83(*
84 displayHelp - display the mc help summary.
85*)
86
87PROCEDURE displayHelp ;
88BEGIN
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)
122END displayHelp ;
123
124
125(*
126 commentBegin - issue a start of comment for the appropriate language.
127*)
128
129PROCEDURE commentBegin (f: File) ;
130BEGIN
131 IF langC OR langCPP
132 THEN
133 FIO.WriteString (f, '/* ')
134 ELSIF langM2
135 THEN
136 FIO.WriteString (f, '(* ')
137 END
138END commentBegin ;
139
140
141(*
142 commentEnd - issue an end of comment for the appropriate language.
143*)
144
145PROCEDURE commentEnd (f: File) ;
146BEGIN
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
154END commentEnd ;
155
156
157(*
158 comment - write a comment to file, f, and also a newline.
159*)
160
161PROCEDURE comment (f: File; a: ARRAY OF CHAR) ;
162BEGIN
163 FIO.WriteString (f, a) ; FIO.WriteLine (f)
164END comment ;
165
166
167(*
168 commentS - write a comment to file, f, and also a newline.
169*)
170
171PROCEDURE commentS (f: File; s: String) ;
172BEGIN
173 s := SFIO.WriteS (f, s) ; FIO.WriteLine (f)
174END commentS ;
175
176
177(*
178 gplBody -
179*)
180
181PROCEDURE gplBody (f: File) ;
182BEGIN
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/>. ")
213END gplBody ;
214
215
216(*
217 glplBody -
218*)
219
220PROCEDURE glplBody (f: File) ;
221BEGIN
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/>. ")
269END glplBody ;
270
271
272(*
273 issueGPL - writes out the summary, GPL/LGPL and/or contributed as a single comment.
274*)
275
276PROCEDURE issueGPL (f: File) ;
277BEGIN
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
297END issueGPL ;
298
299
300(*
301 writeGPLheader - writes out the GPL or the LGPL as a comment.
302*)
303
304PROCEDURE writeGPLheader (f: File) ;
305BEGIN
306 issueGPL (f)
307END writeGPLheader ;
308
309
310(*
311 getCppCommandLine - returns the Cpp command line and all arguments.
312*)
313
314PROCEDURE getCppCommandLine () : String ;
315VAR
316 s: String ;
317BEGIN
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
330END getCppCommandLine ;
331
332
333(*
334 setOutputFile - sets the output filename to output.
335*)
336
337PROCEDURE setOutputFile (output: String) ;
338BEGIN
339 outputFile := output
340END setOutputFile ;
341
342
343(*
344 getOutputFile - sets the output filename to output.
345*)
346
347PROCEDURE getOutputFile () : String ;
348BEGIN
349 RETURN outputFile
350END getOutputFile ;
351
352
353(*
354 setQuiet - sets the quiet flag to, value.
355*)
356
357PROCEDURE setQuiet (value: BOOLEAN) ;
358BEGIN
359 quiet := value
360END setQuiet ;
361
362
363(*
364 getQuiet - return the value of quiet.
365*)
366
367PROCEDURE getQuiet () : BOOLEAN ;
368BEGIN
369 RETURN quiet
370END getQuiet ;
371
372
373(*
374 setVerbose - sets the verbose flag to, value.
375*)
376
377PROCEDURE setVerbose (value: BOOLEAN) ;
378BEGIN
379 verbose := value
380END setVerbose ;
381
382
383(*
384 getVerbose - return the value of verbose.
385*)
386
387PROCEDURE getVerbose () : BOOLEAN ;
388BEGIN
389 RETURN verbose
390END getVerbose ;
391
392
393(*
394 setExtendedOpaque - set extendedOpaque to value.
395*)
396
397PROCEDURE setExtendedOpaque (value: BOOLEAN) ;
398BEGIN
399 extendedOpaque := value
400END setExtendedOpaque ;
401
402
403(*
404 getExtendedOpaque - return the extendedOpaque value.
405*)
406
407PROCEDURE getExtendedOpaque () : BOOLEAN ;
408BEGIN
409 RETURN extendedOpaque
410END getExtendedOpaque ;
411
412
413(*
414 setSearchPath - set the search path for the module sources.
415*)
416
417PROCEDURE setSearchPath (arg: String) ;
418BEGIN
419 prependSearchPath (arg)
420END setSearchPath ;
421
422
423(*
424 setInternalDebugging - turn on/off internal debugging.
425*)
426
427PROCEDURE setInternalDebugging (value: BOOLEAN) ;
428BEGIN
429 internalDebugging := value
430END setInternalDebugging ;
431
432
433(*
434 getInternalDebugging - return the value of internalDebugging.
435*)
436
437PROCEDURE getInternalDebugging () : BOOLEAN ;
438BEGIN
439 RETURN internalDebugging
440END getInternalDebugging ;
441
442
443(*
444 setDebugTopological - sets the flag debugTopological to value.
445*)
446
447PROCEDURE setDebugTopological (value: BOOLEAN) ;
448BEGIN
449 debugTopological := value
450END setDebugTopological ;
451
452
453(*
454 getDebugTopological - returns the flag value of the command
455 line option --debug-top.
456*)
457
458PROCEDURE getDebugTopological () : BOOLEAN ;
459BEGIN
460 RETURN debugTopological
461END getDebugTopological ;
462
463
464(*
465 setHPrefix - saves the H file prefix.
466*)
467
468PROCEDURE setHPrefix (s: String) ;
469BEGIN
470 hPrefix := s
471END setHPrefix ;
472
473
474(*
475 getHPrefix - saves the H file prefix.
476*)
477
478PROCEDURE getHPrefix () : String ;
479BEGIN
480 RETURN hPrefix
481END getHPrefix ;
482
483
484(*
485 setIgnoreFQ - sets the ignorefq flag.
486*)
487
488PROCEDURE setIgnoreFQ (value: BOOLEAN) ;
489BEGIN
490 ignoreFQ := value
491END setIgnoreFQ ;
492
493
494(*
495 getIgnoreFQ - returns the ignorefq flag.
496*)
497
498PROCEDURE getIgnoreFQ () : BOOLEAN ;
499BEGIN
500 RETURN ignoreFQ
501END getIgnoreFQ ;
502
503
504(*
505 getGccConfigSystem - return the value of the gccConfigSystem flag.
506*)
507
508PROCEDURE getGccConfigSystem () : BOOLEAN ;
509BEGIN
510 RETURN gccConfigSystem
511END getGccConfigSystem ;
512
513
514(*
515 optionIs - returns TRUE if the first len (right) characters
516 match left.
517*)
518
519PROCEDURE optionIs (left: ARRAY OF CHAR; right: String) : BOOLEAN ;
520VAR
521 s: String ;
522BEGIN
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
533END optionIs ;
534
535
536(*
537 setLang - set the appropriate output language.
538*)
539
540PROCEDURE setLang (arg: String) ;
541BEGIN
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
558END setLang ;
559
560
561(*
562 handleOption -
563*)
564
565PROCEDURE handleOption (arg: String) ;
566BEGIN
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
624END 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
633PROCEDURE handleOptions () : String ;
634VAR
635 i : CARDINAL ;
636 arg: String ;
637BEGIN
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
658END handleOptions ;
659
660
661BEGIN
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')
686END mcOptions.
This page took 0.116253 seconds and 5 git commands to generate.