diff --git a/tconfpy.py b/tconfpy.py index e94d9ba..43a6cf9 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.161 2004/04/06 19:50:17 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.162 2004/04/07 00:10:37 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -138,6 +138,7 @@ #----------------------------------------------------------# +ALLOWNEW = True # Allow new variable creation in cfg file DEBUG = False # Control Debug output LITERALVARS = False INLITERAL = False # Indicates we are currently in a literal block @@ -302,6 +303,7 @@ Messages["eVALSMALL"] = FILENUM + "%s Is Smaller Than The Minimum Allowed, %s, For Variable '%s'" Messages["eVARRESERVED"] = FILENUM + "Variable Name Cannot Begin With The '%s' Symbol" Messages["eVARNAMESPC"] = FILENUM + "Variable Names May Not Contain Whitespace" +Messages["eVARNEW"] = FILENUM + "New Variable Creation Not Permitted" Messages["eVARNONAME"] = FILENUM + "Variable Name Evaluates To Null String. Not Permitted" Messages["eVARREADONLY"] = FILENUM + "Variable '%s' Is Read-Only. Cannot Change Its Value" Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'" @@ -397,13 +399,14 @@ # Public API To Module # #----------------------------------------------------------# -def ParseConfig(cfgfile, InitialSymTbl={}, Debug=False, LiteralVars=False): +def ParseConfig(cfgfile, InitialSymTbl={}, AllowNewVars=True, Debug=False, LiteralVars=False): global DebugMsgs, ErrMsgs, WarnMsgs, LiteralLines - global CondStack, DEBUG, SymTable, TotalLines, LITERALVARS, INLITERAL + global CondStack, ALLOWNEW, DEBUG, SymTable, TotalLines, LITERALVARS, INLITERAL # Initialize the globals + ALLOWNEW = AllowNewVars DEBUG = Debug LITERALVARS = LiteralVars @@ -1073,9 +1076,16 @@ # create the new entry if l not in SymTable: - d.Default = r - d.Value = r - SymTable[l] = d + + # Only do this if new variable creation allowed + if ALLOWNEW: + d.Default = r + d.Value = r + SymTable[l] = d + + # New vars not allowed + else: + ErrorMsg("eVARNEW", (cfgfile, linenum)) # Otherwise, update an existing entry. # For existing entries we have to first