Corrected logic to check for extraneous text on IFALL, IFANY, IFNONE lines.
Added code to enforce a space after any conditional or directive token.
1 parent 8769dfe commit 728c730b4b490e434b609f32f547e3f8e379117f
@tundra tundra authored on 15 Mar 2004
Showing 1 changed file
View
89
tconfpy.py
 
# Program Information
 
PROGNAME = "tconfpy"
RCSID = "$Id: tconfpy.py,v 1.117 2004/03/15 00:19:56 tundra Exp $"
RCSID = "$Id: tconfpy.py,v 1.118 2004/03/16 03:18:19 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
# Error Messages
###########
 
eERROR = "ERROR"
 
eBADCOND = FILENUM + " Bad Conditional Expression - %s: '%s'"
eSYNTAX = "Incorrect '%s' Syntax"
 
eBADEXPR = FILENUM + " Bad Expression - %s: '%s'"
eCONFOPEN = "Cannot Open The File '%s'"
eENDIFEXTRA = FILENUM + " '" + ENDIF + "' Without Matching Condition"
eENDIFBAD = eSYNTAX % ENDIF
eENDIFMISS = FILENUM + " Missing %d '" + ENDIF + "' Statement(s)"
eIFBAD = eSYNTAX % IF
eINCLBAD = eSYNTAX % INCLUDE
eNOVARREF = "Must Have At Least One Variable Reference"
eVARUNDEF = FILENUM + " " + "Attempt To Reference Undefined Variable '%s'"
 
 
 
# Only attempt on non-blank lines
if line:
 
# Get first token on the line
FIRSTTOK = line.split()[0]
 
#####
# .endif Processing - Must be done before state check
# because .endif can change state
#####
# because .endif can change parser state
#####
 
if line.startswith(ENDIF):
 
# Check for space after conditional
if line.split()[0] != ENDIF:
ErrorMsg(eBADEXPR % (cfgfile, linenum, eENDIFBAD, orig))
 
# This should be the only thing on the line
if line != ENDIF:
elif line != ENDIF:
WarningMsg(wTRAILING % (cfgfile, linenum, ENDIF))
 
# Remove one level of nesting
CondStack.pop()
# .include Processing
#####
 
if line.startswith(INCLUDE):
ParseFile(line.split(INCLUDE)[1].strip())
 
# Make sure a space follows the directive
if line.split()[0] != INCLUDE:
ErrorMsg(eBADEXPR % (cfgfile, linenum, eINCLBAD, orig))
 
else:
ParseFile(line.split(INCLUDE)[1].strip())
 
 
#####
# Conditional Processing
# where string can be any concatentation of text and variable references
#
#####
 
if line.startswith(IF):
 
# Since all conditional lines start with IF,
# test for this case last - i.e. test the for
# longest tokens first.
 
# Is it any of the IF forms?
 
if FIRSTTOK.startswith(IF):
 
IFTYPE = FIRSTTOK
#####
# Existential Conditionals
#####
 
if line.startswith(IFALL) or line.startswith(IFANY) or line.startswith(IFNONE):
 
if line.startswith(IFALL):
IFTYPE = IFALL
if IFTYPE in (IFALL, IFANY, IFNONE):
 
if IFTYPE == IFALL:
line = line.split(IFALL)[1].strip()
 
elif line.startswith(IFANY):
IFTYPE = IFANY
elif IFTYPE == IFANY:
line = line.split(IFANY)[1].strip()
 
else:
IFTYPE = IFNONE
line = line.split(IFNONE)[1].strip()
 
# There must be at least one var reference in the condition
 
if len(vars) > 0:
 
# Only variable references are significant - warn on other text.
 
varlen = 0
# Strip out variable references and see if anything
# other than whitespace is left.
plain = line
for v in vars:
varlen += len(v)
plain.replace(v, "")
plain=plain.replace(v, "")
 
if len(plain.strip()):
WarningMsg(wEXTRATEXT % (cfgfile, linenum, IFTYPE))
 
line = state
 
# Bogus conditional syntax
else:
ErrorMsg(eBADCOND % (cfgfile, linenum, eNOVARREF, orig))
ErrorMsg(eBADEXPR % (cfgfile, linenum, eNOVARREF, orig))
 
#####
# (In)Equality Conditionals
#####
else:
# Check for IF followed by mandatory whitespace
elif line.split()[0] == IF:
line = line.split(IF)[1].strip()
# Handle Equality Form: ".if string == string"
if line.count(EQUIV):
# Handle InEquality Form: ".if string != string"
elif line.count(NOTEQUIV):
pass
 
#####
# Line Started With IF, But Was Not In Any Knwon IF Form
#####
 
else:
ErrorMsg(eBADEXPR % (cfgfile, linenum, eIFBAD, orig))
 
#####
# Handle New Variable Declaration/Assignment
#####