]> thyrsus.com Git - ctopy.git/commitdiff
Prevent internal error from removed inclusion.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 28 Sep 2006 22:10:25 +0000 (22:10 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 28 Sep 2006 22:10:25 +0000 (22:10 +0000)
ctopy

diff --git a/ctopy b/ctopy
index ab94e2a4850067867cf2072950d336c0d32123d4..5ba9f4e39523303f3d4874322f910f74a3a0b4c3 100755 (executable)
--- a/ctopy
+++ b/ctopy
@@ -149,11 +149,13 @@ def ctopy(input, debug=0):
                 state = "text"                
         elif state == "opencomment":
             if input[i] == "\n":
-                if debug:
+                if debug >= 2:
                     print "Open comment ends at %d" % i
                 boundaries.append(i+1)
                 state = "text"
     boundaries.append(len(input))
+    if boundaries[0] == 0:
+        boundaries.pop(0)
     if debug:
         print "Regexp transformation begins"
     regions = []
@@ -191,12 +193,15 @@ def ctopy(input, debug=0):
     if debug:
         print "Import checks begin"
     importlist = []
-    for i in range(len(regions)):
-        if regions[i][0] != '"' and regions[i][0] != "#":
-            for library in ("math", "os", "string", "time"):
-                if re.search(r"\b" + library + r"\.", regions[i]):
-                    if library not in importlist:
-                        importlist.append(library)
+    try:
+        for i in range(len(regions)):
+            if len(regions[i]) and regions[i][0]!='"' and regions[i][0]!="#":
+                for library in ("math", "os", "string", "time"):
+                    if re.search(r"\b" + library + r"\.", regions[i]):
+                        if library not in importlist:
+                            importlist.append(library)
+    except IndexError:
+        sys.stderr.write("ctopy: internal error on region %d (%s).\n" % (i, regions[i]))
     text = "".join(regions)
     importlist = filter(lambda x: ("import %s" % x).find(text) > -1, importlist)
     if importlist: