| |
---|
| | |
---|
| | 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 |
---|
| | |
---|
| |
---|
| | dCMDLINE = "Command Line" |
---|
| | 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:" |
---|
| | dRESOLVEDOPTS = "Resolved Command Line" |
---|
| |
---|
| | #----------------------------------------------------------# |
---|
| | |
---|
| | # Program toggle and option defaults |
---|
| | |
---|
| | IncludedFiles = [] |
---|
| | |
---|
| | ProgramOptions = { |
---|
| | |
---|
| | DEBUG : False, # Debugging off |
---|
| | CASESENSITIVE : True, # Search is case-sensitive |
---|
| |
---|
| | ##### |
---|
| | |
---|
| | 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. |
---|
| | |
---|
| | NUMINCLUDES += 1 |
---|
| |
---|
| | l = l.split(COMMENT)[0] |
---|
| | 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 |
---|
| | |
---|
| | except IOError as e: |
---|
| |
---|
| | envopt = os.getenv(PROGENV) |
---|
| | 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]') |
---|
| | except getopt.GetoptError as e: |
---|
| |
---|
| | if opt == "-c": |
---|
| | ProgramOptions[CASESENSITIVE] = False |
---|
| | |
---|
| | if opt == "-d": |
---|
| | ProgramOptions[DEBUG] = True |
---|
| | DumpState() |
---|
| | |
---|
| | if opt == "-E": |
---|
| | ProgramOptions[ERRORCONTINUE] = True |
---|
| |
---|
| | DumpList(DebugMsg, dCMDLINE, "", sys.argv) |
---|
| | 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 |
---|
| | |
---|
| | targs.DumpObj() |
---|
| |
---|
| | |