diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-05-06 13:43:02 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-05-06 13:49:57 +0900 |
commit | 80a31d6c8a114799dc5284086ffce2e9be34c50e (patch) | |
tree | 1719891657e76c04f063f5ff7b5fdf63d9e562c3 /debian/uncrustify-trinity/uncrustify-trinity-0.75.0/scripts/check_options.py | |
parent | e6ba08c3b21cdb14ee3a97b5d584759a4597b54b (diff) | |
download | extra-dependencies-80a31d6c8a114799dc5284086ffce2e9be34c50e.tar.gz extra-dependencies-80a31d6c8a114799dc5284086ffce2e9be34c50e.zip |
uncrustify-trinity: updated based on upstream version 0.75.0
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'debian/uncrustify-trinity/uncrustify-trinity-0.75.0/scripts/check_options.py')
-rw-r--r-- | debian/uncrustify-trinity/uncrustify-trinity-0.75.0/scripts/check_options.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/debian/uncrustify-trinity/uncrustify-trinity-0.75.0/scripts/check_options.py b/debian/uncrustify-trinity/uncrustify-trinity-0.75.0/scripts/check_options.py new file mode 100644 index 00000000..1d32224b --- /dev/null +++ b/debian/uncrustify-trinity/uncrustify-trinity-0.75.0/scripts/check_options.py @@ -0,0 +1,80 @@ +#! /usr/bin/env python +# +# Check the option usage. +# Make sure the union member matches the option type. +# +from os.path import dirname, join, abspath +from os import listdir, EX_OK, EX_DATAERR +from fnmatch import filter + +# just use the first letter of the member name - should be unique +map_access_type = { + 'b': 'AT_BOOL', + 'a': 'AT_IARF', + 'n': 'AT_NUM', + 'u': 'AT_UNUM', + 'l': 'AT_LINE', + 't': 'AT_POS', +} +map_option_type = {} + + +# checks if while accessing the cpd.settings the right union accessor is used in the file +def check_file(file_path): + problems = 0 + line_no = 0 + + fd = open(file_path, 'r') + for line in fd: + line_no += 1 + + pos_cpd_s = line.find('cpd.settings[UO_') + pos_cpd_e = line[pos_cpd_s:].find(']') + if pos_cpd_s > 0 and pos_cpd_e > 0: + pos_option_s = pos_cpd_s + 13 + pos_option_e = pos_cpd_s + pos_cpd_e + + option = line[pos_option_s : pos_option_e] + union_access = line[pos_option_e + 2] + + if option in map_option_type and union_access in map_access_type: + if map_option_type[option] != map_access_type[union_access]: + print("%s [%d] %s should use %s not %s" % (file_path, line_no, option, + map_option_type[option], map_access_type[union_access])) + problems += 1 + return problems + + +def fill_map_option_type(file_path): + # Read in all the options + fd = open(file_path, 'r') + for line in fd: + if line.find('unc_add_option') > 0 and line.find('UO_') > 0: + splits = line.split(',') + if len(splits) >= 3: + map_option_type[splits[1].strip()] = splits[2].strip() + fd.close() + + +def main(): + src_dir = join(dirname(dirname(abspath(__file__))), 'src') + fill_map_option_type(join(src_dir, 'options.cpp')) + + # Get a list of all the source files + ld = listdir(src_dir) + src_files = filter(ld, '*.cpp') + src_files.extend(filter(ld, '*.h')) + + # Check each source file + problems = 0 + for fn in src_files: + problems += check_file(join(src_dir, fn)) + if problems == 0: + print("No problems found") + return EX_OK + else: + return EX_DATAERR + +if __name__ == '__main__': + exit(main()) + |