]> git.ipfire.org Git - thirdparty/gcc.git/blame - contrib/check-internal-format-escaping.py
PR c++/87554 - ICE with extern template and reference member.
[thirdparty/gcc.git] / contrib / check-internal-format-escaping.py
CommitLineData
2f6d557f 1#!/usr/bin/env python3
2#
3# Check gcc.pot file for gcc-internal-format and print all strings
4# that contain an option that is not wrapped by %<-option_name%>.
5#
6# This file is part of GCC.
7#
8# GCC is free software; you can redistribute it and/or modify it under
9# the terms of the GNU General Public License as published by the Free
10# Software Foundation; either version 3, or (at your option) any later
11# version.
12#
13# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14# WARRANTY; without even the implied warranty of MERCHANTABILITY or
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16# for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with GCC; see the file COPYING3. If not see
20# <http://www.gnu.org/licenses/>. */
21#
22#
23#
24
25import argparse
26import re
27
28parser = argparse.ArgumentParser(description='')
29parser.add_argument('file', help = 'pot file')
30
31args = parser.parse_args()
32
33origin = None
34internal = False
35
36lines = open(args.file).readlines()
37for i, l in enumerate(lines):
38 l = l.strip()
39 s = 'msgid '
40 if l.startswith('#: '):
41 origin = l
42 elif '#, gcc-internal-format' in l:
43 internal = True
44 if l.startswith(s) and origin and internal:
45 j = 0
46 while not lines[i + j].startswith('msgstr'):
47 l = lines[i + j]
48 if l.startswith(s):
49 l = l[len(s):]
50 text = l.strip('"').strip()
51 if text:
52 parts = text.split(' ')
53 for p in parts:
54 if p.startswith('-'):
55 if len(p) >= 2 and (p[1].isalpha() and p != '-INF'):
56 print('%s: %s' % (origin, text))
57 elif p.startswith('__builtin_'):
58 print('%s: %s' % (origin, text))
a0b58a70 59 if re.search("[^%]'", p):
f2a60d44 60 print('%s: %s' % (origin, text))
2f6d557f 61 j += 1
62
63 origin = None
64 internal = False