This makes reconstructing the fixed version of the file a bit more
difficult, but lets us get rid of a cryptic bool.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
scripts/group-qemu-caps.py | 63 +++++++++++++++++---------------------
1 file changed, 28 insertions(+), 35 deletions(-)
diff --git a/scripts/group-qemu-caps.py b/scripts/group-qemu-caps.py
index dce25099b8..36a7d7602f 100755
--- a/scripts/group-qemu-caps.py
+++ b/scripts/group-qemu-caps.py
@@ -61,48 +61,41 @@ def load_caps_flags(lines):
return capsflags
-def regroup_caps(original, start_regex, end_regex,
+def regroup_caps(original,
trailing_newline, counter_prefix, capsflags):
step = 5
fixed = []
- game_on = False
counter = 0
for line in original:
- if game_on:
- if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
- continue
- if re.search(r'''^\s*$''', line):
- continue
- if counter % step == 0:
- if counter != 0:
- fixed.append("")
- fixed.append("%s/* %d */" % (counter_prefix, counter))
-
- if not (line.find("/*") != -1 and line.find("*/") ==
-1):
- # count two-line comments as one line
- counter = counter + 1
-
- if re.search(start_regex, line):
- game_on = True
- elif game_on and re.search(end_regex, line):
- if (counter - 1) % step == 0:
- fixed = fixed[:-1] # /* $counter */
- if counter != 1:
- fixed = fixed[:-1] # \n
-
- if trailing_newline:
+ if re.search(r'''.*/\* [0-9]+ \*/.*''', line):
+ continue
+ if re.search(r'''^\s*$''', line):
+ continue
+ if counter % step == 0:
+ if counter != 0:
fixed.append("")
+ fixed.append("%s/* %d */" % (counter_prefix, counter))
- game_on = False
+ if not (line.find("/*") != -1 and line.find("*/") == -1):
+ # count two-line comments as one line
+ counter = counter + 1
# ensure that flag names in the .c file have the correct flag in the comment
- if game_on and capsflags:
+ if capsflags:
flagname = re.search(r'''.*".*",''', line)
if flagname:
line = flagname[0] + " /* %s */" % capsflags[counter - 1]
fixed.append(line)
+ if (counter - 1) % step == 0:
+ fixed = fixed[:-1] # /* $counter */
+ if counter != 1:
+ fixed = fixed[:-1] # \n
+
+ if trailing_newline:
+ fixed.append("")
+
return fixed
@@ -147,28 +140,28 @@ source_lines = load_file(source_path)
'QEMU_CAPS_LAST /* this must')
capsflags = load_caps_flags(header_lines[start:end])
-header_fixed = regroup_caps(header_lines,
- r'virQEMUCapsFlags grouping marker',
- r'QEMU_CAPS_LAST \/\* this must',
+(source_start, source_end) = find_markers(source_lines,
+ 'virQEMUCaps grouping marker',
+ ' );')
+
+header_fixed = regroup_caps(header_lines[start + 1:end],
1,
" ",
None)
-source_fixed = regroup_caps(source_lines,
- r'virQEMUCaps grouping marker',
- r'\);',
+source_fixed = regroup_caps(source_lines[source_start + 1:source_end],
0,
" ",
capsflags)
if not check_wrapping(header_path,
header_lines,
- header_fixed,
+ header_lines[:start + 1] + header_fixed + header_lines[end:],
args.check):
ret = False
if not check_wrapping(source_path,
source_lines,
- source_fixed,
+ source_lines[:source_start + 1] + source_fixed +
source_lines[source_end:],
args.check):
ret = False
--
2.31.1