diff --git a/tconfpy.py b/tconfpy.py index 55d8fd8..0b56254 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.114 2004/03/14 09:57:13 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.115 2004/03/14 20:59:08 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -80,10 +80,11 @@ # Control and conditional symbols -INCLUDE = ".include" -ENDIF = ".endif" -IF = ".if" -IFNOT = ".ifnot" +CONDINTRO = '.' # Conditional introducer token +INCLUDE = CONDINTRO + "include" +ENDIF = CONDINTRO + "endif" +IF = CONDINTRO + "if" +IFNOT = CONDINTRO + "ifnot" Reserved = ["DELIML", "DELIMR", "DOLLAR", "EQUAL", "EQUIV", "NOTEQUIV", "HASH", "INCLUDE", "ENDIF", "IF", "IFNOT"] @@ -187,8 +188,9 @@ dDEBUG = "DEBUG" -dBLANKLINE = "(Parsed To Blank Line - Ignored)" -dLINEIGNORE = FILENUM + " Line Ignored/Not Included" + PTR + "'%s'\n" +dBLANKLINE = "Parsed To Blank Line - Ignored" +dLINEIGNORE = FILENUM + " '%s' " + PTR + "%s\n" +dNOTINCLUDE = "Line Ignored/Not Included" dNUMLINES = "Processing File '%s' Resulted In %d Total Lines Parsed" dPARSEDLINE = FILENUM + " '%s'" + PTR + "'%s'\n" @@ -357,7 +359,7 @@ # Dereference Variables ########## -def DerefVar(line, cfgfile, linenum): +def DerefVar(line, cfgfile, linenum, reporterr=True): # Find all symbols refrences and replace w/sym table entry if present @@ -370,7 +372,16 @@ # Reference to undefined variable else: - ErrorMsg(eVARUNDEF % (cfgfile, linenum, sym)) + # There are times a reference to an undefined variable + # should not produce and error message. For example, + # during existential conditional processing, we just + # want to check whether variables are defined or not. + # Attempts to reference undefined variables are legitimate + # in this case and ought not to generate an error message. + + if reporterr: + ErrorMsg(eVARUNDEF % (cfgfile, linenum, sym)) + ref_ok = False return line, ref_ok @@ -463,7 +474,7 @@ if not CondStack[-1]: if DEBUG: - DebugMsg(dLINEIGNORE % (cfgfile, linenum, orig)) + DebugMsg(dLINEIGNORE % (cfgfile, linenum, orig, dNOTINCLUDE)) return ##### @@ -487,10 +498,10 @@ # ##### - if line.startswith(IF) or line.startswith(IFNOT): + if line.startswith(IFNOT) or line.startswith(IF): # NOTE: This next bit of logic will fail if you do not - # test the longer of the two tokens first!!!! + # test the longest of the tokens first!!!! if line.startswith(IFNOT): line = line.split(IFNOT)[1].strip() @@ -503,6 +514,10 @@ if line.count(EQUIV): pass + # Handle InEquality Form: ".if string != string" + elif line.count(NOTEQUIV): + pass + # Handle Existential Forms ".if/.ifnot string" else: @@ -510,7 +525,7 @@ if len(VarRef.findall(line)) > 0: # See if the variable(s) resolve - line, ref_ok = DerefVar(line, cfgfile, linenum) + line, ref_ok = DerefVar(line, cfgfile, linenum, reporterr=False) # If we're using '.ifnot', invert the sense of the logic if invert: @@ -528,6 +543,7 @@ else: ErrorMsg(eBADCOND % (cfgfile, linenum, eNOVARREF, orig)) + line, ref_ok = DerefVar(line, cfgfile, linenum) @@ -540,9 +556,12 @@ # Note blank lines for debug purposes if not line: - line = dBLANKLINE + DebugMsg(dLINEIGNORE % (cfgfile, linenum, orig, dBLANKLINE)) - DebugMsg(dPARSEDLINE % (cfgfile, linenum, orig, line)) + else: + DebugMsg(dPARSEDLINE % (cfgfile, linenum, orig, line)) + + # End of 'ParseLine'