| |
---|
| | |
---|
| | # 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 |
---|
| | |
---|
| |
---|
| | eERROR = "ERROR" |
---|
| | |
---|
| | eIFBAD = "'%s' Or '%s' Missing" % (EQUIV, NOTEQUIV) |
---|
| | eNOVARREF = "Must Have At Least One Variable Reference" |
---|
| | eSTARTUP = "<Program Starting>" |
---|
| | |
---|
| | # 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'" |
---|
| | |
---|
| | |
---|
| | ########### |
---|
| |
---|
| | SymTable[sym] = symtbl[sym] |
---|
| | |
---|
| | # Parse the file |
---|
| | |
---|
| | ParseFile(cfgfile) |
---|
| | ParseFile(cfgfile, eSTARTUP, 0) |
---|
| | |
---|
| | # Return the parsing results |
---|
| | |
---|
| | if DEBUG: |
---|
| |
---|
| | ########## |
---|
| | # 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 |
---|
| | |
---|
| | linenum=0 |
---|
| | |
---|
| | # Process and massage the configuration file |
---|
| | for line in cf.read().splitlines(): |
---|
| |
---|
| | |
---|
| | |
---|
| | # 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' |
---|
| | |
---|
| | finalcond = len(CondStack) |
---|
| |
---|
| | line, ref_ok = DerefVar(line.split(INCLUDE)[1].strip(), cfgfile, linenum) |
---|
| | |
---|
| | # Only attempt the include if all the variable dereferencing was successful |
---|
| | if ref_ok: |
---|
| | ParseFile(line) |
---|
| | ParseFile(line, cfgfile, linenum) |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # Conditional Processing |
---|
| |
---|
| | # Force parse state to False on an error |
---|
| | 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: |
---|
| | ErrorMsg("eBADCOND", (cfgfile, linenum, FIRSTTOK, eIFBAD)) |
---|
| |
---|
| | |