From: Eric S. Raymond Date: Tue, 3 Oct 2006 10:55:52 +0000 (+0000) Subject: Now enable handling of printf-like functions when we're not debugging. X-Git-Tag: 1.0~29 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=b0b003ee3cec11f1cbc97675b5f65abdf8555e21;p=ctopy.git Now enable handling of printf-like functions when we're not debugging. --- diff --git a/ctopy b/ctopy index d471b00..1747910 100755 --- 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