StdIOShell.Mod 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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: WORD;
  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 := "Linker.Link";
  25. ELSIF (str = "interpreter") OR (str = "i") THEN str := "InterpreterShell.Start";
  26. ELSIF (str = "execute") OR (str = "e") THEN str := "SystemTools.DoFile";
  27. ELSIF (str = "do") OR (str = "d") THEN str := "SystemTools.DoCommands";
  28. ELSIF (str = "run") OR (str = "r") THEN
  29. IF ~Activate(context, "SystemTools.DoFile") THEN RETURN FALSE END;
  30. str := "Shell.Start";
  31. END;
  32. RETURN Activate(context, str);
  33. END Execute;
  34. TYPE
  35. (* excute the shell and termination in separate thread with proper process data structure *)
  36. Executor=OBJECT
  37. VAR done := FALSE: BOOLEAN;
  38. VAR code := Modules.PowerDown: LONGINT;
  39. PROCEDURE Wait;
  40. BEGIN{EXCLUSIVE}
  41. AWAIT(done);
  42. END Wait;
  43. BEGIN{ACTIVE}
  44. IF Execute(StdIO.env) THEN code := Modules.Reboot END;
  45. FINALLY
  46. IF Verbose THEN
  47. Trace.String("StdIOShell: Exit"); Trace.Ln;
  48. END;
  49. Modules.Shutdown(code);
  50. done := TRUE
  51. END Executor;
  52. VAR execute: Executor;
  53. (* do not add commands here -- the module loader does not finish here and they will not become available *)
  54. BEGIN
  55. NEW(execute); (* execute shell and termination in separate thread *)
  56. execute.Wait; (* will actually never return *)
  57. END StdIOShell.
  58. Linking a command line shell:
  59. Command line shell: (Windows):
  60. Linker.Link --fileFormat=PE32CUI --fileName=oberon.exe --extension=GofW --displacement=401000H Builtins Trace Kernel32 Machine Heaps Modules Objects Kernel KernelLog Streams Commands Files WinFS Clock Dates Reals Strings Diagnostics BitSets StringPool ObjectFile GenericLinker Reflection Loader WinTrace StdIO Traps RelativeFileSystem WMDefaultFont SystemTools Shell StdIOShell ~
  61. Command line shell including compiler (and linker)
  62. Linker.Link --fileFormat=PE32CUI --fileName=oberon.exe --extension=GofW --displacement=401000H Builtins Trace Kernel32 Machine Heaps Modules Objects Kernel KernelLog Streams Commands Files WinFS Clock Dates Reals Strings Diagnostics BitSets StringPool ObjectFile GenericLinker Reflection Loader WinTrace StdIO Traps RelativeFileSystem SystemTools FSTools StdIOShell
  63. Shell Linker Compiler FoxOberonFrontend FoxARMBackend FoxAMDBackend
  64. ~
  65. Command line shell: (Linux):
  66. Linker.Link -p=Linux32 Builtins 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 Loader Shell SystemTools StdIOShell ~
  67. Command line shell including compiler (and linker)
  68. Linker.Link -p=Linux32 Builtins 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 Loader Shell SystemTools StdIOShell
  69. Linker Compiler FoxOberonFrontend FoxARMBackend FoxAMDBackend
  70. ~