Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 806 lines (662 sloc) 19.998 kB
5daf7ed Merge from no_bogosity
korbb authored
1
2 /*
3
4 Test to see if a particular fix should be applied to a header file.
5
4f80d25 2004-08-14 Paolo Bonzini <bonzini@gnu.org>
bonzini authored
6 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004
fef0883 2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
neroden authored
7 Free Software Foundation, Inc.
5daf7ed Merge from no_bogosity
korbb authored
8
9 = = = = = = = = = = = = = = = = = = = = = = = = =
10
11 NOTE TO DEVELOPERS
12
dc7e6b3 * fixinc/fixfixes.c, fixinc/fixtests.c: Update commentary.
zack authored
13 The routines you write here must work closely with fixincl.c.
5daf7ed Merge from no_bogosity
korbb authored
14
15 Here are the rules:
16
17 1. Every test procedure name must be suffixed with "_fix".
18 These routines will be referenced from inclhack.def, sans the suffix.
19
20 2. Use the "FIX_PROC_HEAD()" macro _with_ the "_fix" suffix
21 (I cannot use the ## magic from ANSI C) for defining your entry point.
22
e665080 implement "wrap" c_fix
korbb authored
23 3. Put your test name into the FIXUP_TABLE.
5daf7ed Merge from no_bogosity
korbb authored
24
25 4. Do not read anything from stdin. It is closed.
26
27 5. Write to stderr only in the event of a reportable error
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
28 In such an event, call "exit (EXIT_FAILURE)".
5daf7ed Merge from no_bogosity
korbb authored
29
dc7e6b3 * fixinc/fixfixes.c, fixinc/fixtests.c: Update commentary.
zack authored
30 6. You have access to the fixDescList entry for the fix in question.
e665080 implement "wrap" c_fix
korbb authored
31 This may be useful, for example, if there are interesting strings
32 or pre-compiled regular expressions stored there.
5daf7ed Merge from no_bogosity
korbb authored
33
34 = = = = = = = = = = = = = = = = = = = = = = = = =
35
fef0883 2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
neroden authored
36 This file is part of GCC.
5daf7ed Merge from no_bogosity
korbb authored
37
fef0883 2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
neroden authored
38 GCC is free software; you can redistribute it and/or modify
5daf7ed Merge from no_bogosity
korbb authored
39 it under the terms of the GNU General Public License as published by
40 the Free Software Foundation; either version 2, or (at your option)
41 any later version.
42
fef0883 2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
neroden authored
43 GCC is distributed in the hope that it will be useful,
5daf7ed Merge from no_bogosity
korbb authored
44 but WITHOUT ANY WARRANTY; without even the implied warranty of
45 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 GNU General Public License for more details.
47
48 You should have received a copy of the GNU General Public License
fef0883 2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
neroden authored
49 along with GCC; see the file COPYING. If not, write to
5daf7ed Merge from no_bogosity
korbb authored
50 the Free Software Foundation, 59 Temple Place - Suite 330,
51 Boston, MA 02111-1307, USA. */
52
53 #include "fixlib.h"
6c013a2 implement various pre-processor guards around standard types
korbb authored
54 #define GTYPE_SE_CT 1
5daf7ed Merge from no_bogosity
korbb authored
55
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
56 #ifdef SEPARATE_FIX_PROC
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
57 #include "fixincl.x"
58 #endif
59
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
60 tSCC zNeedsArg[] = "fixincl error: `%s' needs %s argument (c_fix_arg[%d])\n";
61
a95bcb3 * fixinc/fixfixes.c, fixinc/fixlib.c, fixinc/fixlib.h,
neroden authored
62 typedef void t_fix_proc (const char *, const char *, tFixDesc *) ;
5daf7ed Merge from no_bogosity
korbb authored
63 typedef struct {
64 const char* fix_name;
2548396 code cleanups
korbb authored
65 t_fix_proc* fix_proc;
5daf7ed Merge from no_bogosity
korbb authored
66 } fix_entry_t;
67
68 #define FIXUP_TABLE \
210659d enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
69 _FT_( "char_macro_def", char_macro_def_fix ) \
e665080 implement "wrap" c_fix
korbb authored
70 _FT_( "char_macro_use", char_macro_use_fix ) \
71 _FT_( "format", format_fix ) \
72 _FT_( "machine_name", machine_name_fix ) \
6c013a2 implement various pre-processor guards around standard types
korbb authored
73 _FT_( "wrap", wrap_fix ) \
74 _FT_( "gnu_type", gnu_type_fix )
5daf7ed Merge from no_bogosity
korbb authored
75
76
a95bcb3 * fixinc/fixfixes.c, fixinc/fixlib.c, fixinc/fixlib.h,
neroden authored
77 #define FIX_PROC_HEAD( fix ) \
78 static void fix (const char* filname ATTRIBUTE_UNUSED , \
79 const char* text ATTRIBUTE_UNUSED , \
80 tFixDesc* p_fixd ATTRIBUTE_UNUSED )
5daf7ed Merge from no_bogosity
korbb authored
81
2548396 code cleanups
korbb authored
82 #ifdef NEED_PRINT_QUOTE
5daf7ed Merge from no_bogosity
korbb authored
83 /*
84 * Skip over a quoted string. Single quote strings may
85 * contain multiple characters if the first character is
86 * a backslash. Especially a backslash followed by octal digits.
87 * We are not doing a correctness syntax check here.
88 */
89 static char*
a95bcb3 * fixinc/fixfixes.c, fixinc/fixlib.c, fixinc/fixlib.h,
neroden authored
90 print_quote(char q, char* text )
5daf7ed Merge from no_bogosity
korbb authored
91 {
92 fputc( q, stdout );
93
94 for (;;)
95 {
96 char ch = *(text++);
97 fputc( ch, stdout );
98
99 switch (ch)
100 {
101 case '\\':
102 if (*text == NUL)
103 goto quote_done;
104
105 fputc( *(text++), stdout );
106 break;
107
108 case '"':
109 case '\'':
110 if (ch != q)
111 break;
112 /*FALLTHROUGH*/
113
114 case '\n':
115 case NUL:
116 goto quote_done;
117 }
118 } quote_done:;
119
120 return text;
121 }
2548396 code cleanups
korbb authored
122 #endif /* NEED_PRINT_QUOTE */
5daf7ed Merge from no_bogosity
korbb authored
123
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
124
125 /*
6c013a2 implement various pre-processor guards around standard types
korbb authored
126 * Emit the GNU standard type wrapped up in such a way that
127 * this thing can be encountered countless times during a compile
128 * and not cause even a warning.
129 */
130 static const char*
a95bcb3 * fixinc/fixfixes.c, fixinc/fixlib.c, fixinc/fixlib.h,
neroden authored
131 emit_gnu_type (const char* text, regmatch_t* rm )
6c013a2 implement various pre-processor guards around standard types
korbb authored
132 {
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
133 char z_TYPE[ 64 ];
134 char z_type[ 64 ];
6c013a2 implement various pre-processor guards around standard types
korbb authored
135
136 fwrite (text, rm[0].rm_so, 1, stdout);
137
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
138 {
139 const char* ps = text + rm[1].rm_so;
140 const char* pe = text + rm[1].rm_eo;
141 char* pd = z_type;
142 char* pD = z_TYPE;
6c013a2 implement various pre-processor guards around standard types
korbb authored
143
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
144 while (ps < pe)
93ce8ce include:
zack authored
145 *(pD++) = TOUPPER( *(pd++) = *(ps++) );
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
146
147 *pD = *pd = NUL;
148 }
6c013a2 implement various pre-processor guards around standard types
korbb authored
149
150 /*
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
151 * Now print out the reformed typedef,
152 * with a C++ guard for WCHAR
6c013a2 implement various pre-processor guards around standard types
korbb authored
153 */
fadebf1 use platform specific types in gnu_type_fix
korbb authored
154 {
155 tSCC z_fmt[] = "\
cddb977 * fixinc/fixfixes.c (emit_gnu_type): Avoid string concatenation.
ghazi authored
156 #if !defined(_GCC_%s_T)%s\n\
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
157 #define _GCC_%s_T\n\
158 typedef __%s_TYPE__ %s_t;\n\
159 #endif\n";
fadebf1 use platform specific types in gnu_type_fix
korbb authored
160
35823b6 * c-common.c (c_tree_code_name): Const-ification.
ghazi authored
161 const char *const pz_guard = (strcmp (z_type, "wchar") == 0)
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
162 ? " && ! defined(__cplusplus)" : "";
fadebf1 use platform specific types in gnu_type_fix
korbb authored
163
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
164 printf (z_fmt, z_TYPE, pz_guard, z_TYPE, z_TYPE, z_type);
fadebf1 use platform specific types in gnu_type_fix
korbb authored
165 }
6c013a2 implement various pre-processor guards around standard types
korbb authored
166
94f426d rely* on GCC defining the __xxx_TYPE__ macros
korbb authored
167 return text += rm[0].rm_eo;
6c013a2 implement various pre-processor guards around standard types
korbb authored
168 }
169
170
171 /*
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
172 * Copy the `format' string to std out, replacing `%n' expressions
173 * with the matched text from a regular expression evaluation.
174 * Doubled '%' characters will be replaced with a single copy.
175 * '%' characters in other contexts and all other characters are
176 * copied out verbatim.
177 */
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
178 static void
a95bcb3 * fixinc/fixfixes.c, fixinc/fixlib.c, fixinc/fixlib.h,
neroden authored
179 format_write (tCC* format, tCC* text, regmatch_t av[] )
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
180 {
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
181 int c;
45aed2c buglet & relaxed rules
korbb authored
182
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
183 while ((c = (unsigned)*(format++)) != NUL) {
45aed2c buglet & relaxed rules
korbb authored
184
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
185 if (c != '%')
186 {
187 putchar(c);
188 continue;
189 }
45aed2c buglet & relaxed rules
korbb authored
190
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
191 c = (unsigned)*(format++);
192
193 /*
194 * IF the character following a '%' is not a digit,
195 * THEN we will always emit a '%' and we may or may
196 * not emit the following character. We will end on
197 * a NUL and we will emit only one of a pair of '%'.
198 */
8322672 Kaveh's warning patch from 11/19
korbb authored
199 if (! ISDIGIT ( c ))
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
200 {
201 putchar( '%' );
202 switch (c) {
203 case NUL:
204 return;
205 case '%':
206 break;
207 default:
208 putchar(c);
45aed2c buglet & relaxed rules
korbb authored
209 }
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
210 }
45aed2c buglet & relaxed rules
korbb authored
211
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
212 /*
213 * Emit the matched subexpression numbered 'c'.
214 * IF, of course, there was such a match...
215 */
216 else {
217 regmatch_t* pRM = av + (c - (unsigned)'0');
218 size_t len;
45aed2c buglet & relaxed rules
korbb authored
219
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
220 if (pRM->rm_so < 0)
221 continue;
45aed2c buglet & relaxed rules
korbb authored
222
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
223 len = pRM->rm_eo - pRM->rm_so;
224 if (len > 0)
225 fwrite(text + pRM->rm_so, len, 1, stdout);
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
226 }
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
227 }
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
228 }
5daf7ed Merge from no_bogosity
korbb authored
229
45aed2c buglet & relaxed rules
korbb authored
230
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
231 /*
232 * Search for multiple copies of a regular expression. Each block
233 * of matched text is replaced with the format string, as described
234 * above in `format_write'.
235 */
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
236 FIX_PROC_HEAD( format_fix )
5daf7ed Merge from no_bogosity
korbb authored
237 {
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
238 tCC* pz_pat = p_fixd->patch_args[2];
239 tCC* pz_fmt = p_fixd->patch_args[1];
240 regex_t re;
241 regmatch_t rm[10];
5beb4ba Use one makefile for fixinc
korbb authored
242 IGNORE_ARG(filname);
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
243
244 /*
245 * We must have a format
246 */
247 if (pz_fmt == (tCC*)NULL)
248 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
249 fprintf( stderr, zNeedsArg, p_fixd->fix_name, "replacement format", 0 );
250 exit (EXIT_BROKEN);
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
251 }
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
252
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
253 /*
254 * IF we don't have a search text, then go find the first
255 * regular expression among the tests.
256 */
257 if (pz_pat == (tCC*)NULL)
258 {
259 tTestDesc* pTD = p_fixd->p_test_desc;
260 int ct = p_fixd->test_ct;
261 for (;;)
262 {
263 if (ct-- <= 0)
264 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
265 fprintf( stderr, zNeedsArg, p_fixd->fix_name, "search text", 1 );
266 exit (EXIT_BROKEN);
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
267 }
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
268
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
269 if (pTD->type == TT_EGREP)
270 {
271 pz_pat = pTD->pz_test_text;
272 break;
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
273 }
274
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
275 pTD++;
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
276 }
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
277 }
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
278
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
279 /*
280 * Replace every copy of the text we find
281 */
282 compile_re (pz_pat, &re, 1, "format search-text", "format_fix" );
30f9dc1 * Makefile.in (fixinc.sh): Remove gnu-regex.[ch] from dependencies.
zack authored
283 while (xregexec (&re, text, 10, rm, 0) == 0)
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
284 {
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
285 fwrite( text, rm[0].rm_so, 1, stdout );
286 format_write( pz_fmt, text, rm );
287 text += rm[0].rm_eo;
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
288 }
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
289
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
290 /*
291 * Dump out the rest of the file
292 */
293 fputs (text, stdout);
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
294 }
295
e665080 implement "wrap" c_fix
korbb authored
296
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
297 /* Scan the input file for all occurrences of text like this:
298
299 #define TIOCCONS _IO(T, 12)
300
301 and change them to read like this:
302
303 #define TIOCCONS _IO('T', 12)
304
305 which is the required syntax per the C standard. (The definition of
306 _IO also has to be tweaked - see below.) 'IO' is actually whatever you
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
307 provide as the `c_fix_arg' argument. */
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
308
309 FIX_PROC_HEAD( char_macro_use_fix )
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
310 {
311 /* This regexp looks for a traditional-syntax #define (# in column 1)
312 of an object-like macro. */
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
313 static const char pat[] =
314 "^#[ \t]*define[ \t]+[_A-Za-z][_A-Za-z0-9]*[ \t]+";
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
315 static regex_t re;
316
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
317 const char* str = p_fixd->patch_args[1];
318 regmatch_t rm[1];
319 const char *p, *limit;
320 size_t len;
5beb4ba Use one makefile for fixinc
korbb authored
321 IGNORE_ARG(filname);
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
322
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
323 if (str == NULL)
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
324 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
325 fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
326 exit (EXIT_BROKEN);
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
327 }
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
328
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
329 len = strlen (str);
330 compile_re (pat, &re, 1, "macro pattern", "char_macro_use_fix");
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
331
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
332 for (p = text;
30f9dc1 * Makefile.in (fixinc.sh): Remove gnu-regex.[ch] from dependencies.
zack authored
333 xregexec (&re, p, 1, rm, 0) == 0;
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
334 p = limit + 1)
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
335 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
336 /* p + rm[0].rm_eo is the first character of the macro replacement.
337 Find the end of the macro replacement, and the STR we were
338 sent to look for within the replacement. */
339 p += rm[0].rm_eo;
340 limit = p - 1;
341 do
342 {
343 limit = strchr (limit + 1, '\n');
344 if (!limit)
345 goto done;
346 }
347 while (limit[-1] == '\\');
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
348
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
349 do
350 {
351 if (*p == str[0] && !strncmp (p+1, str+1, len-1))
352 goto found;
353 }
354 while (++p < limit - len);
355 /* Hit end of line. */
356 continue;
357
358 found:
359 /* Found STR on this line. If the macro needs fixing,
360 the next few chars will be whitespace or uppercase,
361 then an open paren, then a single letter. */
8322672 Kaveh's warning patch from 11/19
korbb authored
362 while ((ISSPACE (*p) || ISUPPER (*p)) && p < limit) p++;
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
363 if (*p++ != '(')
364 continue;
8322672 Kaveh's warning patch from 11/19
korbb authored
365 if (!ISALPHA (*p))
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
366 continue;
66a3357 * c-format.c (maybe_read_dollar_number): Use safe-ctype macros
ghazi authored
367 if (ISIDNUM (p[1]))
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
368 continue;
369
370 /* Splat all preceding text into the output buffer,
371 quote the character at p, then proceed. */
372 fwrite (text, 1, p - text, stdout);
373 putchar ('\'');
374 putchar (*p);
375 putchar ('\'');
376 text = p + 1;
377 }
378 done:
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
379 fputs (text, stdout);
380 }
381
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
382
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
383 /* Scan the input file for all occurrences of text like this:
384
41cdbdb improve the debug displays, ignore SIGPIPE, and fix char_macro_def regex
korbb authored
385 #define xxxIOxx(x, y) (....'x'<<16....)
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
386
387 and change them to read like this:
388
41cdbdb improve the debug displays, ignore SIGPIPE, and fix char_macro_def regex
korbb authored
389 #define xxxIOxx(x, y) (....x<<16....)
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
390
391 which is the required syntax per the C standard. (The uses of _IO
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
392 also has to be tweaked - see above.) 'IO' is actually whatever
393 you provide as the `c_fix_arg' argument. */
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
394 FIX_PROC_HEAD( char_macro_def_fix )
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
395 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
396 /* This regexp looks for any traditional-syntax #define (# in column 1). */
397 static const char pat[] =
398 "^#[ \t]*define[ \t]+";
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
399 static regex_t re;
400
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
401 const char* str = p_fixd->patch_args[1];
402 regmatch_t rm[1];
403 const char *p, *limit;
404 char arg;
405 size_t len;
5beb4ba Use one makefile for fixinc
korbb authored
406 IGNORE_ARG(filname);
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
407
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
408 if (str == NULL)
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
409 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
410 fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
411 exit (EXIT_BROKEN);
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
412 }
413
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
414 len = strlen (str);
415 compile_re (pat, &re, 1, "macro pattern", "fix_char_macro_defines");
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
416
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
417 for (p = text;
30f9dc1 * Makefile.in (fixinc.sh): Remove gnu-regex.[ch] from dependencies.
zack authored
418 xregexec (&re, p, 1, rm, 0) == 0;
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
419 p = limit + 1)
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
420 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
421 /* p + rm[0].rm_eo is the first character of the macro name.
422 Find the end of the macro replacement, and the STR we were
423 sent to look for within the name. */
424 p += rm[0].rm_eo;
425 limit = p - 1;
426 do
427 {
428 limit = strchr (limit + 1, '\n');
429 if (!limit)
430 goto done;
431 }
432 while (limit[-1] == '\\');
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
433
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
434 do
435 {
436 if (*p == str[0] && !strncmp (p+1, str+1, len-1))
437 goto found;
438 p++;
439 }
66a3357 * c-format.c (maybe_read_dollar_number): Use safe-ctype macros
ghazi authored
440 while (ISIDNUM (*p));
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
441 /* Hit end of macro name without finding the string. */
442 continue;
443
444 found:
445 /* Found STR in this macro name. If the macro needs fixing,
446 there may be a few uppercase letters, then there will be an
447 open paren with _no_ intervening whitespace, and then a
448 single letter. */
8322672 Kaveh's warning patch from 11/19
korbb authored
449 while (ISUPPER (*p) && p < limit) p++;
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
450 if (*p++ != '(')
451 continue;
8322672 Kaveh's warning patch from 11/19
korbb authored
452 if (!ISALPHA (*p))
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
453 continue;
66a3357 * c-format.c (maybe_read_dollar_number): Use safe-ctype macros
ghazi authored
454 if (ISIDNUM (p[1]))
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
455 continue;
456
457 /* The character at P is the one to look for in the following
458 text. */
459 arg = *p;
460 p += 2;
461
462 while (p < limit)
463 {
464 if (p[-1] == '\'' && p[0] == arg && p[1] == '\'')
465 {
466 /* Remove the quotes from this use of ARG. */
467 p--;
468 fwrite (text, 1, p - text, stdout);
469 putchar (arg);
470 p += 3;
471 text = p;
472 }
473 else
474 p++;
475 }
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
476 }
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
477 done:
ada96dc * fixinc/Makefile.in: Correct dependencies of fixincl and fixincl.o.
zack authored
478 fputs (text, stdout);
479 }
480
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
481 /* Fix for machine name #ifdefs that are not in the namespace reserved
482 by the C standard. They won't be defined if compiling with -ansi,
483 and the headers will break. We go to some trouble to only change
484 #ifdefs where the macro is defined by GCC in non-ansi mode; this
485 minimizes the number of headers touched. */
486
487 #define SCRATCHSZ 64 /* hopefully long enough */
488
489 FIX_PROC_HEAD( machine_name_fix )
490 {
491 regmatch_t match[2];
c940c2a enhance the format style c_fix & remove unneeded wrapper funcs
korbb authored
492 const char *line, *base, *limit, *p, *q;
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
493 regex_t *label_re, *name_re;
494 char scratch[SCRATCHSZ];
495 size_t len;
5beb4ba Use one makefile for fixinc
korbb authored
496 IGNORE_ARG(filname);
497 IGNORE_ARG(p_fixd);
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
498
31b04de 2004-08-30 Paolo Bonzini <bonzini@gnu.org>
bonzini authored
499 if (!mn_get_regexps (&label_re, &name_re, "machine_name_fix"))
500 {
501 fputs( "The target machine has no needed machine name fixes\n", stderr );
502 goto done;
503 }
641b112 * frame.c (find_fde): Convert for loop to do-while so compiler
zack authored
504
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
505 scratch[0] = '_';
506 scratch[1] = '_';
507
508 for (base = text;
30f9dc1 * Makefile.in (fixinc.sh): Remove gnu-regex.[ch] from dependencies.
zack authored
509 xregexec (label_re, base, 2, match, 0) == 0;
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
510 base = limit)
511 {
512 base += match[0].rm_eo;
513 /* We're looking at an #if or #ifdef. Scan forward for the
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
514 next non-escaped newline. */
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
515 line = limit = base;
516 do
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
517 {
518 limit++;
519 limit = strchr (limit, '\n');
520 if (!limit)
521 goto done;
522 }
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
523 while (limit[-1] == '\\');
524
525 /* If the 'name_pat' matches in between base and limit, we have
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
526 a bogon. It is not worth the hassle of excluding comments
527 because comments on #if/#ifdef lines are rare, and strings on
528 such lines are illegal.
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
529
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
530 REG_NOTBOL means 'base' is not at the beginning of a line, which
531 shouldn't matter since the name_re has no ^ anchor, but let's
532 be accurate anyway. */
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
533
534 for (;;)
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
535 {
536 again:
537 if (base == limit)
538 break;
539
30f9dc1 * Makefile.in (fixinc.sh): Remove gnu-regex.[ch] from dependencies.
zack authored
540 if (xregexec (name_re, base, 1, match, REG_NOTBOL))
d0989a8 corrected and rewrote char_macro_* fixes to parse the text with regexes
korbb authored
541 goto done; /* No remaining match in this file */
542
543 /* Match; is it on the line? */
544 if (match[0].rm_eo > limit - base)
545 break;
546
547 p = base + match[0].rm_so;
548 base += match[0].rm_eo;
549
550 /* One more test: if on the same line we have the same string
551 with the appropriate underscores, then leave it alone.
552 We want exactly two leading and trailing underscores. */
553 if (*p == '_')
554 {
555 len = base - p - ((*base == '_') ? 2 : 1);
556 q = p + 1;
557 }
558 else
559 {
560 len = base - p - ((*base == '_') ? 1 : 0);
561 q = p;
562 }
563 if (len + 4 > SCRATCHSZ)
564 abort ();
565 memcpy (&scratch[2], q, len);
566 len += 2;
567 scratch[len++] = '_';
568 scratch[len++] = '_';
569
570 for (q = line; q <= limit - len; q++)
571 if (*q == '_' && !strncmp (q, scratch, len))
572 goto again;
573
574 fwrite (text, 1, p - text, stdout);
575 fwrite (scratch, 1, len, stdout);
576
577 text = base;
578 }
17f8e52 * Makefile.in (fixinc.sh): Depend on specs.
zack authored
579 }
580 done:
581 fputs (text, stdout);
582 }
583
584
e665080 implement "wrap" c_fix
korbb authored
585 FIX_PROC_HEAD( wrap_fix )
586 {
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
587 tSCC z_no_wrap_pat[] = "^#if.*__need_";
5beb4ba Use one makefile for fixinc
korbb authored
588 static regex_t no_wrapping_re; /* assume zeroed data */
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
589
f407d61 When wrapping files, guard with both the fix name and the file name
korbb authored
590 tCC* pz_name = NULL;
e665080 implement "wrap" c_fix
korbb authored
591
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
592 if (no_wrapping_re.allocated == 0)
593 compile_re( z_no_wrap_pat, &no_wrapping_re, 0, "no-wrap pattern",
594 "wrap-fix" );
595
596 /*
597 * IF we do *not* match the no-wrap re, then we have a double negative.
598 * A double negative means YES.
599 */
30f9dc1 * Makefile.in (fixinc.sh): Remove gnu-regex.[ch] from dependencies.
zack authored
600 if (xregexec( &no_wrapping_re, text, 0, NULL, 0 ) != 0)
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
601 {
f407d61 When wrapping files, guard with both the fix name and the file name
korbb authored
602 /*
603 * A single file can get wrapped more than once by different fixes.
604 * A single fix can wrap multiple files. Therefore, guard with
605 * *both* the fix name and the file name.
606 */
607 size_t ln = strlen( filname ) + strlen( p_fixd->fix_name ) + 14;
608 char* pz = xmalloc( ln );
609 pz_name = pz;
610 sprintf( pz, "FIXINC_WRAP_%s-%s", filname, p_fixd->fix_name );
611
612 for (pz += 12; 1; pz++) {
613 char ch = *pz;
614
615 if (ch == NUL)
616 break;
617
618 if (! ISALNUM( ch )) {
619 *pz = '_';
620 }
621 else {
622 *pz = TOUPPER( ch );
623 }
624 }
625
626 printf( "#ifndef %s\n", pz_name );
627 printf( "#define %s 1\n\n", pz_name );
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
628 }
e665080 implement "wrap" c_fix
korbb authored
629
630 if (p_fixd->patch_args[1] == (tCC*)NULL)
631 fputs( text, stdout );
632
633 else {
634 fputs( p_fixd->patch_args[1], stdout );
635 fputs( text, stdout );
636 if (p_fixd->patch_args[2] != (tCC*)NULL)
637 fputs( p_fixd->patch_args[2], stdout );
638 }
639
f407d61 When wrapping files, guard with both the fix name and the file name
korbb authored
640 if (pz_name != NULL) {
641 printf( "\n#endif /* %s */\n", pz_name );
e665080 implement "wrap" c_fix
korbb authored
642 free( (void*)pz_name );
f407d61 When wrapping files, guard with both the fix name and the file name
korbb authored
643 }
e665080 implement "wrap" c_fix
korbb authored
644 }
645
646
6c013a2 implement various pre-processor guards around standard types
korbb authored
647 /*
648 * Search for multiple copies of a regular expression. Each block
649 * of matched text is replaced with the format string, as described
650 * above in `format_write'.
651 */
652 FIX_PROC_HEAD( gnu_type_fix )
653 {
654 const char* pz_pat;
655 regex_t re;
656 regmatch_t rm[GTYPE_SE_CT+1];
5beb4ba Use one makefile for fixinc
korbb authored
657 IGNORE_ARG(filname);
6c013a2 implement various pre-processor guards around standard types
korbb authored
658
659 {
660 tTestDesc* pTD = p_fixd->p_test_desc;
661 int ct = p_fixd->test_ct;
662 for (;;)
663 {
664 if (ct-- <= 0)
665 {
666 fprintf (stderr, zNeedsArg, p_fixd->fix_name, "search text", 1);
667 exit (EXIT_BROKEN);
668 }
669
670 if (pTD->type == TT_EGREP)
671 {
672 pz_pat = pTD->pz_test_text;
673 break;
674 }
675
676 pTD++;
677 }
678 }
679
680 compile_re (pz_pat, &re, 1, "gnu type typedef", "gnu_type_fix");
681
30f9dc1 * Makefile.in (fixinc.sh): Remove gnu-regex.[ch] from dependencies.
zack authored
682 while (xregexec (&re, text, GTYPE_SE_CT+1, rm, 0) == 0)
6c013a2 implement various pre-processor guards around standard types
korbb authored
683 {
684 text = emit_gnu_type (text, rm);
685 }
686
687 /*
688 * Dump out the rest of the file
689 */
690 fputs (text, stdout);
691 }
692
693
5daf7ed Merge from no_bogosity
korbb authored
694 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
695
696 test for fix selector
697
698 THIS IS THE ONLY EXPORTED ROUTINE
699
700 */
701 void
a95bcb3 * fixinc/fixfixes.c, fixinc/fixlib.c, fixinc/fixlib.h,
neroden authored
702 apply_fix( tFixDesc* p_fixd, tCC* filname )
5daf7ed Merge from no_bogosity
korbb authored
703 {
d940655 Patch from Philippe De Muyter <phdm@macqel.be>
korbb authored
704 #define _FT_(n,p) { n, p },
5daf7ed Merge from no_bogosity
korbb authored
705 static fix_entry_t fix_table[] = { FIXUP_TABLE { NULL, NULL }};
d940655 Patch from Philippe De Muyter <phdm@macqel.be>
korbb authored
706 #undef _FT_
3098b2d * optabs.c (init_optabs): Initialize fixtab, fixtrunctab, floattab,
gkm authored
707 #define FIX_TABLE_CT (ARRAY_SIZE (fix_table)-1)
5daf7ed Merge from no_bogosity
korbb authored
708
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
709 tCC* fixname = p_fixd->patch_args[0];
5daf7ed Merge from no_bogosity
korbb authored
710 char* buf;
711 int ct = FIX_TABLE_CT;
712 fix_entry_t* pfe = fix_table;
713
714 for (;;)
715 {
716 if (strcmp (pfe->fix_name, fixname) == 0)
717 break;
718 if (--ct <= 0)
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
719 {
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
720 fprintf (stderr, "fixincl error: the `%s' fix is unknown\n",
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
721 fixname );
57adc3a restore old algorighm for char_macro_*_fix routines
korbb authored
722 exit (EXIT_BROKEN);
d570f9d Use C-coded tests and fixes for #endif/#else labels
korbb authored
723 }
724 pfe++;
5daf7ed Merge from no_bogosity
korbb authored
725 }
726
727 buf = load_file_data (stdin);
09fe1d5 Added support for "make check" and the "format" c_fix
korbb authored
728 (*pfe->fix_proc)( filname, buf, p_fixd );
5daf7ed Merge from no_bogosity
korbb authored
729 }
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
730
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
731 #ifdef SEPARATE_FIX_PROC
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
732 tSCC z_usage[] =
733 "USAGE: applyfix <fix-name> <file-to-fix> <file-source> <file-destination>\n";
734 tSCC z_reopen[] =
735 "FS error %d (%s) reopening %s as std%s\n";
736
737 int
a95bcb3 * fixinc/fixfixes.c, fixinc/fixlib.c, fixinc/fixlib.h,
neroden authored
738 main( int argc, char** argv )
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
739 {
740 tFixDesc* pFix;
741 char* pz_tmptmp;
742 char* pz_tmp_base;
743 char* pz_tmp_dot;
744
745 if (argc != 5)
746 {
747 usage_failure:
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
748 fputs (z_usage, stderr);
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
749 return EXIT_FAILURE;
750 }
751
4f80d25 2004-08-14 Paolo Bonzini <bonzini@gnu.org>
bonzini authored
752 initialize_opts ();
753
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
754 {
755 char* pz = argv[1];
756 long idx;
757
8322672 Kaveh's warning patch from 11/19
korbb authored
758 if (! ISDIGIT ( *pz ))
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
759 goto usage_failure;
760
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
761 idx = strtol (pz, &pz, 10);
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
762 if ((*pz != NUL) || ((unsigned)idx >= FIX_COUNT))
763 goto usage_failure;
764 pFix = fixDescList + idx;
765 }
766
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
767 if (freopen (argv[3], "r", stdin) != stdin)
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
768 {
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
769 fprintf (stderr, z_reopen, errno, strerror( errno ), argv[3], "in");
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
770 return EXIT_FAILURE;
771 }
772
6edf18a gcc:
ghazi authored
773 pz_tmptmp = xmalloc (strlen (argv[4]) + 5);
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
774 strcpy( pz_tmptmp, argv[4] );
775
776 /* Don't lose because "12345678" and "12345678X" map to the same
777 file under DOS restricted 8+3 file namespace. Note that DOS
778 doesn't allow more than one dot in the trunk of a file name. */
779 pz_tmp_base = basename( pz_tmptmp );
780 pz_tmp_dot = strchr( pz_tmp_base, '.' );
781 if (pathconf( pz_tmptmp, _PC_NAME_MAX ) <= 12 /* is this DOS or Windows9X? */
782 && pz_tmp_dot != (char*)NULL)
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
783 strcpy (pz_tmp_dot+1, "X"); /* nuke the original extension */
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
784 else
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
785 strcat (pz_tmptmp, ".X");
786 if (freopen (pz_tmptmp, "w", stdout) != stdout)
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
787 {
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
788 fprintf (stderr, z_reopen, errno, strerror( errno ), pz_tmptmp, "out");
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
789 return EXIT_FAILURE;
790 }
791
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
792 apply_fix (pFix, argv[1]);
793 fclose (stdout);
794 fclose (stdin);
795 unlink (argv[4]);
796 if (rename (pz_tmptmp, argv[4]) != 0)
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
797 {
d3aacc3 Prepare for fixincludes on BeOS
korbb authored
798 fprintf (stderr, "error %d (%s) renaming %s to %s\n", errno,
799 strerror( errno ), pz_tmptmp, argv[4]);
70ba55f Implement, but leave disabled, MSDOS functionality
korbb authored
800 return EXIT_FAILURE;
801 }
802
803 return EXIT_SUCCESS;
804 }
805 #endif
Something went wrong with that request. Please try again.