diff --git a/tconfpy.py b/tconfpy.py index 144d979..085a3ad 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.177 2004/04/16 20:23:22 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.178 2004/04/16 23:59:45 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -290,10 +290,11 @@ eBADDEFAULT = "Type Of Default Value Does Not Agree With Type Declared" eBADLEGALVAL = "Type Of One Or More LegalVals Does Not Agree With Type Declared" eBADMINMAX = "Type Of Min Or Max Value Not Appropriate For" +eBADVARREF = "Attempt To Get Value Of Non-Existent Variable" eIFBAD = "'%s' Or '%s' Missing" % (EQUIV, NOTEQUIV) eLEGALVALLIST = "The LegalVal Attribute Is Wrong Type (Must Be A List)" eNOTDESCRIPT = "Invalid Descriptor Type" -eNOVARREF = "Must Have At Least One Variable Reference" +eNOVARS = "This Conditional Requires At Least One Variable Name To Test" eSTARTUP = "" # Error Messages @@ -913,54 +914,51 @@ else: line = line.split(IFNONE)[1].strip() - # There must be at least one var reference in the condition - vars = VarRef.findall(line) + # Dereference any variables - # Only variable references are significant - warn on other text. + line, ref_ok = DerefVar(line, cfgfile, linenum) - # Strip out variable references and see if anything - # other than whitespace is left. + if ref_ok: - plain = line - if vars: - for v in vars: - plain=plain.replace(v, "") + vars = line.split() - # Only arguments that are allowed are variable references - if len(plain.strip()): - ErrorMsg("eIFEXTRATXT", (cfgfile, linenum, FIRSTTOK)) - condstate = False - - if vars: - - # Only do this if the syntax check above was OK - if condstate: - - # Go see how many references actually resolve - - resolved = 0 + # There has to be at least one variable named + if vars: + numexist = 0 + + # Iterate through all named variables to see if they exist for v in vars: - v, ref_ok = DerefVar(v, cfgfile, linenum, reporterr=False) - if ref_ok: - resolved += 1 + + # Handle environment variables + if v[0] == ENVIRO: + if v in os.environ: + numexist += 1 + + # Handle local local variables + if v in SymTable: + numexist += 1 # And set the conditional state accordingly - if FIRSTTOK == IFALL and len(vars) != resolved: + if FIRSTTOK == IFALL and numexist != len(vars): condstate = False - if FIRSTTOK == IFANY and not resolved: + if FIRSTTOK == IFANY and numexist == 0: condstate = False - if FIRSTTOK == IFNONE and resolved: + if FIRSTTOK == IFNONE and numexist != 0: condstate = False - # Bogus conditional syntax - no variable refs found + # Bogus conditional syntax - no variables named + else: + ErrorMsg("eBADCOND", (cfgfile, linenum, FIRSTTOK, eNOVARS)) + condstate = False + + + # Bogus conditional syntax - tried to reference non-existent variable else: - ErrorMsg("eBADCOND", (cfgfile, linenum, FIRSTTOK, eNOVARREF)) - - # Force parse state to False on an error + ErrorMsg("eBADCOND", (cfgfile, linenum, FIRSTTOK, eBADVARREF)) condstate = False #####