diff --git a/tren.py b/tren.py index 4f2f053..9face03 100755 --- a/tren.py +++ b/tren.py @@ -8,7 +8,7 @@ PROGNAME = "tren.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tren.py,v 1.131 2010/01/30 22:10:13 tundra Exp $" +RCSID = "$Id: tren.py,v 1.132 2010/02/01 23:08:22 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -131,7 +131,8 @@ eBADARG = "Invalid command line: %s!" eBADINCL = "option %s requires argument" % INCL -eBOGUSLEN = "Bogus line length '%s'!" +eBADNEWOLD = "Bad -r argument '%s'! Requires exactly one new, old string separator (Default: " + RENSEP + ")" +eBADLEN = "Bad line length '%s'!" eERROR = "ERROR" eFILEOPEN = "Cannot open file '%s': %s!" eLINELEN = "Specified line length too short! Must be at least %s" % MINLEN @@ -504,6 +505,46 @@ # End of 'ErrorMsg()' +##### +# Split -r Argument Into Separate Old And New Strings +##### + +def GetOldNew(arg): + + + escaping = False + numseps = 0 + sepindex = 0 + + i = 0 + while i < len(arg): + + # Scan string ignoring escaped separators + + if arg[i:].startswith(RENSEP): + + if (i > 0 and (arg[i-1] != ESC)) or i == 0: + sepindex = i + numseps += 1 + + i += len(RENSEP) + + else: + i += 1 + + + if numseps != 1: + ErrorMsg(eBADNEWOLD % arg) + sys.exit(1) + + else: + old, new = arg[:sepindex], arg[sepindex + len(RENSEP):] + old = old.replace(ESC + RENSEP, RENSEP) + new = new.replace(ESC + RENSEP, RENSEP) + return [old, new] + +# End of 'GetOldNew()' + ##### # Parse Renaming Requests @@ -711,7 +752,7 @@ if opt == '-R': RENSEP = val if opt == "-r": - RenRequests.append(val.split(RENSEP)) + RenRequests.append(GetOldNew(val)) if opt == "-t": TESTMODE = True if opt == "-v": @@ -721,7 +762,7 @@ try: l = int(val) except: - ErrorMsg(eBOGUSLEN % val) + ErrorMsg(eBADLEN % val) sys.exit(1) if l < MINLEN: ErrorMsg(eLINELEN)