aboutsummaryrefslogtreecommitdiff
path: root/gcc/m2/mc/mcOptions.mod
blob: 2332599d1452dfa0f9600a37c999b35722c2066c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
(* Copyright (C) 2015-2025 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.

GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  *)

IMPLEMENTATION MODULE mcOptions ;

FROM SArgs IMPORT GetArg, Narg ;
FROM mcSearch IMPORT prependSearchPath ;
FROM libc IMPORT exit, printf, time, localtime, time_t, ptrToTM ;
FROM mcPrintf IMPORT printf0, printf1 ;
FROM Debug IMPORT Halt ;
FROM StrLib IMPORT StrLen ;
FROM decl IMPORT setLangC, setLangCP, setLangM2 ;

FROM DynamicStrings IMPORT String, Length, InitString, Mark, Slice, EqualArray,
                           InitStringCharStar, ConCatChar, ConCat, KillString,
                           Dup, string, char, ReplaceChar ;

IMPORT FIO ;
IMPORT SFIO ;

VAR
   langC,
   langCPP,
   langM2,
   gplHeader,
   glplHeader,
   summary,
   contributed,
   scaffoldMain,
   scaffoldDynamic,
   caseRuntime,
   arrayRuntime,
   returnRuntime,
   suppressNoReturn,
   useBoolType,
   gccConfigSystem,
   ignoreFQ,
   debugTopological,
   extendedOpaque,
   internalDebugging,
   verbose,
   quiet            : BOOLEAN ;
   CReal,
   CLongReal,
   CShortReal,
   projectContents,
   summaryContents,
   contributedContents,
   hPrefix,
   outputFile,
   cppArgs,
   cppProgram       : String ;



(*
   getYear - return the year.
*)

PROCEDURE getYear () : CARDINAL ;
VAR
   epoch    : time_t ;
   localTime: ptrToTM ;
BEGIN
   epoch := time (NIL) ;
   localTime := localtime (epoch) ;
   RETURN localTime^.tm_year + 1900
END getYear ;


(*
   displayVersion - displays the version of the compiler.
*)

PROCEDURE displayVersion (mustExit: BOOLEAN) ;
VAR
   year: CARDINAL ;
BEGIN
   year := getYear () ;
   (* These first three calls to printf hide the first line of text away from the year change script.  *)
   printf0 ('Copyright ') ;
   printf0 ('(C)') ;  (* A unicode char here would be good.  *)
   printf1 (' %d Free Software Foundation, Inc.\n', year) ;
   printf0 ('License GPLv3: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n') ;
   printf0 ('This is free software: you are free to change and redistribute it.\n') ;
   printf0 ('There is NO WARRANTY, to the extent permitted by law.\n') ;
   IF mustExit
   THEN
      exit (0)
   END
END displayVersion ;


(*
   displayHelp - display the mc help summary.
*)

