| 1 |
(* Copyright (C) 2015-2025 Free Software Foundation, Inc. *) |
| 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 |
| 15 |
along with GCC; see the file COPYING3. If not see |
| 16 |
<http://www.gnu.org/licenses/>. *) |
| 17 |
|
| 18 |
IMPLEMENTATION MODULE mcOptions ; |
| 19 |
|
| 20 |
FROM SArgs IMPORT GetArg, Narg ; |
| 21 |
FROM mcSearch IMPORT prependSearchPath ; |
| 22 |
FROM libc IMPORT exit, printf, time, localtime, time_t, ptrToTM ; |
| 23 |
FROM mcPrintf IMPORT printf0, printf1 ; |
| 24 |
FROM Debug IMPORT Halt ; |
| 25 |
FROM StrLib IMPORT StrLen ; |
| 26 |
FROM decl IMPORT setLangC, setLangCP, setLangM2 ; |
| 27 |
|
| 28 |
FROM DynamicStrings IMPORT String, Length, InitString, Mark, Slice, EqualArray, |
| 29 |
InitStringCharStar, ConCatChar, ConCat, KillString, |
| 30 |
Dup, string, char, ReplaceChar ; |
| 31 |
|
| 32 |
IMPORT FIO ; |
| 33 |
IMPORT SFIO ; |
| 34 |
|
| 35 |
VAR |
| 36 |
langC, |
| 37 |
langCPP, |
| 38 |
langM2, |
| 39 |
gplHeader, |
| 40 |
glplHeader, |
| 41 |
summary, |
| 42 |
contributed, |
| 43 |
scaffoldMain, |
| 44 |
scaffoldDynamic, |
| 45 |
caseRuntime, |
| 46 |
arrayRuntime, |
| 47 |
returnRuntime, |
| 48 |
suppressNoReturn, |
| 49 |
useBoolType, |
| 50 |
gccConfigSystem, |
| 51 |
ignoreFQ, |
| 52 |
debugTopological, |
| 53 |
extendedOpaque, |
| 54 |
internalDebugging, |
| 55 |
verbose, |
| 56 |
quiet : BOOLEAN ; |
| 57 |
CReal, |
| 58 |
CLongReal, |
| 59 |
CShortReal, |
| 60 |
projectContents, |
| 61 |
summaryContents, |
| 62 |
contributedContents, |
| 63 |
hPrefix, |
| 64 |
outputFile, |
| 65 |
cppArgs, |
| 66 |
cppProgram : String ; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
(* |
| 71 |
getYear - return the year. |
| 72 |
*) |
| 73 |
|
| 74 |
PROCEDURE getYear () : CARDINAL ; |
| 75 |
VAR |
| 76 |
epoch : time_t ; |
| 77 |
localTime: ptrToTM ; |
| 78 |
BEGIN |
| 79 |
epoch := time (NIL) ; |
| 80 |
localTime := localtime (epoch) ; |
| 81 |
RETURN localTime^.tm_year + 1900 |
| 82 |
END getYear ; |
| 83 |
|
| 84 |
|
| 85 |
(* |
| 86 |
displayVersion - displays the version of the compiler. |
| 87 |
*) |
| 88 |
|
| 89 |
PROCEDURE displayVersion (mustExit: BOOLEAN) ; |
| 90 |
VAR |
| 91 |
year: CARDINAL ; |
| 92 |
BEGIN |
| 93 |
year := getYear () ; |
| 94 |
(* These first three calls to printf hide the first line of text away from the year change script. *) |
| 95 |
printf0 ('Copyright ') ; |
| 96 |
printf0 ('(C)') ; (* A unicode char here would be good. *) |
| 97 |
printf1 (' %d Free Software Foundation, Inc.\n', year) ; |
| 98 |
printf0 ('License GPLv3: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n') ; |
| 99 |
printf0 ('This is free software: you are free to change and redistribute it.\n') ; |
| 100 |
printf0 ('There is NO WARRANTY, to the extent permitted by law.\n') ; |
| 101 |
IF mustExit |
| 102 |
THEN |
| 103 |
exit (0) |
| 104 |
END |
| 105 |
END displayVersion ; |
| 106 |
|
| 107 |
|
| 108 |
(* |
| 109 |
displayHelp - display the mc help summary. |
| 110 |
*) |
| 111 |
|
| 112 |
PROCEDURE displayHelp ; |
| 113 |
BEGIN |
| 114 |
printf0 ("usage: mc [--cpp] [-g] [--quiet] [--extended-opaque] [-q] [-v]") ; |
| 115 |
printf0 (" [--verbose] [--version] [--help] [-h] [-Ipath] [--olang=c]") ; |
| 116 |
printf0 (" [--olang=c++] [--olang=m2] [--debug-top]") ; |
| 117 |
printf0 (' [--gpl-header] [--glpl-header] [--summary="foo"]') ; |
| 118 |
printf0 (' [--contributed="foo"] [--project="foo"]') ; |
| 119 |
printf0 (" [--h-file-prefix=foo] [--automatic] [-o=foo] filename\n") ; |
| 120 |
|
| 121 |
printf0 (" --cpp preprocess through the C preprocessor\n") ; |
| 122 |
printf0 (" -g emit debugging directives in the output language") ; |
| 123 |
printf0 (" so that the debugger will refer to the source\n") ; |
| 124 |
printf0 (" -q --quiet no output unless an error occurs\n") ; |
| 125 |
printf0 (" -v --verbose display preprocessor if invoked\n") ; |
| 126 |
printf0 (" --version display version and exit\n") ; |
| 127 |
printf0 (" -h --help display this help message\n") ; |
| 128 |
printf0 (" -Ipath set the module search path\n") ; |
| 129 |
printf0 (" --olang=c generate ansi C output\n") ; |
| 130 |
printf0 (" --olang=c++ generate ansi C++ output\n") ; |
| 131 |
printf0 (" --olang=m2 generate PIM4 output\n") ; |
| 132 |
printf0 (" --extended-opaque parse definition and implementation modules to\n") ; |
| 133 |
printf0 (" generate full type debugging of opaque types\n") ; |
| 134 |
printf0 (" --debug-top debug topological data structure resolving (internal)\n") ; |
| 135 |
printf0 (" --h-file-prefix=foo set the h file prefix to foo\n") ; |
| 136 |
printf0 (" -o=foo set the output file to foo\n") ; |
| 137 |
printf0 (" --ignore-fq do not generate fully qualified idents\n") ; |
| 138 |
printf0 (" --gcc-config-system do not use standard host include files, use gcc config and system instead\n"); |
| 139 |
printf0 (" --gpl-header generate a GPL3 header comment at the top of the file\n") ; |
| 140 |
printf0 (" --glpl-header generate a GLPL3 header comment at the top of the file\n") ; |
| 141 |
printf0 (' --summary="foo" generate a one line summary comment at the top of the file\n') ; |
| 142 |
printf0 (' --contributed="foo" generate a one line contribution comment near the top of the file\n') ; |
| 143 |
printf0 (' --project="foo" include the project name within the GPL3 or GLPL3 header\n') ; |
| 144 |
printf0 (' --automatic generate a comment at the start of the file warning not to edit as it was automatically generated\n') ; |
| 145 |
printf0 (' --scaffold-dynamic generate dynamic module initialization code for C++\n') ; |
| 146 |
printf0 (' --scaffold-main generate main function which calls upon the dynamic initialization support in M2RTS\n') ; |
| 147 |
printf0 (' --suppress-noreturn suppress the emission of any attribute noreturn\n'); |
| 148 |
printf0 (' filename the source file must be the last option\n') ; |
| 149 |
exit (0) |
| 150 |
END displayHelp ; |
| 151 |
|
| 152 |
|
| 153 |
(* |
| 154 |
commentBegin - issue a start of comment for the appropriate language. |
| 155 |
*) |
| 156 |
|
| 157 |
PROCEDURE commentBegin (f: File) ; |
| 158 |
BEGIN |
| 159 |
IF langC OR langCPP |
| 160 |
THEN |
| 161 |
FIO.WriteString (f, '/* ') |
| 162 |
ELSIF langM2 |
| 163 |
THEN |
| 164 |
FIO.WriteString (f, '(* ') |
| 165 |
END |
| 166 |
END commentBegin ; |
| 167 |
|
| 168 |
|
| 169 |
(* |
| 170 |
commentEnd - issue an end of comment for the appropriate language. |
| 171 |
*) |
| 172 |
|
| 173 |
PROCEDURE commentEnd (f: File) ; |
| 174 |
BEGIN |
| 175 |
IF langC OR langCPP |
| 176 |
THEN |
| 177 |
FIO.WriteString (f, ' */') ; FIO.WriteLine (f) |
| 178 |
ELSIF langM2 |
| 179 |
THEN |
| 180 |
FIO.WriteString (f, ' *)') ; FIO.WriteLine (f) |
| 181 |
END |
| 182 |
END commentEnd ; |
| 183 |
|
| 184 |
|
| 185 |
(* |
| 186 |
comment - write a comment to file, f, and also a newline. |
| 187 |
*) |
| 188 |
|
| 189 |
PROCEDURE comment (f: File; a: ARRAY OF CHAR) ; |
| 190 |
BEGIN |
| 191 |
FIO.WriteString (f, a) ; FIO.WriteLine (f) |
| 192 |
END comment ; |
| 193 |
|
| 194 |
|
| 195 |
(* |
| 196 |
commentS - write a comment to file, f, and also a newline. |
| 197 |
*) |
| 198 |
|
| 199 |
PROCEDURE commentS (f: File; s: String) ; |
| 200 |
BEGIN |
| 201 |
s := SFIO.WriteS (f, s) ; FIO.WriteLine (f) |
| 202 |
END commentS ; |
| 203 |
|
| 204 |
|
| 205 |
(* |
| 206 |
gplBody - |
| 207 |
*) |
| 208 |
|
| 209 |
PROCEDURE gplBody (f: File) ; |
| 210 |
VAR |
| 211 |
year: CARDINAL ; |
| 212 |
BEGIN |
| 213 |
year := getYear () ; |
| 214 |
printf1 ('Copyright (C) %d Free Software Foundation, Inc.\n', year) ; |
| 215 |
IF contributed |
| 216 |
THEN |
| 217 |
FIO.WriteString (f, "Contributed by ") ; |
| 218 |
contributedContents := SFIO.WriteS (f, contributedContents) ; |
| 219 |
FIO.WriteString (f, ".") ; |
| 220 |
FIO.WriteLine (f) |
| 221 |
END ; |
| 222 |
FIO.WriteLine (f) ; |
| 223 |
FIO.WriteString (f, "This file is part of ") ; |
| 224 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 225 |
FIO.WriteString (f, ".") ; |
| 226 |
FIO.WriteLine (f) ; FIO.WriteLine (f) ; |
| 227 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 228 |
comment (f, " is software; you can redistribute it and/or modify") ; |
| 229 |
comment (f, "it under the terms of the GNU General Public License as published by") ; |
| 230 |
comment (f, "the Free Software Foundation; either version 3, or (at your option)") ; |
| 231 |
comment (f, "any later version.") ; |
| 232 |
FIO.WriteLine (f) ; |
| 233 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 234 |
comment (f, " is distributed in the hope that it will be useful, but") ; |
| 235 |
comment (f, "WITHOUT ANY WARRANTY; without even the implied warranty of") ; |
| 236 |
comment (f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU") ; |
| 237 |
comment (f, "General Public License for more details.") ; |
| 238 |
FIO.WriteLine (f) ; |
| 239 |
comment (f, "You should have received a copy of the GNU General Public License") ; |
| 240 |
FIO.WriteString (f, "along with ") ; |
| 241 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 242 |
comment (f, "; see the file COPYING. If not,") ; |
| 243 |
FIO.WriteString (f, "see <https://www.gnu.org/licenses/>. ") |
| 244 |
END gplBody ; |
| 245 |
|
| 246 |
|
| 247 |
(* |
| 248 |
glplBody - |
| 249 |
*) |
| 250 |
|
| 251 |
PROCEDURE glplBody (f: File) ; |
| 252 |
VAR |
| 253 |
year: CARDINAL ; |
| 254 |
BEGIN |
| 255 |
year := getYear () ; |
| 256 |
printf1 ('Copyright (C) %d Free Software Foundation, Inc.\n', year) ; |
| 257 |
IF contributed |
| 258 |
THEN |
| 259 |
FIO.WriteString (f, "Contributed by ") ; |
| 260 |
contributedContents := SFIO.WriteS (f, contributedContents) ; |
| 261 |
FIO.WriteString (f, ".") ; |
| 262 |
FIO.WriteLine (f) |
| 263 |
END ; |
| 264 |
FIO.WriteLine (f) ; |
| 265 |
FIO.WriteString (f, "This file is part of ") ; |
| 266 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 267 |
FIO.WriteString (f, ".") ; |
| 268 |
FIO.WriteLine (f) ; FIO.WriteLine (f) ; |
| 269 |
|
| 270 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 271 |
comment (f, " is free software; you can redistribute it and/or modify") ; |
| 272 |
comment (f, "it under the terms of the GNU General Public License as published by") ; |
| 273 |
comment (f, "the Free Software Foundation; either version 3, or (at your option)") ; |
| 274 |
comment (f, "any later version.") ; |
| 275 |
FIO.WriteLine (f) ; |
| 276 |
|
| 277 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 278 |
comment (f, " is software; you can redistribute it and/or modify") ; |
| 279 |
comment (f, "it under the terms of the GNU Lesser General Public License") ; |
| 280 |
comment (f, "as published by the Free Software Foundation; either version 3,") ; |
| 281 |
comment (f, "or (at your option) any later version.") ; |
| 282 |
FIO.WriteLine (f) ; |
| 283 |
|
| 284 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 285 |
comment (f, " is distributed in the hope that it will be useful, but") ; |
| 286 |
comment (f, "WITHOUT ANY WARRANTY; without even the implied warranty of") ; |
| 287 |
comment (f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU") ; |
| 288 |
comment (f, "General Public License for more details.") ; |
| 289 |
FIO.WriteLine (f) ; |
| 290 |
|
| 291 |
comment (f, "You should have received a copy of the GNU General Public License") ; |
| 292 |
FIO.WriteString (f, "along with ") ; |
| 293 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 294 |
comment (f, "; see the file COPYING3. If not see") ; |
| 295 |
comment (f, "<http://www.gnu.org/licenses/>.") ; |
| 296 |
|
| 297 |
FIO.WriteLine (f) ; |
| 298 |
comment (f, "You should have received a copy of the GNU Lesser General Public License") ; |
| 299 |
FIO.WriteString (f, "along with ") ; |
| 300 |
projectContents := SFIO.WriteS (f, projectContents) ; |
| 301 |
comment (f, "; see the file COPYING. If not,") ; |
| 302 |
FIO.WriteString (f, "see <https://www.gnu.org/licenses/>. ") |
| 303 |
END glplBody ; |
| 304 |
|
| 305 |
|
| 306 |
(* |
| 307 |
issueGPL - writes out the summary, GPL/LGPL and/or contributed as a single comment. |
| 308 |
*) |
| 309 |
|
| 310 |
PROCEDURE issueGPL (f: File) ; |
| 311 |
BEGIN |
| 312 |
IF summary OR contributed OR gplHeader OR glplHeader |
| 313 |
THEN |
| 314 |
commentBegin (f) ; |
| 315 |
IF summary |
| 316 |
THEN |
| 317 |
commentS (f, summaryContents) ; |
| 318 |
FIO.WriteLine (f) |
| 319 |
END ; |
| 320 |
IF gplHeader |
| 321 |
THEN |
| 322 |
gplBody (f) |
| 323 |
END ; |
| 324 |
IF glplHeader |
| 325 |
THEN |
| 326 |
glplBody (f) |
| 327 |
END ; |
| 328 |
commentEnd (f) ; |
| 329 |
FIO.WriteLine (f) |
| 330 |
END |
| 331 |
END issueGPL ; |
| 332 |
|
| 333 |
|
| 334 |
(* |
| 335 |
writeGPLheader - writes out the GPL or the LGPL as a comment. |
| 336 |
*) |
| 337 |
|
| 338 |
PROCEDURE writeGPLheader (f: File) ; |
| 339 |
BEGIN |
| 340 |
issueGPL (f) |
| 341 |
END writeGPLheader ; |
| 342 |
|
| 343 |
|
| 344 |
(* |
| 345 |
getCppCommandLine - returns the Cpp command line and all arguments. |
| 346 |
*) |
| 347 |
|
| 348 |
PROCEDURE getCppCommandLine () : String ; |
| 349 |
VAR |
| 350 |
s: String ; |
| 351 |
BEGIN |
| 352 |
IF EqualArray (cppProgram, '') |
| 353 |
THEN |
| 354 |
RETURN NIL |
| 355 |
ELSE |
| 356 |
s := Dup (cppProgram) ; |
| 357 |
s := ConCat (ConCatChar(s, ' '), cppArgs) ; |
| 358 |
IF getQuiet () |
| 359 |
THEN |
| 360 |
s := ConCat (ConCatChar(s, ' '), Mark (InitString ('-quiet'))) |
| 361 |
END ; |
| 362 |
RETURN s |
| 363 |
END |
| 364 |
END getCppCommandLine ; |
| 365 |
|
| 366 |
|
| 367 |
(* |
| 368 |
setOutputFile - sets the output filename to output. |
| 369 |
*) |
| 370 |
|
| 371 |
PROCEDURE setOutputFile (output: String) ; |
| 372 |
BEGIN |
| 373 |
outputFile := output |
| 374 |
END setOutputFile ; |
| 375 |
|
| 376 |
|
| 377 |
(* |
| 378 |
getOutputFile - sets the output filename to output. |
| 379 |
*) |
| 380 |
|
| 381 |
PROCEDURE getOutputFile () : String ; |
| 382 |
BEGIN |
| 383 |
RETURN outputFile |
| 384 |
END getOutputFile ; |
| 385 |
|
| 386 |
|
| 387 |
(* |
| 388 |
setQuiet - sets the quiet flag to, value. |
| 389 |
*) |
| 390 |
|
| 391 |
PROCEDURE setQuiet (value: BOOLEAN) ; |
| 392 |
BEGIN |
| 393 |
quiet := value |
| 394 |
END setQuiet ; |
| 395 |
|
| 396 |
|
| 397 |
(* |
| 398 |
getQuiet - return the value of quiet. |
| 399 |
*) |
| 400 |
|
| 401 |
PROCEDURE getQuiet () : BOOLEAN ; |
| 402 |
BEGIN |
| 403 |
RETURN quiet |
| 404 |
END getQuiet ; |
| 405 |
|
| 406 |
|
| 407 |
(* |
| 408 |
setVerbose - sets the verbose flag to, value. |
| 409 |
*) |
| 410 |
|
| 411 |
PROCEDURE setVerbose (value: BOOLEAN) ; |
| 412 |
BEGIN |
| 413 |
verbose := value |
| 414 |
END setVerbose ; |
| 415 |
|
| 416 |
|
| 417 |
(* |
| 418 |
getVerbose - return the value of verbose. |
| 419 |
*) |
| 420 |
|
| 421 |
PROCEDURE getVerbose () : BOOLEAN ; |
| 422 |
BEGIN |
| 423 |
RETURN verbose |
| 424 |
END getVerbose ; |
| 425 |
|
| 426 |
|
| 427 |
(* |
| 428 |
setExtendedOpaque - set extendedOpaque to value. |
| 429 |
*) |
| 430 |
|
| 431 |
PROCEDURE setExtendedOpaque (value: BOOLEAN) ; |
| 432 |
BEGIN |
| 433 |
extendedOpaque := value |
| 434 |
END setExtendedOpaque ; |
| 435 |
|
| 436 |
|
| 437 |
(* |
| 438 |
getExtendedOpaque - return the extendedOpaque value. |
| 439 |
*) |
| 440 |
|
| 441 |
PROCEDURE getExtendedOpaque () : BOOLEAN ; |
| 442 |
BEGIN |
| 443 |
RETURN extendedOpaque |
| 444 |
END getExtendedOpaque ; |
| 445 |
|
| 446 |
|
| 447 |
(* |
| 448 |
setSuppressNoReturn - set suppressNoReturn to value. |
| 449 |
*) |
| 450 |
|
| 451 |
PROCEDURE setSuppressNoReturn (value: BOOLEAN) ; |
| 452 |
BEGIN |
| 453 |
suppressNoReturn := value |
| 454 |
END setSuppressNoReturn; |
| 455 |
|
| 456 |
|
| 457 |
(* |
| 458 |
getSuppressNoReturn - return the suppressNoReturn value. |
| 459 |
*) |
| 460 |
|
| 461 |
PROCEDURE getSuppressNoReturn () : BOOLEAN ; |
| 462 |
BEGIN |
| 463 |
RETURN suppressNoReturn |
| 464 |
END getSuppressNoReturn ; |
| 465 |
|
| 466 |
|
| 467 |
(* |
| 468 |
setSearchPath - set the search path for the module sources. |
| 469 |
*) |
| 470 |
|
| 471 |
PROCEDURE setSearchPath (arg: String) ; |
| 472 |
BEGIN |
| 473 |
prependSearchPath (arg) |
| 474 |
END setSearchPath ; |
| 475 |
|
| 476 |
|
| 477 |
(* |
| 478 |
setInternalDebugging - turn on/off internal debugging. |
| 479 |
*) |
| 480 |
|
| 481 |
PROCEDURE setInternalDebugging (value: BOOLEAN) ; |
| 482 |
BEGIN |
| 483 |
internalDebugging := value |
| 484 |
END setInternalDebugging ; |
| 485 |
|
| 486 |
|
| 487 |
(* |
| 488 |
getInternalDebugging - return the value of internalDebugging. |
| 489 |
*) |
| 490 |
|
| 491 |
PROCEDURE getInternalDebugging () : BOOLEAN ; |
| 492 |
BEGIN |
| 493 |
RETURN internalDebugging |
| 494 |
END getInternalDebugging ; |
| 495 |
|
| 496 |
|
| 497 |
(* |
| 498 |
setDebugTopological - sets the flag debugTopological to value. |
| 499 |
*) |
| 500 |
|
| 501 |
PROCEDURE setDebugTopological (value: BOOLEAN) ; |
| 502 |
BEGIN |
| 503 |
debugTopological := value |
| 504 |
END setDebugTopological ; |
| 505 |
|
| 506 |
|
| 507 |
(* |
| 508 |
getDebugTopological - returns the flag value of the command |
| 509 |
line option --debug-top. |
| 510 |
*) |
| 511 |
|
| 512 |
PROCEDURE getDebugTopological () : BOOLEAN ; |
| 513 |
BEGIN |
| 514 |
RETURN debugTopological |
| 515 |
END getDebugTopological ; |
| 516 |
|
| 517 |
|
| 518 |
(* |
| 519 |
setHPrefix - saves the H file prefix. |
| 520 |
*) |
| 521 |
|
| 522 |
PROCEDURE setHPrefix (s: String) ; |
| 523 |
BEGIN |
| 524 |
hPrefix := s |
| 525 |
END setHPrefix ; |
| 526 |
|
| 527 |
|
| 528 |
(* |
| 529 |
getHPrefix - saves the H file prefix. |
| 530 |
*) |
| 531 |
|
| 532 |
PROCEDURE getHPrefix () : String ; |
| 533 |
BEGIN |
| 534 |
RETURN hPrefix |
| 535 |
END getHPrefix ; |
| 536 |
|
| 537 |
|
| 538 |
(* |
| 539 |
setIgnoreFQ - sets the ignorefq flag. |
| 540 |
*) |
| 541 |
|
| 542 |
PROCEDURE setIgnoreFQ (value: BOOLEAN) ; |
| 543 |
BEGIN |
| 544 |
ignoreFQ := value |
| 545 |
END setIgnoreFQ ; |
| 546 |
|
| 547 |
|
| 548 |
(* |
| 549 |
getIgnoreFQ - returns the ignorefq flag. |
| 550 |
*) |
| 551 |
|
| 552 |
PROCEDURE getIgnoreFQ () : BOOLEAN ; |
| 553 |
BEGIN |
| 554 |
RETURN ignoreFQ |
| 555 |
END getIgnoreFQ ; |
| 556 |
|
| 557 |
|
| 558 |
(* |
| 559 |
getGccConfigSystem - return the value of the gccConfigSystem flag. |
| 560 |
*) |
| 561 |
|
| 562 |
PROCEDURE getGccConfigSystem () : BOOLEAN ; |
| 563 |
BEGIN |
| 564 |
RETURN gccConfigSystem |
| 565 |
END getGccConfigSystem ; |
| 566 |
|
| 567 |
|
| 568 |
(* |
| 569 |
getScaffoldDynamic - return true if the --scaffold-dynamic option was present. |
| 570 |
*) |
| 571 |
|
| 572 |
PROCEDURE getScaffoldDynamic () : BOOLEAN ; |
| 573 |
BEGIN |
| 574 |
RETURN scaffoldDynamic |
| 575 |
END getScaffoldDynamic ; |
| 576 |
|
| 577 |
|
| 578 |
(* |
| 579 |
getScaffoldMain - return true if the --scaffold-main option was present. |
| 580 |
*) |
| 581 |
|
| 582 |
PROCEDURE getScaffoldMain () : BOOLEAN ; |
| 583 |
BEGIN |
| 584 |
RETURN scaffoldMain |
| 585 |
END getScaffoldMain ; |
| 586 |
|
| 587 |
|
| 588 |
(* |
| 589 |
useBool - should mc use the bool type instead of int. |
| 590 |
*) |
| 591 |
|
| 592 |
PROCEDURE useBool () : BOOLEAN ; |
| 593 |
BEGIN |
| 594 |
RETURN useBoolType |
| 595 |
END useBool ; |
| 596 |
|
| 597 |
|
| 598 |
(* |
| 599 |
getCRealType - returns the string representing the REAL type |
| 600 |
used by C. By default this is "double". |
| 601 |
*) |
| 602 |
|
| 603 |
PROCEDURE getCRealType () : String ; |
| 604 |
BEGIN |
| 605 |
RETURN CReal |
| 606 |
END getCRealType ; |
| 607 |
|
| 608 |
|
| 609 |
(* |
| 610 |
getCLongRealType - returns the string representing the REAL type |
| 611 |
used by C. By default this is "long double". |
| 612 |
*) |
| 613 |
|
| 614 |
PROCEDURE getCLongRealType () : String ; |
| 615 |
BEGIN |
| 616 |
RETURN CLongReal |
| 617 |
END getCLongRealType ; |
| 618 |
|
| 619 |
|
| 620 |
(* |
| 621 |
getCShortRealType - returns the string representing the REAL type |
| 622 |
used by C. By default this is "float". |
| 623 |
*) |
| 624 |
|
| 625 |
PROCEDURE getCShortRealType () : String ; |
| 626 |
BEGIN |
| 627 |
RETURN CShortReal |
| 628 |
END getCShortRealType ; |
| 629 |
|
| 630 |
|
| 631 |
(* |
| 632 |
toCType - returns a new string which has all occurences of '-' |
| 633 |
replaced by ' '. |
| 634 |
*) |
| 635 |
|
| 636 |
PROCEDURE toCType (namedType: String) : String ; |
| 637 |
BEGIN |
| 638 |
RETURN ReplaceChar (Dup (namedType), '-', ' ') |
| 639 |
END toCType ; |
| 640 |
|
| 641 |
|
| 642 |
(* |
| 643 |
setCReal - assigns CReal to namedType after it has been transformed by |
| 644 |
toCType. |
| 645 |
*) |
| 646 |
|
| 647 |
PROCEDURE setCReal (namedType: String) ; |
| 648 |
BEGIN |
| 649 |
CReal := toCType (namedType) |
| 650 |
END setCReal ; |
| 651 |
|
| 652 |
|
| 653 |
(* |
| 654 |
setCShortReal - assigns CShortReal to namedType after it has been |
| 655 |
transformed by toCType. |
| 656 |
*) |
| 657 |
|
| 658 |
PROCEDURE setCShortReal (namedType: String) ; |
| 659 |
BEGIN |
| 660 |
CShortReal := toCType (namedType) |
| 661 |
END setCShortReal ; |
| 662 |
|
| 663 |
|
| 664 |
(* |
| 665 |
setCLongReal - assigns CLongReal to namedType after it has been |
| 666 |
transformed by toCType. |
| 667 |
*) |
| 668 |
|
| 669 |
PROCEDURE setCLongReal (namedType: String) ; |
| 670 |
BEGIN |
| 671 |
CLongReal := toCType (namedType) |
| 672 |
END setCLongReal ; |
| 673 |
|
| 674 |
|
| 675 |
(* |
| 676 |
optionIs - returns TRUE if the first len (right) characters |
| 677 |
match left. |
| 678 |
*) |
| 679 |
|
| 680 |
PROCEDURE optionIs (left: ARRAY OF CHAR; right: String) : BOOLEAN ; |
| 681 |
VAR |
| 682 |
s: String ; |
| 683 |
BEGIN |
| 684 |
IF Length (right) = StrLen (left) |
| 685 |
THEN |
| 686 |
RETURN EqualArray (right, left) |
| 687 |
ELSIF Length (right) > StrLen (left) |
| 688 |
THEN |
| 689 |
s := Mark (Slice (right, 0, StrLen (left))) ; |
| 690 |
RETURN EqualArray (s, left) |
| 691 |
ELSE |
| 692 |
RETURN FALSE |
| 693 |
END |
| 694 |
END optionIs ; |
| 695 |
|
| 696 |
|
| 697 |
(* |
| 698 |
setLang - set the appropriate output language. |
| 699 |
*) |
| 700 |
|
| 701 |
PROCEDURE setLang (arg: String) ; |
| 702 |
BEGIN |
| 703 |
(* must check the longest distinctive string first. *) |
| 704 |
IF optionIs ("c++", arg) |
| 705 |
THEN |
| 706 |
setLangCP ; |
| 707 |
langCPP := TRUE |
| 708 |
ELSIF optionIs ("c", arg) |
| 709 |
THEN |
| 710 |
setLangC ; |
| 711 |
langC := TRUE |
| 712 |
ELSIF optionIs ("m2", arg) |
| 713 |
THEN |
| 714 |
setLangM2 ; |
| 715 |
langM2 := TRUE |
| 716 |
ELSE |
| 717 |
displayHelp |
| 718 |
END |
| 719 |
END setLang ; |
| 720 |
|
| 721 |
|
| 722 |
(* |
| 723 |
handleOption - |
| 724 |
*) |
| 725 |
|
| 726 |
PROCEDURE handleOption (arg: String) ; |
| 727 |
BEGIN |
| 728 |
IF optionIs ("--quiet", arg) OR optionIs ("-q", arg) |
| 729 |
THEN |
| 730 |
setQuiet (TRUE) |
| 731 |
ELSIF optionIs ("--verbose", arg) OR optionIs ("-v", arg) |
| 732 |
THEN |
| 733 |
setVerbose (TRUE) |
| 734 |
ELSIF optionIs ("--version", arg) |
| 735 |
THEN |
| 736 |
displayVersion (TRUE) |
| 737 |
ELSIF optionIs ("--olang=", arg) |
| 738 |
THEN |
| 739 |
setLang (Slice (arg, 8, 0)) |
| 740 |
ELSIF optionIs ("-I", arg) |
| 741 |
THEN |
| 742 |
setSearchPath (Slice (arg, 2, 0)) |
| 743 |
ELSIF optionIs ("--help", arg) OR optionIs ("-h", arg) |
| 744 |
THEN |
| 745 |
displayHelp |
| 746 |
ELSIF optionIs ("--cpp", arg) |
| 747 |
THEN |
| 748 |
cppProgram := InitString ('cpp') |
| 749 |
ELSIF optionIs ("-o=", arg) |
| 750 |
THEN |
| 751 |
setOutputFile (Slice (arg, 3, 0)) |
| 752 |
ELSIF optionIs ("--extended-opaque", arg) |
| 753 |
THEN |
| 754 |
(* setExtendedOpaque (TRUE) *) |
| 755 |
printf0 ("IGNORING --extended-opaque - this option is no longer implemented - please adjust the call to mc\n") |
| 756 |
ELSIF optionIs ("--debug-top", arg) |
| 757 |
THEN |
| 758 |
setDebugTopological (TRUE) |
| 759 |
ELSIF optionIs ("--h-file-prefix=", arg) |
| 760 |
THEN |
| 761 |
setHPrefix (Slice (arg, 16, 0)) |
| 762 |
ELSIF optionIs ("--ignore-fq", arg) |
| 763 |
THEN |
| 764 |
setIgnoreFQ (TRUE) |
| 765 |
ELSIF optionIs ("--gpl-header", arg) |
| 766 |
THEN |
| 767 |
gplHeader := TRUE |
| 768 |
ELSIF optionIs ("--glpl-header", arg) |
| 769 |
THEN |
| 770 |
glplHeader := TRUE |
| 771 |
ELSIF optionIs ('--summary="', arg) |
| 772 |
THEN |
| 773 |
summary := TRUE ; |
| 774 |
summaryContents := Slice (arg, 11, -1) |
| 775 |
ELSIF optionIs ('--contributed="', arg) |
| 776 |
THEN |
| 777 |
contributed := TRUE ; |
| 778 |
contributedContents := Slice (arg, 13, -1) |
| 779 |
ELSIF optionIs ('--project="', arg) |
| 780 |
THEN |
| 781 |
projectContents := Slice (arg, 10, -1) |
| 782 |
ELSIF optionIs ('--gcc-config-system', arg) |
| 783 |
THEN |
| 784 |
gccConfigSystem := TRUE |
| 785 |
ELSIF optionIs ('--scaffold-main', arg) |
| 786 |
THEN |
| 787 |
scaffoldMain := TRUE |
| 788 |
ELSIF optionIs ('--scaffold-dynamic', arg) |
| 789 |
THEN |
| 790 |
scaffoldDynamic := TRUE |
| 791 |
ELSIF optionIs ('--suppress-noreturn', arg) |
| 792 |
THEN |
| 793 |
suppressNoReturn := TRUE |
| 794 |
ELSIF optionIs ("--real=", arg) |
| 795 |
THEN |
| 796 |
setCReal (Slice (arg, 7, 0)) |
| 797 |
ELSIF optionIs ("--longreal=", arg) |
| 798 |
THEN |
| 799 |
setCLongReal (Slice (arg, 11, 0)) |
| 800 |
ELSIF optionIs ("--shortreal=", arg) |
| 801 |
THEN |
| 802 |
setCShortReal (Slice (arg, 12, 0)) |
| 803 |
END |
| 804 |
END handleOption ; |
| 805 |
|
| 806 |
|
| 807 |
(* |
| 808 |
handleOptions - iterates over all options setting appropriate |
| 809 |
values and returns the single source file |
| 810 |
if found at the end of the arguments. |
| 811 |
*) |
| 812 |
|
| 813 |
PROCEDURE handleOptions () : String ; |
| 814 |
VAR |
| 815 |
i : CARDINAL ; |
| 816 |
arg: String ; |
| 817 |
BEGIN |
| 818 |
i := 1 ; |
| 819 |
WHILE GetArg (arg, i) DO |
| 820 |
IF Length (arg) > 0 |
| 821 |
THEN |
| 822 |
IF char (arg, 0)='-' |
| 823 |
THEN |
| 824 |
handleOption (arg) |
| 825 |
ELSE |
| 826 |
IF NOT summary |
| 827 |
THEN |
| 828 |
summaryContents := ConCatChar (ConCat (InitString ('automatically created by mc from '), |
| 829 |
arg), '.') ; |
| 830 |
summary := FALSE |
| 831 |
END ; |
| 832 |
RETURN arg |
| 833 |
END |
| 834 |
END ; |
| 835 |
INC (i) |
| 836 |
END ; |
| 837 |
RETURN NIL |
| 838 |
END handleOptions ; |
| 839 |
|
| 840 |
|
| 841 |
BEGIN |
| 842 |
langC := TRUE ; |
| 843 |
langCPP := FALSE ; |
| 844 |
langM2 := FALSE ; |
| 845 |
gplHeader := FALSE ; |
| 846 |
glplHeader := FALSE ; |
| 847 |
summary := FALSE ; |
| 848 |
contributed := FALSE ; |
| 849 |
caseRuntime := FALSE ; |
| 850 |
arrayRuntime := FALSE ; |
| 851 |
returnRuntime := FALSE ; |
| 852 |
internalDebugging := FALSE ; |
| 853 |
quiet := FALSE ; |
| 854 |
verbose := FALSE ; |
| 855 |
extendedOpaque := FALSE ; |
| 856 |
debugTopological := FALSE ; |
| 857 |
ignoreFQ := FALSE ; |
| 858 |
gccConfigSystem := FALSE ; |
| 859 |
scaffoldMain := FALSE ; |
| 860 |
scaffoldDynamic := FALSE ; |
| 861 |
suppressNoReturn := FALSE ; |
| 862 |
useBoolType := TRUE ; |
| 863 |
hPrefix := InitString ('') ; |
| 864 |
cppArgs := InitString ('') ; |
| 865 |
cppProgram := InitString ('') ; |
| 866 |
outputFile := InitString ('-') ; |
| 867 |
summaryContents := InitString ('') ; |
| 868 |
contributedContents := InitString ('') ; |
| 869 |
projectContents := InitString ('GNU Modula-2') ; |
| 870 |
CReal := InitString ('double') ; |
| 871 |
CLongReal := InitString ('long double') ; |
| 872 |
CShortReal := InitString ('float') |
| 873 |
END mcOptions. |