StdIOShell.Mod 3.7 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): BOOLEAN;
  15. VAR str: ARRAY 256 OF CHAR;
  16. BEGIN
  17. IF ~context.arg.GetString(str) THEN
  18. context.out.String("Critical error: no arg");
  19. RETURN FALSE;
  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 FALSE END;
  29. str := "Shell.Start";
  30. END;
  31. RETURN 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 := FALSE: BOOLEAN;
  37. VAR code := Modules.PowerDown: LONGINT;
  38. PROCEDURE Wait;
  39. BEGIN{EXCLUSIVE}
  40. AWAIT(done);
  41. END Wait;
  42. BEGIN{ACTIVE}
  43. IF Execute(StdIO.env) THEN code := Modules.Reboot END;
  44. FINALLY
  45. IF Verbose THEN
  46. Trace.String("StdIOShell: Exit"); Trace.Ln;
  47. END;
  48. Modules.Shutdown(code);
  49. done := TRUE
  50. END Executor;
  51. VAR execute: Executor;
  52. (* do not add commands here -- the module loader does not finish here and they will not become available *)
  53. BEGIN
  54. NEW(execute); (* execute shell and termination in separate thread *)
  55. execute.Wait; (* will actually never return *)
  56. END StdIOShell.
  57. Linking a command line shell:
  58. Command line shell: (Windows):
  59. 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 ~
  60. Command line shell including compiler (and linker)
  61. 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
  62. Shell StaticLinker Compiler FoxOberonFrontend FoxARMBackend FoxAMDBackend
  63. ~
  64. Command line shell: (Linux):
  65. 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 ~
  66. Command line shell including compiler (and linker)
  67. 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
  68. StaticLinker Compiler FoxOberonFrontend FoxARMBackend FoxAMDBackend
  69. ~