diff --git a/tconfpy.py b/tconfpy.py index 2b3f8b2..aa822dd 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.116 2004/03/14 21:03:36 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.117 2004/03/15 00:19:56 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -84,10 +84,12 @@ INCLUDE = CONDINTRO + "include" ENDIF = CONDINTRO + "endif" IF = CONDINTRO + "if" -IFNOT = CONDINTRO + "ifnot" +IFALL = IF + "all" +IFANY = IF + "any" +IFNONE = IF + "none" Reserved = ["DELIML", "DELIMR", "DOLLAR", "EQUAL", "EQUIV", "NOTEQUIV", - "HASH", "INCLUDE", "ENDIF", "IF", "IFNOT"] + "HASH", "INCLUDE", "ENDIF", "IF", "IFALL", "IFANY", "IFNONE"] # Regular Expressions @@ -100,9 +102,14 @@ # Literals ########### +# String Representations Of Booleans -TRUE = str(True) -FALSE = str(False) +sFALSE = "False" +sNO = "No" +sOFF = "Off" +sON = "On" +sTRUE = "True" +sYES = "Yes" #----------------------------------------------------------# @@ -214,6 +221,7 @@ wWARNING = "WARNING" +wEXTRATEXT = FILENUM + " '%s' Statements Only Process Variables. Extra Text Ignored" wTRAILING = FILENUM + " Trailing Text After '%s' Statement Ignored" @@ -383,7 +391,7 @@ ErrorMsg(eVARUNDEF % (cfgfile, linenum, sym)) ref_ok = False - + return line, ref_ok # End of 'DerefVar()' @@ -484,68 +492,110 @@ if line.startswith(INCLUDE): ParseFile(line.split(INCLUDE)[1].strip()) + ##### - # .if Processing + # Conditional Processing # # Must be one of the following forms - # - # .if string - # .ifnot string - # .if string == string - # .if string != string + # IFALL [var] ... + # IFANY [var] ... + # IFNONE [var] ... + # IF string == string + # IF string != string # # where string can be any concatentation of text and variable references # ##### - if line.startswith(IFNOT) or line.startswith(IF): + if line.startswith(IF): - # NOTE: This next bit of logic will fail if you do not - # test the longest of the tokens first!!!! - - if line.startswith(IFNOT): - line = line.split(IFNOT)[1].strip() - invert = True - else: - line = line.split(IF)[1].strip() - invert = False + # Since all conditional lines start with IF, + # test for this case last - i.e. test the for + # longest tokens first. - # Handle Equality Form: ".if string == string" - if line.count(EQUIV): - pass + ##### + # Existential Conditionals + ##### - # Handle InEquality Form: ".if string != string" - elif line.count(NOTEQUIV): - pass + if line.startswith(IFALL) or line.startswith(IFANY) or line.startswith(IFNONE): - # Handle Existential Forms ".if/.ifnot string" - else: + if line.startswith(IFALL): + IFTYPE = IFALL + line = line.split(IFALL)[1].strip() + + elif line.startswith(IFANY): + IFTYPE = IFANY + line = line.split(IFANY)[1].strip() + + else: + IFTYPE = IFNONE + line = line.split(IFNONE)[1].strip() # There must be at least one var reference in the condition - if len(VarRef.findall(line)) > 0: - # See if the variable(s) resolve - line, ref_ok = DerefVar(line, cfgfile, linenum, reporterr=False) + vars = VarRef.findall(line) + if len(vars) > 0: - # If we're using '.ifnot', invert the sense of the logic - if invert: - ref_ok = not ref_ok + # Only variable references are significant - warn on other text. - # Set parser state accordingly - if ref_ok: - line = TRUE - CondStack.append(True) - else: - line = FALSE - CondStack.append(False) + varlen = 0 + plain = line + for v in vars: + varlen += len(v) + plain.replace(v, "") + + if len(plain.strip()): + WarningMsg(wEXTRATEXT % (cfgfile, linenum, IFTYPE)) + + # Go see how many references actually resolve + + resolved = 0 + for v in vars: + v, ref_ok = DerefVar(v, cfgfile, linenum, reporterr=False) + if ref_ok: + resolved += 1 + + # And set state accordingly + + state = sTRUE + if IFTYPE == IFALL and len(vars) != resolved: + state = sFALSE + + if IFTYPE == IFANY and not resolved: + state = sFALSE + + if IFTYPE == IFNONE and resolved: + state = sFALSE + + CondStack.append(state) + line = state # Bogus conditional syntax else: ErrorMsg(eBADCOND % (cfgfile, linenum, eNOVARREF, orig)) + ##### + # (In)Equality Conditionals + ##### + + else: + line = line.split(IF)[1].strip() + + # Handle Equality Form: ".if string == string" + if line.count(EQUIV): + pass - line, ref_ok = DerefVar(line, cfgfile, linenum) + # Handle InEquality Form: ".if string != string" + elif line.count(NOTEQUIV): + pass + ##### + # Handle New Variable Declaration/Assignment + ##### + + else: + line, ref_ok = DerefVar(line, cfgfile, linenum) ########## @@ -558,6 +608,7 @@ if not line: DebugMsg(dLINEIGNORE % (cfgfile, linenum, orig, dBLANKLINE)) + # All non-blank lines noted here else: DebugMsg(dPARSEDLINE % (cfgfile, linenum, orig, line))