diff options
Diffstat (limited to '')
-rwxr-xr-x | tools/check_val_to_str.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/tools/check_val_to_str.py b/tools/check_val_to_str.py index 417655c3..4ce2ca8c 100755 --- a/tools/check_val_to_str.py +++ b/tools/check_val_to_str.py @@ -73,7 +73,7 @@ def removeComments(code_string): def is_dissector_file(filename): - p = re.compile(r'.*packet-.*\.c') + p = re.compile(r'.*(packet|file)-.*\.c') return p.match(filename) def findDissectorFilesInFolder(folder, recursive=False): @@ -101,7 +101,7 @@ warnings_found = 0 errors_found = 0 # Check the given dissector file. -def checkFile(filename): +def checkFile(filename, generated): global warnings_found global errors_found @@ -130,18 +130,28 @@ def checkFile(filename): # TODO: I suppose it could be escaped, but haven't seen this... if format_string.find('%') != -1: # This is an error as format specifier would show in app - print('Error:', filename, " ", m.group(0), ' - should not have specifiers in unknown string') + print('Error:', filename, " ", m.group(0), + ' - should not have specifiers in unknown string', + '(GENERATED)' if generated else '') errors_found += 1 else: # These ones need to have a specifier, and it should be suitable for an int - specifier_id = format_string.find('%') - if specifier_id == -1: - print('Warning:', filename, " ", m.group(0), ' - should have suitable format specifier in unknown string (or use _const()?)') + count = format_string.count('%') + if count == 0: + print('Warning:', filename, " ", m.group(0), + ' - should have suitable format specifier in unknown string (or use _const()?)', + '(GENERATED)' if generated else '') warnings_found += 1 + elif count > 1: + print('Warning:', filename, " ", m.group(0), + ' - has more than one specifier?', + '(GENERATED)' if generated else '') # TODO: check allowed specifiers (d, u, x, ?) and modifiers (0-9*) in re ? if format_string.find('%s') != -1: # This is an error as this likely causes a crash - print('Error:', filename, " ", m.group(0), ' - inappropriate format specifier in unknown string') + print('Error:', filename, " ", m.group(0), + ' - inappropriate format specifier in unknown string', + '(GENERATED)' if generated else '') errors_found += 1 @@ -158,6 +168,8 @@ parser.add_argument('--commits', action='store', help='last N commits to check') parser.add_argument('--open', action='store_true', help='check open files') +parser.add_argument('--generated', action='store_true', + help='check generated files') args = parser.parse_args() @@ -167,7 +179,7 @@ files = [] if args.file: # Add specified file(s) for f in args.file: - if not f.startswith('epan'): + if not os.path.isfile(f) and not f.startswith('epan'): f = os.path.join('epan', 'dissectors', f) if not os.path.isfile(f): print('Chosen file', f, 'does not exist.') @@ -195,7 +207,7 @@ elif args.open: # Only interested in dissector files. files_staged = list(filter(lambda f : is_dissector_file(f), files_staged)) for f in files_staged: - if not f in files: + if f not in files: files.append(f) else: # Find all dissector files from folder. @@ -219,8 +231,9 @@ else: for f in files: if should_exit: exit(1) - if not isGeneratedFile(f): - checkFile(f) + generated = isGeneratedFile(f) + if args.generated or not generated: + checkFile(f, generated) # Show summary. |