Implemented logic to catch unknown renaming token types.
Slight edits to token-related error messages.
1 parent 56b4571 commit 785594f6b31c7193fea525535362f67cf42fbd90
@tundra tundra authored on 5 Mar 2010
Showing 1 changed file
View
12
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.167 2010/03/06 01:18:02 tundra Exp $"
RCSID = "$Id: tren.py,v 1.168 2010/03/06 01:25:46 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
eBADINCL = "option -%s requires argument" % INCL
eBADINSTANCE = "%s is an invalid replacement instance! Must be integer values in the form: n, n:n, :n, n:, or :"
eBADLEN = "Bad line length '%s'!"
eBADNEWOLD = "Bad -r argument '%s'! Requires exactly one new, old string separator (Default: " + DEFSEP + ")"
eBADRENAMETOK = "Renaming token missing delimiter: %s"
eBADREGEX = "Invalid Regular Expression: %s"
eERROR = "ERROR"
eEXECFAIL = "Command: '%s' Failed To Execute!"
eFILEOPEN = "Cannot open file '%s': %s!"
eNAMELONG = "Renaming '%s' to new name '%s' too long! (Maximum length is %s.)"
eNAMESHORT = "Renaming '%s' to new name '%s' too short! (Minimum length is %s.)"
eNULLARG = "%s cannot be empty!"
eRENAMEFAIL = "Attempt to rename '%s' to '%s' failed : %s!"
eTOKDELIM = "Renaming token '%s' missing delimiter!"
eTOKUNKNOWN = "Renaming Token '%s' is unknown type!"
eTOOMANYINC = "Too many includes! (Max is %d) Possible circular reference?" % MAXINCLUDES
 
 
#####
# There must be an even number of token delimiters
# or the renaming token is malformed
if rentokens and len(rentokens[-1]) != 2:
ErrorMsg(eBADRENAMETOK % renstring)
ErrorMsg(eTOKDELIM % renstring)
 
# Now add the renaming token contents. This will be used to
# figure out what the replacement text should be.
 
# Otherwise swap the command with its results, stripping newlines
else:
r[2] = output.replace("\n", "")
 
# Unrecognized renaming token
else:
ErrorMsg(eTOKUNKNOWN % r[2])
# Do the actual replacement
 
renstring = renstring[:r[0]] + r[2] + renstring[r[1]+1:]