diff --git a/tconfpy.py b/tconfpy.py index 2475143..b43ce9c 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.147 2004/03/25 10:43:45 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.148 2004/03/27 00:56:25 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -91,8 +91,13 @@ # Regular Expressions -reVARREF = r"\%s.+?\%s" % (DELIML, DELIMR) # Variable reference -VarRef = re.compile(reVARREF) +reVARWHITE = r".*\s+.*" +reVARILLEGAL = r"\%s(%s)%s" % (DELIML, reVARWHITE, DELIMR) # Variable reference with spaces in it +reVARREF = r"\%s.+?\%s" % (DELIML, DELIMR) # Variable reference + +VarWhite = re.compile(reVARWHITE) +VarIllegal = re.compile(reVARILLEGAL) +VarRef = re.compile(reVARREF) ########### @@ -248,6 +253,8 @@ Messages["eSTRINGSHORT"] = FILENUM + "Right-Hand-Side, '%s' Shorter Than Min Allowed Length, %s, For Variable '%s'" Messages["eTYPEBAD"] = FILENUM + "Type Mismatch. '%s' Must Be Assigned Values Of Type %s Only" Messages["eVALLARGE"] = FILENUM + "%s Is Larger Than The Maximum Allowed, %s, For Variable '%s'" +Messages["eVARNAMESPC"] = FILENUM + "Variable Names May Not Contain Whitespace" +Messages["eVARNONAME"] = FILENUM + "Variable Name Evaluates To Null String. Not Permitted" Messages["eVALSMALL"] = FILENUM + "%s Is Smaller Than The Minimum Allowed, %s, For Variable '%s'" Messages["eVARREADONLY"] = FILENUM + "Variable '%s' Is Read-Only. Cannot Change Its Value" Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'" @@ -675,7 +682,9 @@ # Namespace Processing ##### - if line == DELIML+DELIMR or (len(VarRef.findall(line)) == 1 and line[0] == DELIML and line[-1] == DELIMR): + if line == DELIML+DELIMR or (len(VarRef.findall(line)) == 1 and \ + line[0] == DELIML and line[-1] == DELIMR and\ + line.count(DELIML) == line.count(DELIMR) == 1): if not CondStack[-1]: if DEBUG: @@ -872,7 +881,7 @@ ##### - # Handle New Variable Declaration/Assignment + # Handle Variable Declaration/Assignment ##### # If we got here it means that none of the conditional forms @@ -886,7 +895,18 @@ DebugMsg("dLINEIGNORE", (cfgfile, linenum, orig, dNOTINCLUDE)) return + # Catch attempts to use whitespace within variable names or references + if VarIllegal.findall(line) or VarWhite.findall(line.split(EQUAL)[0].strip()): + ErrorMsg("eVARNAMESPC", (cfgfile, linenum)) + return + + # Catch attempts to dereference without name + + if line.count(DELIML + DELIMR): + ErrorMsg("eVARNONAME", (cfgfile, linenum)) + return + # Do any necessary variable dereferencing line, ref_ok = DerefVar(line, cfgfile, linenum) @@ -899,10 +919,14 @@ r = line[e+1:].strip() + # Suppress attempts to set null-named variables + + if not l: + ErrorMsg("eVARNONAME", (cfgfile, linenum)) + # Suppress any attempt to change a RO variable - if l in SymTable and not SymTable[l].Writeable: - + elif l in SymTable and not SymTable[l].Writeable: ErrorMsg("eVARREADONLY", (cfgfile, linenum, l)) # Load variable into the symbol table