diff --git a/tconfpy.py b/tconfpy.py index 3cabc1b..b93b56c 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.125 2004/03/21 13:07:50 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.126 2004/03/21 14:00:18 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -103,6 +103,9 @@ ("Yes", True), ("No", False), ("On", True), ("Off", False)) +sFALSE = "False" +sTRUE = "True" + #----------------------------------------------------------# @@ -110,8 +113,9 @@ #----------------------------------------------------------# -DEBUG = False # Control Debug output -IGNORECASE = False # Case observed by default +DEBUG = False # Control Debug output +LITERALVARS = False +INLITERAL = False # Indicates we are currently in a literal block DebugMsg = [] # Place to store and return debug info ErrMsgs = [] # Place to store and return errors @@ -225,7 +229,7 @@ Messages["eBADSYNTAX"] = FILENUM + "Syntax Error. Statement Not In Known Form" Messages["eCONFOPEN"] = FILENUM + "Cannot Open The File '%s'" Messages["eENDIFEXTRA"] = FILENUM + "'" + ENDIF + "' Without Matching Condition" -Messages["eENDIFMISS"] = FILENUM + "Missing %d '" + ENDIF + "' Statement(s)" +Messages["eENDIFMISS"] = FILENUM + "Missing %d" + " '%s' " % 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'" @@ -240,8 +244,9 @@ # Messages -Messages["wEXTRATEXT"] = FILENUM + " '%s' Statements Only Process Variables. Extra Text Ignored" -Messages["wTRAILING"] = FILENUM + " Trailing Text After '%s' Statement Ignored" +Messages["wENDLITMISS"] = FILENUM + "Missing '%s' Statement. All lines treated literally to end-of-file." % ENDLITERAL +Messages["wEXTRATEXT"] = FILENUM + " '%s' Statements Only Process Variables. Extra Text Ignored" +Messages["wTRAILING"] = FILENUM + " Trailing Text After '%s' Statement Ignored" # Determine Length Of Longest Message Type @@ -335,16 +340,15 @@ # Public API To Module # #----------------------------------------------------------# -def ParseConfig(cfgfile, InitialSymTbl={}, IgnoreCase=False, debug=False, LiteralVars=False): +def ParseConfig(cfgfile, InitialSymTbl={}, Debug=False, LiteralVars=False): global DebugMsgs, ErrMsgs, WarnMsgs, LiteralLines - global CondStack, DEBUG, IGNORECASE, SymTable, TotalLines + global CondStack, DEBUG, SymTable, TotalLines, LITERALVARS, INLITERAL # Initialize the globals - DEBUG = debug - IGNORECASE = IgnoreCase - + DEBUG = Debug + LITERALVARS = LiteralVars DebugMsgs = [] ErrMsgs = [] @@ -468,6 +472,10 @@ if finalcond != 1: ErrorMsg("eENDIFMISS", (cfgfile, linenum, finalcond-1)) + # Make sure we ended any literal processing properly + if INLITERAL: + WarningMsg("wENDLITMISS", (cfgfile, linenum)) + # End of 'ParseFile()' @@ -477,7 +485,7 @@ def ParseLine(line, cfgfile, linenum): - global CondStack, MsgList, SymTable + global CondStack, MsgList, SymTable, INLITERAL orig = line # May need copy of original for debug output line = ConditionLine(line) @@ -490,6 +498,40 @@ # Only attempt on non-blank lines if line: + ##### + # LITERAL and ENDLITERAL Processing + # These get highest precedence because they block everything else. + ##### + + if line in (LITERAL, ENDLITERAL): + + if line == LITERAL: + INLITERAL = True + + else: + INLITERAL = False + + + if DEBUG: + DebugMsg("dPARSEDLINE", (cfgfile, linenum, orig, line)) + + return + + # We pass lines as-is, with optional variable replacement, in literal blocks + + if INLITERAL: + + if LITERALVARS: + line, ref_ok = DerefVar(line, cfgfile, linenum) + + LiteralLines.append(line) + + if DEBUG: + DebugMsg("dPARSEDLINE", (cfgfile, linenum, orig, line)) + + return + + # Get first token on the line FIRSTTOK = line.split()[0] @@ -671,8 +713,6 @@ if not condstate: line = sFALSE - - ##### # Handle New Variable Declaration/Assignment