diff --git a/twander.py b/twander.py index 43cf13b..4315f01 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.126 2003/03/04 21:51:44 tundra Exp $" +RCSID = "$Id: twander.py,v 3.127 2003/03/05 23:02:04 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -1107,93 +1107,105 @@ # Additionally, [SYMBOL] can also be an environment # variable - [$SYMBOL] - # Process conditional beginning-of-block statement + ##### + # Process Conditional Beginning-Of-Block Statement + ##### elif fields[0] == CONDIF: - # Process beginning of conditional block - if fields[0] == CONDIF: + # Hack off the conditional statement so we can + # process what's left - # Process string equality checks - if cleanline.count(CONDEQUAL): + condline = cleanline[len(CONDIF):].strip() + + # Iterate through all legitimate possible + # beginning-of-block forms. The iteration + # tuple is in the form: (condition, # of required arguments) - x = cleanline[len(CONDIF):].split(CONDEQUAL) - if len(x) != 2: - WrnMsg(wBADIF % (num, line)) - return + args = [] + condition, var, cmpstr = "", "", "" + + for condtype, numargs in [(CONDEQUAL, 2), (CONDNOTEQUAL, 2), (None, 1)]: - else: - var = x[0].strip()[1:-1] - cmpstr = x[1].strip() - - conditional = FALSE - - #Handle references to Environment Variables - if var[0] == ENVVBL: - if os.getenv(var[1:]) == cmpstr: - conditional = TRUE - - # Handle references to User-Defined Variables - elif UI.SymTable.has_key(var) and UI.SymTable[var] == cmpstr: - conditional = TRUE - - - # Process string inequality checks - elif cleanline.count(CONDNOTEQUAL): - - x = cleanline[len(CONDIF):].split(CONDNOTEQUAL) - if len(x) != 2: - WrnMsg(wBADIF % (num, line)) - return - - else: - var = x[0].strip()[1:-1] - cmpstr = x[1].strip() - - conditional = FALSE - - #Handle references to Environment Variables - if var[0] == ENVVBL: - if os.getenv(var[1:]) != cmpstr: - conditional = TRUE - - # Handle references to User-Defined Variables - elif UI.SymTable.has_key(var) and UI.SymTable[var] != cmpstr: - conditional = TRUE - - - # Process variable existence checks - else: - # Existence checks must be in the form: .if [VAR] + # Process forms that have arguments following the variable reference + if condtype: + if condline.count(condtype): + args = condline.split(condtype) + condition = condtype + break - if len(fields) != 2: - WrnMsg(wBADIF % (num, line)) - return + # Process the existential conditional form - # Presume 2nd field is in the form: [VAR] + else: + args = condline.split() + condition = condtype + break - var = fields[1][1:-1] + # Check for correct syntax + # We have to have the right number of arguments, AND + # the condition variable has to be in proper variable reference form: [VAR] AND + # the rightmost argument cannot be an empty string - conditional = FALSE + if (len(args) != numargs) or (not REVAR.match(args[0].strip())) or (not args[-1]): + WrnMsg(wBADIF % (num, line)) + return - # Handle references to Environment Variables + # Syntax OK, process the conditional test + else: + + # Assume the conditional test fails + conditional = FALSE + + # Strip the reference syntax to get just the variable name + var = args[0].strip()[1:-1] + + # Handle the equality tests + + if condition: + + # De-reference the variable's contents, accomodating + # both Environment and User-Defined variable types + + if var[0] == ENVVBL: + var = os.getenv(var[1:]) + + else: + var = UI.SymTable.get(var) + + + # Get the comparison string + cmpstr = args[1].strip() + + # Now process each type of condition explicitly + + if condition == CONDEQUAL: + if var == cmpstr: + conditional = TRUE + + elif condition == CONDNOTEQUAL: + if var != cmpstr: + conditional = TRUE + + # Handle the existential conditional + else: + if var[0] == ENVVBL: if os.getenv(var[1:]): conditional = TRUE - # Handle references to User-Defined Variables elif UI.SymTable.has_key(var): conditional = TRUE + # Even if the current conditional is True, we do not + # process its contents if the *containing* scope is False. + # i.e., A given conditional's truth is determined by its + # own state AND the state of the containing scope. - # Even if the current conditional is TRUE, we do not - # process its contents if the *containing* scope is false. - # i.e., A given conditional's truth is determined by its - # own state AND the state of the containing scope. + ConditionalStack.append(ConditionalStack[-1] and conditional) - ConditionalStack.append(ConditionalStack[-1] and conditional) - - # Process conditional end-of-block statement + ##### + # Process Conditional End-Of-Block Statement + ##### elif fields[0] == CONDENDIF: @@ -2579,6 +2591,9 @@ if not uwc: return + # Clear current selections + KeySelNone(event) + # Unless the user indicates otherwise, cook the regex so # a match can occur anywhere on the line