StdIOShell.Mod 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. MODULE StdIOShell; (** AUTHOR "Felix Friedrich"; PURPOSE "Command shell for standalone Oberon/A2 Applications"; *)
  2. IMPORT StdIO, Commands, Modules, Trace;
  3. PROCEDURE Activate(context: Commands.Context; CONST cmd: ARRAY OF CHAR): BOOLEAN;
  4. VAR msg: ARRAY 256 OF CHAR; res: LONGINT;
  5. BEGIN
  6. Commands.Activate(cmd, context, {Commands.Wait}, res, msg);
  7. IF res # 0 THEN context.error.String(msg); context.error.Ln; RETURN FALSE END;
  8. RETURN TRUE;
  9. END Activate;
  10. PROCEDURE Execute(context: Commands.Context);
  11. VAR str: ARRAY 256 OF CHAR; b: BOOLEAN;
  12. BEGIN
  13. IF ~context.arg.GetString(str) THEN
  14. context.out.String("Critical error: no arg");
  15. RETURN
  16. END;
  17. IF ~context.arg.GetString(str) THEN
  18. str := "Shell.Start";
  19. ELSIF str = "compile" THEN str := "Compiler.Compile"
  20. ELSIF str="link" THEN str := "StaticLinker.Link"
  21. ELSIF (str="i") OR (str = "interpreter") THEN str := "InterpreterShell.Start"
  22. ELSIF (str = "execute") OR (str="e") THEN str := "SystemTools.DoFile";
  23. ELSIF (str = "run") OR (str="r") THEN
  24. IF ~Activate(context, "SystemTools.DoFile") THEN RETURN END;
  25. str := "Shell.Start";
  26. END;
  27. b := Activate(context, str);
  28. END Execute;
  29. TYPE
  30. (* excute the shell and termination in separate thread with proper process data structure *)
  31. Executor=OBJECT
  32. VAR done: BOOLEAN;
  33. PROCEDURE Wait;
  34. BEGIN{EXCLUSIVE}
  35. AWAIT(done);
  36. END Wait;
  37. BEGIN{ACTIVE}
  38. Execute(StdIO.env);
  39. FINALLY
  40. Trace.String("Closing Shell"); Trace.Ln;
  41. Modules.Shutdown(Modules.PowerDown);
  42. done := TRUE
  43. END Executor;
  44. VAR execute: Executor;
  45. (* do not add commands here -- the module loader does not finish here and they will not become available *)
  46. BEGIN
  47. NEW(execute); (* execute shell and termination in separate thread *)
  48. execute.Wait; (* will actually never return *)
  49. END StdIOShell.
  50. Linking a command line shell:
  51. Command line shell: (Windows):
  52. 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 StdIOShell ~
  53. Command line shell: (Linux):
  54. 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 ~