Rewrote the existential conditional code so that variable names and
references are treated consistently with the rest of the program.
1 parent 94c68a7 commit 25587fa97771281b0c9ce2f460f4d994b324f00b
@tundra tundra authored on 16 Apr 2004
Showing 1 changed file
View
103
tconfpy.py
 
# 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
 
 
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 = "<Program Starting>"
 
# Error Messages
 
 
else:
line = line.split(IFNONE)[1].strip()
 
# There must be at least one var reference in the condition
 
vars = VarRef.findall(line)
 
# Only variable references are significant - warn on other text.
 
# Strip out variable references and see if anything
# other than whitespace is left.
 
plain = line
if vars:
for v in vars:
plain=plain.replace(v, "")
 
# 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
 
# Dereference any variables
 
line, ref_ok = DerefVar(line, cfgfile, linenum)
 
if ref_ok:
 
vars = line.split()
 
# 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
 
#####
# (In)Equality Conditionals - IF string EQUIV/NOTEQUIV string forms