PROCEDURE displayHelp ;
BEGIN
   printf0 ("usage: mc [--cpp] [-g] [--quiet] [--extended-opaque] [-q] [-v]") ;
   printf0 (" [--verbose] [--version] [--help] [-h] [-Ipath] [--olang=c]") ;
   printf0 (" [--olang=c++] [--olang=m2] [--debug-top]") ;
   printf0 (' [--gpl-header] [--glpl-header] [--summary="foo"]') ;
   printf0 (' [--contributed="foo"] [--project="foo"]') ;
   printf0 (" [--h-file-prefix=foo] [--automatic] [-o=foo] filename\n") ;

   printf0 ("  --cpp               preprocess through the C preprocessor\n") ;
   printf0 ("  -g                  emit debugging directives in the output language") ;
   printf0 ("                      so that the debugger will refer to the source\n") ;
   printf0 ("  -q --quiet          no output unless an error occurs\n") ;
   printf0 ("  -v --verbose        display preprocessor if invoked\n") ;
   printf0 ("  --version           display version and exit\n") ;
   printf0 ("  -h --help           display this help message\n") ;
   printf0 ("  -Ipath              set the module search path\n") ;
   printf0 ("  --olang=c           generate ansi C output\n") ;
   printf0 ("  --olang=c++         generate ansi C++ output\n") ;
   printf0 ("  --olang=m2          generate PIM4 output\n") ;
   printf0 ("  --extended-opaque   parse definition and implementation modules to\n") ;
   printf0 ("                      generate full type debugging of opaque types\n") ;
   printf0 ("  --debug-top         debug topological data structure resolving (internal)\n") ;
   printf0 ("  --h-file-prefix=foo set the h file prefix to foo\n") ;
   printf0 ("  -o=foo              set the output file to foo\n") ;
   printf0 ("  --ignore-fq         do not generate fully qualified idents\n") ;
   printf0 ("  --gcc-config-system do not use standard host include files, use gcc config and system instead\n");
   printf0 ("  --gpl-header        generate a GPL3 header comment at the top of the file\n") ;
   printf0 ("  --glpl-header       generate a GLPL3 header comment at the top of the file\n") ;
   printf0 ('  --summary="foo"     generate a one line summary comment at the top of the file\n') ;
   printf0 ('  --contributed="foo" generate a one line contribution comment near the top of the file\n') ;
   printf0 ('  --project="foo"     include the project name within the GPL3 or GLPL3 header\n') ;
   printf0 ('  --automatic         generate a comment at the start of the file warning not to edit as it was automatically generated\n') ;
   printf0 ('  --scaffold-dynamic  generate dynamic module initialization code for C++\n') ;
   printf0 ('  --scaffold-main     generate main function which calls upon the dynamic initialization support in M2RTS\n') ;
   printf0 ('  --suppress-noreturn suppress the emission of any attribute noreturn\n');
   printf0 ('  filename            the source file must be the last option\n') ;
   exit (0)
END displayHelp ;


(*
   commentBegin - issue a start of comment for the appropriate language.
*)

PROCEDURE commentBegin (f: File) ;
BEGIN
   IF langC OR langCPP
   THEN
      FIO.WriteString (f, '/* ')
   ELSIF langM2
   THEN
      FIO.WriteString (f, '(* ')
   END
END commentBegin ;


(*
   commentEnd - issue an end of comment for the appropriate language.
*)

PROCEDURE commentEnd (f: File) ;
BEGIN
   IF langC OR langCPP
   THEN
      FIO.WriteString (f, ' */') ; FIO.WriteLine (f)
   ELSIF langM2
   THEN
      FIO.WriteString (f, ' *)') ; FIO.WriteLine (f)
   END
END commentEnd ;


(*
   comment - write a comment to file, f, and also a newline.
*)

PROCEDURE comment (f: File; a: ARRAY OF CHAR) ;
BEGIN
   FIO.WriteString (f, a) ; FIO.WriteLine (f)
END comment ;


(*
   commentS - write a comment to file, f, and also a newline.
*)

PROCEDURE commentS (f: File; s: String) ;
BEGIN
   s := SFIO.WriteS (f, s) ; FIO.WriteLine (f)
END commentS ;


(*
   gplBody -
*)

PROCEDURE gplBody (f: File) ;
VAR
   year: CARDINAL ;
BEGIN
   year := getYear () ;
   printf1 ('Copyright (C) %d Free Software Foundation, Inc.\n', year) ;
   IF contributed
   THEN
      FIO.WriteString (f, "Contributed by ") ;
      contributedContents := SFIO.WriteS (f, contributedContents) ;
      FIO.WriteString (f, ".") ;
      FIO.WriteLine (f)
   END ;
   FIO.WriteLine (f) ;
   FIO.WriteString (f, "This file is part of ") ;
   projectContents := SFIO.WriteS (f, projectContents) ;
   FIO.WriteString (f, ".") ;
   FIO.WriteLine (f) ; FIO.WriteLine (f) ;
   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, " is software; you can redistribute it and/or modify") ;
   comment (f, "it under the terms of the GNU General Public License as published by") ;
   comment (f, "the Free Software Foundation; either version 3, or (at your option)") ;
   comment (f, "any later version.") ;
   FIO.WriteLine (f) ;
   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, " is distributed in the hope that it will be useful, but") ;
   comment (f, "WITHOUT ANY WARRANTY; without even the implied warranty of") ;
   comment (f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU") ;
   comment (f, "General Public License for more details.") ;
   FIO.WriteLine (f) ;
   comment (f, "You should have received a copy of the GNU General Public License") ;
   FIO.WriteString (f, "along with ") ;
   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, "; see the file COPYING.  If not,") ;
   FIO.WriteString (f, "see <https://www.gnu.org/licenses/>. ")
