1 // Script to edit control_*.c for refactored control reply output functions
6 from coccilib.report import *
8 # reply strings "NNN-foo", "NNN+foo", "NNN foo", etc.
9 r = re.compile(r'^"(\d+)([ +-])(.*)\\r\\n"$')
11 # Generate name of function to call based on which separator character
12 # comes between the numeric code and the text
13 def idname(sep, base):
15 return base + "datareply"
17 return base + "midreply"
19 return base + "endreply"
21 # Generate the actual replacements used by the rules
24 print_report(pos, "%s %s" % (base, s))
27 # String not correct format, so fail match
28 cocci.include_match(False)
29 print_report(pos, "BAD STRING %s" % s)
32 code, sep, s1 = m.groups()
35 # Extra CRLF in string, so fail match
36 cocci.include_match(False)
37 print_report(pos, "extra CRLF in string %s" % s)
40 coccinelle.code = code
41 # Need a string that is a single C token, because Coccinelle only allows
42 # "identifiers" to be output from Python scripts?
43 coccinelle.body = '"%s"' % s1
44 coccinelle.id = idname(sep, base)
54 connection_printf_to_buf@f@p(E, s, ...)
56 connection_write_str_to_buf@f@p(s, E)
67 if f == 'connection_printf_to_buf':
68 gen(s, 'control_printf_', p)
69 elif f == 'connection_write_str_to_buf':
70 gen(s, 'control_write_', p)
72 raise(ValueError("%s: %s" % (f, s)))
78 identifier sc1.body, sc1.id, sc1.code;
81 -connection_write_str_to_buf@f(s, E)
84 -connection_printf_to_buf@f(E, s