| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright (C) 2024-2025 Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# This file is part of GCC. |
| 6 |
# |
| 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 |
| 10 |
# version. |
| 11 |
# |
| 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 |
| 15 |
# for more details. |
| 16 |
# |
| 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/>. |
| 20 |
|
| 21 |
# Unfortunately the SARIF 2.1.0 spec doesn't have memorable anchors |
| 22 |
# for its subsections |
| 23 |
# (filed as https://github.com/oasis-tcs/sarif-spec/issues/533) |
| 24 |
# |
| 25 |
# In the meantime, use this script to generate a table mapping subsections |
| 26 |
# to anchors. |
| 27 |
|
| 28 |
from pprint import pprint |
| 29 |
import re |
| 30 |
|
| 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' |
| 33 |
|
| 34 |
d = {} |
| 35 |
with open(filename_in, encoding='windows-1252') as infile: |
| 36 |
for line in infile: |
| 37 |
m = re.match(r'<p class=MsoToc[0-9]+><a href="#(.*)">(.*)<span.*\n', line) |
| 38 |
if m: |
| 39 |
#print('MATCH') |
| 40 |
#print(repr(line)) |
| 41 |
#print(m.groups()) |
| 42 |
m2 = re.match(r'([0-9.]+) .*', m.group(2)) |
| 43 |
if m2: |
| 44 |
#print(m2.groups()) |
| 45 |
d[m2.group(1)] = m.group(1) |
| 46 |
|
| 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') |
| 50 |
|
| 51 |
outfile.write(f'static const char * const sarif_spec_base_url\n = "{spec_url}";\n\n') |
| 52 |
|
| 53 |
outfile.write('static const struct ref_anchor\n' |
| 54 |
'{\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') |
| 60 |
outfile.write('};') |