END gplBody ;


(*
   glplBody -
*)

PROCEDURE glplBody (f: File) ;
VAR
   year: CARDINAL ;
BEGIN
   year := getYear () ;
   printf1 ('Copyright (C) %d Free Software Foundation, Inc.\n', year) ;
   IF contributed
   THEN
      FIO.WriteString (f, "Contributed by ") ;
      contributedContents := SFIO.WriteS (f, contributedContents) ;
      FIO.WriteString (f, ".") ;
      FIO.WriteLine (f)
   END ;
   FIO.WriteLine (f) ;
   FIO.WriteString (f, "This file is part of ") ;
   projectContents := SFIO.WriteS (f, projectContents) ;
   FIO.WriteString (f, ".") ;
   FIO.WriteLine (f) ; FIO.WriteLine (f) ;

   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, " is free software; you can redistribute it and/or modify") ;
   comment (f, "it under the terms of the GNU General Public License as published by") ;
   comment (f, "the Free Software Foundation; either version 3, or (at your option)") ;
   comment (f, "any later version.") ;
   FIO.WriteLine (f) ;

   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, " is software; you can redistribute it and/or modify") ;
   comment (f, "it under the terms of the GNU Lesser General Public License") ;
   comment (f, "as published by the Free Software Foundation; either version 3,") ;
   comment (f, "or (at your option) any later version.") ;
   FIO.WriteLine (f) ;

   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, " is distributed in the hope that it will be useful, but") ;
   comment (f, "WITHOUT ANY WARRANTY; without even the implied warranty of") ;
   comment (f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU") ;
   comment (f, "General Public License for more details.") ;
   FIO.WriteLine (f) ;

   comment (f, "You should have received a copy of the GNU General Public License") ;
   FIO.WriteString (f, "along with ") ;
   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, "; see the file COPYING3.  If not see") ;
   comment (f, "<http://www.gnu.org/licenses/>.") ;

   FIO.WriteLine (f) ;
   comment (f, "You should have received a copy of the GNU Lesser General Public License") ;
   FIO.WriteString (f, "along with ") ;
   projectContents := SFIO.WriteS (f, projectContents) ;
   comment (f, "; see the file COPYING.  If not,") ;
   FIO.WriteString (f, "see <https://www.gnu.org/licenses/>. ")
END glplBody ;


(*
   issueGPL - writes out the summary, GPL/LGPL and/or contributed as a single comment.
*)

PROCEDURE issueGPL (f: File) ;
BEGIN
   IF summary OR contributed OR gplHeader OR glplHeader
   THEN
      commentBegin (f) ;
      IF summary
      THEN
         commentS (f, summaryContents) ;
         FIO.WriteLine (f)
      END ;
      IF gplHeader
      THEN
         gplBody (f)
      END ;
      IF glplHeader
      THEN
         glplBody (f)
      END ;
      commentEnd (f) ;
      FIO.WriteLine (f)
   END
END issueGPL ;


(*
   writeGPLheader - writes out the GPL or the LGPL as a comment.
*)

PROCEDURE writeGPLheader (f: File) ;
BEGIN
   issueGPL (f)
END writeGPLheader ;


(*
   getCppCommandLine - returns the Cpp command line and all arguments.
*)

PROCEDURE getCppCommandLine () : String ;
VAR
   s: String ;
BEGIN
   IF EqualArray (cppProgram, '')
   THEN
      RETURN NIL
   ELSE
      s := Dup (cppProgram) ;
      s := ConCat (ConCatChar(s, ' '), cppArgs) ;
      IF getQuiet ()
      THEN
         s := ConCat (ConCatChar(s, ' '), Mark (InitString ('-quiet')))
      END ;
      RETURN s
   END
END getCppCommandLine ;


(*
   setOutputFile - sets the output filename to output.
*)

