3 # Copyright (C) 2024 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3, or (at your option) any later
12 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>.
21 # Unfortunately the SARIF 2.1.0 spec doesn't have memorable anchors
23 # (filed as https://github.com/oasis-tcs/sarif-spec/issues/533)
25 # In the meantime, use this script to generate a table mapping subsections
28 from pprint
import pprint
31 spec_url
= 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html'
32 filename_in
= 'sarif-v2.1.0-errata01-os-complete.html'
35 with
open(filename_in
, encoding
='windows-1252') as infile
:
37 m
= re
.match(r
'<p class=MsoToc[0-9]+><a href="#(.*)">(.*)<span.*\n', line
)
42 m2
= re
.match(r
'([0-9.]+) .*', m
.group(2))
45 d
[m2
.group(1)] = m
.group(1)
47 filename_out
= '../gcc/sarif-spec-urls.def'
48 with
open(filename_out
, 'w') as outfile
:
49 outfile
.write('/* Generated by regenerate-sarif-spec-index.py. */\n\n')
51 outfile
.write(f
'static const char * const sarif_spec_base_url\n = "{spec_url}";\n\n')
53 outfile
.write('static const struct ref_anchor\n'
55 ' const char *m_ref;\n'
56 ' const char *m_anchor;\n'
57 '} sarif_spec_anchor_arr[] = {\n');
58 for ref
, anchor
in d
.items():
59 outfile
.write(f
' {{ "{ref}", "{anchor}" }},\n')