diff --git a/tconfpy.py b/tconfpy.py index e785498..55d8fd8 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.113 2004/03/14 09:04:52 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.114 2004/03/14 09:57:13 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -83,9 +83,10 @@ INCLUDE = ".include" ENDIF = ".endif" IF = ".if" +IFNOT = ".ifnot" Reserved = ["DELIML", "DELIMR", "DOLLAR", "EQUAL", "EQUIV", "NOTEQUIV", - "HASH", "INCLUDE", "ENDIF", "IF"] + "HASH", "INCLUDE", "ENDIF", "IF", "IFNOT"] # Regular Expressions @@ -197,10 +198,11 @@ eERROR = "ERROR" -eBADCOND = FILENUM + " Badly Formed Conditional Expression: '%s'" +eBADCOND = FILENUM + " Bad Conditional Expression - %s: '%s'" eCONFOPEN = "Cannot Open The File '%s'" eENDIFEXTRA = FILENUM + " '" + ENDIF + "' Without Matching Condition" eENDIFMISS = FILENUM + " Missing %d '" + ENDIF + "' Statement(s)" +eNOVARREF = "Must Have At Least One Variable Reference" eVARUNDEF = FILENUM + " " + "Attempt To Reference Undefined Variable '%s'" @@ -477,40 +479,44 @@ # Must be one of the following forms - # # .if string + # .ifnot string # .if string == string # .if string != string # + # where string can be any concatentation of text and variable references + # ##### - if line.startswith(IF): - line = line.split(IF)[1].strip() + if line.startswith(IF) or line.startswith(IFNOT): + + # NOTE: This next bit of logic will fail if you do not + # test the longer of the two tokens first!!!! + + if line.startswith(IFNOT): + line = line.split(IFNOT)[1].strip() + invert = True + else: + line = line.split(IF)[1].strip() + invert = False # Handle Equality Form: ".if string == string" if line.count(EQUIV): pass - # Handle Inequality Form: ".if string != string" - elif line.count(NOTEQUIV): - pass - - # Handle Existential Form: ".if string" + # Handle Existential Forms ".if/.ifnot string" else: - # Must be in form: ".if [var]" - trailing garbage ignored + # There must be at least one var reference in the condition + if len(VarRef.findall(line)) > 0: - chk = VarRef.findall(line) - if line[0] == DELIML and len(chk) > 0: - - # Warn if there was trailing garbage - if len(line) != len(chk[0]): - WarningMsg(wTRAILING % (cfgfile, linenum, IF + " " + chk[0])) - - # And condition the line to only contain the variable reference - line = chk[0] - - # Now see if the variable resolved and set state accordingly - + # See if the variable(s) resolve line, ref_ok = DerefVar(line, cfgfile, linenum) + + # If we're using '.ifnot', invert the sense of the logic + if invert: + ref_ok = not ref_ok + + # Set parser state accordingly if ref_ok: line = TRUE CondStack.append(True) @@ -520,8 +526,7 @@ # Bogus conditional syntax else: - ErrorMsg(eBADCOND % (cfgfile, linenum, orig)) - + ErrorMsg(eBADCOND % (cfgfile, linenum, eNOVARREF, orig)) line, ref_ok = DerefVar(line, cfgfile, linenum)