PROCEDURE setOutputFile (output: String) ;
BEGIN
   outputFile := output
END setOutputFile ;


(*
   getOutputFile - sets the output filename to output.
*)

PROCEDURE getOutputFile () : String ;
BEGIN
   RETURN outputFile
END getOutputFile ;


(*
   setQuiet - sets the quiet flag to, value.
*)

PROCEDURE setQuiet (value: BOOLEAN) ;
BEGIN
   quiet := value
END setQuiet ;


(*
   getQuiet - return the value of quiet.
*)

PROCEDURE getQuiet () : BOOLEAN ;
BEGIN
   RETURN quiet
END getQuiet ;


(*
   setVerbose - sets the verbose flag to, value.
*)

PROCEDURE setVerbose (value: BOOLEAN) ;
BEGIN
   verbose := value
END setVerbose ;


(*
   getVerbose - return the value of verbose.
*)

PROCEDURE getVerbose () : BOOLEAN ;
BEGIN
   RETURN verbose
END getVerbose ;


(*
   setExtendedOpaque - set extendedOpaque to value.
*)

PROCEDURE setExtendedOpaque (value: BOOLEAN) ;
BEGIN
   extendedOpaque := value
END setExtendedOpaque ;


(*
   getExtendedOpaque - return the extendedOpaque value.
*)

PROCEDURE getExtendedOpaque () : BOOLEAN ;
BEGIN
   RETURN extendedOpaque
END getExtendedOpaque ;


(*
   setSuppressNoReturn - set suppressNoReturn to value.
*)

PROCEDURE setSuppressNoReturn (value: BOOLEAN) ;
BEGIN
   suppressNoReturn := value
END setSuppressNoReturn;


(*
   getSuppressNoReturn - return the suppressNoReturn value.
*)

PROCEDURE getSuppressNoReturn () : BOOLEAN ;
BEGIN
   RETURN suppressNoReturn
END getSuppressNoReturn ;


(*
   setSearchPath - set the search path for the module sources.
*)

PROCEDURE setSearchPath (arg: String) ;
BEGIN
   prependSearchPath (arg)
END setSearchPath ;


(*
   setInternalDebugging - turn on/off internal debugging.
*)

PROCEDURE setInternalDebugging (value: BOOLEAN) ;
BEGIN
   internalDebugging := value
END setInternalDebugging ;


(*
   getInternalDebugging - return the value of internalDebugging.
*)

PROCEDURE getInternalDebugging () : BOOLEAN ;
BEGIN
   RETURN internalDebugging
END getInternalDebugging ;


(*
   setDebugTopological - sets the flag debugTopological to value.
*)

PROCEDURE setDebugTopological (value: BOOLEAN) ;
BEGIN
   debugTopological := value
END setDebugTopological ;


(*
   getDebugTopological - returns the flag value of the command
                         line option --debug-top.
*)

PROCEDURE getDebugTopological () : BOOLEAN ;
BEGIN
   RETURN debugTopological
END getDebugTopological ;


(*
   setHPrefix - saves the H file prefix.
*)

PROCEDURE setHPrefix (s: String) ;
BEGIN
   hPrefix := s
END setHPrefix ;


(*
   getHPrefix - saves the H file prefix.
*)

PROCEDURE getHPrefix () : String ;
BEGIN
   RETURN hPrefix
END getHPrefix ;


(*
   setIgnoreFQ - sets the ignorefq flag.
*)

PROCEDURE setIgnoreFQ (value: BOOLEAN) ;
BEGIN
   ignoreFQ := value
END setIgnoreFQ ;


(*
   getIgnoreFQ - returns the ignorefq flag.
*)

PROCEDURE getIgnoreFQ () : BOOLEAN ;
BEGIN
   RETURN ignoreFQ
END getIgnoreFQ ;


(*
   getGccConfigSystem - return the value of the gccConfigSystem flag.
*)

PROCEDURE getGccConfigSystem () : BOOLEAN ;
BEGIN
   RETURN gccConfigSystem
END getGccConfigSystem ;


(*
   getScaffoldDynamic - return true if the --scaffold-dynamic option was present.
*)

