Extraneous text on IFALL/ANY/NONE lines now generates error and sets
condition to False.  This was done for semantic consistency with other
directives.
Fixed bug that was causing malformed ENDIF lines to not be reported as an error.
1 parent 3ab0818 commit 330769d23674b19989d6a5d52057c87eb01a6e52
@tundra tundra authored on 24 Mar 2004
Showing 1 changed file
View
60
tconfpy.py
 
# Program Information
 
PROGNAME = "tconfpy"
RCSID = "$Id: tconfpy.py,v 1.130 2004/03/22 17:56:10 tundra Exp $"
RCSID = "$Id: tconfpy.py,v 1.131 2004/03/24 08:47:55 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
Messages["eCONFOPEN"] = FILENUM + "Cannot Open The File '%s'"
Messages["eENDIFEXTRA"] = FILENUM + "'" + ENDIF + "' Without Matching Condition"
Messages["eENDIFMISS"] = FILENUM + "Missing %d" + " '%s' " % ENDIF + " Statement(s)"
Messages["eEQUIVEXTRA"] = FILENUM + "Only a single '%s' Or '%s' Operator Permitted" % (EQUIV, NOTEQUIV)
Messages["eIFEXTRATXT"] = FILENUM + "Extra Text On Line. '%s' Only Accepts Variable References As Arguments"
Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'"
 
 
###########
# Messages
 
Messages["wENDLITMISS"] = FILENUM + "Missing '%s' Statement. All lines treated literally to end-of-file" % ENDLITERAL
Messages["wENDLITEXTRA"] = FILENUM + "'%s' Statement Without Preceding '%s'. Statement Ignored" % (ENDLITERAL, LITERAL)
Messages["wEXTRATEXT"] = FILENUM + " '%s' Statements Only Process Variables. Extra Text Ignored"
Messages["wLITEXTRA"] = FILENUM + "Already In A Literal Block. '%s' Statement Ignored" % LITERAL
 
 
# Determine Length Of Longest Message Type
ErrMsgs = []
WarnMsgs = []
LiteralLines = []
 
CondStack = [True,]
CondStack = [True,] # Always has one entry as a sentinel
TotalLines = 0
 
# Add any passed symbols to the SymbolTable
 
 
# Error, if there are more .endifs than conditionals
if not CondStack:
ErrorMsg("eENDIFEXTRA", (cfgfile, linenum))
CondStack.append(False) # Inhibit further parsing
CondStack.append(False) # Restore sentinel & inhibit further parsing
 
#####
# Check State Of Parser
#####
 
# Only attempt the include if all the variable dereferencing was successful
if ref_ok:
ParseFile(line, cfgfile, linenum)
 
 
#####
# Conditional Processing
#
if vars:
for v in vars:
plain=plain.replace(v, "")
 
# Only arguments that are allowed are variable references
if len(plain.strip()):
WarningMsg("wEXTRATEXT", (cfgfile, linenum, FIRSTTOK))
 
ErrorMsg("eIFEXTRATXT", (cfgfile, linenum, FIRSTTOK))
condstate = False
if vars:
 
# Go see how many references actually resolve
resolved = 0
for v in vars:
v, ref_ok = DerefVar(v, cfgfile, linenum, reporterr=False)
if ref_ok:
resolved += 1
 
# And set the conditional state accordingly
 
if FIRSTTOK == IFALL and len(vars) != resolved:
condstate = False
 
if FIRSTTOK == IFANY and not resolved:
condstate = False
 
if FIRSTTOK == IFNONE and resolved:
condstate = False
# Only do this if the syntax check above was OK
if condstate:
 
# Go see how many references actually resolve
 
resolved = 0
for v in vars:
v, ref_ok = DerefVar(v, cfgfile, linenum, reporterr=False)
if ref_ok:
resolved += 1
 
# And set the conditional state accordingly
 
if FIRSTTOK == IFALL and len(vars) != resolved:
condstate = False
 
if FIRSTTOK == IFANY and not resolved:
condstate = False
 
if FIRSTTOK == IFNONE and resolved:
condstate = False
 
# Bogus conditional syntax - no variable refs found
else:
ErrorMsg("eBADCOND", (cfgfile, linenum, FIRSTTOK, eNOVARREF))
# processing above falls through to here as well. We ignore
# it because any problems with these directives have already been
# handled.
 
elif FIRSTTOK not in (ENDIF, INCLUDE):
elif line != ENDIF and FIRSTTOK != INCLUDE:
ErrorMsg("eBADSYNTAX", (cfgfile, linenum))