Fob.Mod 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. MODULE Fob;
  2. (* Copyright 2017-2023 Arthur Yefimov
  3. This file is part of Free Oberon.
  4. Free Oberon is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Free Oberon is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Free Oberon. If not, see <http://www.gnu.org/licenses/>.
  14. *)
  15. IMPORT FoStrings, Builder, Config, Args, Strings, Out, Platform, Kernel;
  16. (** Free Oberon Console Compiler. Part of Free Oberon IDE internal code *)
  17. PROCEDURE Usage;
  18. VAR s: ARRAY 256 OF CHAR;
  19. BEGIN
  20. Out.String('Free Oberon Compiler version ');
  21. Out.String(Config.version); Out.Ln;
  22. Out.String('Copyright (c) 2017-'); Out.Int(Config.year, 0);
  23. Out.String(' by Arthur Yefimov and others.'); Out.Ln;
  24. Out.String('Fob uses Ofront+ and GCC (MinGW).'); Out.Ln; Out.Ln;
  25. Out.String('Usage:'); Out.Ln; Args.Get(0, s);
  26. Out.String(' '); Out.String(s);
  27. Out.String(' sourceFile'); Out.Ln;
  28. Out.String(' '); Out.String(s);
  29. Out.String(' --lang ru sourceFile'); Out.Ln; Out.Ln;
  30. Out.String('Please specify a single file name - the main module source');
  31. Out.Ln
  32. (*Out.String(' [options] MainModuleSourceFile'); Out.Ln; Out.Ln;
  33. Out.String('Options:'); Out.Ln;
  34. Out.String(' -o file Name of output executable file'); Out.Ln*)
  35. END Usage;
  36. PROCEDURE BuildErrorCallback(fname: ARRAY OF CHAR; col, line, error: INTEGER;
  37. msg: ARRAY OF CHAR);
  38. BEGIN
  39. IF fname[0] # 0X THEN
  40. Out.String(fname);
  41. IF line >= 0 THEN
  42. Out.Char(':'); Out.Int(line, 0); Out.Char(':'); Out.Int(col, 0)
  43. END;
  44. Out.String(': ')
  45. END;
  46. Out.String('error: '); Out.String(msg); Out.Ln
  47. END BuildErrorCallback;
  48. PROCEDURE ParseArgs(VAR mainFname, lang: ARRAY OF CHAR);
  49. VAR i, count: INTEGER;
  50. s: ARRAY 4096 OF CHAR;
  51. BEGIN i := 1; count := Args.Count(); lang := 'en';
  52. WHILE i <= count DO
  53. Args.Get(i, s);
  54. IF s = '--lang' THEN Args.Get(i + 1, lang); INC(i)
  55. ELSIF s = '--debug' THEN Config.SetDebug(TRUE)
  56. ELSE Strings.Copy(s, mainFname)
  57. END;
  58. INC(i)
  59. END
  60. END ParseArgs;
  61. PROCEDURE Do;
  62. VAR modules: Builder.Module;
  63. mainFname, modname, exename, errFname, lang, s: ARRAY 256 OF CHAR;
  64. errLine, errCol, res: INTEGER;
  65. foreign, ok: BOOLEAN;
  66. BEGIN
  67. ParseArgs(mainFname, lang);
  68. FoStrings.SetLang(lang);
  69. Builder.SetWorkDir(mainFname);
  70. Builder.GetModuleName(mainFname, modname);
  71. modules := Builder.UsedModuleList(modname, mainFname,
  72. errFname, errLine, errCol, foreign, res);
  73. IF foreign THEN res := 402 END;
  74. ok := FALSE;
  75. IF res = 0 THEN
  76. IF Builder.CompileAll(modules, exename, TRUE, BuildErrorCallback)
  77. THEN ok := TRUE
  78. END
  79. ELSE (*res = 400-bad file, 401-bad module name, or 402-foreign module*)
  80. FoStrings.MakeErrorStr(res, s);
  81. BuildErrorCallback(errFname, -1, -1, 401, s)
  82. END;
  83. IF ~ok THEN Platform.ExitOS(1) END
  84. END Do;
  85. BEGIN
  86. IF Args.Count() = 0 THEN Usage ELSE Do END
  87. END Fob.