diff --git a/twander.py b/twander.py index 95f9126..c1c1f20 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.116 2003/03/01 00:04:05 tundra Exp $" +RCSID = "$Id: twander.py,v 3.117 2003/03/01 07:32:43 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -524,6 +524,7 @@ CONDENDIF = '.endif' CONDEQUAL = '==' CONDIF = '.if' +CONDNOTEQUAL = '!=' SYMOS = '.OS' SYMPLATFORM = '.PLATFORM' @@ -639,7 +640,7 @@ # Warnings wBADCFGLINE = "Ignoring Line %s.\nBogus Configuration Entry:\n\n%s" -wBADIF = "Ignoring Line %s.\nBogus Beginning-Of-Block Statement: \n\n%s" +wBADIF = "Ignoring Line %s.\nImproperly Formed Condition: \n\n%s" wBADDEBUG = "Ignoring Bogus Debug Level! - %s Is Not In Integer Or Hex Format." wBADENDIF = "Ignoring Line %s!\nBogus End-Of-Block Statement:\n\n%s" wBADENVVBL = "Ignoring Line %s.\nEnvironment Variable %s Not Set:\n\n%s" @@ -844,7 +845,8 @@ # Initialize internal parsing data structures linenum = 0 - ConditionalStack = [TRUE,] + ConditionalStack = [TRUE,] # This is a sentinel and guarantees there will + # will always be something in this stack # Load Symbol Table with predefined symbols @@ -1060,8 +1062,38 @@ if fields[0] == CONDIF: # Process string equality checks - if line.count('=='): - pass + if line.count(CONDEQUAL): + + x = line[len(CONDIF):].split(CONDEQUAL) + if len(x) != 2: + WrnMsg(wBADIF % (num, line)) + return + + else: + var = x[0].strip()[1:-1] + cmpstr = x[1].strip() + + conditional = FALSE + if UI.SymTable.has_key(var) and UI.SymTable[var] == cmpstr: + conditional = TRUE + + + # Process string inequality checks + elif line.count(CONDNOTEQUAL): + + x = line[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 + if UI.SymTable.has_key(var) and UI.SymTable[var] != cmpstr: + conditional = TRUE + # Process variable existence checks else: @@ -1078,17 +1110,12 @@ else: conditional = FALSE - # OK, now we save state of this conditional block - # If this is the first level of conditional, save it directly. + # 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. - if len(ConditionalStack) == 1: - ConditionalStack.append(conditional) - - # But, if we're nesting a conditional and the containing - # block is FALSE, so is the new block. - - else: - ConditionalStack.append(ConditionalStack[-1] and conditional) + ConditionalStack.append(ConditionalStack[-1] and conditional) # Process conditional end-of-block statement @@ -1101,7 +1128,7 @@ # The conditional stack must always have 1 value left in # it *after* all conditional processing. If it does not, - # it means there are more ENDIFs than IFs. + # it means there are more .endifs than .ifs. elif len(ConditionalStack) == 1: WrnMsg(wEXTRAENDIF % (num,line)) @@ -2731,17 +2758,23 @@ def KeySetSortParm(parm): global SORTBYFIELD, SORTREVERSE, SORTSEPARATE + refresh = FALSE + if parm == fREVERSE: SORTREVERSE = not SORTREVERSE + refresh = TRUE elif parm == fSEPARATE: SORTSEPARATE = not SORTSEPARATE + refresh = TRUE - else: + elif parm != SORTBYFIELD: SORTBYFIELD = parm + refresh = TRUE - LoadHelpMenu() - RefreshDirList() + if refresh: + LoadHelpMenu() + RefreshDirList() return 'break'