Sfoglia il codice sorgente

Added support for explicitly setting the value of flags.

A flag can now be set using "--flag" or "--flag=true". To explicitly unset a flag use "--flag=false". This finally allows to overwrite flags where options are parsed in stages (e.g. in the compiler).

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8101 8c9fc860-2736-0410-a75d-ab315db34111
negelef 7 anni fa
parent
commit
b4dbb50dc0
1 ha cambiato i file con 19 aggiunte e 9 eliminazioni
  1. 19 9
      source/Options.Mod

+ 19 - 9
source/Options.Mod

@@ -507,13 +507,24 @@ TYPE
 			index := FindOption(optionName);
 			IF (index # Invalid) THEN
 				IF ~checkTimestamp OR (options[index].timestamp < timestamp) THEN
-					IF (options[index].type = String) THEN
-						options[index].timestamp := timestamp;
+					options[index].timestamp := timestamp;
+					CASE options[index].type OF
+					| Flag:
+						IF (string = "false") THEN
+							options[index].isSet := FALSE;
+							RETURN TRUE;
+						ELSIF (string = "true") THEN
+							options[index].isSet := TRUE;
+							RETURN TRUE;
+						ELSIF (error # NIL) THEN
+							error.String("Option "); ShowOption(ch, name);
+							error.String(" expects a boolean parameter"); error.Ln;
+						END;
+					| String:
 						options[index].isSet := TRUE;
 						COPY(string, options[index].string);
 						RETURN TRUE;
-					ELSIF (options[index].type = Integer) THEN
-						options[index].timestamp := timestamp;
+					| Integer:
 						IF StringToInteger(string, options[index].value, TRUE) THEN
 							options[index].isSet := TRUE;
 							RETURN TRUE;
@@ -521,14 +532,10 @@ TYPE
 							error.String("Option "); ShowOption(ch, name);
 							error.String(" expects decimal number as parameter"); error.Ln;
 						END;
-					ELSIF (options[index].type=Real) THEN
-						options[index].timestamp:=timestamp;
+					| Real:
 						Strings.StrToFloat(string, options[index].rvalue);
 						options[index].isSet:=TRUE;
 						RETURN TRUE;
-					ELSIF (error # NIL) THEN
-						error.String("Option "); ShowOption(ch, name);
-						error.String(" does not have a parameter"); error.Ln;
 					END;
 				ELSIF (error # NIL) THEN
 					error.String("Option "); ShowOption(ch, name);
@@ -798,4 +805,7 @@ Options.Test -afds -b --fdas ~
 
 Options.Test -f  -s=fds ~
 
+Options.Test -f=true ~
+Options.Test --flag=false ~
+
 System.Free Options ~