diff --git a/tren.py b/tren.py index 0b7ec90..a618c81 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.143 2010/02/05 03:48:17 tundra Exp $" +RCSID = "$Id: tren.py,v 1.144 2010/02/05 05:42:45 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -144,7 +144,7 @@ dCURSTATE = "Current State Of Program Options" dDEBUG = "DEBUG" dDUMPOBJ = "Dumping Object %s" -dINCLUDING = "Including file '%s'" +dINCLFILES = "Included Files:" dPROGENV = "$" + PROGENV dRENREQ = "Renaming Request:" dRENTARGET = "Rename Target:" @@ -209,6 +209,8 @@ # Program toggle and option defaults +IncludedFiles = [] + ProgramOptions = { DEBUG : False, # Debugging off @@ -684,35 +686,37 @@ def ProcessIncludes(OPTIONS): - # Make sure the include argument has trailing space or the - # code below will break. - - OPTIONS = " ".join(OPTIONS).replace(INCL, INCL+" ").split() - # Resolve include file references allowing for nested includes. # This has to be done here separate from the command line options so # that getopt() processing below will "see" the included statements. - NUMINCLUDES = 0 while " ". join(OPTIONS).find(INCL) > -1: - # In case we include a -I without a trailing space - - OPTIONS = " ".join(OPTIONS).replace(INCL, INCL+" ").split() - # Get the index of the next include to process. # It cannot be the last item because this means the filename # to include is missing. i = OPTIONS.index(INCL) + # You can't end a command line with the include option and no argument + if i == len(OPTIONS)-1: ErrorMsg(eBADARG % eBADINCL) sys.exit(1) - - file = OPTIONS[i+1] ; lhs = OPTIONS[:i] ; rhs = OPTIONS[i+2:] - + + # Handle the case where the user does- and does not separate + # the option and the filename with a space since both + # forms are legal command line syntax + + # The use included the space + if OPTIONS[i] == INCL: + file = OPTIONS[i+1] ; lhs = OPTIONS[:i] ; rhs = OPTIONS[i+2:] + + # The the option and filename are not space separated + else: + file = OPTIONS[i].replace(INCL,"") ; lhs = OPTIONS[:i] ; rhs = OPTIONS[i+1:] + # Keep track of- and limit the number of includes allowed # This is an easy way to stop circular (infinite) includes. @@ -732,8 +736,9 @@ n += l.split() f.close() - if ProgramOptions[DEBUG]: - DebugMsg(dINCLUDING % file) + # Keep track of the filenames being included + + IncludedFiles.append(os.path.abspath(file)) OPTIONS = lhs + n + rhs @@ -792,21 +797,11 @@ if envopt: OPTIONS = envopt.split() + OPTIONS -# Check for debug manually to see if we want -# debug info about includes - -if DEBUGFLAG in OPTIONS: - ProgramOptions[DEBUG] = True - # Deal with include files OPTIONS = ProcessIncludes(OPTIONS) -# Check for debug manually again before we process the options -# to get debug info on command line expansion - -if DEBUGFLAG in OPTIONS: - ProgramOptions[DEBUG] = True +# And parse the command line try: opts, args = getopt.getopt(OPTIONS, 'abbCcdEefGghl:qR:r:tvw:Xx]') @@ -839,6 +834,7 @@ ProgramOptions[CASESENSITIVE] = False if opt == "-d": + ProgramOptions[DEBUG] = True DumpState() if opt == "-E": @@ -913,6 +909,9 @@ DumpList(DebugMsg, dPROGENV, "", envopt) DumpList(DebugMsg, dRESOLVEDOPTS, "", OPTIONS) + # Dump what we know about included files + + DumpList(DebugMsg, dINCLFILES, "", IncludedFiles) # Dump what we know about the container