annotate gcc/pretty-print.c @ 131:84e7813d76e9

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