inliniac/suricata — pull request #889 by ken-tilera (2014-03-11 22:57:13+00:00)
Title: Enforce coding standard to start function { on new line.

Changes:

int foo(void) {

to:

int foo(void)
{

Ran the python script below, which write the changed files into ./tmp.

./filter-functions.py *.c *.h
mv ./tmp/* .

from sys import argv,stdout
from re import match
from re import search

def is_func(line):
if search('if|for|while|switch',line):
return 0
if search('[]',line):
return 0
if search('->',line):
return 0
if search('&&',line):
return 0
if search('[|][|]',line):
return 0
if search('==',line):
return 0
if search('[)][)]',line):
return 0
if search('TAILQ_FOREACH',line):
return 0
if match('^[ \t]*[)]$',line):
return 0
if search('DETECT_CONTENT_FAST_PATTERN',line):
return 0

return 1

def process_file(fileanme):
f = open(filename)
fout = open("tmp/"+filename, "w")
for line in f.readlines():
m = match("^(.*\)) *{[\n]?$",line)
if m and is_func(m.group(1)) == 1:
fout.write(m.group(1))
fout.write("\n{\n")
else:
fout.write(line)
f.close()
fout.close()

if __name__ == "__main__":
for filename in argv[1:]:
print "Filtering", filename
process_file(filename)

Passes PR Script:
https://buildbot.suricata-ids.org/builders/ken-tilera/builds/130
https://buildbot.suricata-ids.org/builders/ken-tilera-pcap/builds/64