From ec6aa1593f32f5c6d8c4e27f314c7322150215f8 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Sat, 9 Jun 2018 05:12:14 +0200 Subject: verify_value_string_arrays_are_terminated.py: allow dir args and no args So far we call with a $(find . -name "*.[hc]") argument list, which might become too long at some point. Rather include dir walking in the script itself and allow passing dir arguments as well. This is backwards compatible, calling with above file args still works. Change-Id: I36456383906b6295c798b82aa131dda21f8efc02 --- scripts/verify_value_string_arrays_are_terminated.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/verify_value_string_arrays_are_terminated.py b/scripts/verify_value_string_arrays_are_terminated.py index ad936a5..9f0ad82 100755 --- a/scripts/verify_value_string_arrays_are_terminated.py +++ b/scripts/verify_value_string_arrays_are_terminated.py @@ -3,7 +3,7 @@ ''' Usage: - verify_value_string_arrays_are_terminated.py PATH [PATH [...]] + verify_value_string_arrays_are_terminated.py [ROOT_DIR|PATH] [...] e.g. libosmocore/contrib/verify_value_string_arrays_are_terminated.py $(find . -name "*.[hc]") @@ -12,6 +12,7 @@ libosmocore/contrib/verify_value_string_arrays_are_terminated.py $(find . -name import re import sys import codecs +import os.path value_string_array_re = re.compile( r'((\bstruct\s+value_string\b[^{;]*?)\s*=[^{;]*{[^;]*}\s*;)', @@ -22,7 +23,10 @@ terminator_re = re.compile('{}|{\s*' + members + '(0|NULL)\s*,' '\s*' + members + '(0|NULL)\s*}') errors_found = 0 -for f in sys.argv[1:]: +def check_file(f): + global errors_found + if not (f.endswith('.h') or f.endswith('.c') or f.endswith('.cpp')): + return arrays = value_string_array_re.findall(codecs.open(f, "r", "utf-8").read()) for array_def, name in arrays: if not terminator_re.search(array_def): @@ -30,4 +34,16 @@ for f in sys.argv[1:]: % (name, f)) errors_found += 1 +args = sys.argv[1:] +if not args: + args = ['.'] + +for f in args: + if os.path.isdir(f): + for parent_path, subdirs, files in os.walk(f, None, None): + for ff in files: + check_file(os.path.join(parent_path, ff)) + else: + check_file(f) + sys.exit(errors_found) -- cgit v1.2.3