diff --git a/tren.py b/tren.py index 8ae95a8..d0afc05 100755 --- a/tren.py +++ b/tren.py @@ -6,7 +6,8 @@ # Program Information PROGNAME = "tren.py" -RCSID = "$Id: tren.py,v 1.108 2010/01/25 22:21:26 tundra Exp $" +PROGENV = PROGNAME.split(".py")[0].upper() +RCSID = "$Id: tren.py,v 1.109 2010/01/25 23:23:30 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -52,7 +53,7 @@ ##### MAXINCLUDES = 50 # Maximum number of includes allowed - +PADWIDTH = 30 # Column width ##### # Literals @@ -75,7 +76,13 @@ # Debug Messages ##### -dDEBUG = "DEBUG" +DEBUGFLAG = "-d" +dCMDLINE = "Command Line" +dDEBUG = "DEBUG" +dPAIR = "Option/Target Pair" +dPROGENV = "$" + PROGENV +dRESOLVEDOPTS = "Resolved Command Line" + ##### # Error Messages @@ -162,7 +169,7 @@ # Turn A List Into Columns With Space Padding ##### -def ColumnPad(list, padchar=" ", padwidth=20): +def ColumnPad(list, padchar=" ", padwidth=PADWIDTH): retval = "" for l in list: @@ -190,11 +197,6 @@ def DumpState(): - # Dump the command line - DebugMsg(ColumnPad(["Command Line", sys.argv])) - DebugMsg(ColumnPad(["$TREN", os.getenv("TREN")])) - DebugMsg(ColumnPad(["Resolved Options", OPTIONS])) - # Names of all the state variables we want dumped state = [ "DEBUG", @@ -287,7 +289,7 @@ OPTIONS = sys.argv[1:] -envopt = os.getenv(PROGNAME.split(".py")[0].upper()) +envopt = os.getenv(PROGENV) if envopt: OPTIONS = envopt.split() + OPTIONS @@ -334,10 +336,18 @@ ErrorMsg(eFILEOPEN % (file, e.args[1])) sys.exit(1) +# We also need to detect a request for debugging now +# so we don't have to wait for getopt to parse it +# to begin seeing debugging output + +if DEBUGFLAG in OPTIONS: + DEBUG = True + while DEBUGFLAG in OPTIONS: + OPTIONS.remove(DEBUGFLAG) # Break command line into "option ... targets ..." pairs. - +options = OPTIONS # Save for later DOINGOPTS = True cmd = [] @@ -367,12 +377,26 @@ if cmd: COMMANDLINES.append(cmd) + + +if DEBUG: + + # Dump what we know about the command line + + DebugMsg(ColumnPad([dCMDLINE, sys.argv])) + DebugMsg(ColumnPad([dPROGENV, os.getenv("TREN")])) + DebugMsg(ColumnPad([dRESOLVEDOPTS, options])) + + # Now process the command line in "opts... targets" pairs for commandline in COMMANDLINES: + if DEBUG: + DebugMsg(ColumnPad([dPAIR, " ".join(commandline)])) + try: - opts, args = getopt.getopt(commandline, '1abbCcdEefghl:qr:tvXx]') + opts, args = getopt.getopt(commandline, '1abbCcEefghl:qr:tvXx]') except getopt.GetoptError as e: ErrorMsg(eBADARG % e.args[0]) sys.exit(1) @@ -389,8 +413,6 @@ CASE = True if opt == "-c": CASE = False - if opt == "-d": - DumpState() if opt == "-E": ERRORCONTINUE = True if opt == "-e": @@ -417,3 +439,7 @@ REGEX = False if opt == "-x": REGEX = True + +if DEBUG: + # Dump final program state + DumpState()