StdIOShell.Mod 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. MODULE StdIOShell; (** AUTHOR "Felix Friedrich"; PURPOSE "Command shell for standalone Oberon/A2 Applications"; *)
  2. IMPORT StdIO, Commands, Modules, Trace;
  3. CONST Verbose = FALSE;
  4. PROCEDURE Activate(context: Commands.Context; CONST cmd: ARRAY OF CHAR): BOOLEAN;
  5. VAR msg: ARRAY 256 OF CHAR; res: LONGINT;
  6. BEGIN
  7. IF Verbose THEN
  8. Trace.String("StdIOShell: Activate Command "); Trace.String(cmd); Trace.Ln;
  9. END;
  10. Commands.Activate(cmd, context, {Commands.Wait}, res, msg);
  11. IF res # 0 THEN context.error.String(msg); context.error.Ln; RETURN FALSE END;
  12. RETURN TRUE;
  13. END Activate;
  14. PROCEDURE Execute(context: Commands.Context);
  15. VAR str: ARRAY 256 OF CHAR; b: BOOLEAN;
  16. BEGIN
  17. IF ~context.arg.GetString(str) THEN
  18. context.out.String("Critical error: no arg");
  19. RETURN
  20. END;
  21. IF ~context.arg.GetString(str) THEN
  22. str := "Shell.Start";
  23. ELSIF str = "compile" THEN str := "Compiler.Compile"
  24. ELSIF str="link" THEN str := "StaticLinker.Link"
  25. ELSIF (str="i") OR (str = "interpreter") THEN str := "InterpreterShell.Start"
  26. ELSIF (str = "execute") OR (str="e") THEN str := "SystemTools.DoFile";
  27. ELSIF (str = "run") OR (str="r") THEN
  28. IF ~Activate(context, "SystemTools.DoFile") THEN RETURN END;
  29. str := "Shell.Start";
  30. END;
  31. b := Activate(context, str);
  32. END Execute;
  33. TYPE
  34. (* excute the shell and termination in separate thread with proper process data structure *)
  35. Executor=OBJECT
  36. VAR done: BOOLEAN;
  37. PROCEDURE Wait;
  38. BEGIN{EXCLUSIVE}
  39. AWAIT(done);
  40. END Wait;
  41. BEGIN{ACTIVE}
  42. Execute(StdIO.env);
  43. FINALLY
  44. IF Verbose THEN
  45. Trace.String("StdIOShell: Exit"); Trace.Ln;
  46. END;
  47. Modules.Shutdown(Modules.PowerDown);
  48. done := TRUE
  49. END Executor;
  50. VAR execute: Executor;
  51. (* do not add commands here -- the module loader does not finish here and they will not become available *)
  52. BEGIN
  53. NEW(execute); (* execute shell and termination in separate thread *)
  54. execute.Wait; (* will actually never return *)
  55. END StdIOShell.
  56. Linking a command line shell:
  57. Command line shell: (Windows):
  58. StaticLinker.Link --fileFormat=PE32CUI --fileName=oberon.exe --extension=GofW --displacement=401000H Runtime Trace Kernel32 Machine Heaps Modules Objects Kernel KernelLog Streams Commands Files WinFS Clock Dates Reals Strings Diagnostics BitSets StringPool ObjectFile GenericLinker Reflection GenericLoader WinTrace StdIO Traps RelativeFileSystem WMDefaultFont SystemTools Shell StdIOShell ~
  59. Command line shell including compiler (and linker)
  60. StaticLinker.Link --fileFormat=PE32CUI --fileName=oberon.exe --extension=GofW --displacement=401000H Runtime Trace Kernel32 Machine Heaps Modules Objects Kernel KernelLog Streams Commands Files WinFS Clock Dates Reals Strings Diagnostics BitSets StringPool ObjectFile GenericLinker Reflection GenericLoader WinTrace StdIO Traps RelativeFileSystem SystemTools FSTools StdIOShell
  61. Shell StaticLinker Compiler FoxOberonFrontend FoxARMBackend FoxAMDBackend
  62. ~
  63. Command line shell: (Linux):
  64. StaticLinker.Link -p=Linux32G Runtime Trace Glue Unix Machine Heaps Modules Objects Kernel KernelLog Streams Commands Pipes StdIO TrapWriters Reflection Traps Files UnixFiles Clock Dates Reals Strings Diagnostics BitSets StringPool ObjectFile GenericLinker GenericLoader Shell SystemTools StdIOShell ~
  65. Command line shell including compiler (and linker)
  66. StaticLinker.Link -p=Linux32G Runtime Trace Glue Unix Machine Heaps Modules Objects Kernel KernelLog Streams Commands Pipes StdIO TrapWriters Reflection Traps Files UnixFiles Clock Dates Reals Strings Diagnostics BitSets StringPool ObjectFile GenericLinker GenericLoader Shell SystemTools StdIOShell
  67. StaticLinker Compiler FoxOberonFrontend FoxARMBackend FoxAMDBackend
  68. ~