annotate gcc/pretty-print.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Various declarations for language-independent pretty-print subroutines.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "coretypes.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "intl.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "pretty-print.h"
111
kono
parents: 67
diff changeset
26 #include "diagnostic-color.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
27 #include "diagnostic-event-id.h"
111
kono
parents: 67
diff changeset
28 #include "selftest.h"
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
29
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
30 #if HAVE_ICONV
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
31 #include <iconv.h>
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
32 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
111
kono
parents: 67
diff changeset
34 #ifdef __MINGW32__
kono
parents: 67
diff changeset
35
kono
parents: 67
diff changeset
36 /* Replacement for fputs() that handles ANSI escape codes on Windows NT.
kono
parents: 67
diff changeset
37 Contributed by: Liu Hao (lh_mouse at 126 dot com)
kono
parents: 67
diff changeset
38
kono
parents: 67
diff changeset
39 XXX: This file is compiled into libcommon.a that will be self-contained.
kono
parents: 67
diff changeset
40 It looks like that these functions can be put nowhere else. */
kono
parents: 67
diff changeset
41
kono
parents: 67
diff changeset
42 #include <io.h>
kono
parents: 67
diff changeset
43 #define WIN32_LEAN_AND_MEAN 1
kono
parents: 67
diff changeset
44 #include <windows.h>
kono
parents: 67
diff changeset
45
kono
parents: 67
diff changeset
46 /* Write all bytes in [s,s+n) into the specified stream.
kono
parents: 67
diff changeset
47 Errors are ignored. */
kono
parents: 67
diff changeset
48 static void
kono
parents: 67
diff changeset
49 write_all (HANDLE h, const char *s, size_t n)
kono
parents: 67
diff changeset
50 {
kono
parents: 67
diff changeset
51 size_t rem = n;
kono
parents: 67
diff changeset
52 DWORD step;
kono
parents: 67
diff changeset
53
kono
parents: 67
diff changeset
54 while (rem != 0)
kono
parents: 67
diff changeset
55 {
kono
parents: 67
diff changeset
56 if (rem <= UINT_MAX)
kono
parents: 67
diff changeset
57 step = rem;
kono
parents: 67
diff changeset
58 else
kono
parents: 67
diff changeset
59 step = UINT_MAX;
kono
parents: 67
diff changeset
60 if (!WriteFile (h, s + n - rem, step, &step, NULL))
kono
parents: 67
diff changeset
61 break;
kono
parents: 67
diff changeset
62 rem -= step;
kono
parents: 67
diff changeset
63 }
kono
parents: 67
diff changeset
64 }
kono
parents: 67
diff changeset
65
kono
parents: 67
diff changeset
66 /* Find the beginning of an escape sequence.
kono
parents: 67
diff changeset
67 There are two cases:
kono
parents: 67
diff changeset
68 1. If the sequence begins with an ESC character (0x1B) and a second
kono
parents: 67
diff changeset
69 character X in [0x40,0x5F], returns X and stores a pointer to
kono
parents: 67
diff changeset
70 the third character into *head.
kono
parents: 67
diff changeset
71 2. If the sequence begins with a character X in [0x80,0x9F], returns
kono
parents: 67
diff changeset
72 (X-0x40) and stores a pointer to the second character into *head.
kono
parents: 67
diff changeset
73 Stores the number of ESC character(s) in *prefix_len.
kono
parents: 67
diff changeset
74 Returns 0 if no such sequence can be found. */
kono
parents: 67
diff changeset
75 static int
kono
parents: 67
diff changeset
76 find_esc_head (int *prefix_len, const char **head, const char *str)
kono
parents: 67
diff changeset
77 {
kono
parents: 67
diff changeset
78 int c;
kono
parents: 67
diff changeset
79 const char *r = str;
kono
parents: 67
diff changeset
80 int escaped = 0;
kono
parents: 67
diff changeset
81
kono
parents: 67
diff changeset
82 for (;;)
kono
parents: 67
diff changeset
83 {
kono
parents: 67
diff changeset
84 c = (unsigned char) *r;
kono
parents: 67
diff changeset
85 if (c == 0)
kono
parents: 67
diff changeset
86 {
kono
parents: 67
diff changeset
87 /* Not found. */
kono
parents: 67
diff changeset
88 return 0;
kono
parents: 67
diff changeset
89 }
kono
parents: 67
diff changeset
90 if (escaped && 0x40 <= c && c <= 0x5F)
kono
parents: 67
diff changeset
91 {
kono
parents: 67
diff changeset
92 /* Found (case 1). */
kono
parents: 67
diff changeset
93 *prefix_len = 2;
kono
parents: 67
diff changeset
94 *head = r + 1;
kono
parents: 67
diff changeset
95 return c;
kono
parents: 67
diff changeset
96 }
kono
parents: 67
diff changeset
97 if (0x80 <= c && c <= 0x9F)
kono
parents: 67
diff changeset
98 {
kono
parents: 67
diff changeset
99 /* Found (case 2). */
kono
parents: 67
diff changeset
100 *prefix_len = 1;
kono
parents: 67
diff changeset
101 *head = r + 1;
kono
parents: 67
diff changeset
102 return c - 0x40;
kono
parents: 67
diff changeset
103 }
kono
parents: 67
diff changeset
104 ++r;
kono
parents: 67
diff changeset
105 escaped = c == 0x1B;
kono
parents: 67
diff changeset
106 }
kono
parents: 67
diff changeset
107 }
kono
parents: 67
diff changeset
108
kono
parents: 67
diff changeset
109 /* Find the terminator of an escape sequence.
kono
parents: 67
diff changeset
110 str should be the value stored in *head by a previous successful
kono
parents: 67
diff changeset
111 call to find_esc_head().
kono
parents: 67
diff changeset
112 Returns 0 if no such sequence can be found. */
kono
parents: 67
diff changeset
113 static int
kono
parents: 67
diff changeset
114 find_esc_terminator (const char **term, const char *str)
kono
parents: 67
diff changeset
115 {
kono
parents: 67
diff changeset
116 int c;
kono
parents: 67
diff changeset
117 const char *r = str;
kono
parents: 67
diff changeset
118
kono
parents: 67
diff changeset
119 for (;;)
kono
parents: 67
diff changeset
120 {
kono
parents: 67
diff changeset
121 c = (unsigned char) *r;
kono
parents: 67
diff changeset
122 if (c == 0)
kono
parents: 67
diff changeset
123 {
kono
parents: 67
diff changeset
124 /* Not found. */
kono
parents: 67
diff changeset
125 return 0;
kono
parents: 67
diff changeset
126 }
kono
parents: 67
diff changeset
127 if (0x40 <= c && c <= 0x7E)
kono
parents: 67
diff changeset
128 {
kono
parents: 67
diff changeset
129 /* Found. */
kono
parents: 67
diff changeset
130 *term = r;
kono
parents: 67
diff changeset
131 return c;
kono
parents: 67
diff changeset
132 }
kono
parents: 67
diff changeset
133 ++r;
kono
parents: 67
diff changeset
134 }
kono
parents: 67
diff changeset
135 }
kono
parents: 67
diff changeset
136
kono
parents: 67
diff changeset
137 /* Handle a sequence of codes. Sequences that are invalid, reserved,
kono
parents: 67
diff changeset
138 unrecognized or unimplemented are ignored silently.
kono
parents: 67
diff changeset
139 There isn't much we can do because of lameness of Windows consoles. */
kono
parents: 67
diff changeset
140 static void
kono
parents: 67
diff changeset
141 eat_esc_sequence (HANDLE h, int esc_code,
kono
parents: 67
diff changeset
142 const char *esc_head, const char *esc_term)
kono
parents: 67
diff changeset
143 {
kono
parents: 67
diff changeset
144 /* Numbers in an escape sequence cannot be negative, because
kono
parents: 67
diff changeset
145 a minus sign in the middle of it would have terminated it. */
kono
parents: 67
diff changeset
146 long n1, n2;
kono
parents: 67
diff changeset
147 char *eptr, *delim;
kono
parents: 67
diff changeset
148 CONSOLE_SCREEN_BUFFER_INFO sb;
kono
parents: 67
diff changeset
149 COORD cr;
kono
parents: 67
diff changeset
150 /* ED and EL parameters. */
kono
parents: 67
diff changeset
151 DWORD cnt, step;
kono
parents: 67
diff changeset
152 long rows;
kono
parents: 67
diff changeset
153 /* SGR parameters. */
kono
parents: 67
diff changeset
154 WORD attrib_add, attrib_rm;
kono
parents: 67
diff changeset
155 const char *param;
kono
parents: 67
diff changeset
156
kono
parents: 67
diff changeset
157 switch (MAKEWORD (esc_code, *esc_term))
kono
parents: 67
diff changeset
158 {
kono
parents: 67
diff changeset
159 /* ESC [ n1 'A'
kono
parents: 67
diff changeset
160 Move the cursor up by n1 characters. */
kono
parents: 67
diff changeset
161 case MAKEWORD ('[', 'A'):
kono
parents: 67
diff changeset
162 if (esc_head == esc_term)
kono
parents: 67
diff changeset
163 n1 = 1;
kono
parents: 67
diff changeset
164 else
kono
parents: 67
diff changeset
165 {
kono
parents: 67
diff changeset
166 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
167 if (eptr != esc_term)
kono
parents: 67
diff changeset
168 break;
kono
parents: 67
diff changeset
169 }
kono
parents: 67
diff changeset
170
kono
parents: 67
diff changeset
171 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
172 {
kono
parents: 67
diff changeset
173 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
174 /* Stop at the topmost boundary. */
kono
parents: 67
diff changeset
175 if (cr.Y > n1)
kono
parents: 67
diff changeset
176 cr.Y -= n1;
kono
parents: 67
diff changeset
177 else
kono
parents: 67
diff changeset
178 cr.Y = 0;
kono
parents: 67
diff changeset
179 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
180 }
kono
parents: 67
diff changeset
181 break;
kono
parents: 67
diff changeset
182
kono
parents: 67
diff changeset
183 /* ESC [ n1 'B'
kono
parents: 67
diff changeset
184 Move the cursor down by n1 characters. */
kono
parents: 67
diff changeset
185 case MAKEWORD ('[', 'B'):
kono
parents: 67
diff changeset
186 if (esc_head == esc_term)
kono
parents: 67
diff changeset
187 n1 = 1;
kono
parents: 67
diff changeset
188 else
kono
parents: 67
diff changeset
189 {
kono
parents: 67
diff changeset
190 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
191 if (eptr != esc_term)
kono
parents: 67
diff changeset
192 break;
kono
parents: 67
diff changeset
193 }
kono
parents: 67
diff changeset
194
kono
parents: 67
diff changeset
195 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
196 {
kono
parents: 67
diff changeset
197 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
198 /* Stop at the bottommost boundary. */
kono
parents: 67
diff changeset
199 if (sb.dwSize.Y - cr.Y > n1)
kono
parents: 67
diff changeset
200 cr.Y += n1;
kono
parents: 67
diff changeset
201 else
kono
parents: 67
diff changeset
202 cr.Y = sb.dwSize.Y;
kono
parents: 67
diff changeset
203 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
204 }
kono
parents: 67
diff changeset
205 break;
kono
parents: 67
diff changeset
206
kono
parents: 67
diff changeset
207 /* ESC [ n1 'C'
kono
parents: 67
diff changeset
208 Move the cursor right by n1 characters. */
kono
parents: 67
diff changeset
209 case MAKEWORD ('[', 'C'):
kono
parents: 67
diff changeset
210 if (esc_head == esc_term)
kono
parents: 67
diff changeset
211 n1 = 1;
kono
parents: 67
diff changeset
212 else
kono
parents: 67
diff changeset
213 {
kono
parents: 67
diff changeset
214 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
215 if (eptr != esc_term)
kono
parents: 67
diff changeset
216 break;
kono
parents: 67
diff changeset
217 }
kono
parents: 67
diff changeset
218
kono
parents: 67
diff changeset
219 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
220 {
kono
parents: 67
diff changeset
221 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
222 /* Stop at the rightmost boundary. */
kono
parents: 67
diff changeset
223 if (sb.dwSize.X - cr.X > n1)
kono
parents: 67
diff changeset
224 cr.X += n1;
kono
parents: 67
diff changeset
225 else
kono
parents: 67
diff changeset
226 cr.X = sb.dwSize.X;
kono
parents: 67
diff changeset
227 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
228 }
kono
parents: 67
diff changeset
229 break;
kono
parents: 67
diff changeset
230
kono
parents: 67
diff changeset
231 /* ESC [ n1 'D'
kono
parents: 67
diff changeset
232 Move the cursor left by n1 characters. */
kono
parents: 67
diff changeset
233 case MAKEWORD ('[', 'D'):
kono
parents: 67
diff changeset
234 if (esc_head == esc_term)
kono
parents: 67
diff changeset
235 n1 = 1;
kono
parents: 67
diff changeset
236 else
kono
parents: 67
diff changeset
237 {
kono
parents: 67
diff changeset
238 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
239 if (eptr != esc_term)
kono
parents: 67
diff changeset
240 break;
kono
parents: 67
diff changeset
241 }
kono
parents: 67
diff changeset
242
kono
parents: 67
diff changeset
243 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
244 {
kono
parents: 67
diff changeset
245 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
246 /* Stop at the leftmost boundary. */
kono
parents: 67
diff changeset
247 if (cr.X > n1)
kono
parents: 67
diff changeset
248 cr.X -= n1;
kono
parents: 67
diff changeset
249 else
kono
parents: 67
diff changeset
250 cr.X = 0;
kono
parents: 67
diff changeset
251 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
252 }
kono
parents: 67
diff changeset
253 break;
kono
parents: 67
diff changeset
254
kono
parents: 67
diff changeset
255 /* ESC [ n1 'E'
kono
parents: 67
diff changeset
256 Move the cursor to the beginning of the n1-th line downwards. */
kono
parents: 67
diff changeset
257 case MAKEWORD ('[', 'E'):
kono
parents: 67
diff changeset
258 if (esc_head == esc_term)
kono
parents: 67
diff changeset
259 n1 = 1;
kono
parents: 67
diff changeset
260 else
kono
parents: 67
diff changeset
261 {
kono
parents: 67
diff changeset
262 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
263 if (eptr != esc_term)
kono
parents: 67
diff changeset
264 break;
kono
parents: 67
diff changeset
265 }
kono
parents: 67
diff changeset
266
kono
parents: 67
diff changeset
267 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
268 {
kono
parents: 67
diff changeset
269 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
270 cr.X = 0;
kono
parents: 67
diff changeset
271 /* Stop at the bottommost boundary. */
kono
parents: 67
diff changeset
272 if (sb.dwSize.Y - cr.Y > n1)
kono
parents: 67
diff changeset
273 cr.Y += n1;
kono
parents: 67
diff changeset
274 else
kono
parents: 67
diff changeset
275 cr.Y = sb.dwSize.Y;
kono
parents: 67
diff changeset
276 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
277 }
kono
parents: 67
diff changeset
278 break;
kono
parents: 67
diff changeset
279
kono
parents: 67
diff changeset
280 /* ESC [ n1 'F'
kono
parents: 67
diff changeset
281 Move the cursor to the beginning of the n1-th line upwards. */
kono
parents: 67
diff changeset
282 case MAKEWORD ('[', 'F'):
kono
parents: 67
diff changeset
283 if (esc_head == esc_term)
kono
parents: 67
diff changeset
284 n1 = 1;
kono
parents: 67
diff changeset
285 else
kono
parents: 67
diff changeset
286 {
kono
parents: 67
diff changeset
287 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
288 if (eptr != esc_term)
kono
parents: 67
diff changeset
289 break;
kono
parents: 67
diff changeset
290 }
kono
parents: 67
diff changeset
291
kono
parents: 67
diff changeset
292 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
293 {
kono
parents: 67
diff changeset
294 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
295 cr.X = 0;
kono
parents: 67
diff changeset
296 /* Stop at the topmost boundary. */
kono
parents: 67
diff changeset
297 if (cr.Y > n1)
kono
parents: 67
diff changeset
298 cr.Y -= n1;
kono
parents: 67
diff changeset
299 else
kono
parents: 67
diff changeset
300 cr.Y = 0;
kono
parents: 67
diff changeset
301 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
302 }
kono
parents: 67
diff changeset
303 break;
kono
parents: 67
diff changeset
304
kono
parents: 67
diff changeset
305 /* ESC [ n1 'G'
kono
parents: 67
diff changeset
306 Move the cursor to the (1-based) n1-th column. */
kono
parents: 67
diff changeset
307 case MAKEWORD ('[', 'G'):
kono
parents: 67
diff changeset
308 if (esc_head == esc_term)
kono
parents: 67
diff changeset
309 n1 = 1;
kono
parents: 67
diff changeset
310 else
kono
parents: 67
diff changeset
311 {
kono
parents: 67
diff changeset
312 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
313 if (eptr != esc_term)
kono
parents: 67
diff changeset
314 break;
kono
parents: 67
diff changeset
315 }
kono
parents: 67
diff changeset
316
kono
parents: 67
diff changeset
317 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
318 {
kono
parents: 67
diff changeset
319 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
320 n1 -= 1;
kono
parents: 67
diff changeset
321 /* Stop at the leftmost or rightmost boundary. */
kono
parents: 67
diff changeset
322 if (n1 < 0)
kono
parents: 67
diff changeset
323 cr.X = 0;
kono
parents: 67
diff changeset
324 else if (n1 > sb.dwSize.X)
kono
parents: 67
diff changeset
325 cr.X = sb.dwSize.X;
kono
parents: 67
diff changeset
326 else
kono
parents: 67
diff changeset
327 cr.X = n1;
kono
parents: 67
diff changeset
328 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
329 }
kono
parents: 67
diff changeset
330 break;
kono
parents: 67
diff changeset
331
kono
parents: 67
diff changeset
332 /* ESC [ n1 ';' n2 'H'
kono
parents: 67
diff changeset
333 ESC [ n1 ';' n2 'f'
kono
parents: 67
diff changeset
334 Move the cursor to the (1-based) n1-th row and
kono
parents: 67
diff changeset
335 (also 1-based) n2-th column. */
kono
parents: 67
diff changeset
336 case MAKEWORD ('[', 'H'):
kono
parents: 67
diff changeset
337 case MAKEWORD ('[', 'f'):
kono
parents: 67
diff changeset
338 if (esc_head == esc_term)
kono
parents: 67
diff changeset
339 {
kono
parents: 67
diff changeset
340 /* Both parameters are omitted and set to 1 by default. */
kono
parents: 67
diff changeset
341 n1 = 1;
kono
parents: 67
diff changeset
342 n2 = 1;
kono
parents: 67
diff changeset
343 }
kono
parents: 67
diff changeset
344 else if (!(delim = (char *) memchr (esc_head, ';',
kono
parents: 67
diff changeset
345 esc_term - esc_head)))
kono
parents: 67
diff changeset
346 {
kono
parents: 67
diff changeset
347 /* Only the first parameter is given. The second one is
kono
parents: 67
diff changeset
348 set to 1 by default. */
kono
parents: 67
diff changeset
349 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
350 if (eptr != esc_term)
kono
parents: 67
diff changeset
351 break;
kono
parents: 67
diff changeset
352 n2 = 1;
kono
parents: 67
diff changeset
353 }
kono
parents: 67
diff changeset
354 else
kono
parents: 67
diff changeset
355 {
kono
parents: 67
diff changeset
356 /* Both parameters are given. The first one shall be
kono
parents: 67
diff changeset
357 terminated by the semicolon. */
kono
parents: 67
diff changeset
358 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
359 if (eptr != delim)
kono
parents: 67
diff changeset
360 break;
kono
parents: 67
diff changeset
361 n2 = strtol (delim + 1, &eptr, 10);
kono
parents: 67
diff changeset
362 if (eptr != esc_term)
kono
parents: 67
diff changeset
363 break;
kono
parents: 67
diff changeset
364 }
kono
parents: 67
diff changeset
365
kono
parents: 67
diff changeset
366 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
367 {
kono
parents: 67
diff changeset
368 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
369 n1 -= 1;
kono
parents: 67
diff changeset
370 n2 -= 1;
kono
parents: 67
diff changeset
371 /* The cursor position shall be relative to the view coord of
kono
parents: 67
diff changeset
372 the console window, which is usually smaller than the actual
kono
parents: 67
diff changeset
373 buffer. FWIW, the 'appropriate' solution will be shrinking
kono
parents: 67
diff changeset
374 the buffer to match the size of the console window,
kono
parents: 67
diff changeset
375 destroying scrollback in the process. */
kono
parents: 67
diff changeset
376 n1 += sb.srWindow.Top;
kono
parents: 67
diff changeset
377 n2 += sb.srWindow.Left;
kono
parents: 67
diff changeset
378 /* Stop at the topmost or bottommost boundary. */
kono
parents: 67
diff changeset
379 if (n1 < 0)
kono
parents: 67
diff changeset
380 cr.Y = 0;
kono
parents: 67
diff changeset
381 else if (n1 > sb.dwSize.Y)
kono
parents: 67
diff changeset
382 cr.Y = sb.dwSize.Y;
kono
parents: 67
diff changeset
383 else
kono
parents: 67
diff changeset
384 cr.Y = n1;
kono
parents: 67
diff changeset
385 /* Stop at the leftmost or rightmost boundary. */
kono
parents: 67
diff changeset
386 if (n2 < 0)
kono
parents: 67
diff changeset
387 cr.X = 0;
kono
parents: 67
diff changeset
388 else if (n2 > sb.dwSize.X)
kono
parents: 67
diff changeset
389 cr.X = sb.dwSize.X;
kono
parents: 67
diff changeset
390 else
kono
parents: 67
diff changeset
391 cr.X = n2;
kono
parents: 67
diff changeset
392 SetConsoleCursorPosition (h, cr);
kono
parents: 67
diff changeset
393 }
kono
parents: 67
diff changeset
394 break;
kono
parents: 67
diff changeset
395
kono
parents: 67
diff changeset
396 /* ESC [ n1 'J'
kono
parents: 67
diff changeset
397 Erase display. */
kono
parents: 67
diff changeset
398 case MAKEWORD ('[', 'J'):
kono
parents: 67
diff changeset
399 if (esc_head == esc_term)
kono
parents: 67
diff changeset
400 /* This is one of the very few codes whose parameters have
kono
parents: 67
diff changeset
401 a default value of zero. */
kono
parents: 67
diff changeset
402 n1 = 0;
kono
parents: 67
diff changeset
403 else
kono
parents: 67
diff changeset
404 {
kono
parents: 67
diff changeset
405 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
406 if (eptr != esc_term)
kono
parents: 67
diff changeset
407 break;
kono
parents: 67
diff changeset
408 }
kono
parents: 67
diff changeset
409
kono
parents: 67
diff changeset
410 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
411 {
kono
parents: 67
diff changeset
412 /* The cursor is not necessarily in the console window, which
kono
parents: 67
diff changeset
413 makes the behavior of this code harder to define. */
kono
parents: 67
diff changeset
414 switch (n1)
kono
parents: 67
diff changeset
415 {
kono
parents: 67
diff changeset
416 case 0:
kono
parents: 67
diff changeset
417 /* If the cursor is in or above the window, erase from
kono
parents: 67
diff changeset
418 it to the bottom of the window; otherwise, do nothing. */
kono
parents: 67
diff changeset
419 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
420 cnt = sb.dwSize.X - sb.dwCursorPosition.X;
kono
parents: 67
diff changeset
421 rows = sb.srWindow.Bottom - sb.dwCursorPosition.Y;
kono
parents: 67
diff changeset
422 break;
kono
parents: 67
diff changeset
423 case 1:
kono
parents: 67
diff changeset
424 /* If the cursor is in or under the window, erase from
kono
parents: 67
diff changeset
425 it to the top of the window; otherwise, do nothing. */
kono
parents: 67
diff changeset
426 cr.X = 0;
kono
parents: 67
diff changeset
427 cr.Y = sb.srWindow.Top;
kono
parents: 67
diff changeset
428 cnt = sb.dwCursorPosition.X + 1;
kono
parents: 67
diff changeset
429 rows = sb.dwCursorPosition.Y - sb.srWindow.Top;
kono
parents: 67
diff changeset
430 break;
kono
parents: 67
diff changeset
431 case 2:
kono
parents: 67
diff changeset
432 /* Erase the entire window. */
kono
parents: 67
diff changeset
433 cr.X = sb.srWindow.Left;
kono
parents: 67
diff changeset
434 cr.Y = sb.srWindow.Top;
kono
parents: 67
diff changeset
435 cnt = 0;
kono
parents: 67
diff changeset
436 rows = sb.srWindow.Bottom - sb.srWindow.Top + 1;
kono
parents: 67
diff changeset
437 break;
kono
parents: 67
diff changeset
438 default:
kono
parents: 67
diff changeset
439 /* Erase the entire buffer. */
kono
parents: 67
diff changeset
440 cr.X = 0;
kono
parents: 67
diff changeset
441 cr.Y = 0;
kono
parents: 67
diff changeset
442 cnt = 0;
kono
parents: 67
diff changeset
443 rows = sb.dwSize.Y;
kono
parents: 67
diff changeset
444 break;
kono
parents: 67
diff changeset
445 }
kono
parents: 67
diff changeset
446 if (rows < 0)
kono
parents: 67
diff changeset
447 break;
kono
parents: 67
diff changeset
448 cnt += rows * sb.dwSize.X;
kono
parents: 67
diff changeset
449 FillConsoleOutputCharacterW (h, L' ', cnt, cr, &step);
kono
parents: 67
diff changeset
450 FillConsoleOutputAttribute (h, sb.wAttributes, cnt, cr, &step);
kono
parents: 67
diff changeset
451 }
kono
parents: 67
diff changeset
452 break;
kono
parents: 67
diff changeset
453
kono
parents: 67
diff changeset
454 /* ESC [ n1 'K'
kono
parents: 67
diff changeset
455 Erase line. */
kono
parents: 67
diff changeset
456 case MAKEWORD ('[', 'K'):
kono
parents: 67
diff changeset
457 if (esc_head == esc_term)
kono
parents: 67
diff changeset
458 /* This is one of the very few codes whose parameters have
kono
parents: 67
diff changeset
459 a default value of zero. */
kono
parents: 67
diff changeset
460 n1 = 0;
kono
parents: 67
diff changeset
461 else
kono
parents: 67
diff changeset
462 {
kono
parents: 67
diff changeset
463 n1 = strtol (esc_head, &eptr, 10);
kono
parents: 67
diff changeset
464 if (eptr != esc_term)
kono
parents: 67
diff changeset
465 break;
kono
parents: 67
diff changeset
466 }
kono
parents: 67
diff changeset
467
kono
parents: 67
diff changeset
468 if (GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
469 {
kono
parents: 67
diff changeset
470 switch (n1)
kono
parents: 67
diff changeset
471 {
kono
parents: 67
diff changeset
472 case 0:
kono
parents: 67
diff changeset
473 /* Erase from the cursor to the end. */
kono
parents: 67
diff changeset
474 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
475 cnt = sb.dwSize.X - sb.dwCursorPosition.X;
kono
parents: 67
diff changeset
476 break;
kono
parents: 67
diff changeset
477 case 1:
kono
parents: 67
diff changeset
478 /* Erase from the cursor to the beginning. */
kono
parents: 67
diff changeset
479 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
480 cr.X = 0;
kono
parents: 67
diff changeset
481 cnt = sb.dwCursorPosition.X + 1;
kono
parents: 67
diff changeset
482 break;
kono
parents: 67
diff changeset
483 default:
kono
parents: 67
diff changeset
484 /* Erase the entire line. */
kono
parents: 67
diff changeset
485 cr = sb.dwCursorPosition;
kono
parents: 67
diff changeset
486 cr.X = 0;
kono
parents: 67
diff changeset
487 cnt = sb.dwSize.X;
kono
parents: 67
diff changeset
488 break;
kono
parents: 67
diff changeset
489 }
kono
parents: 67
diff changeset
490 FillConsoleOutputCharacterW (h, L' ', cnt, cr, &step);
kono
parents: 67
diff changeset
491 FillConsoleOutputAttribute (h, sb.wAttributes, cnt, cr, &step);
kono
parents: 67
diff changeset
492 }
kono
parents: 67
diff changeset
493 break;
kono
parents: 67
diff changeset
494
kono
parents: 67
diff changeset
495 /* ESC [ n1 ';' n2 'm'
kono
parents: 67
diff changeset
496 Set SGR parameters. Zero or more parameters will follow. */
kono
parents: 67
diff changeset
497 case MAKEWORD ('[', 'm'):
kono
parents: 67
diff changeset
498 attrib_add = 0;
kono
parents: 67
diff changeset
499 attrib_rm = 0;
kono
parents: 67
diff changeset
500 if (esc_head == esc_term)
kono
parents: 67
diff changeset
501 {
kono
parents: 67
diff changeset
502 /* When no parameter is given, reset the console. */
kono
parents: 67
diff changeset
503 attrib_add |= (FOREGROUND_RED | FOREGROUND_GREEN
kono
parents: 67
diff changeset
504 | FOREGROUND_BLUE);
kono
parents: 67
diff changeset
505 attrib_rm = -1; /* Removes everything. */
kono
parents: 67
diff changeset
506 goto sgr_set_it;
kono
parents: 67
diff changeset
507 }
kono
parents: 67
diff changeset
508 param = esc_head;
kono
parents: 67
diff changeset
509 do
kono
parents: 67
diff changeset
510 {
kono
parents: 67
diff changeset
511 /* Parse a parameter. */
kono
parents: 67
diff changeset
512 n1 = strtol (param, &eptr, 10);
kono
parents: 67
diff changeset
513 if (*eptr != ';' && eptr != esc_term)
kono
parents: 67
diff changeset
514 goto sgr_set_it;
kono
parents: 67
diff changeset
515
kono
parents: 67
diff changeset
516 switch (n1)
kono
parents: 67
diff changeset
517 {
kono
parents: 67
diff changeset
518 case 0:
kono
parents: 67
diff changeset
519 /* Reset. */
kono
parents: 67
diff changeset
520 attrib_add |= (FOREGROUND_RED | FOREGROUND_GREEN
kono
parents: 67
diff changeset
521 | FOREGROUND_BLUE);
kono
parents: 67
diff changeset
522 attrib_rm = -1; /* Removes everything. */
kono
parents: 67
diff changeset
523 break;
kono
parents: 67
diff changeset
524 case 1:
kono
parents: 67
diff changeset
525 /* Bold. */
kono
parents: 67
diff changeset
526 attrib_add |= FOREGROUND_INTENSITY;
kono
parents: 67
diff changeset
527 break;
kono
parents: 67
diff changeset
528 case 4:
kono
parents: 67
diff changeset
529 /* Underline. */
kono
parents: 67
diff changeset
530 attrib_add |= COMMON_LVB_UNDERSCORE;
kono
parents: 67
diff changeset
531 break;
kono
parents: 67
diff changeset
532 case 5:
kono
parents: 67
diff changeset
533 /* Blink. */
kono
parents: 67
diff changeset
534 /* XXX: It is not BLINKING at all! */
kono
parents: 67
diff changeset
535 attrib_add |= BACKGROUND_INTENSITY;
kono
parents: 67
diff changeset
536 break;
kono
parents: 67
diff changeset
537 case 7:
kono
parents: 67
diff changeset
538 /* Reverse. */
kono
parents: 67
diff changeset
539 attrib_add |= COMMON_LVB_REVERSE_VIDEO;
kono
parents: 67
diff changeset
540 break;
kono
parents: 67
diff changeset
541 case 22:
kono
parents: 67
diff changeset
542 /* No bold. */
kono
parents: 67
diff changeset
543 attrib_add &= ~FOREGROUND_INTENSITY;
kono
parents: 67
diff changeset
544 attrib_rm |= FOREGROUND_INTENSITY;
kono
parents: 67
diff changeset
545 break;
kono
parents: 67
diff changeset
546 case 24:
kono
parents: 67
diff changeset
547 /* No underline. */
kono
parents: 67
diff changeset
548 attrib_add &= ~COMMON_LVB_UNDERSCORE;
kono
parents: 67
diff changeset
549 attrib_rm |= COMMON_LVB_UNDERSCORE;
kono
parents: 67
diff changeset
550 break;
kono
parents: 67
diff changeset
551 case 25:
kono
parents: 67
diff changeset
552 /* No blink. */
kono
parents: 67
diff changeset
553 /* XXX: It is not BLINKING at all! */
kono
parents: 67
diff changeset
554 attrib_add &= ~BACKGROUND_INTENSITY;
kono
parents: 67
diff changeset
555 attrib_rm |= BACKGROUND_INTENSITY;
kono
parents: 67
diff changeset
556 break;
kono
parents: 67
diff changeset
557 case 27:
kono
parents: 67
diff changeset
558 /* No reverse. */
kono
parents: 67
diff changeset
559 attrib_add &= ~COMMON_LVB_REVERSE_VIDEO;
kono
parents: 67
diff changeset
560 attrib_rm |= COMMON_LVB_REVERSE_VIDEO;
kono
parents: 67
diff changeset
561 break;
kono
parents: 67
diff changeset
562 case 30:
kono
parents: 67
diff changeset
563 case 31:
kono
parents: 67
diff changeset
564 case 32:
kono
parents: 67
diff changeset
565 case 33:
kono
parents: 67
diff changeset
566 case 34:
kono
parents: 67
diff changeset
567 case 35:
kono
parents: 67
diff changeset
568 case 36:
kono
parents: 67
diff changeset
569 case 37:
kono
parents: 67
diff changeset
570 /* Foreground color. */
kono
parents: 67
diff changeset
571 attrib_add &= ~(FOREGROUND_RED | FOREGROUND_GREEN
kono
parents: 67
diff changeset
572 | FOREGROUND_BLUE);
kono
parents: 67
diff changeset
573 n1 -= 30;
kono
parents: 67
diff changeset
574 if (n1 & 1)
kono
parents: 67
diff changeset
575 attrib_add |= FOREGROUND_RED;
kono
parents: 67
diff changeset
576 if (n1 & 2)
kono
parents: 67
diff changeset
577 attrib_add |= FOREGROUND_GREEN;
kono
parents: 67
diff changeset
578 if (n1 & 4)
kono
parents: 67
diff changeset
579 attrib_add |= FOREGROUND_BLUE;
kono
parents: 67
diff changeset
580 attrib_rm |= (FOREGROUND_RED | FOREGROUND_GREEN
kono
parents: 67
diff changeset
581 | FOREGROUND_BLUE);
kono
parents: 67
diff changeset
582 break;
kono
parents: 67
diff changeset
583 case 38:
kono
parents: 67
diff changeset
584 /* Reserved for extended foreground color.
kono
parents: 67
diff changeset
585 Don't know how to handle parameters remaining.
kono
parents: 67
diff changeset
586 Bail out. */
kono
parents: 67
diff changeset
587 goto sgr_set_it;
kono
parents: 67
diff changeset
588 case 39:
kono
parents: 67
diff changeset
589 /* Reset foreground color. */
kono
parents: 67
diff changeset
590 /* Set to grey. */
kono
parents: 67
diff changeset
591 attrib_add |= (FOREGROUND_RED | FOREGROUND_GREEN
kono
parents: 67
diff changeset
592 | FOREGROUND_BLUE);
kono
parents: 67
diff changeset
593 attrib_rm |= (FOREGROUND_RED | FOREGROUND_GREEN
kono
parents: 67
diff changeset
594 | FOREGROUND_BLUE);
kono
parents: 67
diff changeset
595 break;
kono
parents: 67
diff changeset
596 case 40:
kono
parents: 67
diff changeset
597 case 41:
kono
parents: 67
diff changeset
598 case 42:
kono
parents: 67
diff changeset
599 case 43:
kono
parents: 67
diff changeset
600 case 44:
kono
parents: 67
diff changeset
601 case 45:
kono
parents: 67
diff changeset
602 case 46:
kono
parents: 67
diff changeset
603 case 47:
kono
parents: 67
diff changeset
604 /* Background color. */
kono
parents: 67
diff changeset
605 attrib_add &= ~(BACKGROUND_RED | BACKGROUND_GREEN
kono
parents: 67
diff changeset
606 | BACKGROUND_BLUE);
kono
parents: 67
diff changeset
607 n1 -= 40;
kono
parents: 67
diff changeset
608 if (n1 & 1)
kono
parents: 67
diff changeset
609 attrib_add |= BACKGROUND_RED;
kono
parents: 67
diff changeset
610 if (n1 & 2)
kono
parents: 67
diff changeset
611 attrib_add |= BACKGROUND_GREEN;
kono
parents: 67
diff changeset
612 if (n1 & 4)
kono
parents: 67
diff changeset
613 attrib_add |= BACKGROUND_BLUE;
kono
parents: 67
diff changeset
614 attrib_rm |= (BACKGROUND_RED | BACKGROUND_GREEN
kono
parents: 67
diff changeset
615 | BACKGROUND_BLUE);
kono
parents: 67
diff changeset
616 break;
kono
parents: 67
diff changeset
617 case 48:
kono
parents: 67
diff changeset
618 /* Reserved for extended background color.
kono
parents: 67
diff changeset
619 Don't know how to handle parameters remaining.
kono
parents: 67
diff changeset
620 Bail out. */
kono
parents: 67
diff changeset
621 goto sgr_set_it;
kono
parents: 67
diff changeset
622 case 49:
kono
parents: 67
diff changeset
623 /* Reset background color. */
kono
parents: 67
diff changeset
624 /* Set to black. */
kono
parents: 67
diff changeset
625 attrib_add &= ~(BACKGROUND_RED | BACKGROUND_GREEN
kono
parents: 67
diff changeset
626 | BACKGROUND_BLUE);
kono
parents: 67
diff changeset
627 attrib_rm |= (BACKGROUND_RED | BACKGROUND_GREEN
kono
parents: 67
diff changeset
628 | BACKGROUND_BLUE);
kono
parents: 67
diff changeset
629 break;
kono
parents: 67
diff changeset
630 }
kono
parents: 67
diff changeset
631
kono
parents: 67
diff changeset
632 /* Prepare the next parameter. */
kono
parents: 67
diff changeset
633 param = eptr + 1;
kono
parents: 67
diff changeset
634 }
kono
parents: 67
diff changeset
635 while (param != esc_term);
kono
parents: 67
diff changeset
636
kono
parents: 67
diff changeset
637 sgr_set_it:
kono
parents: 67
diff changeset
638 /* 0xFFFF removes everything. If it is not the case,
kono
parents: 67
diff changeset
639 care must be taken to preserve old attributes. */
kono
parents: 67
diff changeset
640 if (attrib_rm != 0xFFFF && GetConsoleScreenBufferInfo (h, &sb))
kono
parents: 67
diff changeset
641 {
kono
parents: 67
diff changeset
642 attrib_add |= sb.wAttributes & ~attrib_rm;
kono
parents: 67
diff changeset
643 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
644 if (attrib_add & COMMON_LVB_REVERSE_VIDEO)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
645 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
646 /* COMMON_LVB_REVERSE_VIDEO is only effective for DBCS.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
647 * Swap foreground and background colors by hand.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
648 */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
649 attrib_add = (attrib_add & 0xFF00)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
650 | ((attrib_add & 0x00F0) >> 4)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
651 | ((attrib_add & 0x000F) << 4);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
652 attrib_add &= ~COMMON_LVB_REVERSE_VIDEO;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
653 }
111
kono
parents: 67
diff changeset
654 SetConsoleTextAttribute (h, attrib_add);
kono
parents: 67
diff changeset
655 break;
kono
parents: 67
diff changeset
656 }
kono
parents: 67
diff changeset
657 }
kono
parents: 67
diff changeset
658
kono
parents: 67
diff changeset
659 int
kono
parents: 67
diff changeset
660 mingw_ansi_fputs (const char *str, FILE *fp)
kono
parents: 67
diff changeset
661 {
kono
parents: 67
diff changeset
662 const char *read = str;
kono
parents: 67
diff changeset
663 HANDLE h;
kono
parents: 67
diff changeset
664 DWORD mode;
kono
parents: 67
diff changeset
665 int esc_code, prefix_len;
kono
parents: 67
diff changeset
666 const char *esc_head, *esc_term;
kono
parents: 67
diff changeset
667
kono
parents: 67
diff changeset
668 h = (HANDLE) _get_osfhandle (_fileno (fp));
kono
parents: 67
diff changeset
669 if (h == INVALID_HANDLE_VALUE)
kono
parents: 67
diff changeset
670 return EOF;
kono
parents: 67
diff changeset
671
kono
parents: 67
diff changeset
672 /* Don't mess up stdio functions with Windows APIs. */
kono
parents: 67
diff changeset
673 fflush (fp);
kono
parents: 67
diff changeset
674
kono
parents: 67
diff changeset
675 if (GetConsoleMode (h, &mode))
kono
parents: 67
diff changeset
676 /* If it is a console, translate ANSI escape codes as needed. */
kono
parents: 67
diff changeset
677 for (;;)
kono
parents: 67
diff changeset
678 {
kono
parents: 67
diff changeset
679 if ((esc_code = find_esc_head (&prefix_len, &esc_head, read)) == 0)
kono
parents: 67
diff changeset
680 {
kono
parents: 67
diff changeset
681 /* Write all remaining characters, then exit. */
kono
parents: 67
diff changeset
682 write_all (h, read, strlen (read));
kono
parents: 67
diff changeset
683 break;
kono
parents: 67
diff changeset
684 }
kono
parents: 67
diff changeset
685 if (find_esc_terminator (&esc_term, esc_head) == 0)
kono
parents: 67
diff changeset
686 /* Ignore incomplete escape sequences at the moment.
kono
parents: 67
diff changeset
687 FIXME: The escape state shall be cached for further calls
kono
parents: 67
diff changeset
688 to this function. */
kono
parents: 67
diff changeset
689 break;
kono
parents: 67
diff changeset
690 write_all (h, read, esc_head - prefix_len - read);
kono
parents: 67
diff changeset
691 eat_esc_sequence (h, esc_code, esc_head, esc_term);
kono
parents: 67
diff changeset
692 read = esc_term + 1;
kono
parents: 67
diff changeset
693 }
kono
parents: 67
diff changeset
694 else
kono
parents: 67
diff changeset
695 /* If it is not a console, write everything as-is. */
kono
parents: 67
diff changeset
696 write_all (h, read, strlen (read));
kono
parents: 67
diff changeset
697
kono
parents: 67
diff changeset
698 return 1;
kono
parents: 67
diff changeset
699 }
kono
parents: 67
diff changeset
700
kono
parents: 67
diff changeset
701 #endif /* __MINGW32__ */
kono
parents: 67
diff changeset
702
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
703 static int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
704 decode_utf8_char (const unsigned char *, size_t len, unsigned int *);
111
kono
parents: 67
diff changeset
705 static void pp_quoted_string (pretty_printer *, const char *, size_t = -1);
kono
parents: 67
diff changeset
706
kono
parents: 67
diff changeset
707 /* Overwrite the given location/range within this text_info's rich_location.
kono
parents: 67
diff changeset
708 For use e.g. when implementing "+" in client format decoders. */
kono
parents: 67
diff changeset
709
kono
parents: 67
diff changeset
710 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
711 text_info::set_location (unsigned int idx, location_t loc,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
712 enum range_display_kind range_display_kind)
111
kono
parents: 67
diff changeset
713 {
kono
parents: 67
diff changeset
714 gcc_checking_assert (m_richloc);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
715 m_richloc->set_range (idx, loc, range_display_kind);
111
kono
parents: 67
diff changeset
716 }
kono
parents: 67
diff changeset
717
kono
parents: 67
diff changeset
718 location_t
kono
parents: 67
diff changeset
719 text_info::get_location (unsigned int index_of_location) const
kono
parents: 67
diff changeset
720 {
kono
parents: 67
diff changeset
721 gcc_checking_assert (m_richloc);
kono
parents: 67
diff changeset
722
kono
parents: 67
diff changeset
723 if (index_of_location == 0)
kono
parents: 67
diff changeset
724 return m_richloc->get_loc ();
kono
parents: 67
diff changeset
725 else
kono
parents: 67
diff changeset
726 return UNKNOWN_LOCATION;
kono
parents: 67
diff changeset
727 }
kono
parents: 67
diff changeset
728
kono
parents: 67
diff changeset
729 // Default construct an output buffer.
kono
parents: 67
diff changeset
730
kono
parents: 67
diff changeset
731 output_buffer::output_buffer ()
kono
parents: 67
diff changeset
732 : formatted_obstack (),
kono
parents: 67
diff changeset
733 chunk_obstack (),
kono
parents: 67
diff changeset
734 obstack (&formatted_obstack),
kono
parents: 67
diff changeset
735 cur_chunk_array (),
kono
parents: 67
diff changeset
736 stream (stderr),
kono
parents: 67
diff changeset
737 line_length (),
kono
parents: 67
diff changeset
738 digit_buffer (),
kono
parents: 67
diff changeset
739 flush_p (true)
kono
parents: 67
diff changeset
740 {
kono
parents: 67
diff changeset
741 obstack_init (&formatted_obstack);
kono
parents: 67
diff changeset
742 obstack_init (&chunk_obstack);
kono
parents: 67
diff changeset
743 }
kono
parents: 67
diff changeset
744
kono
parents: 67
diff changeset
745 // Release resources owned by an output buffer at the end of lifetime.
kono
parents: 67
diff changeset
746
kono
parents: 67
diff changeset
747 output_buffer::~output_buffer ()
kono
parents: 67
diff changeset
748 {
kono
parents: 67
diff changeset
749 obstack_free (&chunk_obstack, NULL);
kono
parents: 67
diff changeset
750 obstack_free (&formatted_obstack, NULL);
kono
parents: 67
diff changeset
751 }
kono
parents: 67
diff changeset
752
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 /* Format an integer given by va_arg (ARG, type-specifier T) where
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 type-specifier is a precision modifier as indicated by PREC. F is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 a string used to construct the appropriate format-specifier. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 #define pp_integer_with_precision(PP, ARG, PREC, T, F) \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 do \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 switch (PREC) \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 { \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 case 0: \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 pp_scalar (PP, "%" F, va_arg (ARG, T)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 break; \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 case 1: \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 pp_scalar (PP, "%l" F, va_arg (ARG, long T)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 break; \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 case 2: \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 pp_scalar (PP, "%" HOST_LONG_LONG_FORMAT F, va_arg (ARG, long long T)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 break; \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 default: \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 break; \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 } \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 while (0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 /* Subroutine of pp_set_maximum_length. Set up PRETTY-PRINTER's
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 internal maximum characters per line. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 pp_set_real_maximum_length (pretty_printer *pp)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 /* If we're told not to wrap lines then do the obvious thing. In case
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 we'll emit prefix only once per message, it is appropriate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 not to increase unnecessarily the line-length cut-off. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 if (!pp_is_wrapping_line (pp)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 || pp_prefixing_rule (pp) == DIAGNOSTICS_SHOW_PREFIX_ONCE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 || pp_prefixing_rule (pp) == DIAGNOSTICS_SHOW_PREFIX_NEVER)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 pp->maximum_length = pp_line_cutoff (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 int prefix_length = pp->prefix ? strlen (pp->prefix) : 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 /* If the prefix is ridiculously too long, output at least
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 32 characters. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 if (pp_line_cutoff (pp) - prefix_length < 32)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 pp->maximum_length = pp_line_cutoff (pp) + 32;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 pp->maximum_length = pp_line_cutoff (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 /* Clear PRETTY-PRINTER's output state. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 pp_clear_state (pretty_printer *pp)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 pp->emitted_prefix = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 pp_indentation (pp) = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
811 /* Print X to PP in decimal. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
812 template<unsigned int N, typename T>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
813 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
814 pp_wide_integer (pretty_printer *pp, const poly_int_pod<N, T> &x)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
815 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
816 if (x.is_constant ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
817 pp_wide_integer (pp, x.coeffs[0]);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
818 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
819 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
820 pp_left_bracket (pp);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
821 for (unsigned int i = 0; i < N; ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
822 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
823 if (i != 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
824 pp_comma (pp);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
825 pp_wide_integer (pp, x.coeffs[i]);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
826 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
827 pp_right_bracket (pp);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
828 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
829 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
830
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
831 template void pp_wide_integer (pretty_printer *, const poly_uint16_pod &);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
832 template void pp_wide_integer (pretty_printer *, const poly_int64_pod &);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
833 template void pp_wide_integer (pretty_printer *, const poly_uint64_pod &);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
834
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 /* Flush the formatted text of PRETTY-PRINTER onto the attached stream. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 pp_write_text_to_stream (pretty_printer *pp)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 const char *text = pp_formatted_text (pp);
111
kono
parents: 67
diff changeset
840 #ifdef __MINGW32__
kono
parents: 67
diff changeset
841 mingw_ansi_fputs (text, pp_buffer (pp)->stream);
kono
parents: 67
diff changeset
842 #else
kono
parents: 67
diff changeset
843 fputs (text, pp_buffer (pp)->stream);
kono
parents: 67
diff changeset
844 #endif
kono
parents: 67
diff changeset
845 pp_clear_output_area (pp);
kono
parents: 67
diff changeset
846 }
kono
parents: 67
diff changeset
847
kono
parents: 67
diff changeset
848 /* As pp_write_text_to_stream, but for GraphViz label output.
kono
parents: 67
diff changeset
849
kono
parents: 67
diff changeset
850 Flush the formatted text of pretty-printer PP onto the attached stream.
kono
parents: 67
diff changeset
851 Replace characters in PPF that have special meaning in a GraphViz .dot
kono
parents: 67
diff changeset
852 file.
kono
parents: 67
diff changeset
853
kono
parents: 67
diff changeset
854 This routine is not very fast, but it doesn't have to be as this is only
kono
parents: 67
diff changeset
855 be used by routines dumping intermediate representations in graph form. */
kono
parents: 67
diff changeset
856
kono
parents: 67
diff changeset
857 void
kono
parents: 67
diff changeset
858 pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record)
kono
parents: 67
diff changeset
859 {
kono
parents: 67
diff changeset
860 const char *text = pp_formatted_text (pp);
kono
parents: 67
diff changeset
861 const char *p = text;
kono
parents: 67
diff changeset
862 FILE *fp = pp_buffer (pp)->stream;
kono
parents: 67
diff changeset
863
kono
parents: 67
diff changeset
864 for (;*p; p++)
kono
parents: 67
diff changeset
865 {
kono
parents: 67
diff changeset
866 bool escape_char;
kono
parents: 67
diff changeset
867 switch (*p)
kono
parents: 67
diff changeset
868 {
kono
parents: 67
diff changeset
869 /* Print newlines as a left-aligned newline. */
kono
parents: 67
diff changeset
870 case '\n':
kono
parents: 67
diff changeset
871 fputs ("\\l", fp);
kono
parents: 67
diff changeset
872 escape_char = true;
kono
parents: 67
diff changeset
873 break;
kono
parents: 67
diff changeset
874
kono
parents: 67
diff changeset
875 /* The following characters are only special for record-shape nodes. */
kono
parents: 67
diff changeset
876 case '|':
kono
parents: 67
diff changeset
877 case '{':
kono
parents: 67
diff changeset
878 case '}':
kono
parents: 67
diff changeset
879 case '<':
kono
parents: 67
diff changeset
880 case '>':
kono
parents: 67
diff changeset
881 case ' ':
kono
parents: 67
diff changeset
882 escape_char = for_record;
kono
parents: 67
diff changeset
883 break;
kono
parents: 67
diff changeset
884
kono
parents: 67
diff changeset
885 /* The following characters always have to be escaped
kono
parents: 67
diff changeset
886 for use in labels. */
kono
parents: 67
diff changeset
887 case '\\':
kono
parents: 67
diff changeset
888 /* There is a bug in some (f.i. 2.36.0) versions of graphiz
kono
parents: 67
diff changeset
889 ( http://www.graphviz.org/mantisbt/view.php?id=2524 ) related to
kono
parents: 67
diff changeset
890 backslash as last char in label. Let's avoid triggering it. */
kono
parents: 67
diff changeset
891 gcc_assert (*(p + 1) != '\0');
kono
parents: 67
diff changeset
892 /* Fall through. */
kono
parents: 67
diff changeset
893 case '"':
kono
parents: 67
diff changeset
894 escape_char = true;
kono
parents: 67
diff changeset
895 break;
kono
parents: 67
diff changeset
896
kono
parents: 67
diff changeset
897 default:
kono
parents: 67
diff changeset
898 escape_char = false;
kono
parents: 67
diff changeset
899 break;
kono
parents: 67
diff changeset
900 }
kono
parents: 67
diff changeset
901
kono
parents: 67
diff changeset
902 if (escape_char)
kono
parents: 67
diff changeset
903 fputc ('\\', fp);
kono
parents: 67
diff changeset
904
kono
parents: 67
diff changeset
905 fputc (*p, fp);
kono
parents: 67
diff changeset
906 }
kono
parents: 67
diff changeset
907
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 pp_clear_output_area (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
911 /* As pp_write_text_to_stream, but for GraphViz HTML-like strings.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
912
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
913 Flush the formatted text of pretty-printer PP onto the attached stream,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
914 escaping these characters
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
915 " & < >
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
916 using XML escape sequences.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
917
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
918 http://www.graphviz.org/doc/info/lang.html#html states:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
919 special XML escape sequences for ", &, <, and > may be necessary in
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
920 order to embed these characters in attribute values or raw text
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
921 This doesn't list "'" (which would normally be escaped in XML
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
922 as "&apos;" or in HTML as "&#39;");.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
923
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
924 Experiments show that escaping "'" doesn't seem to be necessary. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
925
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
926 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
927 pp_write_text_as_html_like_dot_to_stream (pretty_printer *pp)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
928 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
929 const char *text = pp_formatted_text (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
930 const char *p = text;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
931 FILE *fp = pp_buffer (pp)->stream;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
932
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
933 for (;*p; p++)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
934 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
935 switch (*p)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
936 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
937 case '"':
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
938 fputs ("&quot;", fp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
939 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
940 case '&':
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
941 fputs ("&amp;", fp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
942 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
943 case '<':
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
944 fputs ("&lt;", fp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
945 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
946 case '>':
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
947 fputs ("&gt;",fp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
948 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
949
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
950 default:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
951 fputc (*p, fp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
952 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
953 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
954 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
955
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
956 pp_clear_output_area (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
957 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
958
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 /* Wrap a text delimited by START and END into PRETTY-PRINTER. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 pp_wrap_text (pretty_printer *pp, const char *start, const char *end)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
963 bool wrapping_line = pp_is_wrapping_line (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 while (start != end)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 /* Dump anything bordered by whitespaces. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 const char *p = start;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 while (p != end && !ISBLANK (*p) && *p != '\n')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 ++p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 if (wrapping_line
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973 && p - start >= pp_remaining_character_count_for_line (pp))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 pp_newline (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 pp_append_text (pp, start, p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 start = p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
977 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 if (start != end && ISBLANK (*start))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981 pp_space (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 ++start;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 if (start != end && *start == '\n')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
985 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
986 pp_newline (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987 ++start;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992 /* Same as pp_wrap_text but wrap text only when in line-wrapping mode. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 pp_maybe_wrap_text (pretty_printer *pp, const char *start, const char *end)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 if (pp_is_wrapping_line (pp))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 pp_wrap_text (pp, start, end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 pp_append_text (pp, start, end);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 /* Append to the output area of PRETTY-PRINTER a string specified by its
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 STARTing character and LENGTH. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 pp_append_r (pretty_printer *pp, const char *start, int length)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 {
111
kono
parents: 67
diff changeset
1007 output_buffer_append_r (pp_buffer (pp), start, length);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 /* Insert enough spaces into the output area of PRETTY-PRINTER to bring
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 the column position to the current indentation level, assuming that a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012 newline has just been written to the buffer. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 void
111
kono
parents: 67
diff changeset
1014 pp_indent (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 int n = pp_indentation (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017 int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 for (i = 0; i < n; ++i)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020 pp_space (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 /* The following format specifiers are recognized as being client independent:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 %d, %i: (signed) integer in base ten.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 %u: unsigned integer in base ten.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026 %o: unsigned integer in base eight.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 %x: unsigned integer in base sixteen.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 %ld, %li, %lo, %lu, %lx: long versions of the above.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 %lld, %lli, %llo, %llu, %llx: long long versions.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 %wd, %wi, %wo, %wu, %wx: HOST_WIDE_INT versions.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1031 %f: double
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032 %c: character.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033 %s: string.
111
kono
parents: 67
diff changeset
1034 %p: pointer (printed in a host-dependent manner).
kono
parents: 67
diff changeset
1035 %r: if pp_show_color(pp), switch to color identified by const char *.
kono
parents: 67
diff changeset
1036 %R: if pp_show_color(pp), reset color.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 %m: strerror(text->err_no) - does not consume a value from args_ptr.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 %%: '%'.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 %<: opening quote.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 %>: closing quote.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 %': apostrophe (should only be used in untranslated messages;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 translations should use appropriate punctuation directly).
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1043 %@: diagnostic_event_id_ptr, for which event_id->known_p () must be true.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 %.*s: a substring the length of which is specified by an argument
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1045 integer.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046 %Ns: likewise, but length specified as constant in the format string.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047 Flag 'q': quote formatted text (must come immediately after '%').
111
kono
parents: 67
diff changeset
1048 %Z: Requires two arguments - array of int, and len. Prints elements
kono
parents: 67
diff changeset
1049 of the array.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 Arguments can be used sequentially, or through %N$ resp. *N$
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 notation Nth argument after the format string. If %N$ / *N$
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 notation is used, it must be used for all arguments, except %m, %%,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 %<, %> and %', which may not have a number, as they do not consume
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055 an argument. When %M$.*N$s is used, M must be N + 1. (This may
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 also be written %M$.*s, provided N is not otherwise used.) The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 format string must have conversion specifiers with argument numbers
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 1 up to highest argument; each argument may only be used once.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059 A format string can have at most 30 arguments. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 /* Formatting phases 1 and 2: render TEXT->format_spec plus
111
kono
parents: 67
diff changeset
1062 TEXT->args_ptr into a series of chunks in pp_buffer (PP)->args[].
kono
parents: 67
diff changeset
1063 Phase 3 is in pp_output_formatted_text. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 void
111
kono
parents: 67
diff changeset
1066 pp_format (pretty_printer *pp, text_info *text)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 {
111
kono
parents: 67
diff changeset
1068 output_buffer *buffer = pp_buffer (pp);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 const char *p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 const char **args;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 struct chunk_info *new_chunk_array;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 unsigned int curarg = 0, chunk = 0, argno;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 pp_wrapping_mode_t old_wrapping_mode;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 bool any_unnumbered = false, any_numbered = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076 const char **formatters[PP_NL_ARGMAX];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 /* Allocate a new chunk structure. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 new_chunk_array = XOBNEW (&buffer->chunk_obstack, struct chunk_info);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 new_chunk_array->prev = buffer->cur_chunk_array;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 buffer->cur_chunk_array = new_chunk_array;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 args = new_chunk_array->args;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 /* Formatting phase 1: split up TEXT->format_spec into chunks in
111
kono
parents: 67
diff changeset
1085 pp_buffer (PP)->args[]. Even-numbered chunks are to be output
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 verbatim, odd-numbered chunks are format specifiers.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 %m, %%, %<, %>, and %' are replaced with the appropriate text at
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088 this point. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090 memset (formatters, 0, sizeof formatters);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1091
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 for (p = text->format_spec; *p; )
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 while (*p != '\0' && *p != '%')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 obstack_1grow (&buffer->chunk_obstack, *p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100 if (*p == '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103 switch (*++p)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 case '\0':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 gcc_unreachable ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1107
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 case '%':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 obstack_1grow (&buffer->chunk_obstack, '%');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113 case '<':
111
kono
parents: 67
diff changeset
1114 {
kono
parents: 67
diff changeset
1115 obstack_grow (&buffer->chunk_obstack,
kono
parents: 67
diff changeset
1116 open_quote, strlen (open_quote));
kono
parents: 67
diff changeset
1117 const char *colorstr
kono
parents: 67
diff changeset
1118 = colorize_start (pp_show_color (pp), "quote");
kono
parents: 67
diff changeset
1119 obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr));
kono
parents: 67
diff changeset
1120 p++;
kono
parents: 67
diff changeset
1121 continue;
kono
parents: 67
diff changeset
1122 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124 case '>':
111
kono
parents: 67
diff changeset
1125 {
kono
parents: 67
diff changeset
1126 const char *colorstr = colorize_stop (pp_show_color (pp));
kono
parents: 67
diff changeset
1127 obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr));
kono
parents: 67
diff changeset
1128 }
kono
parents: 67
diff changeset
1129 /* FALLTHRU */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 case '\'':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 obstack_grow (&buffer->chunk_obstack,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132 close_quote, strlen (close_quote));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135
111
kono
parents: 67
diff changeset
1136 case 'R':
kono
parents: 67
diff changeset
1137 {
kono
parents: 67
diff changeset
1138 const char *colorstr = colorize_stop (pp_show_color (pp));
kono
parents: 67
diff changeset
1139 obstack_grow (&buffer->chunk_obstack, colorstr,
kono
parents: 67
diff changeset
1140 strlen (colorstr));
kono
parents: 67
diff changeset
1141 p++;
kono
parents: 67
diff changeset
1142 continue;
kono
parents: 67
diff changeset
1143 }
kono
parents: 67
diff changeset
1144
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145 case 'm':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1147 const char *errstr = xstrerror (text->err_no);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148 obstack_grow (&buffer->chunk_obstack, errstr, strlen (errstr));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1150 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154 /* Handled in phase 2. Terminate the plain chunk here. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 obstack_1grow (&buffer->chunk_obstack, '\0');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 gcc_assert (chunk < PP_NL_ARGMAX * 2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 if (ISDIGIT (*p))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 char *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 argno = strtoul (p, &end, 10) - 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 p = end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 gcc_assert (*p == '$');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 any_numbered = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 gcc_assert (!any_unnumbered);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 argno = curarg++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 any_unnumbered = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176 gcc_assert (!any_numbered);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 gcc_assert (argno < PP_NL_ARGMAX);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 gcc_assert (!formatters[argno]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 formatters[argno] = &args[chunk];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 obstack_1grow (&buffer->chunk_obstack, *p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 while (strchr ("qwl+#", p[-1]));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 if (p[-1] == '.')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 /* We handle '%.Ns' and '%.*s' or '%M$.*N$s'
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 (where M == N + 1). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 if (ISDIGIT (*p))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 obstack_1grow (&buffer->chunk_obstack, *p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 while (ISDIGIT (p[-1]));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 gcc_assert (p[-1] == 's');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 gcc_assert (*p == '*');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 obstack_1grow (&buffer->chunk_obstack, '*');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208 if (ISDIGIT (*p))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 char *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 unsigned int argno2 = strtoul (p, &end, 10) - 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 p = end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213 gcc_assert (argno2 == argno - 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214 gcc_assert (!any_unnumbered);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 gcc_assert (*p == '$');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218 formatters[argno2] = formatters[argno];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 gcc_assert (!any_numbered);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223 formatters[argno+1] = formatters[argno];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224 curarg++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 gcc_assert (*p == 's');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 obstack_1grow (&buffer->chunk_obstack, 's');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1231 if (*p == '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1232 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234 obstack_1grow (&buffer->chunk_obstack, '\0');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 gcc_assert (chunk < PP_NL_ARGMAX * 2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 obstack_1grow (&buffer->chunk_obstack, '\0');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 gcc_assert (chunk < PP_NL_ARGMAX * 2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1241 args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 args[chunk] = 0;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1243
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 /* Set output to the argument obstack, and switch line-wrapping and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 prefixing off. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246 buffer->obstack = &buffer->chunk_obstack;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1247 const int old_line_length = buffer->line_length;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1248 old_wrapping_mode = pp_set_verbatim_wrapping (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1249
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 /* Second phase. Replace each formatter with the formatted text it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1251 corresponds to. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1252
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 for (argno = 0; formatters[argno]; argno++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1255 int precision = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256 bool wide = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1257 bool plus = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 bool hash = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1259 bool quote = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1260
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261 /* We do not attempt to enforce any ordering on the modifier
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262 characters. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 for (p = *formatters[argno];; p++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266 switch (*p)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 case 'q':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269 gcc_assert (!quote);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 quote = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273 case '+':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 gcc_assert (!plus);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275 plus = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278 case '#':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 gcc_assert (!hash);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280 hash = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 case 'w':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 gcc_assert (!wide);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 wide = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 case 'l':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 /* We don't support precision beyond that of "long long". */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 gcc_assert (precision < 2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291 precision++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1292 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1296
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1297 gcc_assert (!wide || precision == 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299 if (quote)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1300 pp_begin_quote (pp, pp_show_color (pp));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302 switch (*p)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 {
111
kono
parents: 67
diff changeset
1304 case 'r':
kono
parents: 67
diff changeset
1305 pp_string (pp, colorize_start (pp_show_color (pp),
kono
parents: 67
diff changeset
1306 va_arg (*text->args_ptr,
kono
parents: 67
diff changeset
1307 const char *)));
kono
parents: 67
diff changeset
1308 break;
kono
parents: 67
diff changeset
1309
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 case 'c':
111
kono
parents: 67
diff changeset
1311 {
kono
parents: 67
diff changeset
1312 /* When quoting, print alphanumeric, punctuation, and the space
kono
parents: 67
diff changeset
1313 character unchanged, and all others in hexadecimal with the
kono
parents: 67
diff changeset
1314 "\x" prefix. Otherwise print them all unchanged. */
kono
parents: 67
diff changeset
1315 int chr = va_arg (*text->args_ptr, int);
kono
parents: 67
diff changeset
1316 if (ISPRINT (chr) || !quote)
kono
parents: 67
diff changeset
1317 pp_character (pp, chr);
kono
parents: 67
diff changeset
1318 else
kono
parents: 67
diff changeset
1319 {
kono
parents: 67
diff changeset
1320 const char str [2] = { chr, '\0' };
kono
parents: 67
diff changeset
1321 pp_quoted_string (pp, str, 1);
kono
parents: 67
diff changeset
1322 }
kono
parents: 67
diff changeset
1323 break;
kono
parents: 67
diff changeset
1324 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 case 'd':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 case 'i':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 if (wide)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 pp_wide_integer (pp, va_arg (*text->args_ptr, HOST_WIDE_INT));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 pp_integer_with_precision
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332 (pp, *text->args_ptr, precision, int, "d");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1333 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335 case 'o':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1336 if (wide)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337 pp_scalar (pp, "%" HOST_WIDE_INT_PRINT "o",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338 va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340 pp_integer_with_precision
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 (pp, *text->args_ptr, precision, unsigned, "o");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344 case 's':
111
kono
parents: 67
diff changeset
1345 if (quote)
kono
parents: 67
diff changeset
1346 pp_quoted_string (pp, va_arg (*text->args_ptr, const char *));
kono
parents: 67
diff changeset
1347 else
kono
parents: 67
diff changeset
1348 pp_string (pp, va_arg (*text->args_ptr, const char *));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1349 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1350
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1351 case 'p':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1352 pp_pointer (pp, va_arg (*text->args_ptr, void *));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1353 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1354
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355 case 'u':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 if (wide)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 pp_scalar (pp, HOST_WIDE_INT_PRINT_UNSIGNED,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358 va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1360 pp_integer_with_precision
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 (pp, *text->args_ptr, precision, unsigned, "u");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1364 case 'f':
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1365 pp_double (pp, va_arg (*text->args_ptr, double));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1366 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1367
111
kono
parents: 67
diff changeset
1368 case 'Z':
kono
parents: 67
diff changeset
1369 {
kono
parents: 67
diff changeset
1370 int *v = va_arg (*text->args_ptr, int *);
kono
parents: 67
diff changeset
1371 unsigned len = va_arg (*text->args_ptr, unsigned);
kono
parents: 67
diff changeset
1372
kono
parents: 67
diff changeset
1373 for (unsigned i = 0; i < len; ++i)
kono
parents: 67
diff changeset
1374 {
kono
parents: 67
diff changeset
1375 pp_scalar (pp, "%i", v[i]);
kono
parents: 67
diff changeset
1376 if (i < len - 1)
kono
parents: 67
diff changeset
1377 {
kono
parents: 67
diff changeset
1378 pp_comma (pp);
kono
parents: 67
diff changeset
1379 pp_space (pp);
kono
parents: 67
diff changeset
1380 }
kono
parents: 67
diff changeset
1381 }
kono
parents: 67
diff changeset
1382 break;
kono
parents: 67
diff changeset
1383 }
kono
parents: 67
diff changeset
1384
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1385 case 'x':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1386 if (wide)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1387 pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388 va_arg (*text->args_ptr, unsigned HOST_WIDE_INT));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1389 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1390 pp_integer_with_precision
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1391 (pp, *text->args_ptr, precision, unsigned, "x");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1392 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1393
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1394 case '.':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1395 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396 int n;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397 const char *s;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1398
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1399 /* We handle '%.Ns' and '%.*s' or '%M$.*N$s'
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400 (where M == N + 1). The format string should be verified
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1401 already from the first phase. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1403 if (ISDIGIT (*p))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1405 char *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1406 n = strtoul (p, &end, 10);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1407 p = end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408 gcc_assert (*p == 's');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1410 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1411 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1412 gcc_assert (*p == '*');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1413 p++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1414 gcc_assert (*p == 's');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1415 n = va_arg (*text->args_ptr, int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1416
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1417 /* This consumes a second entry in the formatters array. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1418 gcc_assert (formatters[argno] == formatters[argno+1]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419 argno++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1420 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1421
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1422 s = va_arg (*text->args_ptr, const char *);
111
kono
parents: 67
diff changeset
1423
kono
parents: 67
diff changeset
1424 /* Append the lesser of precision and strlen (s) characters
kono
parents: 67
diff changeset
1425 from the array (which need not be a nul-terminated string).
kono
parents: 67
diff changeset
1426 Negative precision is treated as if it were omitted. */
kono
parents: 67
diff changeset
1427 size_t len = n < 0 ? strlen (s) : strnlen (s, n);
kono
parents: 67
diff changeset
1428
kono
parents: 67
diff changeset
1429 pp_append_text (pp, s, s + len);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1430 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1432
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1433 case '@':
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1434 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1435 /* diagnostic_event_id_t *. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1436 diagnostic_event_id_ptr event_id
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1437 = va_arg (*text->args_ptr, diagnostic_event_id_ptr);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1438 gcc_assert (event_id->known_p ());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1439
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1440 pp_string (pp, colorize_start (pp_show_color (pp), "path"));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1441 pp_character (pp, '(');
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1442 pp_decimal_int (pp, event_id->one_based ());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1443 pp_character (pp, ')');
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1444 pp_string (pp, colorize_stop (pp_show_color (pp)));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1445 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1446 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1447
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1448 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1449 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1450 bool ok;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1451
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1452 /* Call the format decoder.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1453 Pass the address of "quote" so that format decoders can
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1454 potentially disable printing of the closing quote
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1455 (e.g. when printing "'TYPEDEF' aka 'TYPE'" in the C family
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1456 of frontends). */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1457 gcc_assert (pp_format_decoder (pp));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1458 ok = pp_format_decoder (pp) (pp, text, p,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1459 precision, wide, plus, hash, &quote,
111
kono
parents: 67
diff changeset
1460 formatters[argno]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1461 gcc_assert (ok);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1462 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1463 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1464
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1465 if (quote)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1466 pp_end_quote (pp, pp_show_color (pp));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1467
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1468 obstack_1grow (&buffer->chunk_obstack, '\0');
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1469 *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1470 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1471
111
kono
parents: 67
diff changeset
1472 if (CHECKING_P)
kono
parents: 67
diff changeset
1473 for (; argno < PP_NL_ARGMAX; argno++)
kono
parents: 67
diff changeset
1474 gcc_assert (!formatters[argno]);
kono
parents: 67
diff changeset
1475
kono
parents: 67
diff changeset
1476 /* If the client supplied a postprocessing object, call its "handle"
kono
parents: 67
diff changeset
1477 hook here. */
kono
parents: 67
diff changeset
1478 if (pp->m_format_postprocessor)
kono
parents: 67
diff changeset
1479 pp->m_format_postprocessor->handle (pp);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1480
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1481 /* Revert to normal obstack and wrapping mode. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1482 buffer->obstack = &buffer->formatted_obstack;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1483 buffer->line_length = old_line_length;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1484 pp_wrapping_mode (pp) = old_wrapping_mode;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1485 pp_clear_state (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1486 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1487
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1488 /* Format of a message pointed to by TEXT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1489 void
111
kono
parents: 67
diff changeset
1490 pp_output_formatted_text (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1491 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1492 unsigned int chunk;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1493 output_buffer *buffer = pp_buffer (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1494 struct chunk_info *chunk_array = buffer->cur_chunk_array;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1495 const char **args = chunk_array->args;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1496
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1497 gcc_assert (buffer->obstack == &buffer->formatted_obstack);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1498
111
kono
parents: 67
diff changeset
1499 /* This is a third phase, first 2 phases done in pp_format_args.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1500 Now we actually print it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1501 for (chunk = 0; args[chunk]; chunk++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1502 pp_string (pp, args[chunk]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1503
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1504 /* Deallocate the chunk structure and everything after it (i.e. the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1505 associated series of formatted strings). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1506 buffer->cur_chunk_array = chunk_array->prev;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1507 obstack_free (&buffer->chunk_obstack, chunk_array);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1508 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1509
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1510 /* Helper subroutine of output_verbatim and verbatim. Do the appropriate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1511 settings needed by BUFFER for a verbatim formatting. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1512 void
111
kono
parents: 67
diff changeset
1513 pp_format_verbatim (pretty_printer *pp, text_info *text)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1514 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1515 /* Set verbatim mode. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1516 pp_wrapping_mode_t oldmode = pp_set_verbatim_wrapping (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1517
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1518 /* Do the actual formatting. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1519 pp_format (pp, text);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1520 pp_output_formatted_text (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1521
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1522 /* Restore previous settings. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1523 pp_wrapping_mode (pp) = oldmode;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1524 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1525
111
kono
parents: 67
diff changeset
1526 /* Flush the content of BUFFER onto the attached stream. This
kono
parents: 67
diff changeset
1527 function does nothing unless pp->output_buffer->flush_p. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1528 void
111
kono
parents: 67
diff changeset
1529 pp_flush (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1530 {
111
kono
parents: 67
diff changeset
1531 pp_clear_state (pp);
kono
parents: 67
diff changeset
1532 if (!pp->buffer->flush_p)
kono
parents: 67
diff changeset
1533 return;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1534 pp_write_text_to_stream (pp);
111
kono
parents: 67
diff changeset
1535 fflush (pp_buffer (pp)->stream);
kono
parents: 67
diff changeset
1536 }
kono
parents: 67
diff changeset
1537
kono
parents: 67
diff changeset
1538 /* Flush the content of BUFFER onto the attached stream independently
kono
parents: 67
diff changeset
1539 of the value of pp->output_buffer->flush_p. */
kono
parents: 67
diff changeset
1540 void
kono
parents: 67
diff changeset
1541 pp_really_flush (pretty_printer *pp)
kono
parents: 67
diff changeset
1542 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1543 pp_clear_state (pp);
111
kono
parents: 67
diff changeset
1544 pp_write_text_to_stream (pp);
kono
parents: 67
diff changeset
1545 fflush (pp_buffer (pp)->stream);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1546 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1547
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1548 /* Sets the number of maximum characters per line PRETTY-PRINTER can
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1549 output in line-wrapping mode. A LENGTH value 0 suppresses
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1550 line-wrapping. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1551 void
111
kono
parents: 67
diff changeset
1552 pp_set_line_maximum_length (pretty_printer *pp, int length)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1553 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1554 pp_line_cutoff (pp) = length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1555 pp_set_real_maximum_length (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1556 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1557
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1558 /* Clear PRETTY-PRINTER output area text info. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1559 void
111
kono
parents: 67
diff changeset
1560 pp_clear_output_area (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1561 {
111
kono
parents: 67
diff changeset
1562 obstack_free (pp_buffer (pp)->obstack,
kono
parents: 67
diff changeset
1563 obstack_base (pp_buffer (pp)->obstack));
kono
parents: 67
diff changeset
1564 pp_buffer (pp)->line_length = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1565 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1566
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1567 /* Set PREFIX for PRETTY-PRINTER, taking ownership of PREFIX, which
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1568 will eventually be free-ed. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1569
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1570 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1571 pp_set_prefix (pretty_printer *pp, char *prefix)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1572 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1573 free (pp->prefix);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1574 pp->prefix = prefix;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1575 pp_set_real_maximum_length (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1576 pp->emitted_prefix = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1577 pp_indentation (pp) = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1578 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1579
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1580 /* Take ownership of PP's prefix, setting it to NULL.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1581 This allows clients to save, overide, and then restore an existing
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1582 prefix, without it being free-ed. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1583
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1584 char *
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1585 pp_take_prefix (pretty_printer *pp)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1586 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1587 char *result = pp->prefix;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1588 pp->prefix = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1589 return result;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1590 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1591
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1592 /* Free PRETTY-PRINTER's prefix, a previously malloc()'d string. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1593 void
111
kono
parents: 67
diff changeset
1594 pp_destroy_prefix (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1595 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1596 if (pp->prefix != NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1597 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1598 free (pp->prefix);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1599 pp->prefix = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1600 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1601 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1602
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1603 /* Write out PRETTY-PRINTER's prefix. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1604 void
111
kono
parents: 67
diff changeset
1605 pp_emit_prefix (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1606 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1607 if (pp->prefix != NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1608 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1609 switch (pp_prefixing_rule (pp))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1610 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1611 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1612 case DIAGNOSTICS_SHOW_PREFIX_NEVER:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1613 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1614
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1615 case DIAGNOSTICS_SHOW_PREFIX_ONCE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1616 if (pp->emitted_prefix)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1617 {
111
kono
parents: 67
diff changeset
1618 pp_indent (pp);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1619 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1620 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1621 pp_indentation (pp) += 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1622 /* Fall through. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1623
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1624 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1625 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1626 int prefix_length = strlen (pp->prefix);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1627 pp_append_r (pp, pp->prefix, prefix_length);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1628 pp->emitted_prefix = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1629 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1630 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1631 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1632 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1633 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1634
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1635 /* Construct a PRETTY-PRINTER of MAXIMUM_LENGTH characters per line. */
111
kono
parents: 67
diff changeset
1636
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1637 pretty_printer::pretty_printer (int maximum_length)
111
kono
parents: 67
diff changeset
1638 : buffer (new (XCNEW (output_buffer)) output_buffer ()),
kono
parents: 67
diff changeset
1639 prefix (),
kono
parents: 67
diff changeset
1640 padding (pp_none),
kono
parents: 67
diff changeset
1641 maximum_length (),
kono
parents: 67
diff changeset
1642 indent_skip (),
kono
parents: 67
diff changeset
1643 wrapping (),
kono
parents: 67
diff changeset
1644 format_decoder (),
kono
parents: 67
diff changeset
1645 m_format_postprocessor (NULL),
kono
parents: 67
diff changeset
1646 emitted_prefix (),
kono
parents: 67
diff changeset
1647 need_newline (),
kono
parents: 67
diff changeset
1648 translate_identifiers (true),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1649 show_color (),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1650 show_urls (false)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1651 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1652 pp_line_cutoff (this) = maximum_length;
111
kono
parents: 67
diff changeset
1653 /* By default, we emit prefixes once per message. */
kono
parents: 67
diff changeset
1654 pp_prefixing_rule (this) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1655 pp_set_prefix (this, NULL);
111
kono
parents: 67
diff changeset
1656 }
kono
parents: 67
diff changeset
1657
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1658 /* Copy constructor for pretty_printer. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1659
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1660 pretty_printer::pretty_printer (const pretty_printer &other)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1661 : buffer (new (XCNEW (output_buffer)) output_buffer ()),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1662 prefix (),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1663 padding (other.padding),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1664 maximum_length (other.maximum_length),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1665 indent_skip (other.indent_skip),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1666 wrapping (other.wrapping),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1667 format_decoder (other.format_decoder),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1668 m_format_postprocessor (NULL),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1669 emitted_prefix (other.emitted_prefix),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1670 need_newline (other.need_newline),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1671 translate_identifiers (other.translate_identifiers),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1672 show_color (other.show_color),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1673 show_urls (other.show_urls)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1674 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1675 pp_line_cutoff (this) = maximum_length;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1676 /* By default, we emit prefixes once per message. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1677 pp_prefixing_rule (this) = pp_prefixing_rule (&other);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1678 pp_set_prefix (this, NULL);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1679
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1680 if (other.m_format_postprocessor)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1681 m_format_postprocessor = other.m_format_postprocessor->clone ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1682 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1683
111
kono
parents: 67
diff changeset
1684 pretty_printer::~pretty_printer ()
kono
parents: 67
diff changeset
1685 {
kono
parents: 67
diff changeset
1686 if (m_format_postprocessor)
kono
parents: 67
diff changeset
1687 delete m_format_postprocessor;
kono
parents: 67
diff changeset
1688 buffer->~output_buffer ();
kono
parents: 67
diff changeset
1689 XDELETE (buffer);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1690 free (prefix);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1691 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1692
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1693 /* Base class implementation of pretty_printer::clone vfunc. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1694
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1695 pretty_printer *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1696 pretty_printer::clone () const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1697 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1698 return new pretty_printer (*this);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1699 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1700
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1701 /* Append a string delimited by START and END to the output area of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1702 PRETTY-PRINTER. No line wrapping is done. However, if beginning a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1703 new line then emit PRETTY-PRINTER's prefix and skip any leading
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1704 whitespace if appropriate. The caller must ensure that it is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1705 safe to do so. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1706 void
111
kono
parents: 67
diff changeset
1707 pp_append_text (pretty_printer *pp, const char *start, const char *end)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1708 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1709 /* Emit prefix and skip whitespace if we're starting a new line. */
111
kono
parents: 67
diff changeset
1710 if (pp_buffer (pp)->line_length == 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1711 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1712 pp_emit_prefix (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1713 if (pp_is_wrapping_line (pp))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1714 while (start != end && *start == ' ')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1715 ++start;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1716 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1717 pp_append_r (pp, start, end - start);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1718 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1719
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1720 /* Finishes constructing a NULL-terminated character string representing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1721 the PRETTY-PRINTED text. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1722 const char *
111
kono
parents: 67
diff changeset
1723 pp_formatted_text (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1724 {
111
kono
parents: 67
diff changeset
1725 return output_buffer_formatted_text (pp_buffer (pp));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1726 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1727
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1728 /* Return a pointer to the last character emitted in PRETTY-PRINTER's
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1729 output area. A NULL pointer means no character available. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1730 const char *
111
kono
parents: 67
diff changeset
1731 pp_last_position_in_text (const pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1732 {
111
kono
parents: 67
diff changeset
1733 return output_buffer_last_position_in_text (pp_buffer (pp));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1734 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1735
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1736 /* Return the amount of characters PRETTY-PRINTER can accept to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1737 make a full line. Meaningful only in line-wrapping mode. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1738 int
111
kono
parents: 67
diff changeset
1739 pp_remaining_character_count_for_line (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1740 {
111
kono
parents: 67
diff changeset
1741 return pp->maximum_length - pp_buffer (pp)->line_length;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1742 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1743
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1744
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1745 /* Format a message into BUFFER a la printf. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1746 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1747 pp_printf (pretty_printer *pp, const char *msg, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1748 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1749 text_info text;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1750 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1751
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1752 va_start (ap, msg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1753 text.err_no = errno;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1754 text.args_ptr = &ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1755 text.format_spec = msg;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1756 pp_format (pp, &text);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1757 pp_output_formatted_text (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1758 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1759 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1760
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1761
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1762 /* Output MESSAGE verbatim into BUFFER. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1763 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1764 pp_verbatim (pretty_printer *pp, const char *msg, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1765 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1766 text_info text;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1767 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1768
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1769 va_start (ap, msg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1770 text.err_no = errno;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1771 text.args_ptr = &ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1772 text.format_spec = msg;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1773 pp_format_verbatim (pp, &text);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1774 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1775 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1776
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1777
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1778
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1779 /* Have PRETTY-PRINTER start a new line. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1780 void
111
kono
parents: 67
diff changeset
1781 pp_newline (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1782 {
111
kono
parents: 67
diff changeset
1783 obstack_1grow (pp_buffer (pp)->obstack, '\n');
kono
parents: 67
diff changeset
1784 pp_needs_newline (pp) = false;
kono
parents: 67
diff changeset
1785 pp_buffer (pp)->line_length = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1786 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1787
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1788 /* Have PRETTY-PRINTER add a CHARACTER. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1789 void
111
kono
parents: 67
diff changeset
1790 pp_character (pretty_printer *pp, int c)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1791 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1792 if (pp_is_wrapping_line (pp)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1793 /* If printing UTF-8, don't wrap in the middle of a sequence. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1794 && (((unsigned int) c) & 0xC0) != 0x80
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1795 && pp_remaining_character_count_for_line (pp) <= 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1796 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1797 pp_newline (pp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1798 if (ISSPACE (c))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1799 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1800 }
111
kono
parents: 67
diff changeset
1801 obstack_1grow (pp_buffer (pp)->obstack, c);
kono
parents: 67
diff changeset
1802 ++pp_buffer (pp)->line_length;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1803 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1804
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1805 /* Append a STRING to the output area of PRETTY-PRINTER; the STRING may
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1806 be line-wrapped if in appropriate mode. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1807 void
111
kono
parents: 67
diff changeset
1808 pp_string (pretty_printer *pp, const char *str)
kono
parents: 67
diff changeset
1809 {
kono
parents: 67
diff changeset
1810 gcc_checking_assert (str);
kono
parents: 67
diff changeset
1811 pp_maybe_wrap_text (pp, str, str + strlen (str));
kono
parents: 67
diff changeset
1812 }
kono
parents: 67
diff changeset
1813
kono
parents: 67
diff changeset
1814 /* Append the leading N characters of STRING to the output area of
kono
parents: 67
diff changeset
1815 PRETTY-PRINTER, quoting in hexadecimal non-printable characters.
kono
parents: 67
diff changeset
1816 Setting N = -1 is as if N were set to strlen (STRING). The STRING
kono
parents: 67
diff changeset
1817 may be line-wrapped if in appropriate mode. */
kono
parents: 67
diff changeset
1818 static void
kono
parents: 67
diff changeset
1819 pp_quoted_string (pretty_printer *pp, const char *str, size_t n /* = -1 */)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1820 {
111
kono
parents: 67
diff changeset
1821 gcc_checking_assert (str);
kono
parents: 67
diff changeset
1822
kono
parents: 67
diff changeset
1823 const char *last = str;
kono
parents: 67
diff changeset
1824 const char *ps;
kono
parents: 67
diff changeset
1825
kono
parents: 67
diff changeset
1826 /* Compute the length if not specified. */
kono
parents: 67
diff changeset
1827 if (n == (size_t) -1)
kono
parents: 67
diff changeset
1828 n = strlen (str);
kono
parents: 67
diff changeset
1829
kono
parents: 67
diff changeset
1830 for (ps = str; n; ++ps, --n)
kono
parents: 67
diff changeset
1831 {
kono
parents: 67
diff changeset
1832 if (ISPRINT (*ps))
kono
parents: 67
diff changeset
1833 continue;
kono
parents: 67
diff changeset
1834
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1835 /* Don't escape a valid UTF-8 extended char. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1836 const unsigned char *ups = (const unsigned char *) ps;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1837 if (*ups & 0x80)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1838 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1839 unsigned int extended_char;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1840 const int valid_utf8_len = decode_utf8_char (ups, n, &extended_char);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1841 if (valid_utf8_len > 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1842 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1843 ps += valid_utf8_len - 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1844 n -= valid_utf8_len - 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1845 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1846 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1847 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1848
111
kono
parents: 67
diff changeset
1849 if (last < ps)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1850 pp_maybe_wrap_text (pp, last, ps);
111
kono
parents: 67
diff changeset
1851
kono
parents: 67
diff changeset
1852 /* Append the hexadecimal value of the character. Allocate a buffer
kono
parents: 67
diff changeset
1853 that's large enough for a 32-bit char plus the hex prefix. */
kono
parents: 67
diff changeset
1854 char buf [11];
kono
parents: 67
diff changeset
1855 int n = sprintf (buf, "\\x%02x", (unsigned char)*ps);
kono
parents: 67
diff changeset
1856 pp_maybe_wrap_text (pp, buf, buf + n);
kono
parents: 67
diff changeset
1857 last = ps + 1;
kono
parents: 67
diff changeset
1858 }
kono
parents: 67
diff changeset
1859
kono
parents: 67
diff changeset
1860 pp_maybe_wrap_text (pp, last, ps);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1861 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1862
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1863 /* Maybe print out a whitespace if needed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1864
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1865 void
111
kono
parents: 67
diff changeset
1866 pp_maybe_space (pretty_printer *pp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1867 {
111
kono
parents: 67
diff changeset
1868 if (pp->padding != pp_none)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1869 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1870 pp_space (pp);
111
kono
parents: 67
diff changeset
1871 pp->padding = pp_none;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1872 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1873 }
111
kono
parents: 67
diff changeset
1874
kono
parents: 67
diff changeset
1875 // Add a newline to the pretty printer PP and flush formatted text.
kono
parents: 67
diff changeset
1876
kono
parents: 67
diff changeset
1877 void
kono
parents: 67
diff changeset
1878 pp_newline_and_flush (pretty_printer *pp)
kono
parents: 67
diff changeset
1879 {
kono
parents: 67
diff changeset
1880 pp_newline (pp);
kono
parents: 67
diff changeset
1881 pp_flush (pp);
kono
parents: 67
diff changeset
1882 pp_needs_newline (pp) = false;
kono
parents: 67
diff changeset
1883 }
kono
parents: 67
diff changeset
1884
kono
parents: 67
diff changeset
1885 // Add a newline to the pretty printer PP, followed by indentation.
kono
parents: 67
diff changeset
1886
kono
parents: 67
diff changeset
1887 void
kono
parents: 67
diff changeset
1888 pp_newline_and_indent (pretty_printer *pp, int n)
kono
parents: 67
diff changeset
1889 {
kono
parents: 67
diff changeset
1890 pp_indentation (pp) += n;
kono
parents: 67
diff changeset
1891 pp_newline (pp);
kono
parents: 67
diff changeset
1892 pp_indent (pp);
kono
parents: 67
diff changeset
1893 pp_needs_newline (pp) = false;
kono
parents: 67
diff changeset
1894 }
kono
parents: 67
diff changeset
1895
kono
parents: 67
diff changeset
1896 // Add separator C, followed by a single whitespace.
kono
parents: 67
diff changeset
1897
kono
parents: 67
diff changeset
1898 void
kono
parents: 67
diff changeset
1899 pp_separate_with (pretty_printer *pp, char c)
kono
parents: 67
diff changeset
1900 {
kono
parents: 67
diff changeset
1901 pp_character (pp, c);
kono
parents: 67
diff changeset
1902 pp_space (pp);
kono
parents: 67
diff changeset
1903 }
kono
parents: 67
diff changeset
1904
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1905 /* Add a localized open quote, and if SHOW_COLOR is true, begin colorizing
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1906 using the "quote" color. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1907
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1908 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1909 pp_begin_quote (pretty_printer *pp, bool show_color)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1910 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1911 pp_string (pp, open_quote);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1912 pp_string (pp, colorize_start (show_color, "quote"));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1913 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1914
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1915 /* If SHOW_COLOR is true, stop colorizing.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1916 Add a localized close quote. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1917
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1918 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1919 pp_end_quote (pretty_printer *pp, bool show_color)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1920 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1921 pp_string (pp, colorize_stop (show_color));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1922 pp_string (pp, close_quote);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1923 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1924
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1925
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1926 /* The string starting at P has LEN (at least 1) bytes left; if they
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1927 start with a valid UTF-8 sequence, return the length of that
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1928 sequence and set *VALUE to the value of that sequence, and
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1929 otherwise return 0 and set *VALUE to (unsigned int) -1. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1930
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1931 static int
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1932 decode_utf8_char (const unsigned char *p, size_t len, unsigned int *value)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1933 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1934 unsigned int t = *p;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1935
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1936 if (len == 0)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1937 abort ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1938 if (t & 0x80)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1939 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1940 size_t utf8_len = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1941 unsigned int ch;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1942 size_t i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1943 for (t = *p; t & 0x80; t <<= 1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1944 utf8_len++;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1945
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1946 if (utf8_len > len || utf8_len < 2 || utf8_len > 6)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1947 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1948 *value = (unsigned int) -1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1949 return 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1950 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1951 ch = *p & ((1 << (7 - utf8_len)) - 1);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1952 for (i = 1; i < utf8_len; i++)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1953 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1954 unsigned int u = p[i];
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1955 if ((u & 0xC0) != 0x80)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1956 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1957 *value = (unsigned int) -1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1958 return 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1959 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1960 ch = (ch << 6) | (u & 0x3F);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1961 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1962 if ( (ch <= 0x7F && utf8_len > 1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1963 || (ch <= 0x7FF && utf8_len > 2)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1964 || (ch <= 0xFFFF && utf8_len > 3)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1965 || (ch <= 0x1FFFFF && utf8_len > 4)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1966 || (ch <= 0x3FFFFFF && utf8_len > 5)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1967 || (ch >= 0xD800 && ch <= 0xDFFF))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1968 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1969 *value = (unsigned int) -1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1970 return 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1971 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1972 *value = ch;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1973 return utf8_len;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1974 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1975 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1976 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1977 *value = t;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1978 return 1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1979 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1980 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1981
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1982 /* Allocator for identifier_to_locale and corresponding function to
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1983 free memory. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1984
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1985 void *(*identifier_to_locale_alloc) (size_t) = xmalloc;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1986 void (*identifier_to_locale_free) (void *) = free;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1987
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1988 /* Given IDENT, an identifier in the internal encoding, return a
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1989 version of IDENT suitable for diagnostics in the locale character
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1990 set: either IDENT itself, or a string, allocated using
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1991 identifier_to_locale_alloc, converted to the locale character set
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1992 and using escape sequences if not representable in the locale
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1993 character set or containing control characters or invalid byte
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1994 sequences. Existing backslashes in IDENT are not doubled, so the
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1995 result may not uniquely specify the contents of an arbitrary byte
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1996 sequence identifier. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1997
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1998 const char *
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1999 identifier_to_locale (const char *ident)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2000 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2001 const unsigned char *uid = (const unsigned char *) ident;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2002 size_t idlen = strlen (ident);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2003 bool valid_printable_utf8 = true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2004 bool all_ascii = true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2005 size_t i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2006
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2007 for (i = 0; i < idlen;)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2008 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2009 unsigned int c;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2010 size_t utf8_len = decode_utf8_char (&uid[i], idlen - i, &c);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2011 if (utf8_len == 0 || c <= 0x1F || (c >= 0x7F && c <= 0x9F))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2012 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2013 valid_printable_utf8 = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2014 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2015 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2016 if (utf8_len > 1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2017 all_ascii = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2018 i += utf8_len;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2019 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2020
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2021 /* If IDENT contains invalid UTF-8 sequences (which may occur with
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2022 attributes putting arbitrary byte sequences in identifiers), or
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2023 control characters, we use octal escape sequences for all bytes
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2024 outside printable ASCII. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2025 if (!valid_printable_utf8)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2026 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2027 char *ret = (char *) identifier_to_locale_alloc (4 * idlen + 1);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2028 char *p = ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2029 for (i = 0; i < idlen; i++)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2030 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2031 if (uid[i] > 0x1F && uid[i] < 0x7F)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2032 *p++ = uid[i];
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2033 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2034 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2035 sprintf (p, "\\%03o", uid[i]);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2036 p += 4;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2037 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2038 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2039 *p = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2040 return ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2041 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2042
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2043 /* Otherwise, if it is valid printable ASCII, or printable UTF-8
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2044 with the locale character set being UTF-8, IDENT is used. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2045 if (all_ascii || locale_utf8)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2046 return ident;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2047
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2048 /* Otherwise IDENT is converted to the locale character set if
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2049 possible. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2050 #if defined ENABLE_NLS && defined HAVE_LANGINFO_CODESET && HAVE_ICONV
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2051 if (locale_encoding != NULL)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2052 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2053 iconv_t cd = iconv_open (locale_encoding, "UTF-8");
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2054 bool conversion_ok = true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2055 char *ret = NULL;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2056 if (cd != (iconv_t) -1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2057 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2058 size_t ret_alloc = 4 * idlen + 1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2059 for (;;)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2060 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2061 /* Repeat the whole conversion process as needed with
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2062 larger buffers so non-reversible transformations can
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2063 always be detected. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2064 ICONV_CONST char *inbuf = CONST_CAST (char *, ident);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2065 char *outbuf;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2066 size_t inbytesleft = idlen;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2067 size_t outbytesleft = ret_alloc - 1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2068 size_t iconv_ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2069
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2070 ret = (char *) identifier_to_locale_alloc (ret_alloc);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2071 outbuf = ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2072
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2073 if (iconv (cd, 0, 0, 0, 0) == (size_t) -1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2074 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2075 conversion_ok = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2076 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2077 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2078
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2079 iconv_ret = iconv (cd, &inbuf, &inbytesleft,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2080 &outbuf, &outbytesleft);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2081 if (iconv_ret == (size_t) -1 || inbytesleft != 0)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2082 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2083 if (errno == E2BIG)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2084 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2085 ret_alloc *= 2;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2086 identifier_to_locale_free (ret);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2087 ret = NULL;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2088 continue;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2089 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2090 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2091 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2092 conversion_ok = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2093 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2094 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2095 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2096 else if (iconv_ret != 0)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2097 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2098 conversion_ok = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2099 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2100 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2101 /* Return to initial shift state. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2102 if (iconv (cd, 0, 0, &outbuf, &outbytesleft) == (size_t) -1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2103 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2104 if (errno == E2BIG)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2105 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2106 ret_alloc *= 2;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2107 identifier_to_locale_free (ret);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2108 ret = NULL;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2109 continue;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2110 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2111 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2112 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2113 conversion_ok = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2114 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2115 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2116 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2117 *outbuf = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2118 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2119 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2120 iconv_close (cd);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2121 if (conversion_ok)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2122 return ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2123 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2124 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2125 #endif
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2126
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2127 /* Otherwise, convert non-ASCII characters in IDENT to UCNs. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2128 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2129 char *ret = (char *) identifier_to_locale_alloc (10 * idlen + 1);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2130 char *p = ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2131 for (i = 0; i < idlen;)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2132 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2133 unsigned int c;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2134 size_t utf8_len = decode_utf8_char (&uid[i], idlen - i, &c);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2135 if (utf8_len == 1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2136 *p++ = uid[i];
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2137 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2138 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2139 sprintf (p, "\\U%08x", c);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2140 p += 10;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2141 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2142 i += utf8_len;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2143 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2144 *p = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2145 return ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2146 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2147 }
111
kono
parents: 67
diff changeset
2148
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2149 /* Support for encoding URLs.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2150 See egmontkob/Hyperlinks_in_Terminal_Emulators.md
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2151 ( https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda ).
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2152
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2153 > A hyperlink is opened upon encountering an OSC 8 escape sequence with
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2154 > the target URI. The syntax is
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2155 >
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2156 > OSC 8 ; params ; URI ST
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2157 >
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2158 > A hyperlink is closed with the same escape sequence, omitting the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2159 > parameters and the URI but keeping the separators:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2160 >
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2161 > OSC 8 ; ; ST
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2162 >
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2163 > OSC (operating system command) is typically ESC ].
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2164
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2165 Use BEL instead of ST, as that is currently rendered better in some
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2166 terminal emulators that don't support OSC 8, like konsole. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2167
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2168 /* If URL-printing is enabled, write an "open URL" escape sequence to PP
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2169 for the given URL. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2170
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2171 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2172 pp_begin_url (pretty_printer *pp, const char *url)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2173 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2174 if (pp->show_urls)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2175 pp_printf (pp, "\33]8;;%s\a", url);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2176 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2177
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2178 /* If URL-printing is enabled, write a "close URL" escape sequence to PP. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2179
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2180 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2181 pp_end_url (pretty_printer *pp)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2182 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2183 if (pp->show_urls)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2184 pp_string (pp, "\33]8;;\a");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2185 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2186
111
kono
parents: 67
diff changeset
2187 #if CHECKING_P
kono
parents: 67
diff changeset
2188
kono
parents: 67
diff changeset
2189 namespace selftest {
kono
parents: 67
diff changeset
2190
kono
parents: 67
diff changeset
2191 /* Smoketest for pretty_printer. */
kono
parents: 67
diff changeset
2192
kono
parents: 67
diff changeset
2193 static void
kono
parents: 67
diff changeset
2194 test_basic_printing ()
kono
parents: 67
diff changeset
2195 {
kono
parents: 67
diff changeset
2196 pretty_printer pp;
kono
parents: 67
diff changeset
2197 pp_string (&pp, "hello");
kono
parents: 67
diff changeset
2198 pp_space (&pp);
kono
parents: 67
diff changeset
2199 pp_string (&pp, "world");
kono
parents: 67
diff changeset
2200
kono
parents: 67
diff changeset
2201 ASSERT_STREQ ("hello world", pp_formatted_text (&pp));
kono
parents: 67
diff changeset
2202 }
kono
parents: 67
diff changeset
2203
kono
parents: 67
diff changeset
2204 /* Helper function for testing pp_format.
kono
parents: 67
diff changeset
2205 Verify that pp_format (FMT, ...) followed by pp_output_formatted_text
kono
parents: 67
diff changeset
2206 prints EXPECTED, assuming that pp_show_color is SHOW_COLOR. */
kono
parents: 67
diff changeset
2207
kono
parents: 67
diff changeset
2208 static void
kono
parents: 67
diff changeset
2209 assert_pp_format_va (const location &loc, const char *expected,
kono
parents: 67
diff changeset
2210 bool show_color, const char *fmt, va_list *ap)
kono
parents: 67
diff changeset
2211 {
kono
parents: 67
diff changeset
2212 pretty_printer pp;
kono
parents: 67
diff changeset
2213 text_info ti;
kono
parents: 67
diff changeset
2214 rich_location rich_loc (line_table, UNKNOWN_LOCATION);
kono
parents: 67
diff changeset
2215
kono
parents: 67
diff changeset
2216 ti.format_spec = fmt;
kono
parents: 67
diff changeset
2217 ti.args_ptr = ap;
kono
parents: 67
diff changeset
2218 ti.err_no = 0;
kono
parents: 67
diff changeset
2219 ti.x_data = NULL;
kono
parents: 67
diff changeset
2220 ti.m_richloc = &rich_loc;
kono
parents: 67
diff changeset
2221
kono
parents: 67
diff changeset
2222 pp_show_color (&pp) = show_color;
kono
parents: 67
diff changeset
2223 pp_format (&pp, &ti);
kono
parents: 67
diff changeset
2224 pp_output_formatted_text (&pp);
kono
parents: 67
diff changeset
2225 ASSERT_STREQ_AT (loc, expected, pp_formatted_text (&pp));
kono
parents: 67
diff changeset
2226 }
kono
parents: 67
diff changeset
2227
kono
parents: 67
diff changeset
2228 /* Verify that pp_format (FMT, ...) followed by pp_output_formatted_text
kono
parents: 67
diff changeset
2229 prints EXPECTED, with show_color disabled. */
kono
parents: 67
diff changeset
2230
kono
parents: 67
diff changeset
2231 static void
kono
parents: 67
diff changeset
2232 assert_pp_format (const location &loc, const char *expected,
kono
parents: 67
diff changeset
2233 const char *fmt, ...)
kono
parents: 67
diff changeset
2234 {
kono
parents: 67
diff changeset
2235 va_list ap;
kono
parents: 67
diff changeset
2236
kono
parents: 67
diff changeset
2237 va_start (ap, fmt);
kono
parents: 67
diff changeset
2238 assert_pp_format_va (loc, expected, false, fmt, &ap);
kono
parents: 67
diff changeset
2239 va_end (ap);
kono
parents: 67
diff changeset
2240 }
kono
parents: 67
diff changeset
2241
kono
parents: 67
diff changeset
2242 /* As above, but with colorization enabled. */
kono
parents: 67
diff changeset
2243
kono
parents: 67
diff changeset
2244 static void
kono
parents: 67
diff changeset
2245 assert_pp_format_colored (const location &loc, const char *expected,
kono
parents: 67
diff changeset
2246 const char *fmt, ...)
kono
parents: 67
diff changeset
2247 {
kono
parents: 67
diff changeset
2248 /* The tests of colorization assume the default color scheme.
kono
parents: 67
diff changeset
2249 If GCC_COLORS is set, then the colors have potentially been
kono
parents: 67
diff changeset
2250 overridden; skip the test. */
kono
parents: 67
diff changeset
2251 if (getenv ("GCC_COLORS"))
kono
parents: 67
diff changeset
2252 return;
kono
parents: 67
diff changeset
2253
kono
parents: 67
diff changeset
2254 va_list ap;
kono
parents: 67
diff changeset
2255
kono
parents: 67
diff changeset
2256 va_start (ap, fmt);
kono
parents: 67
diff changeset
2257 assert_pp_format_va (loc, expected, true, fmt, &ap);
kono
parents: 67
diff changeset
2258 va_end (ap);
kono
parents: 67
diff changeset
2259 }
kono
parents: 67
diff changeset
2260
kono
parents: 67
diff changeset
2261 /* Helper function for calling testing pp_format,
kono
parents: 67
diff changeset
2262 by calling assert_pp_format with various numbers of arguments.
kono
parents: 67
diff changeset
2263 These exist mostly to avoid having to write SELFTEST_LOCATION
kono
parents: 67
diff changeset
2264 throughout test_pp_format. */
kono
parents: 67
diff changeset
2265
kono
parents: 67
diff changeset
2266 #define ASSERT_PP_FORMAT_1(EXPECTED, FMT, ARG1) \
kono
parents: 67
diff changeset
2267 SELFTEST_BEGIN_STMT \
kono
parents: 67
diff changeset
2268 assert_pp_format ((SELFTEST_LOCATION), (EXPECTED), (FMT), \
kono
parents: 67
diff changeset
2269 (ARG1)); \
kono
parents: 67
diff changeset
2270 SELFTEST_END_STMT
kono
parents: 67
diff changeset
2271
kono
parents: 67
diff changeset
2272 #define ASSERT_PP_FORMAT_2(EXPECTED, FMT, ARG1, ARG2) \
kono
parents: 67
diff changeset
2273 SELFTEST_BEGIN_STMT \
kono
parents: 67
diff changeset
2274 assert_pp_format ((SELFTEST_LOCATION), (EXPECTED), (FMT), \
kono
parents: 67
diff changeset
2275 (ARG1), (ARG2)); \
kono
parents: 67
diff changeset
2276 SELFTEST_END_STMT
kono
parents: 67
diff changeset
2277
kono
parents: 67
diff changeset
2278 #define ASSERT_PP_FORMAT_3(EXPECTED, FMT, ARG1, ARG2, ARG3) \
kono
parents: 67
diff changeset
2279 SELFTEST_BEGIN_STMT \
kono
parents: 67
diff changeset
2280 assert_pp_format ((SELFTEST_LOCATION), (EXPECTED), (FMT), \
kono
parents: 67
diff changeset
2281 (ARG1), (ARG2), (ARG3)); \
kono
parents: 67
diff changeset
2282 SELFTEST_END_STMT
kono
parents: 67
diff changeset
2283
kono
parents: 67
diff changeset
2284 /* Verify that pp_format works, for various format codes. */
kono
parents: 67
diff changeset
2285
kono
parents: 67
diff changeset
2286 static void
kono
parents: 67
diff changeset
2287 test_pp_format ()
kono
parents: 67
diff changeset
2288 {
kono
parents: 67
diff changeset
2289 /* Avoid introducing locale-specific differences in the results
kono
parents: 67
diff changeset
2290 by hardcoding open_quote and close_quote. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2291 auto_fix_quotes fix_quotes;
111
kono
parents: 67
diff changeset
2292
kono
parents: 67
diff changeset
2293 /* Verify that plain text is passed through unchanged. */
kono
parents: 67
diff changeset
2294 assert_pp_format (SELFTEST_LOCATION, "unformatted", "unformatted");
kono
parents: 67
diff changeset
2295
kono
parents: 67
diff changeset
2296 /* Verify various individual format codes, in the order listed in the
kono
parents: 67
diff changeset
2297 comment for pp_format above. For each code, we append a second
kono
parents: 67
diff changeset
2298 argument with a known bit pattern (0x12345678), to ensure that we
kono
parents: 67
diff changeset
2299 are consuming arguments correctly. */
kono
parents: 67
diff changeset
2300 ASSERT_PP_FORMAT_2 ("-27 12345678", "%d %x", -27, 0x12345678);
kono
parents: 67
diff changeset
2301 ASSERT_PP_FORMAT_2 ("-5 12345678", "%i %x", -5, 0x12345678);
kono
parents: 67
diff changeset
2302 ASSERT_PP_FORMAT_2 ("10 12345678", "%u %x", 10, 0x12345678);
kono
parents: 67
diff changeset
2303 ASSERT_PP_FORMAT_2 ("17 12345678", "%o %x", 15, 0x12345678);
kono
parents: 67
diff changeset
2304 ASSERT_PP_FORMAT_2 ("cafebabe 12345678", "%x %x", 0xcafebabe, 0x12345678);
kono
parents: 67
diff changeset
2305 ASSERT_PP_FORMAT_2 ("-27 12345678", "%ld %x", (long)-27, 0x12345678);
kono
parents: 67
diff changeset
2306 ASSERT_PP_FORMAT_2 ("-5 12345678", "%li %x", (long)-5, 0x12345678);
kono
parents: 67
diff changeset
2307 ASSERT_PP_FORMAT_2 ("10 12345678", "%lu %x", (long)10, 0x12345678);
kono
parents: 67
diff changeset
2308 ASSERT_PP_FORMAT_2 ("17 12345678", "%lo %x", (long)15, 0x12345678);
kono
parents: 67
diff changeset
2309 ASSERT_PP_FORMAT_2 ("cafebabe 12345678", "%lx %x", (long)0xcafebabe,
kono
parents: 67
diff changeset
2310 0x12345678);
kono
parents: 67
diff changeset
2311 ASSERT_PP_FORMAT_2 ("-27 12345678", "%lld %x", (long long)-27, 0x12345678);
kono
parents: 67
diff changeset
2312 ASSERT_PP_FORMAT_2 ("-5 12345678", "%lli %x", (long long)-5, 0x12345678);
kono
parents: 67
diff changeset
2313 ASSERT_PP_FORMAT_2 ("10 12345678", "%llu %x", (long long)10, 0x12345678);
kono
parents: 67
diff changeset
2314 ASSERT_PP_FORMAT_2 ("17 12345678", "%llo %x", (long long)15, 0x12345678);
kono
parents: 67
diff changeset
2315 ASSERT_PP_FORMAT_2 ("cafebabe 12345678", "%llx %x", (long long)0xcafebabe,
kono
parents: 67
diff changeset
2316 0x12345678);
kono
parents: 67
diff changeset
2317 ASSERT_PP_FORMAT_2 ("-27 12345678", "%wd %x", (HOST_WIDE_INT)-27, 0x12345678);
kono
parents: 67
diff changeset
2318 ASSERT_PP_FORMAT_2 ("-5 12345678", "%wi %x", (HOST_WIDE_INT)-5, 0x12345678);
kono
parents: 67
diff changeset
2319 ASSERT_PP_FORMAT_2 ("10 12345678", "%wu %x", (unsigned HOST_WIDE_INT)10,
kono
parents: 67
diff changeset
2320 0x12345678);
kono
parents: 67
diff changeset
2321 ASSERT_PP_FORMAT_2 ("17 12345678", "%wo %x", (HOST_WIDE_INT)15, 0x12345678);
kono
parents: 67
diff changeset
2322 ASSERT_PP_FORMAT_2 ("0xcafebabe 12345678", "%wx %x", (HOST_WIDE_INT)0xcafebabe,
kono
parents: 67
diff changeset
2323 0x12345678);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2324 ASSERT_PP_FORMAT_2 ("1.000000 12345678", "%f %x", 1.0, 0x12345678);
111
kono
parents: 67
diff changeset
2325 ASSERT_PP_FORMAT_2 ("A 12345678", "%c %x", 'A', 0x12345678);
kono
parents: 67
diff changeset
2326 ASSERT_PP_FORMAT_2 ("hello world 12345678", "%s %x", "hello world",
kono
parents: 67
diff changeset
2327 0x12345678);
kono
parents: 67
diff changeset
2328
kono
parents: 67
diff changeset
2329 /* Not nul-terminated. */
kono
parents: 67
diff changeset
2330 char arr[5] = { '1', '2', '3', '4', '5' };
kono
parents: 67
diff changeset
2331 ASSERT_PP_FORMAT_3 ("123 12345678", "%.*s %x", 3, arr, 0x12345678);
kono
parents: 67
diff changeset
2332 ASSERT_PP_FORMAT_3 ("1234 12345678", "%.*s %x", -1, "1234", 0x12345678);
kono
parents: 67
diff changeset
2333 ASSERT_PP_FORMAT_3 ("12345 12345678", "%.*s %x", 7, "12345", 0x12345678);
kono
parents: 67
diff changeset
2334
kono
parents: 67
diff changeset
2335 /* We can't test for %p; the pointer is printed in an implementation-defined
kono
parents: 67
diff changeset
2336 manner. */
kono
parents: 67
diff changeset
2337 ASSERT_PP_FORMAT_2 ("normal colored normal 12345678",
kono
parents: 67
diff changeset
2338 "normal %rcolored%R normal %x",
kono
parents: 67
diff changeset
2339 "error", 0x12345678);
kono
parents: 67
diff changeset
2340 assert_pp_format_colored
kono
parents: 67
diff changeset
2341 (SELFTEST_LOCATION,
kono
parents: 67
diff changeset
2342 "normal \33[01;31m\33[Kcolored\33[m\33[K normal 12345678",
kono
parents: 67
diff changeset
2343 "normal %rcolored%R normal %x", "error", 0x12345678);
kono
parents: 67
diff changeset
2344 /* TODO:
kono
parents: 67
diff changeset
2345 %m: strerror(text->err_no) - does not consume a value from args_ptr. */
kono
parents: 67
diff changeset
2346 ASSERT_PP_FORMAT_1 ("% 12345678", "%% %x", 0x12345678);
kono
parents: 67
diff changeset
2347 ASSERT_PP_FORMAT_1 ("` 12345678", "%< %x", 0x12345678);
kono
parents: 67
diff changeset
2348 ASSERT_PP_FORMAT_1 ("' 12345678", "%> %x", 0x12345678);
kono
parents: 67
diff changeset
2349 ASSERT_PP_FORMAT_1 ("' 12345678", "%' %x", 0x12345678);
kono
parents: 67
diff changeset
2350 ASSERT_PP_FORMAT_3 ("abc 12345678", "%.*s %x", 3, "abcdef", 0x12345678);
kono
parents: 67
diff changeset
2351 ASSERT_PP_FORMAT_2 ("abc 12345678", "%.3s %x", "abcdef", 0x12345678);
kono
parents: 67
diff changeset
2352
kono
parents: 67
diff changeset
2353 /* Verify flag 'q'. */
kono
parents: 67
diff changeset
2354 ASSERT_PP_FORMAT_2 ("`foo' 12345678", "%qs %x", "foo", 0x12345678);
kono
parents: 67
diff changeset
2355 assert_pp_format_colored (SELFTEST_LOCATION,
kono
parents: 67
diff changeset
2356 "`\33[01m\33[Kfoo\33[m\33[K' 12345678", "%qs %x",
kono
parents: 67
diff changeset
2357 "foo", 0x12345678);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2358 /* Verify "%@". */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2359 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2360 diagnostic_event_id_t first (2);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2361 diagnostic_event_id_t second (7);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2362
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2363 ASSERT_PP_FORMAT_2 ("first `free' at (3); second `free' at (8)",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2364 "first %<free%> at %@; second %<free%> at %@",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2365 &first, &second);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2366 assert_pp_format_colored
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2367 (SELFTEST_LOCATION,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2368 "first `free' at (3);"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2369 " second `free' at (8)",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2370 "first %<free%> at %@; second %<free%> at %@",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2371 &first, &second);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2372 }
111
kono
parents: 67
diff changeset
2373
kono
parents: 67
diff changeset
2374 /* Verify %Z. */
kono
parents: 67
diff changeset
2375 int v[] = { 1, 2, 3 };
kono
parents: 67
diff changeset
2376 ASSERT_PP_FORMAT_3 ("1, 2, 3 12345678", "%Z %x", v, 3, 0x12345678);
kono
parents: 67
diff changeset
2377
kono
parents: 67
diff changeset
2378 int v2[] = { 0 };
kono
parents: 67
diff changeset
2379 ASSERT_PP_FORMAT_3 ("0 12345678", "%Z %x", v2, 1, 0x12345678);
kono
parents: 67
diff changeset
2380
kono
parents: 67
diff changeset
2381 /* Verify that combinations work, along with unformatted text. */
kono
parents: 67
diff changeset
2382 assert_pp_format (SELFTEST_LOCATION,
kono
parents: 67
diff changeset
2383 "the quick brown fox jumps over the lazy dog",
kono
parents: 67
diff changeset
2384 "the %s %s %s jumps over the %s %s",
kono
parents: 67
diff changeset
2385 "quick", "brown", "fox", "lazy", "dog");
kono
parents: 67
diff changeset
2386 assert_pp_format (SELFTEST_LOCATION, "item 3 of 7", "item %i of %i", 3, 7);
kono
parents: 67
diff changeset
2387 assert_pp_format (SELFTEST_LOCATION, "problem with `bar' at line 10",
kono
parents: 67
diff changeset
2388 "problem with %qs at line %i", "bar", 10);
kono
parents: 67
diff changeset
2389 }
kono
parents: 67
diff changeset
2390
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2391 /* A subclass of pretty_printer for use by test_prefixes_and_wrapping. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2392
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2393 class test_pretty_printer : public pretty_printer
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2394 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2395 public:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2396 test_pretty_printer (enum diagnostic_prefixing_rule_t rule,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2397 int max_line_length)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2398 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2399 pp_set_prefix (this, xstrdup ("PREFIX: "));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2400 wrapping.rule = rule;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2401 pp_set_line_maximum_length (this, max_line_length);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2402 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2403 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2404
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2405 /* Verify that the various values of enum diagnostic_prefixing_rule_t work
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2406 as expected, with and without line wrapping. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2407
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2408 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2409 test_prefixes_and_wrapping ()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2410 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2411 /* Tests of the various prefixing rules, without wrapping.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2412 Newlines embedded in pp_string don't affect it; we have to
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2413 explicitly call pp_newline. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2414 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2415 test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_ONCE, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2416 pp_string (&pp, "the quick brown fox");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2417 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2418 pp_string (&pp, "jumps over the lazy dog");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2419 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2420 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2421 "PREFIX: the quick brown fox\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2422 " jumps over the lazy dog\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2423 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2424 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2425 test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_NEVER, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2426 pp_string (&pp, "the quick brown fox");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2427 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2428 pp_string (&pp, "jumps over the lazy dog");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2429 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2430 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2431 "the quick brown fox\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2432 "jumps over the lazy dog\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2433 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2434 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2435 test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2436 pp_string (&pp, "the quick brown fox");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2437 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2438 pp_string (&pp, "jumps over the lazy dog");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2439 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2440 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2441 "PREFIX: the quick brown fox\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2442 "PREFIX: jumps over the lazy dog\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2443 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2444
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2445 /* Tests of the various prefixing rules, with wrapping. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2446 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2447 test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_ONCE, 20);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2448 pp_string (&pp, "the quick brown fox jumps over the lazy dog");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2449 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2450 pp_string (&pp, "able was I ere I saw elba");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2451 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2452 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2453 "PREFIX: the quick \n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2454 " brown fox jumps \n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2455 " over the lazy \n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2456 " dog\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2457 " able was I ere I \n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2458 " saw elba\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2459 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2460 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2461 test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_NEVER, 20);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2462 pp_string (&pp, "the quick brown fox jumps over the lazy dog");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2463 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2464 pp_string (&pp, "able was I ere I saw elba");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2465 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2466 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2467 "the quick brown fox \n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2468 "jumps over the lazy \n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2469 "dog\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2470 "able was I ere I \n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2471 "saw elba\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2472 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2473 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2474 test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE, 20);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2475 pp_string (&pp, "the quick brown fox jumps over the lazy dog");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2476 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2477 pp_string (&pp, "able was I ere I saw elba");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2478 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2479 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2480 "PREFIX: the quick brown fox jumps over the lazy dog\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2481 "PREFIX: able was I ere I saw elba\n");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2482 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2483
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2484 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2485
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2486 /* Verify that URL-printing works as expected. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2487
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2488 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2489 test_urls ()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2490 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2491 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2492 pretty_printer pp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2493 pp.show_urls = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2494 pp_begin_url (&pp, "http://example.com");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2495 pp_string (&pp, "This is a link");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2496 pp_end_url (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2497 ASSERT_STREQ ("This is a link",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2498 pp_formatted_text (&pp));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2499 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2500
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2501 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2502 pretty_printer pp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2503 pp.show_urls = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2504 pp_begin_url (&pp, "http://example.com");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2505 pp_string (&pp, "This is a link");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2506 pp_end_url (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2507 ASSERT_STREQ ("\33]8;;http://example.com\aThis is a link\33]8;;\a",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2508 pp_formatted_text (&pp));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2509 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2510 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2511
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2512 /* Test multibyte awareness. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2513 static void test_utf8 ()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2514 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2515
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2516 /* Check that pp_quoted_string leaves valid UTF-8 alone. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2517 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2518 pretty_printer pp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2519 const char *s = "\xf0\x9f\x98\x82";
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2520 pp_quoted_string (&pp, s);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2521 ASSERT_STREQ (pp_formatted_text (&pp), s);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2522 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2523
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2524 /* Check that pp_quoted_string escapes non-UTF-8 nonprintable bytes. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2525 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2526 pretty_printer pp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2527 pp_quoted_string (&pp, "\xf0!\x9f\x98\x82");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2528 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2529 "\\xf0!\\x9f\\x98\\x82");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2530 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2531
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2532 /* Check that pp_character will line-wrap at the beginning of a UTF-8
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2533 sequence, but not in the middle. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2534 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2535 pretty_printer pp (3);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2536 const char s[] = "---\xf0\x9f\x98\x82";
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2537 for (int i = 0; i != sizeof (s) - 1; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2538 pp_character (&pp, s[i]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2539 pp_newline (&pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2540 for (int i = 1; i != sizeof (s) - 1; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2541 pp_character (&pp, s[i]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2542 pp_character (&pp, '-');
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2543 ASSERT_STREQ (pp_formatted_text (&pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2544 "---\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2545 "\xf0\x9f\x98\x82\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2546 "--\xf0\x9f\x98\x82\n"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2547 "-");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2548 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2549
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2550 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2551
111
kono
parents: 67
diff changeset
2552 /* Run all of the selftests within this file. */
kono
parents: 67
diff changeset
2553
kono
parents: 67
diff changeset
2554 void
kono
parents: 67
diff changeset
2555 pretty_print_c_tests ()
kono
parents: 67
diff changeset
2556 {
kono
parents: 67
diff changeset
2557 test_basic_printing ();
kono
parents: 67
diff changeset
2558 test_pp_format ();
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2559 test_prefixes_and_wrapping ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2560 test_urls ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2561 test_utf8 ();
111
kono
parents: 67
diff changeset
2562 }
kono
parents: 67
diff changeset
2563
kono
parents: 67
diff changeset
2564 } // namespace selftest
kono
parents: 67
diff changeset
2565
kono
parents: 67
diff changeset
2566 #endif /* CHECKING_P */