cppcheck-htmlreport now takes a parameter for source code encoding to support non ascii characters.
Also present a nicer error message if highlighting fail for a file.
This commit is contained in:
parent
f6c24f9070
commit
628f4ad6e7
|
@ -199,6 +199,7 @@ if __name__ == '__main__':
|
||||||
parser.add_option("--file", dest="file", help="The cppcheck xml output file to read defects from. Default is reading from stdin.")
|
parser.add_option("--file", dest="file", help="The cppcheck xml output file to read defects from. Default is reading from stdin.")
|
||||||
parser.add_option("--report-dir", dest="report_dir", help="The directory where the html report content is written.")
|
parser.add_option("--report-dir", dest="report_dir", help="The directory where the html report content is written.")
|
||||||
parser.add_option("--source-dir", dest="source_dir", help="Base directory where source code files can be found.")
|
parser.add_option("--source-dir", dest="source_dir", help="Base directory where source code files can be found.")
|
||||||
|
parser.add_option("--source-encoding", dest="source_encoding", help="Encoding of source code.", default=None)
|
||||||
|
|
||||||
# Parse options and make sure that we have an output directory set.
|
# Parse options and make sure that we have an output directory set.
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
@ -248,6 +249,7 @@ if __name__ == '__main__':
|
||||||
# file that contains one or more errors.
|
# file that contains one or more errors.
|
||||||
print("Processing errors")
|
print("Processing errors")
|
||||||
for filename, data in files.iteritems():
|
for filename, data in files.iteritems():
|
||||||
|
try:
|
||||||
htmlfile = data["htmlfile"]
|
htmlfile = data["htmlfile"]
|
||||||
errors = data["errors"]
|
errors = data["errors"]
|
||||||
|
|
||||||
|
@ -263,7 +265,7 @@ if __name__ == '__main__':
|
||||||
content = stream.read()
|
content = stream.read()
|
||||||
stream.close()
|
stream.close()
|
||||||
|
|
||||||
htmlFormatter = AnnotateCodeFormatter(linenos=True, style='colorful', hl_lines=lines, lineanchors="line")
|
htmlFormatter = AnnotateCodeFormatter(linenos=True, style='colorful', hl_lines=lines, lineanchors="line", encoding=options.source_encoding)
|
||||||
htmlFormatter.errors = errors
|
htmlFormatter.errors = errors
|
||||||
stream = file(os.path.join(options.report_dir, htmlfile), "w")
|
stream = file(os.path.join(options.report_dir, htmlfile), "w")
|
||||||
stream.write(HTML_HEAD % (options.title, htmlFormatter.get_style_defs(".highlight"), options.title))
|
stream.write(HTML_HEAD % (options.title, htmlFormatter.get_style_defs(".highlight"), options.title))
|
||||||
|
@ -272,6 +274,8 @@ if __name__ == '__main__':
|
||||||
stream.close()
|
stream.close()
|
||||||
|
|
||||||
print(" " + filename)
|
print(" " + filename)
|
||||||
|
except Exception, message:
|
||||||
|
print("ERROR: Filename: %s, %s" % (filename, message))
|
||||||
|
|
||||||
# Generate a master index.html file that will contain a list of
|
# Generate a master index.html file that will contain a list of
|
||||||
# all the errors created.
|
# all the errors created.
|
||||||
|
|
Loading…
Reference in New Issue