summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-06-09 05:12:14 +0200
committerHarald Welte <laforge@gnumonks.org>2018-07-05 06:56:49 +0000
commitec6aa1593f32f5c6d8c4e27f314c7322150215f8 (patch)
tree6b1de8ef94061b8de68322825ad91278495a87fb /scripts
parent6866852c371c48b0ba57bdf48070701060840ca3 (diff)
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
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/verify_value_string_arrays_are_terminated.py20
1 files changed, 18 insertions, 2 deletions
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)