Explorar o código

Added proper result value for commands and use context.error consistently. There are probably many more commands that need to be modified accordingly.

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8407 8c9fc860-2736-0410-a75d-ab315db34111
negelef %!s(int64=6) %!d(string=hai) anos
pai
achega
32be4c4f62

+ 3 - 1
source/Compiler.Mod

@@ -489,7 +489,7 @@ TYPE
 				END;
 			END;
 		END;
-		IF error THEN context.result := -1 ELSE context.result := Commands.Ok END;
+		IF error THEN context.result := Commands.CommandError ELSE context.result := Commands.Ok END;
 
 	END Compile;
 
@@ -533,6 +533,8 @@ TYPE
 	BEGIN
 		IF context.arg.GetString(name) & context.arg.GetString(defaults) THEN
 			DoAddPlatform(name, defaults);
+		ELSE
+			context.result := Commands.CommandParseError;
 		END;
 	END AddPlatform;
 	

+ 46 - 17
source/FSTools.Mod

@@ -130,8 +130,10 @@ BEGIN
 		ExpandAlias(alias, genvol, genfs);
 		IF (Files.This(prefix) # NIL) THEN
 			context.error.String(prefix); context.error.String("; already used"); context.error.Ln;
+			context.result := Commands.CommandError;
 		ELSIF (genvol = "") OR (genfs = "") THEN
 			context.error.String(prefix); context.error.String(": unknown alias "); context.error.String(alias); context.error.Ln;
+			context.result := Commands.CommandError;
 		ELSE
 			IF genvol # "NIL" THEN
 				NEW(parvol, context.in, context.arg, context.out, context.error, context.caller);
@@ -165,11 +167,12 @@ BEGIN
 					parvol.vol.Finalize()	(* unmount volume *)
 				END
 			ELSE
-				(* skip *)
+				context.result := Commands.CommandError;
 			END
 		END;
 	ELSE
 		context.error.String('Expected parameters: prefix alias ([volpar] ["|" fspar]'); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END Mount;
 
@@ -199,9 +202,11 @@ BEGIN
 		ELSE
 			context.error.String(prefix); context.error.Char(":");
 			context.error.String(" can't unmount boot volume. Use \f parameter to force unmounting."); context.error.Ln;
+			context.result := Commands.CommandError;
 		END
 	ELSE
 		context.error.String(prefix); context.error.Char(":"); context.error.String(" not found"); context.error.Ln;
+		context.result := Commands.CommandError;
 	END
 END Unmount;
 
@@ -221,6 +226,7 @@ BEGIN
 		END
 	ELSE
 		context.error.String(prefix);  context.error.String(": not found"); context.error.Ln;
+		context.result := Commands.CommandError;
 	END;
 END SetDefault;
 
@@ -265,11 +271,11 @@ BEGIN
 	END;
 	IF ~found THEN
 		IF (prefix = "") THEN
-			context.out.String("No file systems found."); context.out.Ln;
+			context.error.String("No file systems found.");
 		ELSE
-			context.out.String("File system "); context.out.String(prefix); context.out.String(" not found.");
-			context.out.Ln;
+			context.error.String("File system "); context.error.String(prefix); context.error.String(" not found.");
 		END;
+		context.error.Ln; context.result := Commands.CommandError;
 	END;
 END Watch;
 
@@ -332,6 +338,8 @@ BEGIN
 			END
 		END;
 		context.out.Ln;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Directory;
 
@@ -421,17 +429,20 @@ BEGIN
 					EnumerateDirectory(enum, enumProc, options, enumContext, filemask, arguments^);
 					enum.Close;
 				ELSE
-					context.out.String("Procedure "); context.out.String(commandProcStr); context.out.String(" not found");
-					context.out.Ln;
+					context.error.String("Procedure "); context.error.String(commandProcStr); context.error.String(" not found");
+					context.error.Ln; context.result := Commands.CommandError;
 				END;
 			ELSE
-				context.out.String("Command procedure error, res: "); context.out.Int(res, 0);
-				context.out.String(" ("); context.out.String(msg); context.out.String(")");
-				context.out.Ln;
+				context.error.String("Command procedure error, res: "); context.error.Int(res, 0);
+				context.error.String(" ("); context.error.String(msg); context.error.String(")");
+				context.error.Ln; context.result := Commands.CommandError;
 			END;
 		ELSE
-			context.out.String("FSTools.Enumerate [Options] pattern ~"); context.out.Ln;
+			context.error.String("FSTools.Enumerate [Options] pattern ~"); context.error.Ln;
+			context.result := Commands.CommandParseError;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Enumerate;
 
@@ -480,7 +491,10 @@ BEGIN
 			context.out.String("Created file "); context.out.String(filename); context.out.Ln;
 		ELSE
 			context.out.String("FSTools.CreateFile filename [content] ~"); context.out.Ln;
+			context.result := Commands.CommandParseError;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END CreateFile;
 
@@ -503,12 +517,14 @@ BEGIN
 			context.error.String("Error: Could not copy file "); context.error.String(sourceFullname);
 			context.error.String(" to "); context.error.String(targetFullname); context.error.String(", res: ");
 			context.error.Int(res, 0); context.error.Ln;
+			context.result := Commands.CommandError;
 			RETURN;
 		END;
 	END;
 	context.out.Int(nofFilesCopied, 0); context.out.String(" files copied");
 	IF (nofErrors > 0) THEN
 		context.out.String(" ("); context.out.Int(nofErrors, 0); context.out.String(" errors)");
+		context.result := Commands.CommandError;
 	END;
 	context.out.Ln;
 END CopyTo;
@@ -561,6 +577,7 @@ BEGIN
 					context.error.String("failed "); ShowRes(context.error, res); context.error.Ln;
 					context.error.Update;
 					error := TRUE;
+					IF ~ignoreErrors THEN context.result := Commands.CommandError END;
 				END;
 			END;
 		END;
@@ -568,6 +585,7 @@ BEGIN
 			context.out.Int(n, 0); context.out.String(" of "); context.out.Int(nofFiles, 0);  context.out.String(" files copied."); context.out.Ln;
 		ELSE
 			context.out.String("No files copied."); context.out.Ln;
+			IF ~ignoreErrors THEN context.result := Commands.CommandError END;
 		END;
 	END;
 END CopyFiles;
@@ -636,6 +654,7 @@ BEGIN
 					END;
 					context.out.String("failed "); ShowRes(context.out, res); context.out.Ln;
 					error := TRUE;
+					IF ~ignoreErrors THEN context.result := Commands.CommandError END;
 				END;
 				INC(n);
 				context.out.Update;
@@ -645,6 +664,7 @@ BEGIN
 			context.out.String("No files matching the mask found."); context.out.Ln;
 		ELSE
 			context.error.String("Syntax Error: No files deleted"); context.error.Ln;
+			IF ~ignoreErrors THEN context.result := Commands.CommandError END;
 		END;
 	END;
 END DeleteFiles;
@@ -677,6 +697,7 @@ BEGIN
 				IF res # Files.Ok THEN
 					context.error.String("failed "); ShowRes(context.error, res); context.error.Ln;
 					error := TRUE;
+					IF ~ignoreErrors THEN context.result := Commands.CommandError END;
 				ELSE
 					context.out.String("done."); context.out.Ln;
 					INC(n);
@@ -687,6 +708,7 @@ BEGIN
 			context.out.Int(n, 0); context.out.String(" of "); context.out.Int(nofFiles, 0); context.out.String(" files renamed."); context.out.Ln;
 		ELSE
 			context.out.String("No files renamed."); context.out.Ln;
+			IF ~ignoreErrors THEN context.result := Commands.CommandError END;
 		END;
 	END;
 END RenameFiles;
@@ -699,9 +721,11 @@ BEGIN
 		IF (res # Files.Ok) THEN
 			context.out.String("Could not create directory '"); context.out.String(path); context.out.String("', res: ");
 			ShowRes(context.out, res); context.out.Ln;
+			context.result := Commands.CommandError;
 		END;
 	ELSE
-		context.out.String("Usage: FSTools.CreateDirectory <path> ~"); context.out.Ln;
+		context.error.String("Usage: FSTools.CreateDirectory <path> ~"); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END CreateDirectory;
 
@@ -713,9 +737,11 @@ BEGIN
 		IF (res # Files.Ok) THEN
 			context.out.String("Could not delete directory '"); context.out.String(path); context.out.String("', res: ");
 			ShowRes(context.out, res); context.out.Ln;
+			context.result := Commands.CommandError;
 		END;
 	ELSE
-		context.out.String("Usage: FSTools.DeleteDirectory <path> ~"); context.out.Ln;
+		context.error.String("Usage: FSTools.DeleteDirectory <path> ~"); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END DeleteDirectory;
 
@@ -818,11 +844,11 @@ BEGIN
 			END;
 		ELSE
 			context.error.String("File "); context.error.String(filename); context.error.String(" not found");
-			context.error.Ln;
+			context.error.Ln; context.result := Commands.CommandError;
 		END;
 	ELSE
 		context.error.String("File "); context.error.String(filename); context.error.String(" not found");
-		context.error.Ln;
+		context.error.Ln; context.result := Commands.CommandParseError;
 	END;
 END CompareFiles;
 
@@ -900,11 +926,13 @@ BEGIN
 
 	IF (CountCharacters(mask, "?") > 0) THEN
 		context.error.String("Syntax Error in "); context.error.String(mask); context.error.String(": '?' matching characters not implemented for target mask"); context.error.Ln;
+		context.result := Commands.CommandError;
 		RETURN FALSE;
 	END;
 
 	IF (CountCharacters(prefix, "*") # 0) OR (CountCharacters(path, "*") # 0) THEN
 		context.error.String("Syntax Error in "); context.error.String(mask); context.error.String(": Target prefix/path may not contain '*' characters"); context.error.Ln;
+		context.result := Commands.CommandError;
 		RETURN FALSE;
 	END;
 
@@ -997,7 +1025,7 @@ BEGIN
 			done := TRUE;
 		ELSE
 			context.error.String("Command parsing error (res: "); context.error.Int(context.arg.res, 0); context.error.String(")");
-			error := TRUE;
+			error := TRUE; context.result := Commands.CommandError;
 		END;
 	END;
 	IF error THEN count := Error; END;
@@ -1020,6 +1048,7 @@ BEGIN
 	ELSE
 		count := Error;
 		context.error.String("Expected two filenames as arguments"); context.error.Ln;
+		context.result := Commands.CommandError;
 	END;
 	RETURN count;
 END GetSimpleFileLists;
@@ -1063,7 +1092,7 @@ BEGIN
 			error := TRUE;
 		END;
 	END;
-	IF error THEN count := Error; END;
+	IF error THEN count := Error; context.result := Commands.CommandError END;
 	RETURN count;
 END GetFileLists;
 
@@ -1129,4 +1158,4 @@ FSTools.DeleteFiles X:*.Bak ~
 
 FSTools.SplitFile BootManager.Bin 0200H BootManagerMBR.Bin BootManagerTail.Bin ~
 
-FSTools.Directory Test.Mod ~
+FSTools.Directory Test.Mod ~

+ 8 - 8
source/Linker.Mod

@@ -972,7 +972,6 @@ VAR options: Options.Options;
 	linkRoot: ARRAY 256 OF CHAR; logFile: Files.File; log: Files.Writer;
 	use: SET;
 	exportString: ARRAY 1024 OF CHAR;
-	error: BOOLEAN;
 	parsed: BOOLEAN;
 	position: LONGINT;
 	name: ARRAY 32 OF CHAR;
@@ -998,7 +997,9 @@ BEGIN
 	IF options.GetString("platform", name) THEN
 		reader := defaults.Get(name);
 		IF reader = NIL THEN 
-			context.error.String("Unknown platform"); context.error.Ln 
+			context.error.String("Unknown platform"); context.error.Ln;
+			context.result := Commands.CommandError;
+			RETURN;
 		ELSE
 			parsed := options.ParseStaged(reader, context.error) & parsed;
 			context.arg.SetPos(position);
@@ -1028,6 +1029,8 @@ BEGIN
 		code.exportInfo := ParseExports(exportString);
 		IF code.exportInfo = NIL THEN
 			context.error.String("Syntax error in export list or empty export list."); context.error.Ln;
+			context.result := Commands.CommandError;
+			RETURN;
 		ELSE
 			COPY(codeFileName, code.exportInfo.name);
 		END;
@@ -1054,10 +1057,7 @@ BEGIN
 	(* do linking after having read in all blocks to account for potential constraints *)
 	IF ~linker.error THEN linker.Link; END;
 
-	error := linker.error;
-	error := error OR ~CheckExports(code.exportInfo, context.error);
-
-	IF ~error THEN
+	IF ~linker.error & CheckExports(code.exportInfo, context.error) THEN
 		IF (code.displacement # 0) & (linker.log # NIL) THEN linker.log.String("code displacement 0"); linker.log.Hex(code.displacement,-8); linker.log.String("H"); linker.log.Ln END;
 		WriteOutputFile (code, codeFileName, linker, codeFileFormat);
 		IF data # code THEN
@@ -1075,9 +1075,9 @@ BEGIN
 		IF log # NIL THEN
 			log.Update; Files.Register(logFile);
 		END;
+	ELSE
+		context.result := Commands.CommandError;
 	END;
-
-	IF error THEN context.result := Commands.CommandError; END;
 END Link;
 
 PROCEDURE ShowDefaults*(context: Commands.Context);

+ 1 - 1
source/MinosLinker.Mod

@@ -315,7 +315,7 @@ VAR
 			S.SkipWhitespace;  S.String( fileIn );
 			IF fileIn[0] # 0X THEN linker.Link (fileIn, success) END;
 		END;
-		IF success THEN linker.End; END;
+		IF success THEN linker.End ELSE context.result := Commands.CommandError END;
 		SetLog(NIL);
 	END DoLink;
 

+ 75 - 20
source/Partitions.Mod

@@ -86,9 +86,13 @@ BEGIN
 		operation := Lib.operations.GetByUid(uid);
 		IF operation # NIL THEN
 			operation.Show(context.out, TRUE);
-		ELSE context.error.String("Error: Operation UID "); context.error.Int(uid, 0); context.error.String(" not found"); context.error.Ln;
+		ELSE
+			context.error.String("Error: Operation UID "); context.error.Int(uid, 0); context.error.String(" not found"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
-	ELSE context.error.String("Exspected parameters: uid"); context.error.Ln;
+	ELSE
+		context.error.String("Exspected parameters: uid"); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END ShowOp;
 
@@ -101,9 +105,14 @@ BEGIN
 		IF operation # NIL THEN
 			operation.Abort;
 			context.out.String("Operation UID "); context.out.Int(uid, 0); context.out.String(" aborted"); context.out.Ln;
-		ELSE context.error.String("Error: Operation UID "); context.error.Int(uid, 0); context.error.String(" not found"); context.error.Ln;
+		ELSE
+			context.error.String("Error: Operation UID "); context.error.Int(uid, 0); context.error.String(" not found"); context.error.Ln;
+			context.result := Commands.CommandParseError;
+
 		END;
-	ELSE context.error.String("Exspected parameters: uid"); context.error.Ln;
+	ELSE
+		context.error.String("Exspected parameters: uid"); context.error.Ln;
+		context.result := Commands.CommandError;
 	END;
 END Abort;
 
@@ -116,6 +125,7 @@ BEGIN
 			context.out.String("Operation UID "); context.out.Int(uid, 0); context.out.String(" has been removed"); context.out.Ln;
 		ELSE
 			context.error.String("Error: Could not remove operation UID "); context.error.Int(uid, 0); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	ELSIF context.arg.res = Streams.FormatError THEN
 		par := "";
@@ -129,10 +139,15 @@ BEGIN
 				context.out.String("All finished operation have been removed"); context.out.Ln;
 			ELSE
 				context.error.String("Expected parameters: uid | all | finished"); context.error.Ln;
+				context.result := Commands.CommandParseError;
 			END;
-		ELSE context.error.String("Expected parameters: uid | all | finished"); context.error.Ln;
+		ELSE
+			context.error.String("Expected parameters: uid | all | finished"); context.error.Ln;
+			context.result := Commands.CommandParseError;
 		END;
-	ELSE context.error.String("Expected parameters: uid | all | finished"); context.error.Ln;
+	ELSE
+		context.error.String("Expected parameters: uid | all | finished"); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END Remove;
 
@@ -150,6 +165,7 @@ BEGIN
 			mount.SetBlockingStart;
 		ELSE
 			context.error.String("Expected parameters: dev#part alias prefix"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END Mount;
@@ -184,6 +200,7 @@ BEGIN
 				formatAos.SetBlockingStart;
 			ELSE
 				context.error.String("File system "); context.error.String(fsname); context.error.String(" is not supported"); context.error.Ln;
+				context.result := Commands.CommandError;
 			END;
 		ELSE (* optional parameters not specified *)
 			NEW(formatAos, selection.disk, selection.partition, context.out);
@@ -209,6 +226,7 @@ BEGIN
 			updateBootFile.SetBlockingStart;
 		ELSE
 			context.error.String("Expected parameters: dev#part bootfilename"); context.error.Ln;
+			context.result := Commands.CommandParseError;
 		END;
 	END;
 END UpdateBootFile;
@@ -272,6 +290,7 @@ BEGIN
 			setConfig.SetBlockingStart;
 		ELSE
 			context.error.String("Expected argument stream that supports SetPos"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END SetConfig;
@@ -303,11 +322,17 @@ BEGIN
 					NEW(change, selection.disk, selection.partition, context.out);
 					change.SetParameters(oldtype, newtype);
 					change.SetBlockingStart;
-				ELSE context.error.String("Expected parameters: dev#part oldtype newtype, failed to parse newtype"); context.error.Ln;
+				ELSE
+					context.error.String("Expected parameters: dev#part oldtype newtype, failed to parse newtype"); context.error.Ln;
+					context.result := Commands.CommandParseError;
 				END;
-			ELSE context.error.String("Expected parameters: dev#part oldtype newtype, failed to parse oldtype"); context.error.Ln;
+			ELSE
+				context.error.String("Expected parameters: dev#part oldtype newtype, failed to parse oldtype"); context.error.Ln;
+				context.result := Commands.CommandParseError;
 			END;
-		ELSE context.error.String("Operation not support for floppy disk drives."); context.error.Ln;
+		ELSE
+			context.error.String("Operation not support for floppy disk drives."); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END ChangeType;
@@ -325,9 +350,13 @@ BEGIN
 				NEW(delete, selection.disk, selection.partition, context.out);
 				delete.SetParameters(type);
 				delete.SetBlockingStart;
-			ELSE context.error.String("Expected parameters: dev#part type sizeMB, error while parsing type"); context.error.Ln;
+			ELSE
+				context.error.String("Expected parameters: dev#part type sizeMB, error while parsing type"); context.error.Ln;
+				context.result := Commands.CommandParseError;
 			END;
-		ELSE context.error.String("Operation not supported for floppy disks"); context.error.Ln;
+		ELSE
+			context.error.String("Operation not supported for floppy disks"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END Delete;
@@ -345,11 +374,17 @@ BEGIN
 					NEW(create, selection.disk, selection.partition, context.out);
 					create.SetParameters(size, type, FALSE);
 					create.SetBlockingStart;
-				ELSE context.error.String("Expected parameters: dev#part type sizeMB, error while parsing size"); context.error.Ln;
+				ELSE
+					context.error.String("Expected parameters: dev#part type sizeMB, error while parsing size"); context.error.Ln;
+					context.result := Commands.CommandParseError;
 				END;
-			ELSE context.error.String("Expected parameters: dev#part type sizeMB, error while parsing type"); context.error.Ln;
+			ELSE
+				context.error.String("Expected parameters: dev#part type sizeMB, error while parsing type"); context.error.Ln;
+				context.result := Commands.CommandParseError;
 			END;
-		ELSE context.error.String("Operation not supported on floppy disks"); context.error.Ln;
+		ELSE
+			context.error.String("Operation not supported on floppy disks"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END Create;
@@ -378,6 +413,7 @@ BEGIN
 			setFlags.SetBlockingStart;
 		ELSE
 			context.error.String("Operation not supported for floppy disks"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END ChangeActiveBit;
@@ -395,6 +431,7 @@ BEGIN
 			IF context.arg.GetInteger(block, FALSE) THEN
 				IF ~context.arg.GetInteger(numblocks, FALSE) THEN
 					context.error.String("Exspected parameters: dev#part filename [block numblocks], failed to parse numblocks"); context.error.Ln;
+					context.result := Commands.CommandParseError;
 					RETURN;
 				END;
 			ELSE (* optional parameters not specified *)
@@ -405,6 +442,7 @@ BEGIN
 			fileToPartition.SetBlockingStart;
 		ELSE
 			context.error.String("Exspected parameters: dev#part name [block numblocks], failed to parse filename"); context.error.Ln;
+			context.result := Commands.CommandParseError;
 		END;
 	END;
 END FileToPartition;
@@ -423,6 +461,7 @@ BEGIN
 			IF context.arg.GetInteger(block, FALSE) THEN
 				IF ~context.arg.GetInteger(numblocks, FALSE) THEN
 					context.error.String("Exspected parameters: dev#part filename [block numblocks], failed to parse numblocks"); context.error.Ln;
+					context.result := Commands.CommandParseError;
 					RETURN;
 				END;
 			ELSE (* optional parameters not specified *)
@@ -433,7 +472,9 @@ BEGIN
 			partitionToFile.SetBlockingStart;
 			context.out.String("Partitions UID "); context.out.Int(partitionToFile.uid, 0); context.out.String(": Started PartitionToFile on ");
 			context.out.String(partitionToFile.diskpartString); context.out.Ln;
-		ELSE context.error.String("Exspected parameters: dev#part name [block numblocks], failed to parse filename"); context.error.Ln;
+		ELSE
+			context.error.String("Exspected parameters: dev#part name [block numblocks], failed to parse filename"); context.error.Ln;
+			context.result := Commands.CommandParseError;
 		END;
 	END;
 END PartitionToFile;
@@ -458,11 +499,17 @@ BEGIN
 						writeMBR.SetParameters(filename, TRUE, FALSE);
 					END;
 					writeMBR.SetBlockingStart;
-				ELSE context.error.String("Expected parameters: dev#0 filename, failed to parse filename"); context.error.Ln;
+				ELSE
+					context.error.String("Expected parameters: dev#0 filename, failed to parse filename"); context.error.Ln;
+					context.result := Commands.CommandParseError;
 				END;
-			ELSE context.error.String("Expected parameters: dev#0 filename, partition is not 0"); context.error.Ln;
+			ELSE
+				context.error.String("Expected parameters: dev#0 filename, partition is not 0"); context.error.Ln;
+				context.result := Commands.CommandParseError;
 			END;
-		ELSE context.error.String("Operation not supported for floppy disks"); context.error.Ln;
+		ELSE
+			context.error.String("Operation not supported for floppy disks"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END WriteMBR;
@@ -482,6 +529,7 @@ BEGIN
 			updateLoader.SetBlockingStart;
 		ELSE
 			context.error.String("Expected parameters: dev#part bootloader"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END;
 END UpdateBootLoader;
@@ -525,6 +573,7 @@ BEGIN
 			showBlocks.SetBlockingStart;
 		ELSE
 			context.error.String("Exspected parameters: dev#part block [numblocks], failed to parse block"); context.error.Ln;
+			context.result := Commands.CommandParseError;
 		END;
 	END;
 END ShowBlocks;
@@ -544,9 +593,11 @@ BEGIN
 			Lib.Eject(dev, temp); context.out.String(temp); context.out.Ln;
 		ELSE
 			context.error.String("Device "); context.error.String(name); context.error.String(" not found"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	ELSE
 		context.error.String("Expected parameters: dev"); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END Eject;
 
@@ -565,9 +616,11 @@ BEGIN
 			Lib.Sync(dev, temp); context.out.String(temp); context.out.Ln;
 		ELSE
 			context.error.String("Device "); context.error.String(name); context.error.String(" not found"); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	ELSE
 		context.error.String("Expected parameters: dev"); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END Sync;
 
@@ -612,6 +665,7 @@ BEGIN
 		END;
 	ELSE
 		context.error.String("No Devices found"); context.error.Ln;
+		context.result := Commands.CommandError;
 	END;
 	Lib.diskModel.Release;
 END Show;
@@ -699,6 +753,7 @@ BEGIN
 	selection.disk.device := NIL; selection.partition := -1; (* invalid *)
 	IF ~context.arg.GetString(devpart) THEN
 		context.error.String("Expected parameters: dev#part"); context.error.Ln; context.error.Update;
+		context.result := Commands.CommandParseError;
 		RETURN FALSE;
 	END;
 	context.arg.SkipWhitespace;
@@ -716,11 +771,11 @@ BEGIN
 		RETURN TRUE;
 	ELSE
 		context.error.String("Partition "); context.error.String(devpart); context.out.String(" not found."); context.error.Ln;
-		context.error.Update;
+		context.error.Update; context.result := Commands.CommandError;
 	END;
 	RETURN FALSE;
 END GetSelection;
 
 END Partitions.
 
-System.Free DiskBenchmark Partitions ~
+System.Free DiskBenchmark Partitions ~

+ 2 - 1
source/RelativeFileSystem.Mod

@@ -1,6 +1,6 @@
 MODULE RelativeFileSystem ;	(**  AUTHOR "fof"; PURPOSE "";  **)
 
-IMPORT Files,UTF8Strings;
+IMPORT Files,UTF8Strings, Commands;
 TYPE PathName=ARRAY 272 OF CHAR;
 
 	FileSystem = OBJECT(Files.FileSystem)
@@ -122,6 +122,7 @@ TYPE PathName=ARRAY 272 OF CHAR;
 				Files.Add(fs, context.prefix);
 			ELSE
 				context.out.String("file system could not be found: "); context.out.String(str); context.out.Ln;
+				context.result := Commands.CommandError;
 			END;
 		END;
 	END NewFS;

+ 2 - 2
source/Serials.Mod

@@ -366,14 +366,14 @@ VAR
 BEGIN
 	GetPortParameters(context.arg, portNumber, bps, data, parity, stop, params, res);
 	IF (portNumber > 0) & (res # 0) THEN
-		context.result := 1;
+		context.result := Commands.CommandError;
 		context.error.String("Invalid port settings, res="); context.error.Int(res,0); context.error.Ln;
 		RETURN;
 	END;
 
 	SetTracePort(portNumber, bps, data, parity, stop, res);
 	IF res # 0 THEN
-		context.result := 2;
+		context.result := Commands.CommandError;
 		context.error.String("Failed to setup trace port, res="); context.error.Int(res,0); context.error.Ln;
 	END;
 END SetTrace;

+ 2 - 2
source/ShellSerial.Mod

@@ -54,7 +54,7 @@ VAR
 	i, receiveRes: LONGINT;
 BEGIN
 	IF ~context.arg.GetString(fileName) & (modemMode # XYModem.YModem) THEN
-		context.result := 1;
+		context.result := Commands.CommandParseError;
 		context.error.String("file name is missing"); context.error.Ln;
 		RETURN;
 	END;
@@ -201,7 +201,7 @@ VAR
 BEGIN {EXCLUSIVE}
 	Serials.GetPortParameters(context.arg, portNbr, bps, data, parity, stop, params, res);
 	IF res # 0 THEN
-		context.result := 1;
+		context.result := Commands.CommandError;
 		context.error.String("Invalid port settings, res="); context.error.Int(res,0); context.error.Ln;
 		RETURN;
 	END;

+ 11 - 5
source/System.Mod

@@ -111,6 +111,8 @@ BEGIN
 		reverse := ~options.GetFlag("r");
 		first := FALSE;
 		List(Modules.root);
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END ListModules;
 
@@ -151,7 +153,8 @@ BEGIN
 			context.out.Ln;
 		END
 	ELSE
-		context.error.String("Module not found"); context.error.Ln
+		context.error.String("Module not found"); context.error.Ln;
+		context.result := Commands.CommandError;
 	END;
 END ListCommands;
 
@@ -165,7 +168,7 @@ BEGIN
 	ELSIF (string = "commands") THEN ListCommands(context);
 	ELSE
 		context.error.String('Usage: System.List ("plugins"|"modules"|("commands" moduleName))');
-		context.error.Ln;
+		context.error.Ln; context.result := Commands.CommandParseError;
 	END;
 END List;
 
@@ -192,6 +195,7 @@ BEGIN
 		END;
 	ELSE
 		context.error.String("Module "); context.error.String(name); context.error.String(" is not loaded."); context.error.Ln;
+		context.result := Commands.CommandError;
 	END;
 END WhoImports;
 
@@ -230,8 +234,8 @@ BEGIN
 			context.error.String(" ("); context.error.String(msg); context.error.String(")");
 		END;
 		context.error.Ln;
+		context.result := Commands.CommandError;
 	END;
-	
 END ModuleState;
 
 
@@ -375,7 +379,7 @@ BEGIN
 		ProcessInfo.ShowStack(process, context.out);
 	ELSE
 		context.error.String("Process ID = "); context.error.Int(pid, 0); context.error.String(" not found.");
-		context.error.Ln;
+		context.error.Ln; context.result := Commands.CommandError;
 	END;
 END ShowStack;
 
@@ -443,9 +447,11 @@ BEGIN
 			context.result := res;
 		ELSE
 			context.error.String("Error: no such file: "); context.error.String(filename); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	ELSE
-		context.error.String("Error: mo filename provided."); context.error.String(filename); context.error.Ln;
+		context.error.String("Error: no filename provided."); context.error.String(filename); context.error.Ln;
+		context.result := Commands.CommandParseError;
 	END;
 END DoFile;
 

+ 20 - 3
source/VirtualDisks.Mod

@@ -187,17 +187,26 @@ BEGIN
 						file.WriteBytes(rider, buffer^, 0, blocksize);
 						IF rider.res # 0 THEN
 							context.error.String("Error: Could not write bytes to file"); context.error.Ln;
+							context.result := Commands.CommandError;
 							RETURN;
 						END;
 					END;
 					Files.Register(file);
 					context.out.String("done."); context.out.Ln;
-				ELSE context.error.String("Could not create file '"); context.error.String(filename); context.error.String("'"); context.error.Ln;
+				ELSE
+					context.error.String("Could not create file '"); context.error.String(filename); context.error.String("'"); context.error.Ln;
+					context.result := Commands.CommandError;
 				END;
-			ELSE context.error.String("nbrOfBlocks parameter expected."); context.error.Ln;
+			ELSE
+				context.error.String("nbrOfBlocks parameter expected."); context.error.Ln;
+				context.result := Commands.CommandParseError;
 			END;
-		ELSE context.error.String("filename parameter expected."); context.error.Ln;
+		ELSE
+			context.error.String("filename parameter expected."); context.error.Ln;
+			context.result := Commands.CommandParseError;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Create;
 
@@ -260,10 +269,14 @@ BEGIN
 				context.out.Ln;
 			ELSE
 				context.error.String("Could not register disk, res: "); context.error.Int(res, 0); context.error.Ln;
+				context.result := Commands.CommandError;
 			END;
 		ELSE
 			context.error.String(filename); context.error.String(" not found"); context.out.Ln;
+			context.result := Commands.CommandError;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Install;
 
@@ -300,7 +313,10 @@ BEGIN
 			context.out.Ln;
 		ELSE
 			context.error.String("Could not register disk, res: "); context.error.Int(res, 0); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END InstallRamdisk;
 
@@ -332,6 +348,7 @@ BEGIN
 		END;
 	ELSE
 		context.out.String(" not found");
+		context.result := Commands.CommandError;
 	END;
 	context.out.Ln;
 END Uninstall;

+ 10 - 3
source/Windows.WinDisks.Mod

@@ -193,6 +193,7 @@ VAR
 			END;
 		ELSE
 			context.error.String( diskname );  context.error.String( " not found" );  context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END Uninstall;
 
@@ -277,7 +278,7 @@ VAR
 			ELSE
 				context.error.String("Windows Error Code: "); context.error.Int(errorcode, 0);
 			END;
-			context.error.Ln;
+			context.error.Ln; context.result := Commands.CommandError;
 		END;
 		RETURN handle # Kernel32.InvalidHandleValue;
 	END OpenVolume;
@@ -298,6 +299,7 @@ VAR
 		IF done > 0 THEN
 			IF extents.NumberOfDiskExtents = 0 THEN
 				context.error.String( "no disk extents used, probably the drive is physical already " );  context.error.Ln;
+				context.result := Commands.CommandError;
 			ELSIF extents.NumberOfDiskExtents = 1 THEN
 				drive := extents.extents[0].DiskNumber;
 				IF GetDiskGeometry( handle, pdg ) THEN bps := pdg.BytesPerSector ELSE bps := 512 END;
@@ -307,12 +309,15 @@ VAR
 				name := "PhysicalDrive";  AppendInt( name, drive );  context.out.String( "Mapping to drive : " );  context.out.String( name );  context.out.Ln;
 				IF ~OpenVolume( handle, flags,name, context) THEN 
 					context.error.String( "volume could not be opened. " ); context.error.Ln; 
+					context.result := Commands.CommandError;
 				END;
 			ELSE
 				context.error.String( "cannot handle volumes with more than one extent (yet) " ); context.error.Ln;
+				context.result := Commands.CommandError;
 			END;
 		ELSE
 			context.error.String( "GetPhysicalDrive: no success, probably the drive is already physical" ); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
 	END GetPhysicalDrive;
 
@@ -345,6 +350,7 @@ VAR
 			IF ~GetDiskGeometry( handle, pdg ) THEN
 				Kernel32.CloseHandle( handle );
 				context.error.String( "Could not determine disk geometry " );  context.error.Ln;
+				context.result := Commands.CommandError;
 			ELSE
 				ReportDiskGeometry( pdg, context.out);
 				IF pdg.MediaType = RemovableMedia THEN INCL(flags,Disks.Removable) END;
@@ -359,8 +365,9 @@ VAR
 					AddDisk( vd );
 					context.out.String( diskname );  context.out.String( " registered." ); context.out.Ln;
 				ELSE
-					  Kernel32.CloseHandle( handle );
-					context.out.String( "Could not register disk, res: " ); context.out.Int( res, 0 ); context.out.Ln;
+					Kernel32.CloseHandle( handle );
+					context.error.String( "Could not register disk, res: " ); context.error.Int( res, 0 ); context.error.Ln;
+					context.result := Commands.CommandError;
 				END;
 			END;
 		END;

+ 16 - 1
source/ZipTool.Mod

@@ -113,6 +113,8 @@ BEGIN
 	IF options.Parse(context.arg, context.error) THEN
 		context.arg.SkipWhitespace; context.arg.String(archiveName);
 		WriteDirectory(context.out, context.error, archiveName, options.GetFlag("details"), res);
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Directory;
 
@@ -269,9 +271,12 @@ BEGIN
 				IF (nofErrors = 1) THEN context.out.String(" error)");
 				ELSE context.out.String(" errors)");
 				END;
+				context.result := Commands.CommandError;
 			END;
 			context.out.Ln;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Extract;
 
@@ -347,10 +352,13 @@ BEGIN
 					IF (nofErrors = 1) THEN context.out.String("1 error)");
 					ELSE context.out.Int(nofErrors, 0); context.out.String(" errors)");
 					END;
+					context.result := Commands.CommandError;
 				END;
 				IF (nofExtracted > 1) OR (nofErrors > 0) THEN context.out.Ln; END;
 			END;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END ExtractAll;
 
@@ -466,12 +474,16 @@ BEGIN
 			IF (nofErrors > 0) THEN
 				context.out.String(" ("); context.out.Int(nofErrors, 0);
 				IF (nofErrors = 1) THEN context.out.String(" error)"); ELSE context.out.String(" errors)"); END;
+				context.result := Commands.CommandError;
 			END;
 			IF (nofAdded > 1) OR (nofErrors > 0) THEN context.out.Ln; END;
 		ELSE
 			context.error.String("Could not create archive '"); context.error.String(archiveName); context.error.String("': ");
 			Zip.ShowError(res, context.error); context.error.Ln;
+			context.result := Commands.CommandError;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Add;
 
@@ -525,9 +537,12 @@ BEGIN
 				IF (nofErrors = 1) THEN context.out.String("error)");
 				ELSE context.out.String(" errors)");
 				END;
+				context.result := Commands.CommandError;
 			END;
 			IF (nofDeleted > 1) OR (nofErrors > 0) THEN context.out.Ln; END;
 		END;
+	ELSE
+		context.result := Commands.CommandParseError;
 	END;
 END Delete;
 
@@ -540,4 +555,4 @@ ZipTool.Directory --details ZeroSkin.zip ~
 
 ZipTool.Extract ZeroSkin.zip arrow.png ~
 
-ZipTool.ExtractAll ZeroSkin.zip ~
+ZipTool.ExtractAll ZeroSkin.zip ~