#!/usr/bin/env python
"""
This script is converting the misra documentation RST file into a text file
that can be used as text-rules for cppcheck.
Usage:
convert_misra_doc.py -i INPUT [-o OUTPUT] [-j JSON] [-s RULES,[...,RULES]]
INPUT - RST file containing the list of misra rules.
OUTPUT - file to store the text output to be used by cppcheck.
If not specified, the result will be printed to stdout.
JSON - cppcheck json file to be created (optional).
RULES - list of rules to skip during the analysis, comma separated
(e.g. 1.1,1.2,1.3,...)
"""
import sys, getopt, re
# MISRA rule are identified by two numbers, e.g. Rule 1.2, the main rule number
# and a sub-number. This dictionary contains the number of the MISRA rule as key
# and the maximum sub-number for that rule as value.
misra_c2012_rules = {
1:4,
2:7,
3:2,
4:2,
5:9,
6:2,
7:4,
8:14,
9:5,
10:8,
11:9,
12:5,
13:6,
14:4,
15:7,
16:7,
17:8,
18:8,
19:2,
20:14,
21:21,
22:10
}
def main(argv):
infile = ''
outfile = ''
outstr = sys.stdout
jsonfile = ''
force_skip = ''
try:
opts, args = getopt.getopt(argv,"hi:o:j:s:",
["input=","output=","json=","skip="])
except getopt.GetoptError:
print('convert-misra.py -i [-o