PROCEDURE getScaffoldDynamic () : BOOLEAN ;
BEGIN
   RETURN scaffoldDynamic
END getScaffoldDynamic ;


(*
   getScaffoldMain - return true if the --scaffold-main option was present.
*)

PROCEDURE getScaffoldMain () : BOOLEAN ;
BEGIN
   RETURN scaffoldMain
END getScaffoldMain ;


(*
   useBool - should mc use the bool type instead of int.
*)

PROCEDURE useBool () : BOOLEAN ;
BEGIN
   RETURN useBoolType
END useBool ;


(*
   getCRealType - returns the string representing the REAL type
                  used by C.  By default this is "double".
*)

PROCEDURE getCRealType () : String ;
BEGIN
   RETURN CReal
END getCRealType ;


(*
   getCLongRealType - returns the string representing the REAL type
                      used by C.  By default this is "long double".
*)

PROCEDURE getCLongRealType () : String ;
BEGIN
   RETURN CLongReal
END getCLongRealType ;


(*
   getCShortRealType - returns the string representing the REAL type
                       used by C.  By default this is "float".
*)

PROCEDURE getCShortRealType () : String ;
BEGIN
   RETURN CShortReal
END getCShortRealType ;


(*
   toCType - returns a new string which has all occurences of '-'
             replaced by ' '.
*)

PROCEDURE toCType (namedType: String) : String ;
BEGIN
   RETURN ReplaceChar (Dup (namedType), '-', ' ')
END toCType ;


(*
   setCReal - assigns CReal to namedType after it has been transformed by
              toCType.
*)

PROCEDURE setCReal (namedType: String) ;
BEGIN
   CReal := toCType (namedType)
END setCReal ;


(*
   setCShortReal - assigns CShortReal to namedType after it has been
                   transformed by toCType.
*)

PROCEDURE setCShortReal (namedType: String) ;
BEGIN
   CShortReal := toCType (namedType)
END setCShortReal ;


(*
   setCLongReal - assigns CLongReal to namedType after it has been
                  transformed by toCType.
*)

PROCEDURE setCLongReal (namedType: String) ;
BEGIN
   CLongReal := toCType (namedType)
END setCLongReal ;


(*
   optionIs - returns TRUE if the first len (right) characters
              match left.
*)

PROCEDURE optionIs (left: ARRAY OF CHAR; right: String) : BOOLEAN ;
VAR
   s: String ;
BEGIN
   IF Length (right) = StrLen (left)
   THEN
      RETURN EqualArray (right, left)
   ELSIF  Length (right) > StrLen (left)
   THEN
      s := Mark (Slice (right, 0, StrLen (left))) ;
      RETURN EqualArray (s, left)
   ELSE
      RETURN FALSE
   END
END optionIs ;


(*
   setLang - set the appropriate output language.
*)

PROCEDURE setLang (arg: String) ;
BEGIN
   (* must check the longest distinctive string first.  *)
   IF optionIs ("c++", arg)
   THEN
      setLangCP ;
      langCPP := TRUE
   ELSIF optionIs ("c", arg)
   THEN
      setLangC ;
      langC := TRUE
   ELSIF optionIs ("m2", arg)
   THEN
      setLangM2 ;
      langM2 := TRUE
   ELSE
      displayHelp
   END
END setLang ;


(*
   handleOption -
*)

