Browse Source

introduced a method to determine whether a command context is the context of a currently executed shell command - needed for serial shell commands which use the same serial port as the shell

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7663 8c9fc860-2736-0410-a75d-ab315db34111
eth.morozova 7 years ago
parent
commit
174d672ab0
1 changed files with 12 additions and 0 deletions
  1. 12 0
      source/Shell.Mod

+ 12 - 0
source/Shell.Mod

@@ -149,6 +149,8 @@ TYPE
 
 
 		commandHistory : CommandHistory;
 		commandHistory : CommandHistory;
 		firstCR : CHAR;
 		firstCR : CHAR;
+		
+		currentCommand: Command;
 
 
 		PROCEDURE &Init*(in: Streams.Reader; out, err: Streams.Writer; echo: BOOLEAN; CONST prompt: ARRAY OF CHAR);
 		PROCEDURE &Init*(in: Streams.Reader; out, err: Streams.Writer; echo: BOOLEAN; CONST prompt: ARRAY OF CHAR);
 		BEGIN
 		BEGIN
@@ -557,7 +559,9 @@ TYPE
 					IF (res # Commands.Ok) THEN
 					IF (res # Commands.Ok) THEN
 						context.error.String(errormsg); context.error.Ln;
 						context.error.String(errormsg); context.error.Ln;
 					ELSE
 					ELSE
+						currentCommand := c;
 						Commands.Activate(c.command, c.context, flags, res, msg);
 						Commands.Activate(c.command, c.context, flags, res, msg);
+						currentCommand := NIL;
 				(*		IF wait & (cmd.pipe # NIL) THEN
 				(*		IF wait & (cmd.pipe # NIL) THEN
 							KernelLog.String("Pipe closed"); KernelLog.Ln;
 							KernelLog.String("Pipe closed"); KernelLog.Ln;
 							cmd.pipe.Close;
 							cmd.pipe.Close;
@@ -602,6 +606,14 @@ TYPE
 			END;
 			END;
 			context.out.Update; context.error.Update
 			context.out.Update; context.error.Update
 		END Run;
 		END Run;
+		
+		(**
+			Returns TRUE if the given context is the context of currently executed command
+		*)
+		PROCEDURE IsCurrentCmdContext*(context: Commands.Context): BOOLEAN;
+		BEGIN
+			RETURN context = currentCommand.context;
+		END IsCurrentCmdContext;
 
 
 		PROCEDURE AwaitDeath*;
 		PROCEDURE AwaitDeath*;
 		BEGIN {EXCLUSIVE}
 		BEGIN {EXCLUSIVE}