inliniac/suricata — pull request #1076 by ken-tilera (2014-07-30 19:10:23+00:00)
Title: Enforce coding standard to start function { on new line.

Changes:

int foo(void) {

to:

int foo(void)
{

Replaces PR 889 (rebased by rerunning script).

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)