PROCEDURE handleOption (arg: String) ;
BEGIN
   IF optionIs ("--quiet", arg) OR optionIs ("-q", arg)
   THEN
      setQuiet (TRUE)
   ELSIF optionIs ("--verbose", arg) OR optionIs ("-v", arg)
   THEN
      setVerbose (TRUE)
   ELSIF optionIs ("--version", arg)
   THEN
      displayVersion (TRUE)
   ELSIF optionIs ("--olang=", arg)
   THEN
      setLang (Slice (arg, 8, 0))
   ELSIF optionIs ("-I", arg)
   THEN
      setSearchPath (Slice (arg, 2, 0))
   ELSIF optionIs ("--help", arg) OR optionIs ("-h", arg)
   THEN
      displayHelp
   ELSIF optionIs ("--cpp", arg)
   THEN
      cppProgram := InitString ('cpp')
   ELSIF optionIs ("-o=", arg)
   THEN
      setOutputFile (Slice (arg, 3, 0))
   ELSIF optionIs ("--extended-opaque", arg)
   THEN
      (* setExtendedOpaque (TRUE) *)
      printf0 ("IGNORING --extended-opaque - this option is no longer implemented - please adjust the call to mc\n")
   ELSIF optionIs ("--debug-top", arg)
   THEN
      setDebugTopological (TRUE)
   ELSIF optionIs ("--h-file-prefix=", arg)
   THEN
      setHPrefix (Slice (arg, 16, 0))
   ELSIF optionIs ("--ignore-fq", arg)
   THEN
      setIgnoreFQ (TRUE)
   ELSIF optionIs ("--gpl-header", arg)
   THEN
      gplHeader := TRUE
   ELSIF optionIs ("--glpl-header", arg)
   THEN
      glplHeader := TRUE
   ELSIF optionIs ('--summary="', arg)
   THEN
      summary := TRUE ;
      summaryContents := Slice (arg, 11, -1)
   ELSIF optionIs ('--contributed="', arg)
   THEN
      contributed := TRUE ;
      contributedContents := Slice (arg, 13, -1)
   ELSIF optionIs ('--project="', arg)
   THEN
      projectContents := Slice (arg, 10, -1)
   ELSIF optionIs ('--gcc-config-system', arg)
   THEN
      gccConfigSystem := TRUE
   ELSIF optionIs ('--scaffold-main', arg)
   THEN
      scaffoldMain := TRUE
   ELSIF optionIs ('--scaffold-dynamic', arg)
   THEN
      scaffoldDynamic := TRUE
   ELSIF optionIs ('--suppress-noreturn', arg)
   THEN
      suppressNoReturn := TRUE
   ELSIF optionIs ("--real=", arg)
   THEN
      setCReal (Slice (arg, 7, 0))
   ELSIF optionIs ("--longreal=", arg)
   THEN
      setCLongReal (Slice (arg, 11, 0))
   ELSIF optionIs ("--shortreal=", arg)
   THEN
      setCShortReal (Slice (arg, 12, 0))
   END
END handleOption ;


(*
   handleOptions - iterates over all options setting appropriate
                   values and returns the single source file
                   if found at the end of the arguments.
*)

PROCEDURE handleOptions () : String ;
VAR
   i  : CARDINAL ;
   arg: String ;
BEGIN
   i := 1 ;
   WHILE GetArg (arg, i) DO
      IF Length (arg) > 0
      THEN
         IF char (arg, 0)='-'
         THEN
            handleOption (arg)
         ELSE
            IF NOT summary
            THEN
               summaryContents := ConCatChar (ConCat (InitString ('automatically created by mc from '),
                                                      arg), '.') ;
               summary := FALSE
            END ;
            RETURN arg
         END
      END ;
      INC (i)
   END ;
   RETURN NIL
END handleOptions ;


BEGIN
   langC := TRUE ;
   langCPP := FALSE ;
   langM2 := FALSE ;
   gplHeader := FALSE ;
   glplHeader := FALSE ;
   summary := FALSE ;
   contributed := FALSE ;
   caseRuntime := FALSE ;
   arrayRuntime := FALSE ;
   returnRuntime := FALSE ;
   internalDebugging := FALSE ;
   quiet := FALSE ;
   verbose := FALSE ;
   extendedOpaque := FALSE ;
   debugTopological := FALSE ;
   ignoreFQ := FALSE ;
   gccConfigSystem := FALSE ;
   scaffoldMain := FALSE ;
   scaffoldDynamic := FALSE ;
   suppressNoReturn := FALSE ;
   useBoolType := TRUE ;
   hPrefix := InitString ('') ;
   cppArgs := InitString ('') ;
   cppProgram := InitString ('') ;
   outputFile := InitString ('-') ;
   summaryContents := InitString ('') ;
   contributedContents := InitString ('') ;
   projectContents := InitString ('GNU Modula-2') ;
   CReal := InitString ('double') ;
   CLongReal := InitString ('long double') ;
   CShortReal := InitString ('float')
END mcOptions.