# Parser for cppcheck_run.log files import sys def usage(): print( 'usage: python chhpcheck-parse.py [OPTIONS] ' ) print( ' --severity limit which severities are shown (Warnings, Errors, locations; default=WEl)' ) sys.exit(1) import getopt try: opts, args = getopt.getopt( sys.argv[1:], 'h', longopts=['help', 'severity='] ) except getopt.GetoptError as err: print( '-F-', err ) # something like "option -a not recognized" usage() if len(args) != 1: usage() logfile = args[0] severities = 'WEl' for opt, arg in opts: if opt in ('--severity'): severities = arg class LineError( Exception ): def __init__( self, message, line=None ): global line_number, logfile if line is None: line = line_number super().__init__( f'{logfile}+{line}: {message}' ) handle = open( logfile, "r" ) line_number = 0 def nextline(): global handle, line_number line_number += 1 line = handle.readline() if not line: raise LineError( 'unexpected end-of-file' ) return line.strip() while True: line = nextline() if line == '': break import re while True: line = nextline() if line == '': break if not line.startswith( '