diff --git a/tconfpy.py b/tconfpy.py index 01d2873..3f025ed 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.121 2004/03/19 11:03:33 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.122 2004/03/19 22:41:17 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -225,14 +225,16 @@ eIFBAD = "'%s' Or '%s' Missing" % (EQUIV, NOTEQUIV) eNOVARREF = "Must Have At Least One Variable Reference" +eSTARTUP = "" # Messages Messages["eBADCOND"] = FILENUM + "Bad '%s' Directive. %s" Messages["eBADSYNTAX"] = FILENUM + "Syntax Error. Statement Not In Known Form" -Messages["eCONFOPEN"] = "Cannot Open The File '%s'" +Messages["eCONFOPEN"] = FILENUM + "Cannot Open The File '%s'" Messages["eENDIFEXTRA"] = FILENUM + "'" + ENDIF + "' Without Matching Condition" Messages["eENDIFMISS"] = FILENUM + "Missing %d '" + ENDIF + "' Statement(s)" +Messages["eEQUIVEXTRA"] = FILENUM + "Only a single '%s' Or '%s' Operator Permitted" % (EQUIV, NOTEQUIV) Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'" @@ -366,7 +368,7 @@ # Parse the file - ParseFile(cfgfile) + ParseFile(cfgfile, eSTARTUP, 0) # Return the parsing results @@ -440,15 +442,15 @@ # Parse A File ########## -def ParseFile(cfgfile): +def ParseFile(cfgfile, current_cfg, current_linenum): global IgnoreCase, MsgList, SymTable, TotalLines try: cf = open(cfgfile) - # Successful open of config file - Begin processing it + # Successful open of config file - Begin processing it linenum=0 # Process and massage the configuration file @@ -465,8 +467,7 @@ # File open failed for some reason except: - - ErrorMsg("eCONFOPEN", (cfgfile,)) # Record the error + ErrorMsg("eCONFOPEN", (current_cfg, current_linenum, cfgfile)) # Record the error # Make sure we had all condition blocks balanced with matching '.endif' @@ -537,7 +538,7 @@ # Only attempt the include if all the variable dereferencing was successful if ref_ok: - ParseFile(line) + ParseFile(line, cfgfile, linenum) ##### @@ -620,19 +621,46 @@ condstate = False ##### - # (In)Equality Conditionals - IF string ==/!= string forms + # (In)Equality Conditionals - IF string EQUIV/NOTEQUIV string forms ##### else: line = line.split(IF)[1].strip() - - # Handle Equality Form: ".IF string == string" - if EQUIV in line: - pass - # Handle InEquality Form: "IF string != string" - elif NOTEQUIV in line: - pass + if EQUIV in line or NOTEQUIV in line: + + # Only one operator permitted + if (line.count(EQUIV) + line.count(NOTEQUIV)) > 1: + ErrorMsg("eEQUIVEXTRA", (cfgfile, linenum)) + condstate = False + + else: + + # Dereference all variables + line, ref_ok = DerefVar(line, cfgfile, linenum) + + # Reference to undefined variables forces False + if not ref_ok: + condstate = False + + # So does a failure of the equality test itself + else: + invert = False + operator = EQUIV + condstate = True + + if operator not in line: # Must be NOTEQUIV + invert = True + operator = NOTEQUIV + + line = line.split(operator) + + if line[0].strip() != line[1].strip(): + condstate = False + + if invert: + condstate = not condstate + # Conditional Syntax Error else: