diff --git a/tconfpy.py b/tconfpy.py index 7c7ea58..3300bb9 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.140 2004/03/25 00:18:44 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.141 2004/03/25 00:52:31 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -238,7 +238,11 @@ Messages["eIFEXTRATXT"] = FILENUM + "Extra Text On Line. '%s' Only Accepts Variable References As Arguments" Messages["eVARREADONLY"] = FILENUM + "Variable '%s' Is Read-Only. Cannot Change Its Value" Messages["eRESERVED"] = FILENUM + "Cannot Modify Value Of Reserved Symbol '%s'" +Messages["eSTRINGLONG"] = FILENUM + "String '%s' Longer Than Max Allowed Length, %d" +Messages["eSTRINGSHORT"] = FILENUM + "String '%s' Shorter Than Min Allowed Length, %d" Messages["eTYPEBAD"] = FILENUM + "Type Mismatch. '%s' Must Be Assigned Values Of Type %s Only" +Messages["eVALSMALL"] = FILENUM + "%d Is Smaller Than The Minimum Allowed, %d" +Messages["eVALLARGE"] = FILENUM + "%d Is Larger Than The Maximum Allowed, %d" Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'" @@ -855,6 +859,12 @@ # Otherwise, update an existing entry else: + update = True + des = SymTable[l] + typ = des.Type + lv = des.LegalVals + low = des.Min + up = des.Max # Type Enforcement # We try to coerce the new value into @@ -863,8 +873,6 @@ # and do nothing. try: - typ = SymTable[l].Type - # Booleans are a special case - we accept only # a limited number of strings on the RHS @@ -876,10 +884,38 @@ r = typ(r) except: + update = False ErrorMsg("eTYPEBAD", (cfgfile, linenum, l, str(typ).split()[1][:-1])) - # Finally, we can save the new variable - SymTable[l].Value = r + + # Check bounds for interger and floats + + if typ in (TYPE_FLOAT, TYPE_INT): + + if low and r < low: + ErrorMsg("eVALSMALL", (cfgfile, linenum, r, low)) + update = False + + if up and r > up: + ErrorMsg("eVALLARGE", (cfgfile, linenum, r, up)) + update = False + + # Check bounds for strings - these are min/max string lengths, if present + + if typ == TYPE_STRING: + + if low and len(r) < low: + ErrorMsg("eSTRINGSHORT", (cfgfile, linenum, r, low)) + update = False + + if up and len(r) > up: + ErrorMsg("eSTRINGLONG", (cfgfile, linenum, r, up)) + update = False + + + # Update variable if all tests passed + if update: + SymTable[l].Value = r ##### # Line Format Is Not In One Of The Recognized Forms - Syntax Error