Added logic to subdivide command line into "opts... targets..." pairs.
1 parent 567601d commit 392d975601b1ad4f2e1fb61696b35b609151315e
@tundra tundra authored on 25 Jan 2010
Showing 1 changed file
View
184
tren.py
 
# 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
 
TARGET = ALL # Can be "All", "Name", or "Ext"
TESTMODE = False
 
 
# Global data structures
 
COMMANDLINES = [] # Stores "options... targets" from command line
 
 
 
#--------------------------- Code Begins Here ---------------------------------#
 
 
# 1) Prepending any options specified in the environment variable.
#
# 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.
#
 
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:
ErrorMsg(eTOOMANYINC)
ErrorMsg(eFILEOPEN % (file, e.args[1]))
sys.exit(1)
 
 
# Now process the command line options
 
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:
 
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
# Break command line into "option ... targets ..." pairs.
 
 
DOINGOPTS = True
cmd = []
 
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