diff --git a/tren.py b/tren.py index 587cb63..076792b 100755 --- a/tren.py +++ b/tren.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tren.py" -RCSID = "$Id: tren.py,v 1.104 2010/01/22 20:33:06 tundra Exp $" +RCSID = "$Id: tren.py,v 1.105 2010/01/23 00:38:55 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -51,6 +51,8 @@ # Constants ##### +MAXINCLUDES = 50 # Maximum number of includes allowed + ##### # Literals @@ -81,7 +83,8 @@ eBADARG = "Invalid or malformed command line argument!" eBADINCL = "%s Option Missing Filename Specification!" % INCL eERROR = "ERROR" -eFILEOPEN = "Cannot Open File '%s' Because: %s" +eFILEOPEN = "Cannot Open File '%s': %s!" +eTOOMANYINC = "Too Many Includes! (Max Is %d) Possible Circular Reference?" % MAXINCLUDES ##### @@ -282,6 +285,7 @@ # 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: # Get the index of the next include to process. @@ -295,6 +299,13 @@ file = OPTIONS[i+1] ; lhs = OPTIONS[:i] ; rhs = OPTIONS[i+2:] + # Keep track of- and limit the number of includes allowed + + NUMINCLUDES += 1 + if NUMINCLUDES >= MAXINCLUDES: + ErrorMsg(eTOOMANYINC) + sys.exit(1) + # Replace insert option on the command line with that file's contents try: @@ -310,6 +321,7 @@ ErrorMsg(eFILEOPEN % (file, e.args[1])) sys.exit(1) + # Now process the command line options try: