Parcourir la source

"run" 0or "r" will keep a console open while "execute" or "e" will just execute the commands in a script.

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7075 8c9fc860-2736-0410-a75d-ab315db34111
felixf il y a 8 ans
Parent
commit
9be0a2fcf7
1 fichiers modifiés avec 17 ajouts et 7 suppressions
  1. 17 7
      source/StdIOShell.Mod

+ 17 - 7
source/StdIOShell.Mod

@@ -2,23 +2,33 @@ MODULE StdIOShell; (** AUTHOR ""; PURPOSE ""; *)
 
 IMPORT StdIO, Commands, Streams, Modules, Objects, Shell;
 
+PROCEDURE Activate(context: Commands.Context; CONST cmd: ARRAY OF CHAR): BOOLEAN;
+VAR msg: ARRAY 256 OF CHAR;  res: LONGINT; 
+BEGIN
+	Commands.Activate(cmd, context, {Commands.Wait}, res, msg);
+	IF res # 0 THEN context.error.String(msg); context.error.Ln; RETURN FALSE END;
+	RETURN TRUE;
+END Activate;
+
 PROCEDURE Execute(context: Commands.Context);
-VAR str, msg: ARRAY 256 OF CHAR;  res: LONGINT; shell: Shell.Shell; 
+VAR str, msg: ARRAY 256 OF CHAR;  res: LONGINT; shell: Shell.Shell; b: BOOLEAN;
 BEGIN
 	IF ~context.arg.GetString(str) THEN  
 		context.out.String("Critical error: no arg"); 
-		RETURN END;
+		RETURN 
+	END;
 	IF ~context.arg.GetString(str) THEN 
 		str := "Shell.Start";
-	END;
-	IF str = "compile" THEN str := "Compiler.Compile"
+	ELSIF str = "compile" THEN str := "Compiler.Compile"
 	ELSIF str="link" THEN str := "StaticLinker.Link"
 	ELSIF (str="i") OR (str = "interpreter") THEN str := "InterpreterShell.Start"
-	ELSIF (str = "run") OR (str="r") THEN str := "SystemTools.DoFile"
+	ELSIF (str = "execute") OR (str="e") THEN str := "SystemTools.DoFile";
+	ELSIF (str = "run") OR (str="r") THEN 
+		IF ~Activate(context, "SystemTools.DoFile") THEN RETURN END;
+		str := "Shell.Start";
 	END;
 	
-	Commands.Activate(str, context, {Commands.Wait}, res, msg);
-	IF res # 0 THEN context.error.String(msg); context.error.Ln; END;
+	b := Activate(context, str);
 END Execute;
 
 (* do not add commands here -- the module loader does not finish here and they will not become available *)