diff --git a/tren.py b/tren.py index 8451806..8ae95a8 100755 --- a/tren.py +++ b/tren.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tren.py" -RCSID = "$Id: tren.py,v 1.107 2010/01/23 01:12:16 tundra Exp $" +RCSID = "$Id: tren.py,v 1.108 2010/01/25 22:21:26 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -138,6 +138,11 @@ TESTMODE = False +# Global data structures + +COMMANDLINES = [] # Stores "options... targets" from command line + + #--------------------------- Code Begins Here ---------------------------------# @@ -265,7 +270,11 @@ # # 2) Resolving any include file references # -# 3) Building the data structures that depend on the file/dir names +# 3) Separating the command line into [options ... filenames ..] +# groupings so that user can interweave multiple options +# and names on the command line. +# +# 4) Building the data structures that depend on the file/dir names # specified for renaming. We have to do this first, because # -r renaming operations specified on the command line will # need this information if they make use of renaming tokens. @@ -301,6 +310,7 @@ file = OPTIONS[i+1] ; lhs = OPTIONS[:i] ; rhs = OPTIONS[i+2:] # Keep track of- and limit the number of includes allowed + # This is an easy way to stop circular (infinite) includes. NUMINCLUDES += 1 if NUMINCLUDES >= MAXINCLUDES: @@ -325,51 +335,85 @@ sys.exit(1) -# Now process the command line options +# Break command line into "option ... targets ..." pairs. -try: - opts, args = getopt.getopt(OPTIONS, '1abbCcdEefghl:qr:tvXx]') -except getopt.GetoptError as e: - ErrorMsg(eBADARG % e.args[0]) - sys.exit(1) -for opt, val in opts: +DOINGOPTS = True +cmd = [] - if opt == "-1": - GLOBAL = False - if opt == "-a": - TARGET = ALL - if opt == "-b": - TARGET = NAM - if opt == "-C": - CASE = True - if opt == "-c": - CASE = False - if opt == "-d": - DumpState() - if opt == "-E": - ERRORCONTINUE = True - if opt == "-e": - TARGET = EXT - if opt == "-f": - FORCERENAM = True - if opt == "-g": - GLOBAL = True - if opt == "-h": - Usage() - sys.exit(0) - if opt == "-l": - EXTDELIM = val - if opt == "-q": - QUIET = True - if opt == "-r": - pass - if opt == "-t": - TESTMODE = True - if opt == "-v": - PrintStdout(RCSID) - sys.exit(0) - if opt == "-X": - REGEX = False - if opt == "-x": - REGEX = True +while OPTIONS: + + i = OPTIONS[0] + OPTIONS = OPTIONS[1:] + + # Process options + if i.startswith("-"): + if DOINGOPTS: + cmd.append(i) + + # Starting a new "options... targets ..." pair + else: + COMMANDLINES.append(cmd) + cmd = [] + DOINGOPTS = True + cmd.append(i) + + # Process targets + else: + DOINGOPTS = False + cmd.append(i) + + +if cmd: + COMMANDLINES.append(cmd) + +# Now process the command line in "opts... targets" pairs + +for commandline in COMMANDLINES: + + try: + opts, args = getopt.getopt(commandline, '1abbCcdEefghl:qr:tvXx]') + except getopt.GetoptError as e: + ErrorMsg(eBADARG % e.args[0]) + sys.exit(1) + + for opt, val in opts: + + if opt == "-1": + GLOBAL = False + if opt == "-a": + TARGET = ALL + if opt == "-b": + TARGET = NAM + if opt == "-C": + CASE = True + if opt == "-c": + CASE = False + if opt == "-d": + DumpState() + if opt == "-E": + ERRORCONTINUE = True + if opt == "-e": + TARGET = EXT + if opt == "-f": + FORCERENAM = True + if opt == "-g": + GLOBAL = True + if opt == "-h": + Usage() + sys.exit(0) + if opt == "-l": + EXTDELIM = val + if opt == "-q": + QUIET = True + if opt == "-r": + pass + if opt == "-t": + TESTMODE = True + if opt == "-v": + PrintStdout(RCSID) + sys.exit(0) + if opt == "-X": + REGEX = False + if opt == "-x": + REGEX = True