diff --git a/twander.py b/twander.py index c1c1f20..4973895 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.117 2003/03/01 07:32:43 tundra Exp $" +RCSID = "$Id: twander.py,v 3.118 2003/03/01 08:21:28 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -653,6 +653,7 @@ wDUPKEY = "Ignoring Line %s.\nFound Duplicate Command Key '%s':\n\n%s" wEXTRAENDIF = "Ignoring Line %s!\nNo Conditional Block To End:\n\n%s" wLINKBACK = "%s Points Back To Own Directory" +wMISSENDIF = "Configuration File Is Missing %s " + CONDENDIF +" Statement(s)" wNOCMDS = "Running With No Commands Defined!" wNOREBIND = "Ignoring Line %s.\nCannot Rebind This Keyboard Or Mouse Button Combination:\n\n%s" wREDEFVAR = "Ignoring Line %s.\nCannot Redefine Variable %s:\n\n%s" @@ -984,6 +985,11 @@ except: WrnMsg(wCONFOPEN % CONF) + MissingEndIfs = len(ConditionalStack) - 1 + + if MissingEndIfs: + WrnMsg(wMISSENDIF % str(MissingEndIfs)) + # Make sure any options we've changed are implemented if DoOptionsProcessing: ProcessOptions() @@ -1047,12 +1053,15 @@ # Legal conditional statements are in one of several forms: # - # .IF [SYMBOL] - # .IF [SYMBOL] == string - # .IF [SYMBOL]== string - # .IF [SYMBOL] ==string - # .IF [SYMBOL]==string - # .ENDIF + # .if [SYMBOL] + # .if [SYMBOL] == string OR .if [SYMBOL] != string + # .if [SYMBOL]== string OR .if [SYMBOL]!= string + # .if [SYMBOL] ==string OR .if [SYMBOL] !=string + # .if [SYMBOL]==string OR .if [SYMBOL]!=string + # .endif + + # Additionally, [SYMBOL] can also be an environment + # variable - [$SYMBOL] # Process conditional beginning-of-block statement @@ -1074,7 +1083,14 @@ cmpstr = x[1].strip() conditional = FALSE - if UI.SymTable.has_key(var) and UI.SymTable[var] == cmpstr: + + #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 @@ -1091,13 +1107,20 @@ cmpstr = x[1].strip() conditional = FALSE - if UI.SymTable.has_key(var) and UI.SymTable[var] != cmpstr: + + #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] + # Existence checks must be in the form: .if [VAR] if len(fields) != 2: WrnMsg(wBADIF % (num, line)) @@ -1105,10 +1128,19 @@ # Presume 2nd field is in the form: [VAR] - if UI.SymTable.has_key(fields[1][1:-1]): + var = fields[1][1:-1] + + conditional = FALSE + + # Handle references to Environment Variables + 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 - else: - conditional = FALSE + # Even if the current conditional is TRUE, we do not # process its contents if the *containing* scope is false.