diff --git a/tconfpy.py b/tconfpy.py index fe27a59..2e13be1 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.105 2004/03/12 00:58:52 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.106 2004/03/12 08:32:35 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -127,6 +127,7 @@ ########## dDEBUG = "DEBUG" +dLINEIGNORE = "%s Line %d Ignored/Not Included" dNUMLINES = "Processing '%s' Resulted In %d Total Lines Parsed" dPARSEDLINE = "%s Line %d Parses To: %s" @@ -134,8 +135,9 @@ # Error Messages ########### -eCONFOPEN = "Cannot Open The File '%s'" -eERROR = "ERROR" +eCONFOPEN = "Cannot Open The File '%s'" +eENDIFEXTRA = "%s Line %d: " + ENDIF + " Without Matching Condition" +eERROR = "ERROR" ########### @@ -147,7 +149,8 @@ # Warning Messages ########### -wWARNING = "WARNING" +wENDIFBAD = "%s Line %d: Text After " + ENDIF + " Ignored" +wWARNING = "WARNING" #--------------------------- Code Begins Here ---------------------------------# @@ -335,15 +338,43 @@ # Only attempt on non-blank lines if line: - # Substitute references to reserved symbols + # Process .endif statements before checking state since + # these potentially change the state. - for ref in Reserved.keys(): - line = line.replace("%s%s%s" % (DELIML, ref, DELIMR), Reserved[ref]) + if line.startswith(ENDIF): + + # This should be the only thing on the line + if line != ENDIF: + WarningMsg(wENDIFBAD % (cfgfile, linenum)) + + # Remove one level of nesting + CondStack.pop() + + # Error, if there are more .endifs than conditionals + if not CondStack: + ErrorMsg(eENDIFEXTRA % (cfgfile, linenum)) + CondStack.append(False) # Inhibit further parsing + + # If we are in a False conditional block, this line + # is ignored. + + print linenum, CondStack, line + if not CondStack[-1]: + if DEBUG: + DebugMsg(dLINEIGNORE %(cfgfile, linenum)) + return # Process .include statements if line.startswith(INCLUDE): + ParseFile(line.split(INCLUDE)[1].strip()) + return + + # Substitute references to reserved symbols + + for ref in Reserved.keys(): + line = line.replace("%s%s%s" % (DELIML, ref, DELIMR), Reserved[ref]) ##########