]> thyrsus.com Git - ctopy.git/commitdiff
Now enable handling of printf-like functions when we're not debugging.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 3 Oct 2006 10:55:52 +0000 (10:55 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 3 Oct 2006 10:55:52 +0000 (10:55 +0000)
ctopy

diff --git a/ctopy b/ctopy
index d471b0063f9a846c65560da90b9eb7630c3b6a28..17479109ec8b6bd39a123b40bf3fc5555bb4c624 100755 (executable)
--- a/ctopy
+++ b/ctopy
@@ -45,7 +45,7 @@ import sys, re
 
 stringify = []
 
-printflike = ("printf", "sprintf", "vfprintf")
+printflike = ["printf", "sprintf", "vfprintf"]
 
 shorthands = {
     'id' : r"[a-zA-Z_][a-zA-Z0-9._]*",
@@ -323,27 +323,27 @@ def ctopy(input):
         pp.pprint(regions)
     if debug >= 2:
         print "Processing printf-like functions"
-        for (i, here) in enumerate(regions):
-            if regions[i][0] != '"' or not "%" in here:
-                continue
-            else:
-                for func in printflike:
-                    if re.search(r"\b%s\([^;]*\Z" % func, regions[i]):
-                        break
-                    else:
-                        continue       # Didn't find printf-like function
-            regions[i+1] = " % (" + regions[i+1][1:].lstrip()
-            j = 3
-            parenlevel = 0
-            while j < len(regions[i+1]):
-                if regions[i+1][j] == "(":
-                    parenlevel += 1
-                if regions[i+1][j] == ")":
-                    parenlevel -= 1
-                if parenlevel == 0:
-                    regions[i+1] = regions[i+1][:j] + ")" + regions[i+1][j:]
+    for (i, here) in enumerate(regions):
+        if regions[i][0] != '"' or not "%" in here:
+            continue
+        else:
+            for func in printflike:
+                if re.search(r"\b%s\([^;]*\Z" % func, regions[i]):
                     break
-                j += 1
+                else:
+                    continue   # Didn't find printf-like function
+        regions[i+1] = " % (" + regions[i+1][1:].lstrip()
+        j = 3
+        parenlevel = 0
+        while j < len(regions[i+1]):
+            if regions[i+1][j] == "(":
+                parenlevel += 1
+            if regions[i+1][j] == ")":
+                parenlevel -= 1
+            if parenlevel == 0:
+                regions[i+1] = regions[i+1][:j] + ")" + regions[i+1][j:]
+                break
+            j += 1
     try:
         for i in range(len(regions)):
             if regions[i][:2] == "/*":
@@ -463,6 +463,8 @@ def process_hint(line):
             shorthands["type"] += r"|\b" + tok + r"\b" 
         elif cmd == "class":
             shorthands["class"] += r"|\b" + tok + r"\b"
+        elif cmd == "printflike":
+            printflike.append(tok)
 
 if __name__ == "__main__":
     import getopt