OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / fixincludes / inclhack.def
1 /* -*- Mode: C -*-  */
2
3 autogen definitions fixincl;
4
5 /* Define all the fixes we know about for repairing damaged headers.
6    Please see the README before adding or changing entries in this file.
7
8    This is the sort command:
9
10    blocksort output=inclhack.sorted \
11           pattern='^/\*$' \
12           trailer='^/\*EOF\*[/]' \
13           input=inclhack.def \
14           key='hackname[        ]*=[    ]*(.*);'
15
16    Set up a debug test so we can make the templates emit special
17    code while debugging these fixes:  */
18
19 #ifdef DEBUG
20 FIXINC_DEBUG = yes;
21 #endif
22
23 /* On AIX when _LARGE_FILES is defined stdio.h defines fopen to
24  * fopen64 etc. and this causes problems when building with g++
25  * because cstdio udefs everything from stdio.h, leaving us with
26  * ::fopen has not been declared errors. This fixes stdio.h to
27  * undef those defines and use __asm__ to alias the symbols if
28  * building with g++ and -D_LARGE_FILES
29  */
30 fix = {
31     hackname  = AAB_aix_stdio;
32     files     = stdio.h;
33     select    = "define fopen fopen64";
34     mach      = "*-*-aix*";
35     test-text = ''; /* no way to test */
36
37     c_fix     = wrap;
38
39     c_fix_arg = "";
40
41     c_fix_arg = <<- _EOArg_
42
43         #if defined __GNUG__ && defined _LARGE_FILES && defined __cplusplus
44         #define __need__aix_stdio_h_fix
45         #ifdef __need__aix_stdio_h_fix
46         #undef fseeko
47         #undef ftello
48         #undef fgetpos
49         #undef fsetpos
50         #undef fopen
51         #undef freopen
52         /* Alias the symbols using asm */
53         extern "C" {
54         extern int fgetpos(FILE *, fpos64_t *) __asm__("fgetpos64");
55         extern FILE *fopen(const char *, const char *) __asm__("fopen64");
56         extern FILE *freopen(const char *, const char *, FILE *) __asm__("freopen64");
57         extern int fseeko(FILE *, off64_t, int) __asm__("fseeko64");
58         extern int fsetpos(FILE *, const fpos64_t *) __asm__("fsetpos64");
59         extern off64_t ftello(FILE *) __asm__("ftello64");
60         }
61         #endif
62         #endif
63
64         _EOArg_;
65 };
66
67
68 /*
69  *  On Mac OS 10.3.9, the 'long double' functions are available in
70  *  libSystem, but are not prototyped in math.h.
71  */
72 fix = {
73   hackname  = AAB_darwin7_9_long_double_funcs;
74   mach      = "*-*-darwin7.9*";
75   files     = architecture/ppc/math.h;
76   bypass    = "powl";
77   replace = <<- _EndOfHeader_
78         /* This file prototypes the long double functions available on Mac OS
79            10.3.9.  */
80         #ifndef __MATH__
81         # undef __APPLE_CC__
82         # define __APPLE_CC__  1345
83         # include_next <architecture/ppc/math.h>
84         # undef __APPLE_CC__
85         # define __APPLE_CC__ 1
86         # ifndef __LIBMLDBL_COMPAT
87         #  ifdef __LONG_DOUBLE_128__
88         #   define __LIBMLDBL_COMPAT(sym) __asm("_" #sym "$LDBL128")
89         #  else
90         #   define __LIBMLDBL_COMPAT(sym)
91         #  endif /* __LONG_DOUBLE_128__ */
92         # endif /* __LIBMLDBL_COMPAT */
93         # ifdef __cplusplus
94            extern "C" {
95         # endif
96           extern long double acosl( long double ) __LIBMLDBL_COMPAT(acosl);
97           extern long double asinl( long double ) __LIBMLDBL_COMPAT(asinl);
98           extern long double atanl( long double ) __LIBMLDBL_COMPAT(atanl);
99           extern long double atan2l( long double, long double ) __LIBMLDBL_COMPAT(atan2l);
100           extern long double cosl( long double ) __LIBMLDBL_COMPAT(cosl);
101           extern long double sinl( long double ) __LIBMLDBL_COMPAT(sinl);
102           extern long double tanl( long double ) __LIBMLDBL_COMPAT(tanl);
103           extern long double acoshl( long double ) __LIBMLDBL_COMPAT(acoshl);
104           extern long double asinhl( long double ) __LIBMLDBL_COMPAT(asinhl);
105           extern long double atanhl( long double ) __LIBMLDBL_COMPAT(atanhl);
106           extern long double coshl( long double ) __LIBMLDBL_COMPAT(coshl);
107           extern long double sinhl( long double ) __LIBMLDBL_COMPAT(sinhl);
108           extern long double tanhl( long double ) __LIBMLDBL_COMPAT(tanhl);
109           extern long double expl( long double ) __LIBMLDBL_COMPAT(expl);
110           extern long double exp2l( long double ) __LIBMLDBL_COMPAT(exp2l);
111           extern long double expm1l( long double ) __LIBMLDBL_COMPAT(expm1l);
112           extern long double logl( long double ) __LIBMLDBL_COMPAT(logl);
113           extern long double log10l( long double ) __LIBMLDBL_COMPAT(log10l);
114           extern long double log2l( long double ) __LIBMLDBL_COMPAT(log2l);
115           extern long double log1pl( long double ) __LIBMLDBL_COMPAT(log1pl);
116           extern long double logbl( long double ) __LIBMLDBL_COMPAT(logbl);
117           extern long double modfl( long double, long double * ) __LIBMLDBL_COMPAT(modfl);
118           extern long double ldexpl( long double, int ) __LIBMLDBL_COMPAT(ldexpl);
119           extern long double frexpl( long double, int * ) __LIBMLDBL_COMPAT(frexpl);
120           extern int ilogbl( long double ) __LIBMLDBL_COMPAT(ilogbl);
121           extern long double scalbnl( long double, int ) __LIBMLDBL_COMPAT(scalbnl);
122           extern long double scalblnl( long double, long int ) __LIBMLDBL_COMPAT(scalblnl);
123           extern long double fabsl( long double ) __LIBMLDBL_COMPAT(fabsl);
124           extern long double cbrtl( long double ) __LIBMLDBL_COMPAT(cbrtl);
125           extern long double hypotl( long double, long double ) __LIBMLDBL_COMPAT(hypotl);
126           extern long double powl( long double, long double ) __LIBMLDBL_COMPAT(powl);
127           extern long double sqrtl( long double ) __LIBMLDBL_COMPAT(sqrtl);
128           extern long double erfl( long double ) __LIBMLDBL_COMPAT(erfl);
129           extern long double erfcl( long double ) __LIBMLDBL_COMPAT(erfcl);
130           extern long double lgammal( long double ) __LIBMLDBL_COMPAT(lgammal);
131           extern long double tgammal( long double ) __LIBMLDBL_COMPAT(tgammal);
132           extern long double ceill( long double ) __LIBMLDBL_COMPAT(ceill);
133           extern long double floorl( long double ) __LIBMLDBL_COMPAT(floorl);
134           extern long double nearbyintl( long double ) __LIBMLDBL_COMPAT(nearbyintl);
135           extern long double rintl( long double ) __LIBMLDBL_COMPAT(rintl);
136           extern long int lrintl( long double ) __LIBMLDBL_COMPAT(lrintl);
137           extern long long int llrintl( long double ) __LIBMLDBL_COMPAT(llrintl);
138           extern long double roundl( long double ) __LIBMLDBL_COMPAT(roundl);
139           extern long int lroundl( long double ) __LIBMLDBL_COMPAT(lroundl);
140           extern long long int llroundl( long double ) __LIBMLDBL_COMPAT(llroundl);
141           extern long double truncl( long double ) __LIBMLDBL_COMPAT(truncl);
142           extern long double fmodl( long double, long double) __LIBMLDBL_COMPAT(fmodl);
143           extern long double remainderl( long double, long double ) __LIBMLDBL_COMPAT(remainderl);
144           extern long double remquol( long double, long double, int * ) __LIBMLDBL_COMPAT(remquol);
145           extern long double copysignl( long double, long double ) __LIBMLDBL_COMPAT(copysignl);
146           extern long double nanl( const char * ) __LIBMLDBL_COMPAT(nanl);
147           extern long double nextafterl( long double, long double ) __LIBMLDBL_COMPAT(nextafterl);
148           extern long double nexttowardl( long double, long double ) __LIBMLDBL_COMPAT(nexttowardl);
149           extern long double fdiml( long double, long double ) __LIBMLDBL_COMPAT(fdiml);
150           extern long double fmaxl( long double, long double ) __LIBMLDBL_COMPAT(fmaxl);
151           extern long double fminl( long double, long double ) __LIBMLDBL_COMPAT(fminl);
152           extern long double fmal( long double, long double, long double ) __LIBMLDBL_COMPAT(fmal);
153         # ifdef __cplusplus
154            }
155         # endif
156         #endif /* __MATH__ */
157         _EndOfHeader_;
158 };
159
160
161 /*
162  *  ... and for the previous fix to be useful, you have to not use ""
163  *  includes.
164  */
165 fix = {
166   hackname  = AAB_darwin7_9_long_double_funcs_2;
167   mach      = "*-*-darwin7.9*";
168   files     = math.h;
169   select    = '#include[ \t]+\"';
170   c_fix     = format;
171   c_fix_arg = "%1<%2.h>";
172   
173   c_fix_arg = '([ \t]*#[ \t]*include[ \t]+)"([a-z0-9/]+)\.h"';
174   
175   test_text = '#include "architecture/ppc/math.h"';
176 };
177
178
179 /*
180  *  This fixes __FD_ZERO bug for linux 2.x.y (x <= 2 && y <= some n)
181  */
182 fix = {
183     hackname = AAB_fd_zero_asm_posix_types_h;
184     files    = asm/posix_types.h;
185     mach     = 'i[34567]86-*-linux*';
186     bypass   = '} while';
187     bypass   = 'x86_64';
188     bypass   = 'posix_types_64';
189
190     /*
191      * Define _POSIX_TYPES_H_WRAPPER at the end of the wrapper, not
192      * the start, so that if #include_next gets another instance of
193      * the wrapper, this will follow the #include_next chain until
194      * we arrive at the real <asm/posix_types.h>.
195      */
196     replace  = <<-  _EndOfHeader_
197         /* This file fixes a bug in the __FD_ZERO macro
198            for older versions of the Linux kernel. */
199         #ifndef _POSIX_TYPES_H_WRAPPER
200         #include <features.h>
201          #include_next <asm/posix_types.h>
202         
203         #if defined(__FD_ZERO) && !defined(__GLIBC__)
204         #undef __FD_ZERO
205         #define __FD_ZERO(fdsetp) \
206           do { \
207             int __d0, __d1; \
208                 __asm__ __volatile__("cld ; rep ; stosl" \
209                         : "=&c" (__d0), "=&D" (__d1) \
210                         : "a" (0), "0" (__FDSET_LONGS), \
211                           "1" ((__kernel_fd_set *) (fdsetp)) :"memory"); \
212           } while (0)
213         #endif
214         
215         #define _POSIX_TYPES_H_WRAPPER
216         #endif /* _POSIX_TYPES_H_WRAPPER */
217         _EndOfHeader_;
218 };
219
220
221 /*
222  *  This fixes __FD_ZERO bug for glibc-1.x
223  */
224 fix = {
225     hackname = AAB_fd_zero_gnu_types_h;
226     files    = gnu/types.h;
227     mach     = 'i[34567]86-*-linux*';
228
229     /*
230      * Define _TYPES_H_WRAPPER at the end of the wrapper, not
231      * the start, so that if #include_next gets another instance of
232      * the wrapper, this will follow the #include_next chain until
233      * we arrive at the real <gnu/types.h>.
234      */
235     replace  = <<-  _EndOfHeader_
236         /* This file fixes a bug in the __FD_ZERO macro present in glibc 1.x. */
237         #ifndef _TYPES_H_WRAPPER
238         #include <features.h>
239         #include_next <gnu/types.h>
240
241         #if defined(__FD_ZERO) && !defined(__GLIBC__)
242         #undef __FD_ZERO
243         # define __FD_ZERO(fdsetp) \
244           do { \
245             int __d0, __d1; \
246                 __asm__ __volatile__("cld ; rep ; stosl" \
247                 : "=&c" (__d0), "=&D" (__d1) \
248                 : "a" (0), "0" (__FDSET_LONGS), \
249                   "1" ((__fd_set *) (fdsetp)) :"memory"); \
250           } while (0)
251         #endif
252
253         #define _TYPES_H_WRAPPER
254         #endif /* _TYPES_H_WRAPPER */
255         _EndOfHeader_;
256 };
257
258
259 /*
260  *  This fixes __FD_ZERO bug for glibc-2.0.x
261  */
262 fix = {
263     hackname = AAB_fd_zero_selectbits_h;
264     files    = selectbits.h;
265     mach     = 'i[34567]86-*-linux*';
266
267     /*
268      * Define _SELECTBITS_H_WRAPPER at the end of the wrapper, not
269      * the start, so that if #include_next gets another instance of
270      * the wrapper, this will follow the #include_next chain until
271      * we arrive at the real <selectbits.h>.
272      */
273     replace  = <<-  _EndOfHeader_
274         /* This file fixes a bug in the __FD_ZERO macro present in glibc 2.0.x. */
275         #ifndef _SELECTBITS_H_WRAPPER
276           #include <features.h>
277           #include_next <selectbits.h>
278
279           #if defined(__FD_ZERO) && defined(__GLIBC__) \\
280           && defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \\
281           && __GLIBC_MINOR__ == 0
282              #undef __FD_ZERO
283              #define __FD_ZERO(fdsetp) \\
284              do { \\
285                 int __d0, __d1; \\
286               __asm__ __volatile__ ("cld; rep; stosl" \\
287                         : "=&c" (__d0), "=&D" (__d1) \\
288                         : "a" (0), "0" (sizeof (__fd_set) \\
289                                         / sizeof (__fd_mask)), \\
290                           "1" ((__fd_mask *) (fdsetp)) \\
291                         : "memory"); \\
292               } while (0)
293           #endif
294
295           #define _SELECTBITS_H_WRAPPER
296         #endif /* _SELECTBITS_H_WRAPPER */
297         _EndOfHeader_;
298 };
299
300
301 /*
302  * Solaris <sys/varargs.h> is a DDK (aka kernel-land) header providing
303  * the same interface as <stdarg.h>.  No idea why they couldn't have just
304  * used the standard header.
305  */
306 fix = {
307     hackname = AAB_solaris_sys_varargs_h;
308     files    = "sys/varargs.h";
309     mach     = '*-*-solaris*';
310     replace  = <<-  _EndOfHeader_
311         #ifdef __STDC__
312           #include <stdarg.h>
313         #else
314           #include <varargs.h>
315         #endif
316         _EndOfHeader_;
317 };
318
319
320 /*
321  *  Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
322  *  declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
323  *  many other systems have similar text but correct versions of the file.
324  *  To ensure only Sun's is fixed, we grep for a likely unique string.
325  *  Fix also on sysV68 R3V7.1 (head/memory.h\t50.1\t )
326  */
327 fix = {
328     hackname = AAB_sun_memcpy;
329     files    = memory.h;
330     select   = "/\\*\t@\\(#\\)"
331              "(head/memory.h\t50.1\t "
332              "|memory\\.h 1\\.[2-4] 8./../.. SMI; from S5R2 1\\.2\t)\\*/";
333
334     replace = <<-  _EndOfHeader_
335         /* This file was generated by fixincludes */
336         #ifndef __memory_h__
337           #define __memory_h__
338
339           #ifdef __STDC__
340             extern void *memccpy();
341             extern void *memchr();
342             extern void *memcpy();
343             extern void *memset();
344           #else
345             extern char *memccpy();
346             extern char *memchr();
347             extern char *memcpy();
348             extern char *memset();
349           #endif /* __STDC__ */
350
351           extern int memcmp();
352
353         #endif /* __memory_h__ */
354         _EndOfHeader_;
355 };
356
357
358 /*
359  * complex.h on AIX 5 and AIX 6 define _Complex_I and I in terms of __I,
360  * which only is provided by AIX xlc C99.
361  */
362 fix = {
363     hackname  = aix_complex;
364     mach      = "*-*-aix*";
365     files     = complex.h;
366     select    = "#define[ \t]_Complex_I[ \t]__I";
367     c_fix     = format;
368     c_fix_arg = "#define _Complex_I (__extension__ 1.0iF)";
369     test_text = "#define _Complex_I     __I\n";
370 };
371
372 /*
373  *  malloc.h on AIX6 uses XLC++ specific builtin syntax
374  */
375 fix = {
376     hackname  = aix_malloc;
377     mach      = "*-*-aix*";
378     files     = "malloc.h";
379     select    = "#ifdef __cplusplus";
380     c_fix     = format;
381     c_fix_arg = "#if (defined(__cplusplus) && defined(__IBMCPP__))";
382     test_text = "#ifdef __cplusplus";
383 };
384
385 /*
386  * net/if_arp.h defines a variable fc_softc instead of adding a
387  * typedef for the struct on AIX 5.2, 5.3, 6.1 and 7.1
388  */
389 fix = {
390     hackname  = aix_net_if_arp;
391     mach      = "*-*-aix*";
392     files     = "net/if_arp.h";
393     select    = "^struct  fc_softc \\{";
394     c_fix     = format;
395     c_fix_arg = "typedef struct _fc_softc {";
396     test_text = "struct  fc_softc {\n  int a;\n};";
397 };
398
399 /*
400  *  pthread.h on AIX defines PTHREAD_ONCE_INIT without enough braces.
401  */
402 fix = {
403     hackname  = aix_once_init_1;
404     mach      = "*-*-aix*";
405     files     = "pthread.h";
406     select    = "#define[ \t]PTHREAD_ONCE_INIT \\\\\n"
407                 "\\{ \\\\\n";
408     c_fix     = format;
409     c_fix_arg = "#define PTHREAD_ONCE_INIT \\\n"
410                 "{{ \\\n";
411     test_text = "#define PTHREAD_ONCE_INIT \\\\\n"
412                 "{ \\\\\n";
413 };
414
415 fix = {
416     hackname  = aix_once_init_2;
417     mach      = "*-*-aix*";
418     files     = "pthread.h";
419     select    = "[ \t]0 \\\\\n"
420                 "\\}\n";
421     c_fix     = format;
422     c_fix_arg = "       0 \\\n"
423                 "}}\n";
424     test_text = "       0 \\\\\n"
425                 "}\n";
426 };
427
428 /*
429  *  pthread.h on AIX 4.3.3 tries to define a macro without whitspace
430  *  which violates a requirement of ISO C.
431  */
432 fix = {
433     hackname  = aix_pthread;
434     files     = "pthread.h";
435     select    = "(#define [A-Za-z_0-9]+)(\\\\\n[^A-Za-z_0-9 \t\n(])";
436     c_fix     = format;
437     c_fix_arg = "%1 %2";
438     test_text = "#define PTHREAD_MUTEX_INITIALIZER\\\\\n"
439                 "{...init stuff...}";
440 };
441
442
443 /*
444  *  AIX stdint.h fixes.
445  */
446 fix = {
447     hackname  = aix_stdint_1;
448     mach      = "*-*-aix*";
449     files     = stdint-aix.h, stdint.h;
450     select    = "#define[ \t]UINT8_MAX[ \t]\\(255U\\)\n"
451                 "#define[ \t]UINT16_MAX[ \t]\\(65535U\\)";
452     c_fix     = format;
453     c_fix_arg = "#define UINT8_MAX      (255)\n"
454                 "#define UINT16_MAX     (65535)";
455     test_text = "#define UINT8_MAX      (255U)\n"
456                 "#define UINT16_MAX     (65535U)";
457 };
458
459
460 fix = {
461     hackname  = aix_stdint_2;
462     mach      = "*-*-aix*";
463     files     = stdint-aix.h, stdint.h;
464     select    = "#define[ \t]INTPTR_MIN[ \t]INT64_MIN\n"
465                 "#define[ \t]INTPTR_MAX[ \t]INT64_MAX\n"
466                 "#define[ \t]UINTPTR_MAX[ \t]UINT64_MAX\n"
467                 "#else\n"
468                 "#define[ \t]INTPTR_MIN[ \t]INT32_MIN\n"
469                 "#define[ \t]INTPTR_MAX[ \t]INT32_MAX\n"
470                 "#define[ \t]UINTPTR_MAX[ \t]UINT32_MAX";
471     c_fix     = format;
472     c_fix_arg = "#define INTPTR_MIN     (-INTPTR_MAX-1)\n"
473                 "#define INTPTR_MAX     9223372036854775807L\n"
474                 "#define UINTPTR_MAX    18446744073709551615UL\n"
475                 "#else\n"
476                 "#define INTPTR_MIN     (-INTPTR_MAX-1)\n"
477                 "#define INTPTR_MAX     2147483647L\n"
478                 "#define UINTPTR_MAX    4294967295UL";
479     test_text = "#define INTPTR_MIN     INT64_MIN\n"
480                 "#define INTPTR_MAX     INT64_MAX\n"
481                 "#define UINTPTR_MAX    UINT64_MAX\n"
482                 "#else\n"
483                 "#define INTPTR_MIN     INT32_MIN\n"
484                 "#define INTPTR_MAX     INT32_MAX\n"
485                 "#define UINTPTR_MAX    UINT32_MAX";
486 };
487
488
489 fix = {
490     hackname  = aix_stdint_3;
491     mach      = "*-*-aix*";
492     files     = stdint-aix.h, stdint.h;
493     select    = "#define[ \t]PTRDIFF_MIN[ \t]INT64_MIN\n"
494                 "#define[ \t]PTRDIFF_MAX[ \t]INT64_MAX\n"
495                 "#else\n"
496                 "#define[ \t]PTRDIFF_MIN[ \t]*INT32_MIN\n"
497                 "#define[ \t]PTRDIFF_MAX[ \t]*INT32_MAX";
498     c_fix     = format;
499     c_fix_arg = "#define PTRDIFF_MIN    (-9223372036854775807L - 1)\n"
500                 "#define PTRDIFF_MAX    9223372036854775807L\n"
501                 "#else\n"
502                 "#define PTRDIFF_MIN    (-2147483647L - 1)\n"
503                 "#define PTRDIFF_MAX    2147483647L";
504     test_text = "#define PTRDIFF_MIN    INT64_MIN\n"
505                 "#define PTRDIFF_MAX    INT64_MAX\n"
506                 "#else\n"
507                 "#define PTRDIFF_MIN     INT32_MIN\n"
508                 "#define PTRDIFF_MAX    INT32_MAX";
509 };
510
511
512 fix = {
513     hackname  = aix_stdint_4;
514     mach      = "*-*-aix*";
515     files     = stdint-aix.h, stdint.h;
516     select    = "#define[ \t]SIZE_MAX[ \t]UINT64_MAX\n"
517                 "#else\n"
518                 "#define[ \t]SIZE_MAX[ \t]*UINT32_MAX";
519     c_fix     = format;
520     c_fix_arg = "#define SIZE_MAX       18446744073709551615UL\n"
521                 "#else\n"
522                 "#define SIZE_MAX       4294967295UL";
523     test_text = "#define SIZE_MAX       UINT64_MAX\n"
524                 "#else\n"
525                 "#define SIZE_MAX        UINT32_MAX";
526 };
527
528
529 fix = {
530     hackname  = aix_stdint_5;
531     mach      = "*-*-aix*";
532     files     = stdint-aix.h, stdint.h;
533     select    = "#define[ \t]UINT8_C\\(c\\)[ \t]__CONCAT__\\(c,U\\)\n"
534                 "#define[ \t]UINT16_C\\(c\\)[ \t]__CONCAT__\\(c,U\\)";
535     c_fix     = format;
536     c_fix_arg = "#define UINT8_C(c)     c\n"
537                 "#define UINT16_C(c)    c";
538     test_text = "#define UINT8_C(c)     __CONCAT__(c,U)\n"
539                 "#define UINT16_C(c)    __CONCAT__(c,U)";
540 };
541
542
543 /*
544  *  sys/machine.h on AIX 4.3.3 puts whitespace between a \ and a newline
545  *  in an otherwise harmless (and #ifed out) macro definition
546  */
547 fix = {
548     hackname  = aix_sysmachine;
549     files     = sys/machine.h;
550     select    = "\\\\ +\n";
551     c_fix     = format;
552     c_fix_arg = "\\\n";
553     test_text = "#define FOO \\\n"
554     " bar \\ \n baz \\ \n bat";
555 };
556
557
558 /*
559  *  sys/wait.h on AIX 5.2 defines macros that have both signed and
560  *  unsigned types in conditional expressions.
561  */
562 fix = {
563     hackname  = aix_syswait_2;
564     files     = sys/wait.h;
565     select    = '\? (\(\(\(\(unsigned[^)]*\)[^)]*\) >> [^)]*\) \& 0xff\) : -1)';
566     c_fix     = format;
567     c_fix_arg = "? (int)%1";
568     test_text = "#define WSTOPSIG(__x)    (int)(WIFSTOPPED(__x) ? ((((unsigned int)__x) >> 8) & 0xff) : -1)";
569 };
570
571
572 /*
573  *  sys/signal.h on some versions of AIX uses volatile in the typedef of
574  *  sig_atomic_t, which causes gcc to generate a warning about duplicate
575  *  volatile when a sig_atomic_t variable is declared volatile, as
576  *  required by ANSI C.
577  */
578 fix = {
579     hackname  = aix_volatile;
580     files     = sys/signal.h;
581     select    = "typedef volatile int sig_atomic_t";
582     c_fix     = format;
583     c_fix_arg = "typedef int sig_atomic_t";
584     test_text = "typedef volatile int sig_atomic_t;";
585 };
586
587
588 /*
589  *  Fix __assert declaration in assert.h on Alpha OSF/1.
590  */
591 fix = {
592     hackname  = alpha___assert;
593     files     = "assert.h";
594     select    = '__assert\(char \*, char \*, int\)';
595     c_fix     = format;
596     c_fix_arg = "__assert(const char *, const char *, int)";
597     test_text = 'extern void __assert(char *, char *, int);';
598 };
599
600
601 /*
602  *  Obey __PRAGMA_EXTERN_PREFIX for Tru64 UNIX V4/5 headers.
603  */
604 fix = {
605     hackname  = alpha___extern_prefix;
606     select    = "(.*)(defined\\(__DECC\\)|def[ \t]*__DECC)[ \t]*\n"
607                 "(#[ \t]*pragma[ \t]*extern_prefix.*)";
608
609     mach      = "alpha*-dec-osf*";
610     c_fix     = format;
611     c_fix_arg = "%1 (defined(__DECC) || defined(__PRAGMA_EXTERN_PREFIX))\n%3";
612
613     test_text = "#ifdef  __DECC\n"
614                 "#pragma extern_prefix \"_P\"\n"
615                 "#   if defined(__DECC)\n"
616                 "#     pragma extern_prefix \"_E\"\n"
617                 "# if !defined(_LIBC_POLLUTION_H_) && defined(__DECC)\n"
618                 "#  pragma extern_prefix \"\"";
619 };
620
621
622 /*
623  *  Obey __PRAGMA_EXTERN_PREFIX for Tru64 UNIX V4/5 <standards.h>.
624  */
625 fix = {
626     hackname  = alpha___extern_prefix_standards;
627     files     = standards.h;
628     select    = ".*!defined\\(_LIBC_POLLUTION_H_\\) && !defined\\(__DECC\\)";
629
630     mach      = "alpha*-dec-osf*";
631     c_fix     = format;
632     c_fix_arg = "%0 && !defined(__PRAGMA_EXTERN_PREFIX)";
633
634     test_text = "#if (_ISO_C_SOURCE>=19990L) "
635                 "&& !defined(_LIBC_POLLUTION_H_) && !defined(__DECC)";
636 };
637
638
639 /*
640  *  Obey __PRAGMA_EXTERN_PREFIX for Tru64 UNIX V5 <sys/mount.h> and
641  *  <sys/stat.h>.  The tests for __DECC are special in various ways, so
642  *  alpha__extern_prefix cannot be used.
643  */
644 fix = {
645     hackname  = alpha___extern_prefix_sys_stat;
646     files     = sys/stat.h;
647     files     = sys/mount.h;
648     select    = "#[ \t]*if[ \t]*defined\\(__DECC\\)";
649
650     mach      = "alpha*-dec-osf5*";
651     c_fix     = format;
652     c_fix_arg = "%0 || defined(__PRAGMA_EXTERN_PREFIX)";
653
654     test_text = "#   if defined(__DECC)";
655 };
656
657
658 /*
659  *  Fix assert macro in assert.h on Alpha OSF/1.
660  *  The superfluous int cast breaks C++.
661  */
662 fix = {
663     hackname  = alpha_assert;
664     files     = "assert.h";
665     select    = "(#[ \t]*" 'define assert\(EX\).*)\(\(int\) \(EX\)\)';
666     c_fix     = format;
667     c_fix_arg = "%1(EX)";
668     test_text = '#define assert(EX) (((int) (EX)) ? (void)0 '
669                 ': __assert(#EX, __FILE__, __LINE__))';
670 };
671
672
673 /*
674  *  Fix #defines under Alpha OSF/1:
675  *  The following files contain '#pragma extern_prefix "_FOO"' followed by
676  *  a '#define something(x,y,z) _FOOsomething(x,y,z)'.  The intent of these
677  *  statements is to reduce namespace pollution.  While these macros work
678  *  properly in most cases, they don't allow you to take a pointer to the
679  *  "something" being modified.  To get around this limitation, change these
680  *  statements to be of the form '#define something _FOOsomething'.
681  *
682  *  sed ain't egrep, lesson 2463:  sed can use self-referential
683  *  regular expressions.  In the substitute expression below,
684  *  "\\1" and "\\2" refer to subexpressions found earlier in the
685  *  same match.  So, we continue to use sed.  "extern_prefix" will
686  *  be a rare match anyway...
687  */
688 fix = {
689     hackname = alpha_bad_lval;
690
691     select   = "^[ \t]*#[ \t]*pragma[ \t]+extern_prefix";
692     mach      = "alpha*-dec-osf*";
693
694     sed      =
695         "s/^[ \t]*#[ \t]*define[ \t][ \t]*\\([^(]*\\)\\(([^)]*)\\)[ \t]*"
696                "\\(_.*\\)\\1\\2[ \t]*$/#define \\1 \\3\\1/";
697
698     test_text = '#pragma extern_prefix "_FOO"'"\n"
699                 "#define something(x,y,z) _FOOsomething(x,y,z)\n"
700                 "#define mumble _FOOmumble";
701 };
702
703
704 /*
705  *  Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
706  */
707 fix = {
708     hackname  = alpha_getopt;
709     files     = "stdio.h";
710     files     = "stdlib.h";
711     select    = 'getopt\(int, char \*\[\], *char \*\)';
712     c_fix     = format;
713     c_fix_arg = "getopt(int, char *const[], const char *)";
714     test_text = 'extern int getopt(int, char *[], char *);';
715 };
716
717
718 /*
719  *  Fix missing semicolon on Alpha OSF/4 in <net/if.h>
720  */
721 fix = {
722     hackname  = alpha_if_semicolon;
723     files     = net/if.h;
724     select    = "struct[ \t]+sockaddr[ \t]+vmif_paddr[ \t]+/\\*";
725     c_fix     = format;
726     c_fix_arg = "struct sockaddr vmif_paddr;\t/*";
727     test_text = '     struct  sockaddr vmif_paddr     /* protocol address */';
728 };
729
730
731 /*
732  * Remove erroneous parentheses in sym.h on Alpha OSF/1.
733  */
734 fix = {
735     hackname  = alpha_parens;
736     files     = sym.h;
737     select    = '#ifndef\(__mips64\)';
738     c_fix     = format;
739     c_fix_arg = "#ifndef __mips64";
740     test_text = "#ifndef(__mips64) /* bogus */\nextern int foo;\n#endif";
741 };
742
743
744 /*
745  *  Obey __PRAGMA_EXTERN_PREFIX for Tru64 UNIX <pthread.h>.
746  */
747 fix = {
748     hackname  = alpha_pthread;
749     files     = pthread.h;
750     select    = "((#[ \t]*if)([ \t]*defined[ \t]*\\(_PTHREAD_ENV_DECC\\)"
751                 "|def _PTHREAD_ENV_DECC)(.*))\n"
752                 "(#[ \t]*define _PTHREAD_USE_PTDNAM_)";
753
754     mach      = "alpha*-dec-osf*";
755     c_fix     = format;
756     c_fix_arg = "%2 defined (_PTHREAD_ENV_DECC)%4 "
757                 "|| defined (__PRAGMA_EXTERN_PREFIX)\n%5";
758
759     test_text = "#  if defined (_PTHREAD_ENV_DECC) "
760                       "|| defined (_PTHREAD_ENV_EPCC)\n"
761                 "#   define _PTHREAD_USE_PTDNAM_\n"
762                 "#  endif\n"
763                 "#  ifdef _PTHREAD_ENV_DECC\n"
764                 "#   define _PTHREAD_USE_PTDNAM_\n"
765                 "#  endif";
766 };
767
768
769 /*
770  *  Recognize GCC in Tru64 UNIX V5.1B <pthread.h>.
771  */
772 fix = {
773     hackname  = alpha_pthread_gcc;
774     files     = pthread.h;
775     select    = "#else\n# error <pthread.h>: unrecognized compiler.";
776
777     mach      = "alpha*-dec-osf*";
778     c_fix     = format;
779     c_fix_arg = "#elif defined (__GNUC__)\n"
780                 "# define _PTHREAD_ENV_GCC\n"
781                 "%0";
782
783     test_text = "# define _PTHREAD_ENV_INTELC\n"
784                 "#else\n"
785                 "# error <pthread.h>: unrecognized compiler.\n"
786                 "#endif";
787 };
788
789
790 /*
791  * Compaq Tru64 v5.1 defines all of its PTHREAD_*_INITIALIZER macros
792  * incorrectly, specifying less fields in the initializers than are
793  * defined in the corresponding structure types.  Use of these macros
794  * in user code results in spurious warnings.
795  */
796 fix = {
797     hackname  = alpha_pthread_init;
798     files     = pthread.h;
799     select    = ' \* @\(#\).RCSfile: pthread\.h,v \$'
800                 ' .Revision: 1\.1\.33\.21 \$ \(DEC\)'
801                 ' .Date: 2000/08/15 15:30:13 \$';
802     mach      = "alpha*-dec-osf*";
803     sed       = "s@MVALID\\(.*\\)A}@MVALID\\1A, 0, 0, 0, 0, 0, 0 }@\n"
804                 "s@MVALID\\(.*\\)_}@MVALID\\1_, 0, 0, 0, 0 }@\n"
805                 "s@CVALID\\(.*\\)A}@CVALID\\1A, 0, 0, 0, 0 }@\n"
806                 "s@CVALID\\(.*\\)_}@CVALID\\1_, 0, 0 }@\n"
807                 "s@WVALID\\(.*\\)A}@WVALID\\1A, 0, 0, 0, 0, 0, 0, 0, 0, 0 }@\n"
808                 "s@WVALID\\(.*\\)_}@WVALID\\1_, 0, 0, 0, 0, 0, 0, 0 }@\n";
809     test_text = <<- _EOText_
810         /*
811          * @(#)_RCSfile: pthread.h,v $ _Revision: 1.1.33.21 $ (DEC) _Date: 2000/08/15 15:30:13 $
812          */
813         #ifndef _PTHREAD_NOMETER_STATIC
814         # define PTHREAD_MUTEX_INITIALIZER \
815             {_PTHREAD_MSTATE_CONFIG, _PTHREAD_MVALID | _PTHREAD_MVF_STA}
816         # define PTHREAD_COND_INITIALIZER \
817             {_PTHREAD_CSTATE_SLOW, _PTHREAD_CVALID | _PTHREAD_CVF_STA}
818         # define PTHREAD_MUTEX_INITWITHNAME_NP(_n_,_a_) \
819             {_PTHREAD_MSTATE_CONFIG, _PTHREAD_MVALID | _PTHREAD_MVF_STA, _n_, _a_}
820         # define PTHREAD_COND_INITWITHNAME_NP(_n_,_a_) \
821             {_PTHREAD_CSTATE_SLOW, _PTHREAD_CVALID | _PTHREAD_CVF_STA, _n_, _a_}
822         #else
823         # define PTHREAD_MUTEX_INITIALIZER {0, _PTHREAD_MVALID | _PTHREAD_MVF_STA}
824         # define PTHREAD_MUTEX_INITWITHNAME_NP(_n_,_a_) \
825             {0, _PTHREAD_MVALID | _PTHREAD_MVF_STA, _n_, _a_}
826         # define PTHREAD_COND_INITWITHNAME_NP(_n_,_a_) \
827             {0, _PTHREAD_CVALID | _PTHREAD_CVF_STA, _n_, _a_}
828         #endif
829
830         #define PTHREAD_RWLOCK_INITIALIZER {_PTHREAD_RWVALID | _PTHREAD_RWVF_STA}
831         #define PTHREAD_RWLOCK_INITWITHNAME_NP(_n_,_a_) \
832                 {_PTHREAD_RWVALID | _PTHREAD_RWVF_STA, _n_, _a_}
833         _EOText_;
834 };
835
836
837 /*
838  *  Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
839  *  And OpenBSD.
840  */
841 fix = {
842     hackname = alpha_sbrk;
843     files    = unistd.h;
844     select   = "char[ \t]*\\*[\t ]*sbrk[ \t]*\\(";
845     c_fix     = format;
846     c_fix_arg = "void *sbrk(";
847     test_text = "extern char* sbrk(ptrdiff_t increment);";
848 };
849
850
851 /*
852  *  For C++, avoid any typedef or macro definition of bool,
853  *  and use the built in type instead.
854  *  HP/UX 10.20 also has it in curses_colr/curses.h.
855  */
856 fix = {
857     hackname  = avoid_bool_define;
858     files     = curses.h;
859     files     = curses_colr/curses.h;
860     files     = term.h;
861     files     = tinfo.h;
862
863     select    = "#[ \t]*define[ \t]+bool[ \t]";
864     bypass    = "__cplusplus";
865
866     c_fix     = format;
867     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
868     c_fix_arg = "^[ \t]*#[ \t]*define[ \t]+bool[ \t].*";
869
870     test_text = "# define bool\t char \n";
871 };
872
873
874 fix = {
875     hackname = avoid_bool_type;
876     files    = curses.h;
877     files    = curses_colr/curses.h;
878     files    = term.h;
879     files    = tinfo.h;
880
881     select    = "^[ \t]*typedef[ \t].*[ \t]bool[ \t]*;";
882     bypass    = "__cplusplus";
883
884     c_fix     = format;
885     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
886
887     test_text = "typedef unsigned int\tbool \t; /* bool\n type */";
888 };
889
890
891 /*
892  *  For C++, avoid any typedef definition of wchar_t,
893  *  and use the built in type instead.
894  *  Don't do this for headers that are smart enough to do the right
895  *  thing (recent [n]curses.h and Xlib.h).
896  *  Don't do it for <linux/nls.h> which is never used from C++ anyway,
897  *  and will be broken by the edit.
898  */
899
900 fix = {
901     hackname = avoid_wchar_t_type;
902
903     select    = "^[ \t]*typedef[ \t].*[ \t]wchar_t[ \t]*;";
904     bypass    = "__cplusplus";
905     bypass    = "_LINUX_NLS_H";
906     bypass    = "XFree86: xc/lib/X11/Xlib\\.h";
907
908     c_fix     = format;
909     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
910
911     test_text = "typedef unsigned short\twchar_t \t; /* wchar_t\n type */";
912 };
913
914
915 /*
916  *  Fix `typedef struct term;' on hppa1.1-hp-hpux9.
917  */
918 fix = {
919     hackname  = bad_struct_term;
920     files     = curses.h;
921     select    = "^[ \t]*typedef[ \t]+struct[ \t]+term[ \t]*;";
922     c_fix     = format;
923     c_fix_arg = "struct term;";
924
925     test_text = 'typedef struct term;';
926 };
927
928
929 /*
930  *  Fix one other error in this file:
931  *  a mismatched quote not inside a C comment.
932  */
933 fix = {
934     hackname  = badquote;
935     files     = sundev/vuid_event.h;
936     select    = "doesn't";
937     c_fix     = format;
938     c_fix_arg = "does not";
939
940     test_text = "/* doesn't have matched single quotes */";
941 };
942
943
944 /*
945  *  check for broken assert.h that needs stdio.h
946  */
947 fix = {
948     hackname  = broken_assert_stdio;
949     files     = assert.h;
950     select    = stderr;
951     bypass    = "include.*stdio\\.h";
952     c_fix     = wrap;
953     c_fix_arg = "#include <stdio.h>\n";
954     test_text = "extern FILE* stderr;";
955 };
956
957
958 /*
959  *  check for broken assert.h that needs stdlib.h
960  */
961 fix = {
962     hackname  = broken_assert_stdlib;
963     files     = assert.h;
964     select    = 'exit *\(|abort *\(';
965     bypass    = "include.*stdlib\\.h";
966     c_fix     = wrap;
967     c_fix_arg = "#ifdef __cplusplus\n"
968                 "#include <stdlib.h>\n"
969                 "#endif\n";
970     test_text = "extern void exit ( int );";
971 };
972
973
974 /*
975  *  Remove `extern double cabs' declarations from math.h.
976  *  This conflicts with C99.  Discovered on AIX.
977  *  IRIX 5 and IRIX 6 before 6.5.18 (where C99 support was introduced)
978  *  declares cabs() to take a struct __cabs_s argument.
979  *  SunOS4 has its cabs() declaration followed by a comment which
980  *  terminates on the following line.
981  *  Darwin hides its broken cabs in architecture-specific subdirs.
982  */
983 fix = {
984     hackname = broken_cabs;
985     files    = math.h, "architecture/*/math.h";
986     select   = "^extern[ \t]+double[ \t]+cabs";
987
988     sed       = "s/^extern[ \t]*double[ \t]*cabs[ \t]*\([^\\\)]*\);//";
989     sed       = "s/^extern[ \t]*long[ \t]*double[ \t]*cabsl[ \t]*\([^\\\)]*\);//";
990
991     test_text = "#ifdef __STDC__\n"
992                 "extern     double   cabs(struct dbl_hypot);\n"
993                 "#else\n"
994                 "extern     double   cabs();\n"
995                 "#endif\n"
996                 "extern double cabs ( _Complex z );\n"
997                 "extern double cabs(); /* This is a comment\n"
998                 "                         and it ends here. */\n"
999                 "extern double  cabs(struct __cabs_s);\n"
1000                 "extern long double cabsl( struct __cabsl_s );";
1001 };
1002
1003
1004 /*
1005  * Fixup Darwin's broken check for __builtin_nanf.
1006  */    
1007 fix = {
1008     hackname  = broken_nan;
1009     /*
1010      *  It is tempting to omit the first "files" entry.  Do not.
1011      *  The testing machinery will take the first "files" entry as the name
1012      *  of a test file to play with.  It would be a nuisance to have a directory
1013      *  with the name "*".
1014      */
1015     files     = "architecture/ppc/math.h";
1016     files     = "architecture/*/math.h";
1017     select    = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)";
1018     bypass    = "powl";
1019     c_fix     = format; 
1020     c_fix_arg = "#if 1";
1021     test_text = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)";
1022 };
1023
1024
1025 /*
1026  *  Various systems derived from BSD4.4 contain a macro definition
1027  *  for vfscanf that interacts badly with requirements of builtin-attrs.def.
1028  *  Known to be fixed in FreeBSD 5 system headers.
1029  */
1030 fix = {
1031     hackname  = bsd_stdio_attrs_conflict;
1032     mach      = "*-*-*bsd*";
1033     mach      = "*-*-*darwin*";
1034     files     = stdio.h;
1035     select    = "^#define[ \t]*vfscanf[ \t]*__svfscanf[ \t]*$";
1036     c_fix     = format;
1037     c_fix_arg = '#define _BSD_STRING(_BSD_X) _BSD_STRINGX(_BSD_X)' "\n"
1038                 '#define _BSD_STRINGX(_BSD_X) #_BSD_X' "\n"
1039                 'int vfscanf(FILE *, const char *, __builtin_va_list) '
1040                 '__asm__ (_BSD_STRING(__USER_LABEL_PREFIX__) "__svfscanf");';
1041     test_text = '#define  vfscanf       __svfscanf';
1042 };
1043
1044 /*
1045  * 'g++ -std=c++11' defines __cplusplus to 201103L, which suggests
1046  * that it conforms to ISO/IEC 14882:2011.  It currently does
1047  * not support the [[noreturn]] procedure attribute.
1048  * When it does, this hack should be removed.
1049  * SEE:  gcc.gnu.org/bugzilla/show_bug.cgi?id=51776
1050  */
1051 fix = {
1052     hackname  = cdef_cplusplus;
1053     files     = sys/cdefs.h;
1054     select    = '\[\[noreturn\]\]';
1055     c_fix     = format;
1056     c_fix_arg = '__attribute__((__noreturn__))';
1057     test_text = "#define _Noreturn      [[noreturn]]";
1058 };
1059
1060 /*
1061  *  Fix various macros used to define ioctl numbers.
1062  *  The traditional syntax was:
1063  *
1064  *    #define _CTRL(n, x) (('n'<<8)+x)
1065  *    #define TCTRLCFOO _CTRL(T, 1)
1066  *
1067  *  but this does not work with the C standard, which disallows macro
1068  *  expansion inside strings.  We have to rewrite it thus:
1069  *
1070  *    #define _CTRL(n, x) ((n<<8)+x)
1071  *    #define TCTRLCFOO  _CTRL('T', 1)
1072  *
1073  *  The select expressions match too much, but the c_fix code is cautious.
1074  *
1075  *  CTRL might be: CTRL _CTRL ISCTRL BSD43_CTRL ...
1076  */
1077 fix = {
1078     hackname  = ctrl_quotes_def;
1079     select    = "define[ \t]+[A-Z0-9_]+CTRL\\([a-zA-Z][,)]";
1080     c_fix     = char_macro_def;
1081     c_fix_arg = "CTRL";
1082
1083     /*
1084      *  This is two tests in order to ensure that the "CTRL(c)" can
1085      *  be selected in isolation from the multi-arg format
1086      */
1087     test_text = "#define BSD43_CTRL(n, x) (('n'<<8)+x)\n";
1088     test_text = "#define _CTRL(c) ('c'&037)";
1089 };
1090
1091 fix = {
1092     hackname  = ctrl_quotes_use;
1093     select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
1094     c_fix     = char_macro_use;
1095     c_fix_arg = "CTRL";
1096     test_text = "#define TCTRLFOO BSD43_CTRL(T, 1)";
1097 };
1098
1099
1100 /*
1101  *  sys/mman.h on HP/UX is not C++ ready,
1102  *  even though NO_IMPLICIT_EXTERN_C is defined on HP/UX.
1103  *
1104  *  rpc/types.h on OSF1/2.0 is not C++ ready,
1105  *  even though NO_IMPLICIT_EXTERN_C is defined for the alpha.
1106  *
1107  *  The problem is the declaration of malloc.
1108  */
1109 fix = {
1110     hackname = cxx_unready;
1111     files    = sys/mman.h;
1112     files    = rpc/types.h;
1113     select   = '[^#]+malloc.*;';  /* Catch any form of declaration
1114                                      not within a macro.  */
1115     bypass   = '"C"|__BEGIN_DECLS';
1116
1117     c_fix     = wrap;
1118     c_fix_arg = "#ifdef __cplusplus\n"
1119                 "extern \"C\" {\n"
1120                 "#endif\n";
1121     c_fix_arg = "#ifdef __cplusplus\n"
1122                 "}\n"
1123                 "#endif\n";
1124     test_text = "extern void* malloc( size_t );";
1125 };
1126
1127
1128 /*
1129  *  On darwin8 and earlier, mach-o/swap.h isn't properly guarded
1130  *  by 'extern "C"'.  On darwin7 some mach/ headers aren't properly guarded.
1131  */
1132 fix = {
1133   hackname  = darwin_externc;
1134   mach      = "*-*-darwin*";
1135   files     = mach-o/swap.h;
1136   files     = mach/mach_time.h;
1137   files     = mach/mach_traps.h;
1138   files     = mach/message.h;
1139   files     = mach/mig.h;
1140   files     = mach/semaphore.h;
1141   bypass    = "extern \"C\"";
1142   bypass    = "__BEGIN_DECLS";
1143   c_fix     = wrap;
1144   c_fix_arg = "#ifdef __cplusplus\n"
1145               "extern \"C\" {\n"
1146               "#endif\n";
1147   c_fix_arg = "#ifdef __cplusplus\n"
1148               "}\n"
1149               "#endif\n";
1150   test_text = "extern void swap_fat_header();\n";
1151 };
1152
1153
1154 /*
1155  * AvailabilityMacros.h on Darwin breaks with GCC 4.0, because of
1156  * bad __GNUC__ tests.
1157  */
1158
1159 fix = {
1160   hackname  = darwin_gcc4_breakage;
1161   mach      = "*-*-darwin*";
1162   files     = AvailabilityMacros.h;
1163   select    = "\\(__GNUC__ >= 3\\) && \\(__GNUC_MINOR__ >= 1\\)";
1164   c_fix     = format;
1165   c_fix_arg = "((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))";
1166   test_text = "#if defined(__GNUC__) && (__GNUC__ >= 3) && "
1167               "(__GNUC_MINOR__ >= 1)\n";
1168 };
1169
1170
1171 /*
1172  *  __private_extern__ doesn't exist in FSF GCC.  Even if it did,
1173  *  why would you ever put it in a system header file?
1174  */
1175 fix = {
1176   hackname  = darwin_private_extern;
1177   mach      = "*-*-darwin*";
1178   files     = mach-o/dyld.h;
1179   select    = "__private_extern__ [a-z_]+ _dyld_";
1180   c_fix     = format;
1181   c_fix_arg = "extern";
1182   c_fix_arg = "__private_extern__";
1183   test_text = "__private_extern__ int _dyld_func_lookup(\n"
1184               "const char *dyld_func_name,\n"
1185               "unsigned long *address);\n";
1186 };
1187
1188
1189 /*
1190  * Darwin headers have a stdint.h that defines UINT8_C and UINT16_C to
1191  * unsigned constants.
1192  */
1193 fix = {
1194     hackname  = darwin_stdint_1;
1195     mach      = "*-*-darwin*";
1196     files     = stdint-darwin.h, stdint.h;
1197     c_fix     = format;
1198     c_fix_arg = "#define UINT8_C(v)\tv\n#define UINT16_C(v)\tv";
1199     select    = "#define UINT8_C\\(v\\)[ \t]+\\(v ## U\\)\n"
1200                 "#define UINT16_C\\(v\\)[ \t]+\\(v ## U\\)";
1201     test_text = "#define UINT8_C(v)   (v ## U)\n"
1202                 "#define UINT16_C(v)  (v ## U)";
1203 };
1204
1205
1206 /*
1207  * Darwin headers have a stdint.h that defines INTPTR_MIN and INTPTR_MAX
1208  * with wrong types.
1209  */
1210 fix = {
1211     hackname  = darwin_stdint_2;
1212     mach      = "*-*-darwin*";
1213     files     = stdint-darwin.h, stdint.h;
1214     c_fix     = format;
1215     c_fix_arg = "#if __WORDSIZE == 64\n"
1216                 "#define INTPTR_MAX 9223372036854775807L\n"
1217                 "#define INTPTR_MIN (-INTPTR_MAX-1)\n"
1218                 "#else\n"
1219                 "#define INTPTR_MAX 2147483647L\n"
1220                 "#define INTPTR_MIN (-INTPTR_MAX-1)\n"
1221                 "#endif";
1222     select    = "#if __WORDSIZE == 64\n"
1223                 "#define INTPTR_MIN[ \t]+INT64_MIN\n"
1224                 "#define INTPTR_MAX[ \t]+INT64_MAX\n"
1225                 "#else\n"
1226                 "#define INTPTR_MIN[ \t]+INT32_MIN\n"
1227                 "#define INTPTR_MAX[ \t]+INT32_MAX\n"
1228                 "#endif";
1229     test_text = "#if __WORDSIZE == 64\n"
1230                 "#define INTPTR_MIN        INT64_MIN\n"
1231                 "#define INTPTR_MAX        INT64_MAX\n"
1232                 "#else\n"
1233                 "#define INTPTR_MIN        INT32_MIN\n"
1234                 "#define INTPTR_MAX        INT32_MAX\n"
1235                 "#endif";
1236 };
1237
1238
1239 /*
1240  * Darwin headers have a stdint.h that defines UINTPTR_MAX with a wrong type.
1241  */
1242 fix = {
1243     hackname  = darwin_stdint_3;
1244     mach      = "*-*-darwin*";
1245     files     = stdint-darwin.h, stdint.h;
1246     c_fix     = format;
1247     c_fix_arg = "#if __WORDSIZE == 64\n"
1248                 "#define UINTPTR_MAX 18446744073709551615UL\n"
1249                 "#else\n"
1250                 "#define UINTPTR_MAX 4294967295UL\n"
1251                 "#endif";
1252     select    = "#if __WORDSIZE == 64\n"
1253                 "#define UINTPTR_MAX[ \t]+UINT64_MAX\n"
1254                 "#else\n"
1255                 "#define UINTPTR_MAX[ \t]+UINT32_MAX\n"
1256                 "#endif";
1257     test_text = "#if __WORDSIZE == 64\n"
1258                 "#define UINTPTR_MAX       UINT64_MAX\n"
1259                 "#else\n"
1260                 "#define UINTPTR_MAX       UINT32_MAX\n"
1261                 "#endif";
1262 };
1263
1264
1265 /*
1266  * Darwin headers have a stdint.h that defines SIZE_MAX with a wrong type.
1267  */
1268 fix = {
1269     hackname  = darwin_stdint_4;
1270     mach      = "*-*-darwin*";
1271     files     = stdint-darwin.h, stdint.h;
1272     c_fix     = format;
1273     c_fix_arg = "#if __WORDSIZE == 64\n"
1274                 "#define SIZE_MAX 18446744073709551615UL\n"
1275                 "#else\n"
1276                 "#define SIZE_MAX 4294967295UL\n"
1277                 "#endif";
1278     select    = "#if __WORDSIZE == 64\n"
1279                 "#define SIZE_MAX[ \t]+UINT64_MAX\n"
1280                 "#else\n"
1281                 "#define SIZE_MAX[ \t]+UINT32_MAX\n"
1282                 "#endif";
1283     test_text = "#if __WORDSIZE == 64\n"
1284                 "#define SIZE_MAX          UINT64_MAX\n"
1285                 "#else\n"
1286                 "#define SIZE_MAX          UINT32_MAX\n"
1287                 "#endif";
1288 };
1289
1290
1291 /*
1292  * Darwin headers have a stdint.h that defines {U,}INTMAX_{MIN,MAX}
1293  * with a wrong type.
1294  */
1295 fix = {
1296     hackname  = darwin_stdint_5;
1297     mach      = "*-*-darwin*";
1298     files     = stdint-darwin.h, stdint.h;
1299     c_fix     = format;
1300     c_fix_arg = "#if __WORDSIZE == 64\n"
1301                 "#define INTMAX_MIN   (-9223372036854775807L - 1)\n"
1302                 "#define INTMAX_MAX   9223372036854775807L\n"
1303                 "#define UINTMAX_MAX  18446744073709551615UL\n"
1304                 "#else\n"
1305                 "#define INTMAX_MIN   (-9223372036854775807LL - 1)\n"
1306                 "#define INTMAX_MAX   9223372036854775807LL\n"
1307                 "#define UINTMAX_MAX  18446744073709551615ULL\n"
1308                 "#endif";
1309     select    = "#define INTMAX_MIN[ \t]+INT64_MIN\n"
1310                 "#define INTMAX_MAX[ \t]+INT64_MAX\n"
1311                 "\n"
1312                 "#define UINTMAX_MAX[ \t]+UINT64_MAX";
1313     test_text = "#define INTMAX_MIN        INT64_MIN\n"
1314                 "#define INTMAX_MAX        INT64_MAX\n"
1315                 "\n"
1316                 "#define UINTMAX_MAX       UINT64_MAX";
1317 };
1318
1319
1320 /*
1321  * Darwin headers have a stdint.h that defines {U,}INTMAX_C
1322  * with a wrong type.
1323  */
1324 fix = {
1325     hackname  = darwin_stdint_6;
1326     mach      = "*-*-darwin*";
1327     files     = stdint-darwin.h, stdint.h;
1328     c_fix     = format;
1329     c_fix_arg = "#if __WORDSIZE == 64\n"
1330                 "#define PTRDIFF_MIN (-9223372036854775807L - 1)\n"
1331                 "#define PTRDIFF_MAX 9223372036854775807L\n"
1332                 "#else\n"
1333                 "#define PTRDIFF_MIN (-2147483647 - 1)\n"
1334                 "#define PTRDIFF_MAX 2147483647\n"
1335                 "#endif";
1336     select    = "#if __WORDSIZE == 64\n"
1337                 "#define PTRDIFF_MIN[ \t]+INT64_MIN\n"
1338                 "#define PTRDIFF_MAX[ \t]+INT64_MAX\n"
1339                 "#else\n"
1340                 "#define PTRDIFF_MIN[ \t]+INT32_MIN\n"
1341                 "#define PTRDIFF_MAX[ \t]+INT32_MAX\n"
1342                 "#endif";
1343     test_text = "#if __WORDSIZE == 64\n"
1344                 "#define PTRDIFF_MIN       INT64_MIN\n"
1345                 "#define PTRDIFF_MAX       INT64_MAX\n"
1346                 "#else\n"
1347                 "#define PTRDIFF_MIN       INT32_MIN\n"
1348                 "#define PTRDIFF_MAX       INT32_MAX\n"
1349                 "#endif";
1350 };
1351
1352
1353 /*
1354  * Darwin headers have a stdint.h that defines {U,}INTMAX_C
1355  * with a wrong type.
1356  */
1357 fix = {
1358     hackname  = darwin_stdint_7;
1359     mach      = "*-*-darwin*";
1360     files     = stdint-darwin.h, stdint.h;
1361     c_fix     = format;
1362     c_fix_arg = "#if __WORDSIZE == 64\n"
1363                 "#define INTMAX_C(v)  (v ## L)\n"
1364                 "#define UINTMAX_C(v) (v ## UL)\n"
1365                 "#else\n"
1366                 "#define INTMAX_C(v)  (v ## LL)\n"
1367                 "#define UINTMAX_C(v) (v ## ULL)\n"
1368                 "#endif";
1369     select    = "#define INTMAX_C\\(v\\)[ \t]+\\(v ## LL\\)\n"
1370                 "#define UINTMAX_C\\(v\\)[ \t]+\\(v ## ULL\\)";
1371     test_text = "#define INTMAX_C(v)  (v ## LL)\n"
1372                 "#define UINTMAX_C(v) (v ## ULL)";
1373 };
1374
1375
1376 /*
1377  *  Fix <c_asm.h> on Digital UNIX V4.0:
1378  *  It contains a prototype for a DEC C internal asm() function,
1379  *  clashing with gcc's asm keyword.  So protect this with __DECC.
1380  */
1381 fix = {
1382     hackname = dec_intern_asm;
1383     files    = c_asm.h;
1384     sed = "/^[ \t]*float[ \t]*fasm/i\\\n#ifdef __DECC\n";
1385     sed = "/^[ \t]*#[ \t]*pragma[ \t]*intrinsic([ \t]*dasm/a\\\n"
1386           "#endif\n";
1387     test_text =
1388     "float fasm {\n"
1389     "    ... asm stuff ...\n"
1390     "};\n#pragma intrinsic( dasm )\n/* END ASM TEST*/";
1391 };
1392
1393
1394 /*
1395  * Fix typo in <wchar.h> on DJGPP 2.03.
1396  */
1397 fix = {
1398     hackname  = djgpp_wchar_h;
1399     file      = wchar.h;
1400     select    = "__DJ_wint_t";
1401     bypass    = "sys/djtypes.h";
1402     c_fix     = format;
1403     c_fix_arg = "%0\n#include <sys/djtypes.h>";
1404     c_fix_arg = "#include <stddef.h>";
1405     test_text = "#include <stddef.h>\n"
1406                 "extern __DJ_wint_t x;\n";
1407 };
1408
1409
1410 /*
1411  * Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
1412  */
1413 fix = {
1414     hackname  = ecd_cursor;
1415     files     = "sunwindow/win_lock.h";
1416     files     = "sunwindow/win_cursor.h";
1417     select    = 'ecd\.cursor';
1418     c_fix     = format;
1419     c_fix_arg = 'ecd_cursor';
1420
1421     test_text = "#ifdef ecd.cursor\n#error bogus\n#endif /* ecd+cursor */";
1422 };
1423
1424
1425 /*
1426  *  Between 8/24/1998 and 2/17/2001, FreeBSD system headers presume
1427  *  neither the existence of GCC 3 nor its exact feature set yet break
1428  *  (by design?) when __GNUC__ is set beyond 2.
1429  */
1430 fix = {
1431     hackname  = freebsd_gcc3_breakage;
1432     mach      = "*-*-freebsd*";
1433     files     = sys/cdefs.h;
1434     select    = '^#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7$';
1435     bypass    = '__GNUC__[ \t]*([>=]=[ \t]*[3-9]|>[ \t]*2)';
1436     c_fix     = format;
1437     c_fix_arg = '%0 || __GNUC__ >= 3';
1438     test_text = '#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7';
1439 };
1440
1441
1442 /*
1443  *  Some releases of FreeBSD 4 and FreeBSD 5.0 and 5.1 system headers presume
1444  *  neither the existence of GCC 4 nor its exact feature set yet break
1445  *  (by design?) when __GNUC__ is set beyond 3.
1446  */
1447 fix = {
1448     hackname  = freebsd_gcc4_breakage;
1449     mach      = "*-*-freebsd*"; 
1450     files     = sys/cdefs.h;
1451     select    = '^#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 \|\| __GNUC__ == 3$';
1452     c_fix     = format;
1453     c_fix_arg = '#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3';
1454     test_text = '#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3';
1455 };
1456
1457
1458 /*
1459  *  Some versions of glibc don't expect the C99 inline semantics.
1460  */
1461 fix = {
1462     hackname  = glibc_c99_inline_1;
1463     files     = features.h, '*/features.h';
1464     select    = "^ *&& !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__$";
1465     c_fix     = format;
1466     c_fix_arg = "%0 && (defined __extern_inline || defined __GNUC_GNU_INLINE__)";
1467     test_text = <<-EOT
1468         #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
1469             && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__
1470         # define __USE_EXTERN_INLINES   1
1471         #endif
1472         EOT;
1473 };
1474
1475
1476 /*
1477  *  Similar, but a version that didn't have __NO_INLINE__
1478  */
1479 fix = {
1480     hackname  = glibc_c99_inline_1a;
1481     files     = features.h, '*/features.h';
1482     select    = "(\\) && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__)\n"
1483                 "(#[ \t]*define[ \t]*__USE_EXTERN_INLINES[ \t]*1)";
1484     c_fix     = format;
1485     c_fix_arg = "%1 && (defined __extern_inline || defined __GNUC_GNU_INLINE__)\n%2";
1486     test_text = <<-EOT
1487         #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__
1488         # define __USE_EXTERN_INLINES   1
1489         #endif
1490         EOT;
1491 };
1492
1493
1494 /*
1495  * The glibc_c99_inline_1 fix should have fixed everything.  Unfortunately
1496  * there are many glibc headers which do not respect __USE_EXTERN_INLINES.
1497  * The remaining glibc_c99_inline_* fixes deal with some of those headers.
1498  */
1499 fix = {
1500     hackname  = glibc_c99_inline_2;
1501     files     = sys/stat.h, '*/sys/stat.h';
1502     select    = "extern __inline__ int";
1503     sed     = "s/extern int \\(stat\\)/"
1504               "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1505               "__inline__ int \\1/";
1506     sed     = "s/extern int \\([lf]stat\\)/"
1507               "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1508               "__inline__ int \\1/";
1509     sed     = "s/extern int \\(mknod\\)/"
1510               "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1511               "__inline__ int \\1/";
1512     sed     = "s/extern int __REDIRECT\\(_NTH\\)\\{0,1\\} (\\(stat\\)/"
1513               "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1514               "__inline__ int __REDIRECT\\1 (\\2/";
1515     sed     = "s/extern int __REDIRECT\\(_NTH\\)\\{0,1\\} (\\([lf]stat\\)/"
1516               "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1517               "__inline__ int __REDIRECT\\1 (\\2/";
1518     sed     = "s/^extern __inline__ int/"
1519               "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1520               "__inline__ int/";
1521     test_text = <<-EOT
1522         extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
1523         extern __inline__ int
1524         __NTH (fstat64 (int __fd, struct stat64 *__statbuf))
1525         {}
1526         EOT;
1527 };
1528
1529
1530 fix = {
1531     hackname  = glibc_c99_inline_3;
1532     files     = bits/string2.h, '*/bits/string2.h';
1533     select    = "extern __inline";
1534     bypass    = "__extern_inline|__GNU_STDC_INLINE__";
1535     c_fix     = format;
1536     c_fix_arg = "# if defined(__cplusplus) || defined(__GNUC_STDC_INLINE__)";
1537     c_fix_arg = "^# ifdef __cplusplus$";
1538     test_text = <<-EOT
1539         # ifdef __cplusplus
1540         #  define __STRING_INLINE inline
1541         # else
1542         #  define __STRING_INLINE extern __inline
1543         # endif
1544         EOT;
1545 };
1546
1547
1548 fix = {
1549     hackname  = glibc_c99_inline_4;
1550     files     = sys/sysmacros.h, '*/sys/sysmacros.h', wchar.h, '*/wchar.h';
1551     bypass    = "__extern_inline|__gnu_inline__";
1552     select    = "(^| )extern __inline";
1553     c_fix     = format;
1554     c_fix_arg = "%0 __attribute__ ((__gnu_inline__))";
1555     test_text = <<-EOT
1556         __extension__ extern __inline unsigned int
1557         extern __inline unsigned int
1558         EOT;
1559 };
1560
1561
1562 /*  glibc-2.3.5 defines pthread mutex initializers incorrectly,
1563  *  so we replace them with versions that correspond to the
1564  *  definition.
1565  */
1566 fix = {
1567     hackname = glibc_mutex_init;
1568     files    = pthread.h;
1569     select   = '\{ *\{ *0, *\} *\}';
1570     sed      = "/define[ \t]\\{1,\\}PTHREAD_MUTEX_INITIALIZER[ \t]*\\\\/{\n"
1571                "N\ns/{ { 0, } }/{ { 0, 0, 0, 0, 0, 0 } }/\n}";
1572     sed      = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
1573                "\\(RECURSIVE\\)_NP\\) }/{ \\1, 0 }/";
1574     sed      = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
1575                "\\(ERRORCHECK\\)_NP\\) }/{ \\1, 0 }/";
1576     sed      = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
1577                "\\(ADAPTIVE\\)_NP\\) }/{ \\1, 0 }/";
1578     sed      = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
1579                "\\(RECURSIVE\\)_NP\\) }/{ \\1, 0, 0 }/";
1580     sed      = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
1581                "\\(ERRORCHECK\\)_NP\\) }/{ \\1, 0, 0 }/";
1582     sed      = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
1583                "\\(ADAPTIVE\\)_NP\\) }/{ \\1, 0, 0 }/";
1584     sed      = "/define[ \t]\\{1,\\}PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\/"
1585                "N;s/^[ \t]*#[ \t]*"
1586                "\\(define[ \t]\\{1,\\}PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\\\)\\n"
1587                "[ \t]*{ { 0, } }/# if __WORDSIZE == 64\\\n"
1588                "#  \\1\\\n"
1589                "  { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
1590                "# else\\\n"
1591                "#  \\1\\\n"
1592                "  { { 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
1593                "# endif/";
1594     sed      = "s/{ \\(0, 0, 0, 0, 0, 0, "
1595                "PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP\\) }/{ \\1, 0 }/";
1596     sed      = "/define[ \t]\\{1,\\}PTHREAD_COND_INITIALIZER/"
1597                "s/{ { 0, } }/{ { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }/";
1598
1599     test_text = <<- _EOText_
1600         #define PTHREAD_MUTEX_INITIALIZER \\
1601           { { 0, } }
1602         #ifdef __USE_GNU
1603         # if __WORDSIZE == 64
1604         #  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \\
1605           { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP } }
1606         #  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \\
1607           { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP } }
1608         #  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \\
1609           { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP } }
1610         # else
1611         #  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \\
1612           { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP } }
1613         #  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \\
1614           { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP } }
1615         #  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \\
1616           { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP } }
1617         # endif
1618         #endif
1619         # define PTHREAD_RWLOCK_INITIALIZER \\
1620           { { 0, } }
1621         # ifdef __USE_GNU
1622         #  if __WORDSIZE == 64
1623         #   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \\
1624           { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                           \\
1625               PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
1626         #  else
1627         #   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \\
1628           { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
1629         #  endif
1630         # endif
1631         #define PTHREAD_COND_INITIALIZER { { 0, } }
1632         _EOText_;
1633 };
1634
1635
1636 /* glibc versions before 2.5 have a version of stdint.h that defines
1637    UINT8_C and UINT16_C to produce unsigned constants, as do uClibc
1638    versions with stdint.h based on those glibc versions.  */
1639 fix = {
1640     hackname  = glibc_stdint;
1641     files     = stdint.h;
1642     select    = "GNU C Library";
1643     c_fix     = format;
1644     c_fix_arg = "# define UINT8_C(c)\tc\n# define UINT16_C(c)\tc";
1645     c_fix_arg = "# define UINT8_C\\(c\\)\tc ## U\n# define UINT16_C\\(c\\)\tc ## U";
1646     test_text = "/* This file is part of the GNU C Library.  */\n# define UINT8_C(c)\tc ## U\n# define UINT16_C(c)\tc ## U";
1647 };
1648
1649
1650 /* Some versions of glibc have a version of bits/string2.h that
1651    produces "value computed is not used" warnings from strncpy; fix
1652    this definition by using __builtin_strncpy instead as in newer
1653    versions.  */
1654 fix = {
1655     hackname  = glibc_strncpy;
1656     files     = bits/string2.h;
1657     bypass    = "__builtin_strncpy";
1658     c_fix     = format;
1659     c_fix_arg = "#  define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)";
1660     c_fix_arg = "#  define strncpy([^\n]*\\\\\n)*[^\n]*";
1661     test_text = <<-EOT
1662         #  define strncpy(dest, src, n) \
1663           (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n)      \\
1664                           ? (strlen (src) + 1 >= ((size_t) (n))                       \\
1665                              ? (char *) memcpy (dest, src, n)                         \\
1666                              : strncpy (dest, src, n))                                \\
1667                           : strncpy (dest, src, n)))
1668         EOT;
1669
1670 };
1671
1672 /* glibc's tgmath.h relies on an expression that is not an integer
1673    constant expression being treated as it was by GCC 4.4 and
1674    earlier.  */
1675 fix = {
1676     hackname  = glibc_tgmath;
1677     files     = tgmath.h;
1678     select    = '\(\(\(type\) 0.25\) && \(\(type\) 0.25 - 1\)\)';
1679     bypass    = "__floating_type\\(type\\) \\\\\n.*__builtin_classify_type";
1680     c_fix     = format;
1681     c_fix_arg = "(__builtin_classify_type ((type) 0) == 8 || (__builtin_classify_type ((type) 0) == 9 && __builtin_classify_type (__real__ ((type) 0)) == 8))";
1682     test_text = "# define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))";
1683 };
1684
1685 /*
1686  * Fix these files to use the types we think they should for
1687  * ptrdiff_t, size_t, and wchar_t.
1688  *
1689  * This defines the types in terms of macros predefined by our 'cpp'.
1690  * This is supposedly necessary for glibc's handling of these types.
1691  * It's probably not necessary for anyone else, but it doesn't hurt.
1692  */
1693 fix = {
1694     hackname  = gnu_types;
1695     files  = "sys/types.h";
1696     files  = "stdlib.h";
1697     files  = "sys/stdtypes.h";
1698     files  = "stddef.h";
1699     files  = "memory.h";
1700     files  = "unistd.h";
1701     bypass    = '_GCC_(PTRDIFF|SIZE|WCHAR)_T';
1702     select    = "^[ \t]*typedef[ \t]+.*[ \t](ptrdiff|size|wchar)_t;";
1703     c_fix     = gnu_type;
1704     /* The Solaris 10 headers already define these types correctly.  */
1705     mach   = '*-*-solaris2.1[0-9]*';
1706     not_machine = true;
1707
1708     test_text = "typedef long int ptrdiff_t; /* long int */\n"
1709                 "typedef uint_t size_t; /* uint_t */\n"
1710                 "typedef ushort_t wchar_t; /* ushort_t */";
1711 };
1712
1713
1714 /*
1715  *  Fix HP & Sony's use of "../machine/xxx.h"
1716  *  to refer to:  <machine/xxx.h>
1717  */
1718 fix = {
1719     hackname  = hp_inline;
1720     files     = sys/spinlock.h;
1721     files     = machine/machparam.h;
1722     select    = "[ \t]*#[ \t]*include[ \t]+"  '"\.\./machine/';
1723
1724     c_fix     = format;
1725     c_fix_arg = "%1<machine/%2.h>";
1726
1727     c_fix_arg = "([ \t]*#[ \t]*include[ \t]+)"  '"\.\./machine/'
1728                 '([a-z]+)\.h"';
1729
1730     test_text = ' # include "../machine/mumble.h"';
1731 };
1732
1733
1734 /*
1735  *  Check for (...) in C++ code in HP/UX sys/file.h.
1736  */
1737 fix = {
1738     hackname  = hp_sysfile;
1739     files     = sys/file.h;
1740     select    = "HPUX_SOURCE";
1741
1742     c_fix     = format;
1743     c_fix_arg = "(struct file *, ...)";
1744     c_fix_arg = '\(\.\.\.\)';
1745
1746     test_text = "extern void foo(...); /* HPUX_SOURCE - bad varargs */";
1747 };
1748
1749
1750 /*
1751  *  Un-Hide a series of five FP defines from post-1999 compliance GCC:
1752  *  FP_NORMAL, FP_ZERO, FP_INFINITE, FP_SUBNORMAL and FP_NAN
1753  */
1754 fix = {
1755      hackname  = hppa_hpux_fp_macros;
1756      mach      = "hppa*-hp-hpux11*";
1757      files     = math.h;
1758      select    = "#[ \t]*define[ \t]*FP_NORMAL.*\n"
1759                  "#[ \t]*define[ \t]*FP_ZERO.*\n"
1760                  "#[ \t]*define[ \t]*FP_INFINITE.*\n"
1761                  "#[ \t]*define[ \t]*FP_SUBNORMAL.*\n"
1762                  "#[ \t]*define[ \t]*FP_NAN.*\n";
1763      c_fix     = format;
1764      c_fix_arg = <<- _EOFix_
1765         #endif /* _INCLUDE_HPUX_SOURCE */
1766
1767         #if defined(_INCLUDE_HPUX_SOURCE) || \
1768            (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
1769         %0#endif
1770
1771         #ifdef _INCLUDE_HPUX_SOURCE
1772
1773         _EOFix_;
1774
1775      test_text =
1776             "#  define FP_NORMAL     0\n"
1777             "#  define FP_ZERO       1\n"
1778             "#  define FP_INFINITE   2\n"
1779             "#  define FP_SUBNORMAL  3\n"
1780             "#  define FP_NAN        4\n";
1781 };
1782
1783
1784 /*
1785  * Delete C++ double pow (double, int) inline function from HP-UX 10 & 11
1786  * math.h to prevent clash with define in c_std/bits/std_cmath.h.
1787  */
1788 fix = {
1789     hackname  = hpux10_cpp_pow_inline;
1790     files     = fixinc-test-limits.h, math.h;
1791     select    = <<-     END_POW_INLINE
1792         ^# +ifdef +__cplusplus
1793          +\}
1794          +inline +double +pow\(double +__d,int +__expon\) +\{
1795         [       ]+return +pow\(__d,\(double\)__expon\);
1796          +\}
1797          +extern +"C" +\{
1798         #else
1799         # +endif
1800         END_POW_INLINE;
1801  
1802     c_fix     = format;
1803     c_fix_arg = "";
1804
1805     test_text =
1806         "#    ifdef __cplusplus\n"
1807         "     }\n"
1808         "     inline double pow(double __d,int __expon) {\n"
1809         "\t return pow(__d,(double)__expon);\n"
1810         "     }\n"
1811         '     extern "C"' " {\n"
1812         "#else\n"
1813         "#    endif";
1814 };
1815
1816 fix = {
1817      hackname  = hpux11_cpp_pow_inline;
1818      files     = math.h;
1819      select    = " +inline double pow\\(double d,int expon\\) \\{\n"
1820                  " +return pow\\(d, \\(double\\)expon\\);\n"
1821                  " +\\}\n";
1822      c_fix     = format;
1823      c_fix_arg = "";
1824
1825      test_text =
1826             "   inline double pow(double d,int expon) {\n"
1827             "     return pow(d, (double)expon);\n"
1828             "   }\n";
1829 };
1830
1831
1832 /*
1833  *  Fix hpux 10.X missing ctype declarations 1
1834  */
1835 fix = {
1836     hackname = hpux10_ctype_declarations1;
1837     files    = ctype.h;
1838     select   = "^#[ \t]*define _toupper\\(__c\\)[ \t]*__toupper\\(__c\\)";
1839     bypass   = "^[ \t]*extern[ \t]*int[ \t]*__tolower[ \t]*\\(";
1840     c_fix     = format;
1841     c_fix_arg = "#ifdef _PROTOTYPES\n"
1842                 "extern int __tolower(int);\n"
1843                 "extern int __toupper(int);\n"
1844                 "#else /* NOT _PROTOTYPES */\n"
1845                 "extern int __tolower();\n"
1846                 "extern int __toupper();\n"
1847                 "#endif /* _PROTOTYPES */\n\n"
1848                 "%0\n";
1849
1850     test_text = "#  define _toupper(__c)         __toupper(__c)\n";
1851 };
1852
1853
1854 /*
1855  *  Fix hpux 10.X missing ctype declarations 2
1856  */
1857 fix = {
1858     hackname = hpux10_ctype_declarations2;
1859     files    = ctype.h;
1860     select   = "^#  if defined\\(_SB_CTYPE_MACROS\\) && \\!defined\\(__lint\\)";
1861     bypass   = "^[ \t]*extern[ \t]*int[ \t]*_isalnum[ \t]*\\(";
1862     c_fix     = format;
1863     c_fix_arg = "%0\n\n"
1864                 "#ifdef _PROTOTYPES\n"
1865                 "     extern int _isalnum(int);\n"
1866                 "     extern int _isalpha(int);\n"
1867                 "     extern int _iscntrl(int);\n"
1868                 "     extern int _isdigit(int);\n"
1869                 "     extern int _isgraph(int);\n"
1870                 "     extern int _islower(int);\n"
1871                 "     extern int _isprint(int);\n"
1872                 "     extern int _ispunct(int);\n"
1873                 "     extern int _isspace(int);\n"
1874                 "     extern int _isupper(int);\n"
1875                 "     extern int _isxdigit(int);\n"
1876                 "#  else /* not _PROTOTYPES */\n"
1877                 "     extern int _isalnum();\n"
1878                 "     extern int _isalpha();\n"
1879                 "     extern int _iscntrl();\n"
1880                 "     extern int _isdigit();\n"
1881                 "     extern int _isgraph();\n"
1882                 "     extern int _islower();\n"
1883                 "     extern int _isprint();\n"
1884                 "     extern int _ispunct();\n"
1885                 "     extern int _isspace();\n"
1886                 "     extern int _isupper();\n"
1887                 "     extern int _isxdigit();\n"
1888                 "#endif /* _PROTOTYPES */\n";
1889
1890     test_text = "#  if defined(_SB_CTYPE_MACROS) && !defined(__lint)\n"
1891                 "     extern unsigned int *__SB_masks;\n";
1892 };
1893
1894
1895 /*
1896  *  Fix hpux 10.X missing stdio declarations
1897  */
1898 fix = {
1899     hackname = hpux10_stdio_declarations;
1900     files    = stdio.h;
1901     select   = "^#[ \t]*define _iob[ \t]*__iob";
1902     bypass   = "^[ \t]*extern[ \t]*int[ \t]*vsnprintf[ \t]*\\(";
1903     c_fix     = format;
1904     c_fix_arg = "%0\n\n"
1905         "#  if defined(__STDC__) || defined(__cplusplus)\n"
1906         "     extern int snprintf(char *, size_t, const char *, ...);\n"
1907         "     extern int vsnprintf(char *, size_t, const char *, __va_list);\n"
1908         "#  else /* not __STDC__) || __cplusplus */\n"
1909         "     extern int snprintf();\n"
1910         "     extern int vsnprintf();\n"
1911         "#  endif /* __STDC__) || __cplusplus */\n";
1912
1913     test_text = "#  define _iob __iob\n";
1914 };
1915
1916
1917 /*
1918  *  Make sure hpux defines abs in header.
1919  */
1920 fix = {
1921     hackname  = hpux11_abs;
1922     mach      = "*-hp-hpux11*";
1923     files     = stdlib.h;
1924     select    = "ifndef _MATH_INCLUDED";
1925     c_fix     = format;
1926     c_fix_arg = "if !defined(_MATH_INCLUDED) || defined(__GNUG__)";
1927     test_text = "#ifndef _MATH_INCLUDED";
1928 };
1929
1930
1931 /*
1932  *  Keep HP-UX 11 from stomping on C++ math namespace
1933  *  with defines for fabsf.
1934  */
1935 fix = {
1936     hackname  = hpux11_fabsf;
1937     files     = math.h;
1938     select    = "^[ \t]*#[ \t]*define[ \t]+fabsf\\(.*";
1939     bypass    = "__cplusplus";
1940
1941     c_fix     = format;
1942     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
1943
1944     test_text =
1945     "#ifdef _PA_RISC\n"
1946     "#  define fabsf(x) ((float)fabs((double)(float)(x)))\n"
1947     "#endif";
1948 };
1949
1950
1951 /*
1952  *  Fix C99 constant in __POINTER_SET define.
1953  */
1954 fix = {
1955     hackname  = hpux11_pthread_const;
1956     mach      = "*-hp-hpux11.[0-3]*";
1957     files     = sys/pthread.h;
1958     select    = "^#define[ \t]*__POINTER_SET[ \t]*\\(\\(void \\*\\) 1LL\\)";
1959
1960     c_fix     = format;
1961     c_fix_arg = "#define __POINTER_SET\t\t((void *) 1L)";
1962     test_text = "#define __POINTER_SET\t\t((void *) 1LL)";
1963 };
1964
1965
1966 /*
1967  * Prevent HP-UX 11 from defining __size_t and preventing size_t from
1968  * being defined by having it define _hpux_size_t instead.
1969  */
1970 fix = {
1971     hackname  = hpux11_size_t;
1972     mach      = "*-hp-hpux11*";
1973     select    = "__size_t";
1974
1975     c_fix     = format;
1976     c_fix_arg = "_hpux_size_t";
1977
1978     test_text =
1979     "#define __size_t size_t\n"
1980     "       extern int getpwuid_r( char *, __size_t, struct passwd **);\n";
1981 };
1982
1983
1984 /*
1985  *  Fix hpux 11.00 broken snprintf declaration
1986  *  (third argument is char *, needs to be const char * to prevent
1987  *  spurious warnings with -Wwrite-strings or in C++).
1988  */
1989 fix = {
1990     hackname = hpux11_snprintf;
1991     files    = stdio.h;
1992     select   = '(extern int snprintf *\(char *\*, *(|__|_hpux_)size_t,)'
1993                                     ' *(char *\*, *\.\.\.\);)';
1994     c_fix     = format;
1995     c_fix_arg = '%1 const %3';
1996
1997     test_text = "extern int snprintf(char *, size_t, char *, ...);\n"
1998                 "extern int snprintf(char *, __size_t, char *, ...);\n"
1999                 "extern int snprintf(char *, _hpux_size_t, char *, ...);";
2000 };
2001
2002 /*
2003  *  Fix hpux 11.00 broken vsnprintf declaration
2004  */
2005 fix = {
2006     hackname = hpux11_vsnprintf;
2007     files    = stdio.h;
2008     select   = '(extern int vsnprintf\(char \*, _[hpux]*_size_t, '
2009                                      'const char \*,) __va__list\);';
2010     c_fix     = format;
2011     c_fix_arg = "%1 __va_list);";
2012
2013     test_text = 'extern int vsnprintf(char *, _hpux_size_t, const char *,'
2014                                      ' __va__list);';
2015 };
2016
2017
2018 /*
2019  *  get rid of bogus inline definitions in HP-UX 8.0
2020  */
2021 fix = {
2022     hackname = hpux8_bogus_inlines;
2023     files    = math.h;
2024     select   = inline;
2025     bypass   = "__GNUG__";
2026     sed = "s@inline int abs(int [a-z][a-z]*) {.*}"
2027            "@extern \"C\" int abs(int);@";
2028     sed = "s@inline double abs(double [a-z][a-z]*) {.*}@@";
2029     sed = "s@inline int sqr(int [a-z][a-z]*) {.*}@@";
2030     sed = "s@inline double sqr(double [a-z][a-z]*) {.*}@@";
2031     test_text = "inline int abs(int v) { return (v>=0)?v:-v; }\n"
2032                 "inline double sqr(double v) { return v**0.5; }";
2033 };
2034
2035
2036 /*
2037  *  Fix hpux broken ctype macros
2038  */
2039 fix = {
2040     hackname = hpux_ctype_macros;
2041     files    = ctype.h;
2042     select   = '((: |\()__SB_masks \? )'
2043                '(__SB_masks\[__(alnum|c)\] & _IS)';
2044     c_fix     = format;
2045     c_fix_arg = "%1(int)%3";
2046
2047     test_text = ": __SB_masks ? __SB_masks[__alnum] & _ISCNTRL\n"
2048                 "# define isalpha(__c) (__SB_masks ? __SB_masks[__c] & _IS\n";
2049 };
2050
2051
2052 /*
2053  *  Fix hpux broken #ifndef _XOPEN_SOURCE_EXTENDED conditional on htonl etc.
2054  */
2055 fix = {
2056     hackname = hpux_htonl;
2057     files    = netinet/in.h;
2058     select   = "#ifndef _XOPEN_SOURCE_EXTENDED[ \t]*\n"
2059                "(/\\*\n"
2060                " \\* Macros for number representation conversion\\.\n"
2061                " \\*/\n"
2062                "#ifndef ntohl)";
2063     c_fix     = format;
2064     c_fix_arg = "#if 1\n%1";
2065
2066     test_text = "#ifndef _XOPEN_SOURCE_EXTENDED\n"
2067                 "/*\n"
2068                 " * Macros for number representation conversion.\n"
2069                 " */\n"
2070                 "#ifndef ntohl\n"
2071                 "#define ntohl(x)        (x)\n"
2072                 "#define ntohs(x)        (x)\n"
2073                 "#define htonl(x)        (x)\n"
2074                 "#define htons(x)        (x)\n"
2075                 "#endif\n"
2076                 "#endif  /* ! _XOPEN_SOURCE_EXTENDED */";
2077 };
2078
2079
2080 /*
2081  * HP-UX long_double
2082  */
2083 fix = {
2084     hackname  = hpux_long_double;
2085     mach      = "*-*-hpux10*";
2086     mach      = "*-*-hpux11.[012]*";
2087     files     = stdlib.h;
2088     select    = "extern[ \t]long_double[ \t]strtold";
2089     bypass    = "long_double_t";
2090     sed       = "/^#[ \t]*ifndef _LONG_DOUBLE/,/\\/\\* _LONG_DOUBLE \\*\\//D";
2091     sed       = "s/long_double/long double/g";
2092
2093     test_text = "#  ifndef _LONG_DOUBLE\n"
2094                 "#    define _LONG_DOUBLE\n"
2095                 "     typedef struct {\n"
2096                 "       unsigned int word1, word2, word3, word4;\n"
2097                 "     } long_double;\n"
2098                 "#  endif /* _LONG_DOUBLE */\n"
2099                 "extern long_double strtold(const char *, char **);\n";
2100 };
2101
2102  /*
2103   * We cannot use the above rule on 11.31 because it removes the strtold
2104   * definition.  ia64 is OK with no hack, PA needs some help.
2105   */
2106 fix = {
2107     hackname  = hpux_long_double_2;
2108     mach      = "hppa*-*-hpux11.3*";
2109     files     = stdlib.h;
2110     select    = "#[ \t]*if[ \t]*!defined\\(__ia64\\) \\|\\| defined\\(_PROTOTYPES\\) \\|\\| defined\\(_LONG_DOUBLE_STRUCT\\)";
2111     c_fix     = format;
2112     c_fix_arg = "#  if !defined(_PROTOTYPES) || defined(_LONG_DOUBLE_STRUCT)";
2113
2114     test_text = "#  if !defined(__ia64) || !defined(_PROTOTYPES) || defined(_LONG_DOUBLE_STRUCT)\n";
2115 };
2116
2117 /*
2118  *  Fix hpux10.20 <sys/time.h> to avoid invalid forward decl
2119  */
2120 fix = {
2121     hackname = hpux_systime;
2122     files    = sys/time.h;
2123     select   = "^extern struct sigevent;";
2124
2125     c_fix     = format;
2126     c_fix_arg = "struct sigevent;";
2127
2128     test_text = 'extern struct sigevent;';
2129 };
2130
2131
2132 /*
2133  *  Wrap spu_info in ifdef _KERNEL.  GCC cannot handle an array of unknown
2134  *  type and mpinfou is only defined when _KERNEL is set.
2135  */
2136 fix = {
2137     hackname = hpux_spu_info;
2138     mach     = "*-hp-hpux*";
2139     /*
2140      *  It is tempting to omit the first "files" entry.  Do not.
2141      *  The testing machinery will take the first "files" entry as the name
2142      *  of a test file to play with.  It would be a nuisance to have a directory
2143      *  with the name "*".
2144      */
2145     files    = "ia64/sys/getppdp.h";
2146     files    = "*/sys/getppdp.h";
2147     select   = "^.*extern.*spu_info.*";
2148
2149     c_fix     = format;
2150     c_fix_arg = "#ifdef _KERNEL\n%0\n#endif";
2151
2152     test_text = "extern union mpinfou spu_info[];";
2153 };
2154
2155 fix = {
2156     hackname  = hpux11_extern_sendfile;
2157     mach      = "*-hp-hpux11.[12]*";
2158     files     = sys/socket.h;
2159     select    = "^[ \t]*extern sbsize_t sendfile.*\n.*, int\\)\\);\n";
2160     c_fix     = format;
2161     c_fix_arg = "#ifndef _APP32_64BIT_OFF_T\n%0#endif\n";
2162     test_text = "   extern sbsize_t sendfile __((int, int, off_t, bsize_t,\n                               const struct iovec *, int));\n";
2163 };
2164
2165 fix = {
2166     hackname  = hpux11_extern_sendpath;
2167     mach      = "*-hp-hpux11.[12]*";
2168     files     = sys/socket.h;
2169     select    = "^[ \t]*extern sbsize_t sendpath.*\n.*, int\\)\\);\n";
2170     c_fix     = format;
2171     c_fix_arg = "#ifndef _APP32_64BIT_OFF_T\n%0#endif\n";
2172     test_text = "   extern sbsize_t sendpath __((int, int, off_t, bsize_t,\n                               const struct iovec *, int));\n";
2173 };
2174
2175 fix = {
2176     hackname  = hpux_extern_errno;
2177     mach      = "*-hp-hpux10.*";
2178     mach      = "*-hp-hpux11.[0-2]*";
2179     files     = errno.h;
2180     select    = "^[ \t]*extern int errno;$";
2181     c_fix     = format;
2182     c_fix_arg = "#ifdef __cplusplus\nextern \"C\" {\n#endif\n%0\n#ifdef __cplusplus\n}\n#endif";
2183     test_text = "   extern int errno;\n";
2184 };
2185
2186
2187 /*
2188  *  Add missing braces to pthread initializer defines.
2189  */
2190 fix = {
2191     hackname  = hpux_pthread_initializers;
2192     mach      = "*-hp-hpux11.[0-3]*";
2193     files     = sys/pthread.h;
2194     sed       = "s@^[ \t]*1, 1, 1, 1,[ \t]*\\\\"
2195                  "@\t{ 1, 1, 1, 1 },\t\t\t\t\t\t\t\\\\@";
2196     sed       = "s@^[ \t]*1,[ \t]*\\\\"
2197                  "@\t{ 1, 0 }@";
2198     sed       = "/^[ \t]*0$/d";
2199     sed       = "s@__PTHREAD_MUTEX_VALID, 0"
2200                  "@{ __PTHREAD_MUTEX_VALID, 0 }@";
2201     sed       = "s@^[ \t]*0, 0, -1, 0,[ \t]*\\\\"
2202                  "@\t{ 0, 0, -1, 0 },\t\t\t\t\t\t\\\\@";
2203     sed       = "s@0, __LWP_MTX_VALID, 0, 1, 1, 1, 1,[ \t]*\\\\"
2204                  "@{ 0, __LWP_MTX_VALID }, { 0, 1, 1, 1, 1 },\t\t\t\\\\@";
2205     sed       = "s@^[ \t]*__LWP_MTX_VALID, 0, 1, 1, 1, 1,[ \t]*\\\\"
2206                  "@\t{ 0, __LWP_MTX_VALID }, { 0, 1, 1, 1, 1 },\t\t\t\\\\@";
2207     sed       = "s@^[ \t]*0, 0[ \t]*\\\\"
2208                  "@\t{ 0, 0 }\t\t\t\t\t\t\t\\\\@";
2209     sed       = "s@__PTHREAD_COND_VALID, 0"
2210                  "@{ __PTHREAD_COND_VALID, 0 }@";
2211     sed       = "s@__LWP_COND_VALID, 0,[ \t]*\\\\"
2212                  "@{ __LWP_COND_VALID, 0 },\t\t\t\t\t\\\\@";
2213     sed       = "s@__PTHREAD_RWLOCK_VALID, 0"
2214                  "@{ __PTHREAD_RWLOCK_VALID, 0 }@";
2215     sed       = "s@__LWP_RWLOCK_VALID, 0,[ \t]*\\\\"
2216                  "@{ __LWP_RWLOCK_VALID, 0 },\t\t\t\t\t\\\\@";
2217     sed       = "s@^[ \t]*0, 0, 0, 0, 0, 0, 0[ \t]*\\\\"
2218                  "@\t{ 0, 0, 0, 0, 0 }, { 0, 0}\t\t\t\t\t\\\\@";
2219     test_text = "#define PTHREAD_MUTEX_INITIALIZER  {\t\t\t\t\t\\\\\n"
2220                 "\t__PTHREAD_MUTEX_VALID, 0,\t\t\t\t\t\\\\\n"
2221                 "\t(PTHREAD_MUTEX_DEFAULT | PTHREAD_PROCESS_PRIVATE),\t\t\\\\\n"
2222                 "\t__SPNLCK_INITIALIZER,\t\t\t\t\t\t\\\\\n"
2223                 "\t0, 0, -1, 0,\t\t\t\t\t\t\t\\\\\n"
2224                 "\t0, __LWP_MTX_VALID, 0, 1, 1, 1, 1,\t\t\t\t\\\\\n"
2225                 "\t0, 0\t\t\t\t\t\t\t\t\\\\\n"
2226                 "}\n";
2227 };
2228
2229 fix = {
2230     hackname  = hpux_c99_intptr;
2231     mach      = "*-hp-hpux11.3*";
2232     files     = stdint-hpux11.h, stdint.h;
2233     sed       = "s@^[ \t]*#[ \t]*define[ \t]*PTRDIFF_MAX[ \t]*INT32_MAX[ \t]*$@#define PTRDIFF_MAX (2147483647l)@";
2234     sed       = "s@^[ \t]*#[ \t]*define[ \t]*PTRDIFF_MIN[ \t]*INT32_MIN[ \t]*$@#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)@";
2235     sed       = "s@^[ \t]*#[ \t]*define[ \t]*INTPTR_MAX[ \t]*INT32_MAX[ \t]*$@#define INTPTR_MAX (2147483647l)@";
2236     sed       = "s@^[ \t]*#[ \t]*define[ \t]*INTPTR_MIN[ \t]*INT32_MIN[ \t]*$@#define INTPTR_MIN (-INTPTR_MAX - 1)@";
2237     sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINTPTR_MAX[ \t]*UINT32_MAX[ \t]*$@#define UINTPTR_MAX (4294967295ul)@";
2238     sed       = "s@^[ \t]*#[ \t]*define[ \t]*SIZE_MAX[ \t]*UINT32_MAX[ \t]*$@#define SIZE_MAX (4294967295ul)@";
2239     test_text = "#define PTRDIFF_MAX    INT32_MAX\n"
2240                 "#define PTRDIFF_MIN    INT32_MIN\n"
2241                 "#define INTPTR_MAX     INT32_MAX\n"
2242                 "#define INTPTR_MIN     INT32_MIN\n"
2243                 "#define UINTPTR_MAX    UINT32_MAX\n"
2244                 "#define SIZE_MAX       UINT32_MAX\n";
2245 };
2246
2247 /*
2248  * These hacks are need in inttypes.h on 11.23 and in stdint.h on 11.31.
2249  */
2250
2251 fix = {
2252     hackname  = hpux_c99_inttypes;
2253     mach      = "*-hp-hpux11.[23]*";
2254     files     = inttypes.h;
2255     files     = stdint-hpux11.h, stdint.h;
2256     sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT8_C(__c)[ \t]*__CONCAT_U__(__c)[ \t]*$@#define UINT8_C(__c) (__c)@";
2257     sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT16_C(__c)[ \t]*__CONCAT_U__(__c)[ \t]*$@#define UINT16_C(__c) (__c)@";
2258     sed       = "s@^[ \t]*#[ \t]*define[ \t]*INT32_C(__c)[ \t]*__CONCAT__(__c,l)[ \t]*$@#define INT32_C(__c) (__c)@";
2259     sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT32_C(__c)[ \t].*$@#define UINT32_C(__c) __CONCAT__(__c,u)@";
2260     test_text = "#define UINT8_C(__c)     __CONCAT_U__(__c)\n"
2261                 "#define UINT16_C(__c)    __CONCAT_U__(__c)\n"
2262                 "#define INT32_C(__c)     __CONCAT__(__c,l)\n"
2263                 "#define UINT32_C(__c)     __CONCAT__(__c,ul)\n";
2264 };
2265
2266 fix = {
2267     hackname  = hpux_c99_inttypes2;
2268     mach      = "*-hp-hpux11.2*";
2269     files     = stdint-hpux11.h, stdint.h;
2270     sed       = "s@^[ \t]*#[ \t]*define[ \t]*INT8_C(__c)[ \t]*((signed char)(__c))[ \t]*$@#define INT8_C(__c) (__c)@";
2271     sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT8_C(__c)[ \t]*((unsigned char)(__c))[ \t]*$@#define UINT8_C(__c) (__c)@";
2272     sed       = "s@^[ \t]*#[ \t]*define[ \t]*INT16_C(__c)[ \t]*((short)(__c))[ \t]*$@#define INT16_C(__c) (__c)@";
2273     sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT16_C(__c)[ \t]*((unsigned short)(__c))[ \t]*$@#define UINT16_C(__c) (__c)@";
2274     test_text = "#  define      INT8_C(__c)     ((signed char)(__c))\n"
2275                 "#  define      UINT8_C(__c)    ((unsigned char)(__c))\n"
2276                 "#  define      INT16_C(__c)    ((short)(__c))\n"
2277                 "#  define      UINT16_C(__c)   ((unsigned short)(__c))\n";
2278 };
2279
2280 fix = {
2281     hackname  = hpux_stdint_least_fast;
2282     mach      = "*-hp-hpux11.2*";
2283     files     = stdint-hpux11.h, stdint.h;
2284     select    =
2285         "^[ \t]*#[ \t]*define[ \t]+UINT_(LEAST|FAST)64_MAX[ \t]+ULLONG_MAX";
2286     c_fix     = format;
2287     c-fix-arg = "#  define      UINT_%164_MAX   __UINT64_MAX__";
2288     test-text = "#  define       UINT_FAST64_MAX        ULLONG_MAX\n"
2289                 "#  define       UINT_LEAST64_MAX        ULLONG_MAX\n";
2290         _EOFix_;
2291 };
2292
2293 fix = {
2294     hackname  = hpux_inttype_int8_t;
2295     mach      = "*-hp-hpux1[01].*";
2296     files     = sys/_inttypes.h;
2297     select    = "^[ \t]*typedef[ \t]*char[ \t]*int(_least){0,1}8_t.*";
2298     c_fix     = format;
2299     c_fix_arg = "typedef signed char int%18_t;";
2300     test_text = "typedef char int_least8_t;\n"
2301                 "typedef char int8_t;\n";
2302 };
2303
2304 fix = {
2305     hackname  = hpux_imaginary_i;
2306     mach      = "ia64-hp-hpux11.*";
2307     files     = complex.h;
2308     select    = "^[ \t]*#[ \t]*define[ \t]*_Complex_I.*";
2309     c_fix     = format;
2310     c_fix_arg = "#define _Complex_I (__extension__ 1.0iF)";
2311     test_text = "#define _Complex_I (0.f+_Imaginary_I)\n";
2312 };
2313
2314 /*
2315  *  Fix glibc definition of HUGE_VAL in terms of hex floating point constant
2316  */
2317 fix = {
2318     hackname  = huge_val_hex;
2319     files     = bits/huge_val.h;
2320     select    = "^#[ \t]*define[ \t]*HUGE_VAL[ \t].*0x1\\.0p.*";
2321     bypass    = "__builtin_huge_val";
2322
2323     c_fix     = format;
2324     c_fix_arg = "#define HUGE_VAL (__builtin_huge_val())\n";
2325
2326     test_text = "# define HUGE_VAL\t(__extension__ 0x1.0p2047)";
2327 };
2328
2329
2330 /*
2331  *  Fix glibc definition of HUGE_VALF in terms of hex floating point constant
2332  */
2333 fix = {
2334     hackname  = huge_valf_hex;
2335     files     = bits/huge_val.h;
2336     select    = "^#[ \t]*define[ \t]*HUGE_VALF[ \t].*0x1\\.0p.*";
2337     bypass    = "__builtin_huge_valf";
2338
2339     c_fix     = format;
2340     c_fix_arg = "#define HUGE_VALF (__builtin_huge_valf())\n";
2341
2342     test_text = "#  define HUGE_VALF (__extension__ 0x1.0p255f)";
2343 };
2344
2345
2346 /*
2347  *  Fix glibc definition of HUGE_VALL in terms of hex floating point constant
2348  */
2349 fix = {
2350     hackname  = huge_vall_hex;
2351     files     = bits/huge_val.h;
2352     select    = "^#[ \t]*define[ \t]*HUGE_VALL[ \t].*0x1\\.0p.*";
2353     bypass    = "__builtin_huge_vall";
2354
2355     c_fix     = format;
2356     c_fix_arg = "#define HUGE_VALL (__builtin_huge_vall())\n";
2357
2358     test_text = "#  define HUGE_VALL (__extension__ 0x1.0p32767L)";
2359 };
2360
2361
2362 /*
2363  *  Fix return type of abort and free
2364  */
2365 fix = {
2366     hackname  = int_abort_free_and_exit;
2367     files     = stdlib.h;
2368     select    = "int[ \t]+(abort|free|exit)[ \t]*\\(";
2369     bypass    = "_CLASSIC_ANSI_TYPES";
2370
2371     c_fix     = format;
2372     c_fix_arg = "void\t%1(";
2373
2374     test_text = "extern int abort(int);\n"
2375                 "extern int free(void*);\n"
2376                 "extern int exit(void*);";
2377 };
2378
2379
2380 /*
2381  *  Fix various macros used to define ioctl numbers.
2382  *  The traditional syntax was:
2383  *
2384  *    #define _IO(n, x) (('n'<<8)+x)
2385  *    #define TIOCFOO _IO(T, 1)
2386  *
2387  *  but this does not work with the C standard, which disallows macro
2388  *  expansion inside strings.  We have to rewrite it thus:
2389  *
2390  *    #define _IO(n, x) ((n<<8)+x)
2391  *    #define TIOCFOO  _IO('T', 1)
2392  *
2393  *  The select expressions match too much, but the c_fix code is cautious.
2394  *
2395  *  _IO might be: _IO DESIO BSD43__IO with W, R, WR, C, ... suffixes.
2396  */
2397 fix = {
2398     hackname  = io_quotes_def;
2399     select    = "define[ \t]+[A-Z0-9_]+IO[A-Z]*\\([a-zA-Z][,)]";
2400     c_fix     = char_macro_def;
2401     c_fix_arg = "IO";
2402     test_text =
2403     "#define BSD43__IOWR(n, x) (('n'<<8)+x)\n"
2404     "#define _IOWN(x,y,t)  (_IOC_IN|(((t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)\n"
2405     "#define _IO(x,y)      ('x'<<8|y)";
2406     test_text =
2407     "#define XX_IO(x)        ('x'<<8|256)";
2408 };
2409
2410 fix = {
2411     hackname  = io_quotes_use;
2412     select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+IO[A-Z]*[ \t]*"
2413                 "\\( *[^,']";
2414     c_fix     = char_macro_use;
2415     c_fix_arg = "IO";
2416     test_text = "#define TIOCFOO BSD43__IOWR(T, 1)\n"
2417                 "#define TIOCFOO \\\\\n"
2418                 "BSD43__IOWR(T, 1) /* Some are multi-line */";
2419 };
2420
2421
2422 /*
2423  *  Check for missing ';' in struct
2424  */
2425 fix = {
2426     hackname = ip_missing_semi;
2427     files    = netinet/ip.h;
2428     select   = "}$";
2429     sed      = "/^struct/,/^};/s/}$/};/";
2430     test_text=
2431     "struct mumble {\n"
2432     "  union {\n"
2433     "    int x;\n"
2434     "  }\n"
2435     "}; /* mumbled struct */\n";
2436 };
2437
2438
2439 /*
2440  *  IRIX 6.5.1[89] <internal/sgimacros.h> unconditionally defines
2441  *  __restrict as restrict iff __c99.  This is wrong for C++, which
2442  *  needs many C99 features, but only supports __restrict.
2443  */
2444 fix = {
2445     hackname  = irix___restrict;
2446     files     = internal/sgimacros.h;
2447     select    = "(#ifdef __c99\n)(#[ \t]*define __restrict restrict)";
2448
2449     mach      = "mips-sgi-irix6.5";
2450     c_fix     = format;
2451     c_fix_arg = "%1"
2452                 "#  ifndef __cplusplus\n%2\n#  endif";
2453
2454     test_text = "#ifdef __c99\n#  define __restrict restrict";
2455 };
2456
2457 /*
2458  * IRIX 6.5.22 <internal/math_core.h> uses the SGI c99 __generic() intrinsic
2459  * to define the fpclasify, isfinite, isinf, isnan, isnormal and signbit 
2460  * functions.
2461  *
2462  * This was probably introduced around IRIX 6.5.18
2463  */
2464 fix = {
2465     hackname  = irix___generic1;
2466     files     = internal/math_core.h;
2467     mach      = "mips-sgi-irix6.5";
2468     select    = "#define ([a-z]+)\\(x\\) *__generic.*";
2469
2470     c_fix     = format;
2471     c_fix_arg = "extern int %1(double);\n"
2472                 "extern int %1f(float);\n"
2473                 "extern int %1l(long double);\n"
2474                 "#define %1(x) (sizeof(x) == sizeof(double) ? _%1(x) \\\n"
2475                 "               : sizeof(x) == sizeof(float) ? _%1f(x) \\\n"
2476                 "               : _%1l(x))\n";
2477
2478     test_text = 
2479       "#define isnan(x) __generic(x,,, _isnan, _isnanf, _isnanl,,,)(x)\n";
2480 };
2481
2482
2483 /* Likewise <internal/math_core.h> on IRIX 6.5.19 and later uses the SGI
2484    compiler's __generic intrinsic to define isgreater, isgreaterequal,
2485    isless, islessequal, islessgreater and isunordered functions.  */
2486 fix = {
2487     hackname  = irix___generic2;
2488     files     = internal/math_core.h;
2489     mach      = "mips-sgi-irix6.5";
2490     select    = "#define ([a-z]+)\\(x,y\\) *__generic.*";
2491
2492     c_fix     = format;
2493     c_fix_arg = "#define %1(x,y) \\\n"
2494                 "  ((sizeof(x)<=4 && sizeof(y)<=4) ? _%1f(x,y) \\\n"
2495                 "   : (sizeof(x)<=8 && sizeof(y)<=8) ? _%1(x,y) \\\n"
2496                 "   : _%1l(x,y))\n";
2497
2498     test_text = 
2499       "#define isless(x,y)         __generic(x,y,, _isless, _islessf, _islessl,,,)(x,y)";
2500 };
2501
2502
2503 /*
2504  *  IRIX 5.2's <sys/asm.h> contains an asm comment with a contraction
2505  *  that causes the assembly preprocessor to complain about an
2506  *  unterminated character constant.
2507  */
2508 fix = {
2509     hackname  = irix_asm_apostrophe;
2510     files     = sys/asm.h;
2511
2512     select    = "^[ \t]*#.*[Ww]e're";
2513     c_fix     = format;
2514     c_fix_arg = "%1 are";
2515     c_fix_arg = "^([ \t]*#.*[Ww]e)'re";
2516     test_text = "\t# and we're on vacation";
2517 };
2518
2519
2520 /*
2521  * IRIX 6.5 complex.h defines _Complex_I and _Imaginary_I in terms of __I__,
2522  * which is a MIPSpro compiler builtin.  Remove _Imaginary_I and imaginary
2523  * definitions which are not supported by GCC. 
2524  */
2525 fix = {
2526     hackname  = irix_complex;
2527     mach      = "mips-sgi-irix6.5";
2528     files     = complex.h;
2529     select    = "#define[ \t]_Complex_I[ \t]\\(\\(float[ \t]_Complex\\)[ \t]\\(__I__\\)\\)";
2530     sed       = "s/#define[ \t]_Complex_I[ \t]((float[ \t]_Complex)[ \t](__I__))/"
2531                 "#define _Complex_I (__extension__ 1.0iF)/";
2532     sed       = "/#define[ \t]imaginary[ \t]_Imaginary/d";
2533     sed       = "/#define[ \t]_Imaginary_I/d";
2534     sed       = "s/#define[ \t]I[ \t]_Imaginary_I/#define I _Complex_I/";
2535     test_text = "#define _Complex_I ((float _Complex) (__I__))\n"
2536                 "#define imaginary _Imaginary\n"
2537                 "// #define _Imaginary_I ((float _Imaginary) 1)\n"
2538                 "#define _Imaginary_I __I__\n"
2539                 "#define I _Imaginary_I";
2540 };
2541
2542
2543 /*
2544  *  Non-traditional "const" declaration in Irix's limits.h.
2545  */
2546 fix = {
2547     hackname    = irix_limits_const;
2548     files       = fixinc-test-limits.h, limits.h;
2549     select      = "^extern const ";
2550     c_fix       = format;
2551     c_fix_arg   = "extern __const ";
2552     test_text   = "extern const char limit; /* test limits */";
2553 };
2554
2555
2556 /*
2557  *  IRIX 6.5 PTHREAD_*_INITIALIZER need an additional level of braces in
2558  *  <pthread.h>.
2559  */
2560 fix = {
2561     hackname    = irix_pthread_init;
2562     files       = pthread.h;
2563     select      = "^(#define[ \t]+PTHREAD_.*_INITIALIZER[ \t]+)(\\{ 0 \\})";
2564
2565     mach        = "mips-sgi-irix6.5";
2566     c_fix       = format;
2567     c_fix_arg   = "%1{ %2 }";
2568     test_text   = "#define PTHREAD_MUTEX_INITIALIZER    { 0 }\n"
2569                   "#define PTHREAD_COND_INITIALIZER     { 0 }\n"
2570                   "#define PTHREAD_RWLOCK_INITIALIZER   { 0 }";
2571 };
2572
2573
2574 /*
2575  *  IRIX 6.5.1[78] <sys/socket.h> has a broken definition of socklen_t.
2576  *  Various socket function prototypes use different types instead,
2577  *  depending on the API in use (BSD, XPG4/5), but the socklen_t
2578  *  definition doesn't reflect this (SGI Bug Id 864477, fixed in
2579  *  IRIX 6.5.19).
2580  */
2581 fix = {
2582     hackname  = irix_socklen_t;
2583     files     = sys/socket.h;
2584     select    = "(#define _SOCKLEN_T\n)(typedef u_int32_t socklen_t;)";
2585
2586     mach      = "mips-sgi-irix6.5";
2587     c_fix     = format;
2588     c_fix_arg = "%1"
2589                 "#if _NO_XOPEN4 && _NO_XOPEN5\n"
2590                 "typedef int socklen_t;\n"
2591                 "#else\n"
2592                 "%2\n"
2593                 "#endif /* _NO_XOPEN4 && _NO_XOPEN5 */";
2594
2595     test_text = "#define _SOCKLEN_T\ntypedef u_int32_t socklen_t;";
2596 };
2597
2598 /*
2599  *  IRIX 6.5 <stdint.h> only works with ISO C99 and errors out
2600  *  otherwise.
2601  */
2602 fix = {
2603     hackname  = irix_stdint_c99_mode;
2604     files     = stdint.h;
2605     select = "(#ifndef __c99\n)(#error This header file is to be used only for c99 mode compilations)";
2606
2607     mach      = "mips-sgi-irix6.5";
2608     c_fix  = format;
2609     c_fix_arg = "#if 0\n"
2610                 "%2";
2611     test_text =
2612     "#ifndef __c99\n#error This header file is to be used only for c99 mode compilations\n#else";
2613 };
2614
2615
2616 /*
2617  *  IRIX 6.5 <stdint.h> has some *_MIN/MAX constants whose types don't
2618  *  match the corresponding types, as required by ISO C99.
2619  */
2620 fix = {
2621     hackname  = irix_stdint_c99_types;
2622     files     = stdint-irix65.h, stdint.h;
2623     mach      = "mips-sgi-irix6.5";
2624     sed       = "s@^#define INT64_MIN.*(-0x7fffffffffffffff - 1)$@"
2625                 "#define INT64_MIN               (-0x7fffffffffffffffLL - 1)@";
2626     sed       = "s@^#define INT64_MAX.*0x7fffffffffffffff$@"
2627                 "#define INT64_MAX               0x7fffffffffffffffLL@";
2628     sed       = "s@^#define UINT32_MAX.*0xffffffff$@"
2629                 "#define UINT32_MAX              0xffffffffU@";
2630     sed       = "s@^#define UINT64_MAX.*0xffffffffffffffff$@"
2631                 "#define UINT64_MAX              0xffffffffffffffffULL@";
2632     sed       = "s@^#define INTPTR_MIN.*INT32_MIN$@"
2633                 "#define INTPTR_MIN              (-0x7fffffffL - 1)@";
2634     sed       = "s@^#define INTPTR_MAX.*INT32_MAX$@"
2635                 "#define INTPTR_MAX              0x7fffffffL@";
2636     sed       = "s@^#define UINTPTR_MAX.*UINT32_MAX$@"
2637                 "#define UINTPTR_MAX             0xffffffffUL@";
2638     sed       = "s@^#define INTPTR_MIN.*INT64_MIN@"
2639                 "#define INTPTR_MIN              (-0x7fffffffffffffffL - 1)@";
2640     sed       = "s@^#define INTPTR_MAX.*INT64_MAX$@"
2641                 "#define INTPTR_MAX              0x7fffffffffffffffL@";
2642     sed       = "s@^#define UINTPTR_MAX.*UINT64_MAX$@"
2643                 "#define UINTPTR_MAX             0xffffffffffffffffUL@";
2644     sed       = "s@^#define PTRDIFF_MIN.*INT64_MIN$@"
2645                 "#define PTRDIFF_MIN             (-0x7fffffffffffffffL - 1)@";
2646     sed       = "s@^#define PTRDIFF_MAX.*INT64_MAX$@"
2647                 "#define PTRDIFF_MAX             0x7fffffffffffffffL@";
2648     sed       = "s@^#define SIZE_MAX.*UINT64_MAX$@"
2649                 "#define SIZE_MAX                0xffffffffffffffffUL@";
2650     test_text = "#define INT64_MIN               (-0x7fffffffffffffff - 1)\n"
2651                 "#define INT64_MAX               0x7fffffffffffffff\n"
2652                 "#define UINT32_MAX              0xffffffff\n"
2653                 "#define UINT64_MAX              0xffffffffffffffff\n"
2654                 "#define INTPTR_MIN              INT32_MIN\n"
2655                 "#define INTPTR_MAX              INT32_MAX\n"
2656                 "#define UINTPTR_MAX             UINT32_MAX\n"
2657                 "#define INTPTR_MIN              INT64_MIN\n"
2658                 "#define INTPTR_MAX              INT64_MAX\n"
2659                 "#define UINTPTR_MAX             UINT64_MAX\n"
2660                 "#define PTRDIFF_MIN             INT64_MIN\n"
2661                 "#define PTRDIFF_MAX             INT64_MAX\n"
2662                 "#define SIZE_MAX                UINT64_MAX";
2663 };
2664
2665
2666 /*
2667  *  IRIX 6.5 <stdint.h> uses casts in some macros which cannot thus be used
2668  *  in preprocessor tests, although ISO C99 requires this.
2669  */
2670 fix = {
2671     hackname  = irix_stdint_c99_macros;
2672     files     = stdint-irix65.h, stdint.h;
2673     mach      = "mips-sgi-irix6.5";
2674     sed       = "s@^#define INT8_C(x).*int.*_t.*$@#define INT8_C(x)               (x)@";
2675     sed       = "s@^#define INT16_C(x).*int.*_t.*$@#define INT16_C(x)              (x)@";
2676     sed       = "s@^#define INT32_C(x).*int.*_t.*$@#define INT32_C(x)              (x)@";
2677     sed       = "s@^#define INT64_C(x).*int.*_t.*$@#define INT64_C(x)              (x ## LL)@";
2678     sed       = "s@^#define UINT8_C(x).*int.*_t.*$@#define UINT8_C(x)              (x)@";
2679     sed       = "s@^#define UINT16_C(x).*int.*_t.*$@#define UINT16_C(x)             (x)@";
2680     sed       = "s@^#define UINT32_C(x).*int.*_t.*$@#define UINT32_C(x)             (x ## U)@";
2681     sed       = "s@^#define UINT64_C(x).*int.*_t.*$@#define UINT64_C(x)             (x ## ULL)@";
2682     sed       = "s@^#define INTMAX_C(x).*int.*_t.*$@#define INTMAX_C(x)             (x ## LL)@";
2683     sed       = "s@^#define UINTMAX_C(x).*int.*_t.*$@#define UINTMAX_C(x)            (x ## ULL)@";
2684     test_text = "#define INT8_C(x)               (int_least8_t)(x)\n"
2685                 "#define INT16_C(x)              (int_least16_t)(x)\n"
2686                 "#define INT32_C(x)              (int_least32_t)(x)\n"
2687                 "#define INT64_C(x)              (int_least64_t)(x)\n"
2688                 "#define UINT8_C(x)              (uint_least8_t)(x)\n"
2689                 "#define UINT16_C(x)             (uint_least16_t)(x)\n"
2690                 "#define UINT32_C(x)             (uint_least32_t)(x)\n"
2691                 "#define UINT64_C(x)             (uint_least64_t)(x)\n"
2692                 "#define INTMAX_C(x)             (intmax_t)(x)\n"
2693                 "#define UINTMAX_C(x)            (uintmax_t)(x)";
2694 };
2695
2696
2697 /*
2698  *  IRIX 5.x's stdio.h and IRIX 6.5's internal/stdio_core.h declare
2699  *  some functions that take a va_list as
2700  *  taking char *.  However, GCC uses void * for va_list, so
2701  *  calling vfprintf with a va_list fails in C++.  */
2702 fix = {
2703     hackname  = irix_stdio_va_list;
2704     files     = stdio.h;
2705     files     = internal/stdio_core.h;
2706
2707     select = '/\* va_list \*/ char \*';
2708     c_fix  = format;
2709     c_fix_arg = "__gnuc_va_list";
2710     test_text =
2711     "extern int printf( const char *, /* va_list */ char * );";
2712 };
2713
2714
2715 /*
2716  *  IRIX 6.5.19 <internal/wchar_core.h> provides the XPG4 variant of
2717  *  wcsftime by default.  ISO C99 requires the XPG5 variant instead.
2718  */
2719 fix = {
2720     hackname  = irix_wcsftime;
2721     files     = internal/wchar_core.h;
2722     select    = "#if _NO_XOPEN5\n(extern size_t[ \t]+wcsftime.*const char \*.*)";
2723
2724     mach      = "mips-sgi-irix6.5";
2725     c_fix     = format;
2726     c_fix_arg = "#if _NO_XOPEN5 && !defined(__c99)\n%1";
2727
2728     test_text = "#if _NO_XOPEN5\n"
2729                 "extern size_t wcsftime(wchar_t *, "
2730                 "__SGI_LIBC_NAMESPACE_QUALIFIER size_t, const char *, "
2731                 "const struct tm *);";
2732 };
2733
2734
2735 /*
2736  * These files in Sun OS 4.x and ARM/RISCiX and BSD4.3
2737  * use / * * / to concatenate tokens.
2738  */
2739 fix = {
2740     hackname = kandr_concat;
2741     files  = "sparc/asm_linkage.h";
2742     files  = "sun*/asm_linkage.h";
2743     files  = "arm/as_support.h";
2744     files  = "arm/mc_type.h";
2745     files  = "arm/xcb.h";
2746     files  = "dev/chardefmac.h";
2747     files  = "dev/ps_irq.h";
2748     files  = "dev/screen.h";
2749     files  = "dev/scsi.h";
2750     files  = "sys/tty.h";
2751     files  = "Xm.acorn/XmP.h";
2752     files  = bsd43/bsd43_.h;
2753     select = '/\*\*/';
2754     c_fix     = format;
2755     c_fix_arg = '##';
2756     test_text = "#define __CONCAT__(a,b) a/**/b";
2757 };
2758
2759
2760 /* The /usr/include/sys/ucontext.h on ia64-*linux-gnu systems defines
2761  * an _SC_GR0_OFFSET macro using an idiom that isn't a compile time
2762  * constant on recent versions of g++.
2763  */
2764 fix = {
2765     hackname = linux_ia64_ucontext;
2766     files = "sys/ucontext.h";
2767     mach = "ia64-*-linux*";
2768     select = '\(\(\(char \*\) &\(\(struct sigcontext \*\) 0\)'
2769              '->sc_gr\[0\]\) - \(char \*\) 0\)';
2770     c_fix = format;
2771     c_fix_arg = "__builtin_offsetof \(struct sigcontext, sc_gr[0]\)";
2772     test_text = "# define _SC_GR0_OFFSET\t\\\\\n"
2773         "\t(((char *) &((struct sigcontext *) 0)->sc_gr[0]) - (char *) 0)\n";
2774 };
2775
2776
2777 /* 
2778  *  Remove header file warning from sys/time.h.  Autoconf's
2779  *  AC_HEADER_TIME recommends to include both sys/time.h and time.h
2780  *  which causes warning on LynxOS.  Remove the warning.
2781  */
2782 fix = {
2783     hackname  = lynxos_no_warning_in_sys_time_h;
2784     files     = sys/time.h;
2785     select    = "#warning[ \t]+Using <time.h> instead of <sys/time.h>";
2786     c_fix     = format;
2787     c_fix_arg = "";
2788     test_text = "#warning Using <time.h> instead of <sys/time.h>";
2789 };
2790
2791
2792 /* 
2793  *  Add missing declaration for putenv.
2794  */
2795 fix = {
2796     hackname  = lynxos_missing_putenv;
2797     mach      = '*-*-lynxos*';
2798     files     = stdlib.h;
2799     bypass    = 'putenv[ \t]*\\(';
2800     select    = "extern char \\*getenv[ \t]*_AP\\(\\(const char \\*\\)\\);";
2801     c_fix     = format;
2802     c_fix_arg = "%0\n"
2803         "extern int putenv                              _AP((char *));";
2804     c_fix_arg = "extern char \\*getenv[ \t]*_AP\\(\\(const char \\*\\)\\);";
2805     test_text = "extern char *getenv    _AP((const char *));";
2806 };
2807
2808
2809 /*
2810  * Fix BSD machine/ansi.h to use __builtin_va_list to define _BSD_VA_LIST_.
2811  *
2812  * On NetBSD, machine is a symbolic link to an architecture specific
2813  * directory name, so we can't match a specific file name here.
2814  */
2815 fix = {
2816     hackname = machine_ansi_h_va_list;
2817     select   = "define[ \t]+_BSD_VA_LIST_[ \t]";
2818     bypass   = '__builtin_va_list';
2819
2820     c_fix     = format;
2821     c_fix_arg = "%1__builtin_va_list";
2822     c_fix_arg = "(define[ \t]+_BSD_VA_LIST_[ \t]+).*";
2823
2824     test_text = " # define _BSD_VA_LIST_\tchar**";
2825 };
2826
2827
2828 /*
2829  *  Fix non-ansi machine name defines
2830  */
2831 fix = {
2832     hackname  = machine_name;
2833     c_test    = machine_name;
2834     c_fix     = machine_name;
2835
2836     test_text = "/* MACH_DIFF: */\n"
2837     "#if defined( i386 ) || defined( sparc ) || defined( vax )"
2838     "\n/* no uniform test, so be careful  :-) */";
2839 };
2840
2841
2842 /*
2843  *  Some math.h files define struct exception (it's in the System V
2844  *  Interface Definition), which conflicts with the class exception defined
2845  *  in the C++ file std/stdexcept.h.  We redefine it to __math_exception.
2846  *  This is not a great fix, but I haven't been able to think of anything
2847  *  better.
2848  */
2849 fix = {
2850     hackname  = math_exception;
2851     files     = math.h;
2852     select    = "struct exception";
2853     /*
2854      * This should be bypassed on __cplusplus, but some supposedly C++ C++
2855      * aware headers, such as Solaris 8 and 9, don't wrap their struct
2856      * exception either.  So currently we bypass only for glibc, based on a
2857      * comment in the fixed glibc header.  Ick.
2858      */
2859     bypass    = 'We have a problem when using C\+\+|for C\+\+, '
2860                 '_[a-z0-9A-Z_]+_exception; for C, exception';
2861     c_fix     = wrap;
2862
2863     c_fix_arg = "#ifdef __cplusplus\n"
2864                 "#define exception __math_exception\n"
2865                 "#endif\n";
2866
2867     c_fix_arg = "#ifdef __cplusplus\n"
2868                 "#undef exception\n"
2869                 "#endif\n";
2870
2871     test_text = "typedef struct exception t_math_exception;";
2872 };
2873
2874
2875 /*
2876  *  This looks pretty broken to me.  ``dbl_max_def'' will contain
2877  *  "define DBL_MAX " at the start, when what we really want is just
2878  *  the value portion.  Can't figure out how to write a test case
2879  *  for this either  :-(
2880  */
2881 fix = {
2882     hackname = math_huge_val_from_dbl_max;
2883     files    = math.h;
2884
2885     /*
2886      * IF HUGE_VAL is defined to be DBL_MAX *and* DBL_MAX is _not_ defined
2887      * in math.h, this fix applies.
2888      */
2889     select   = "define[ \t]+HUGE_VAL[ \t]+DBL_MAX";
2890     bypass   = "define[ \t]+DBL_MAX";
2891
2892     shell    =
2893     /*
2894      *  See if we have a definition for DBL_MAX in float.h.
2895      *  If we do, we will replace the one in math.h with that one.
2896      */
2897
2898     "\tdbl_max_def=`egrep 'define[ \t]+DBL_MAX[ \t]+.*' float.h "
2899                    "| sed 's/.*DBL_MAX[ \t]*//' 2>/dev/null`\n\n"
2900
2901     "\tif ( test -n \"${dbl_max_def}\" ) > /dev/null 2>&1\n"
2902     "\tthen sed -e '/define[ \t]*HUGE_VAL[ \t]*DBL_MAX/"
2903                         "s@DBL_MAX@'\"$dbl_max_def@\"\n"
2904     "\telse cat\n"
2905     "\tfi";
2906
2907     test_text =
2908     "`echo '#define DBL_MAX\t3.1415e+9 /* really big */' >> float.h`\n"
2909     "#define HUGE_VAL DBL_MAX";
2910 };
2911
2912
2913 /*
2914  *  nested comment
2915  */
2916 fix = {
2917     hackname  = nested_auth_des;
2918     files     = rpc/rpc.h;
2919     select    = '(/\*.*rpc/auth_des\.h>.*)/\*';
2920     c_fix     = format;
2921     c_fix_arg = "%1*/ /*";
2922     test_text = "/*#include <rpc/auth_des.h> /* skip this */";
2923 };
2924
2925
2926 /*
2927  *  Some versions of NetBSD don't expect the C99 inline semantics.
2928  */
2929 fix = {
2930     hackname  = netbsd_c99_inline_1;
2931     mach      = "*-*-netbsd*";
2932     files     = signal.h;
2933     select    = "extern __inline int";
2934
2935     c_fix     = format;
2936     c_fix_arg = "extern\n"
2937                 "#ifdef __GNUC_STDC_INLINE__\n"
2938                 "__attribute__((__gnu_inline__))\n"
2939                 "#endif\n"
2940                 "__inline int";
2941
2942     test_text = "extern __inline int\nsigaddset(sigset_t *set, int signo)\n{}";
2943 };
2944
2945
2946 fix = {
2947     hackname  = netbsd_c99_inline_2;
2948     mach      = "*-*-netbsd*";
2949     files     = signal.h;
2950     select    = "#define _SIGINLINE extern __inline";
2951
2952     c_fix     = format;
2953     c_fix_arg = <<- _EOArg_
2954         #ifdef __GNUC_STDC_INLINE__
2955         #define _SIGINLINE extern __attribute__((__gnu_inline__)) __inline
2956         #else
2957         %0
2958         #endif
2959         _EOArg_;
2960
2961     test_text = "#define _SIGINLINE extern __inline";
2962 };
2963
2964
2965 /*
2966  * NetBSD has a semicolon after the ending '}' for some extern "C".
2967  */
2968 fix = {
2969     hackname  = netbsd_extra_semicolon;
2970     mach      = "*-*-netbsd*";
2971     files     = sys/cdefs.h;
2972     select    = "#define[ \t]*__END_DECLS[ \t]*};";
2973
2974     c_fix     = format;
2975     c_fix_arg = "#define __END_DECLS }";
2976
2977     test_text = "#define __END_DECLS };";
2978 };
2979
2980
2981 /* newlib's stdint.h has several failures to conform to C99.  The fix
2982    for these removed a comment that can be matched to identify unfixed
2983    versions.  */
2984 fix = {
2985     hackname  = newlib_stdint_1;
2986     files     = stdint-newlib.h, stdint.h;
2987     select    = "@todo - Add support for wint_t types";
2988     sed       = "s@#define INT32_MIN.*@#define INT32_MIN (-INT32_MAX - 1)@";
2989     sed       = "s@#define INT32_MAX.*@#define INT32_MAX __INT32_MAX__@";
2990     sed       = "s@#define UINT32_MAX.*@#define UINT32_MAX __UINT32_MAX__@";
2991     sed       = "s@#define INT_LEAST32_MIN.*@#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)@";
2992     sed       = "s@#define INT_LEAST32_MAX.*@#define INT_LEAST32_MAX __INT_LEAST32_MAX__@";
2993     sed       = "s@#define UINT_LEAST32_MAX.*@#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__@";
2994     sed       = 's@#define INT_FAST\([0-9]*\)_MIN.*@#define INT_FAST\1_MIN (-INT_FAST\1_MAX - 1)@';
2995     sed       = 's@#define INT_FAST\([0-9]*\)_MAX.*@#define INT_FAST\1_MAX __INT_FAST\1_MAX__@';
2996     sed       = 's@#define UINT_FAST\([0-9]*\)_MAX.*@#define UINT_FAST\1_MAX __UINT_FAST\1_MAX__@';
2997     sed       = "s@#define SIZE_MAX.*@#define SIZE_MAX __SIZE_MAX__@";
2998     sed       = "s@#define PTRDIFF_MIN.*@#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)@";
2999     sed       = "s@#define PTRDIFF_MAX.*@#define PTRDIFF_MAX __PTRDIFF_MAX__@";
3000     sed       = "s@#define UINT8_C.*@#define UINT8_C(c) __UINT8_C(c)@";
3001     sed       = "s@#define UINT16_C.*@#define UINT16_C(c) __UINT16_C(c)@";
3002     test_text = "/* @todo - Add support for wint_t types. */\n"
3003                 "#define INT32_MIN (-2147483647-1)\n"
3004                 "#define INT32_MAX 2147483647\n"
3005                 "#define UINT32_MAX 4294967295U\n"
3006                 "#define INT_LEAST32_MIN (-2147483647-1)\n"
3007                 "#define INT_LEAST32_MAX 2147483647\n"
3008                 "#define UINT_LEAST32_MAX 4294967295U\n"
3009                 "#define INT_FAST8_MIN INT8_MIN\n"
3010                 "#define INT_FAST8_MAX INT8_MAX\n"
3011                 "#define UINT_FAST8_MAX UINT8_MAX\n"
3012                 "#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)\n"
3013                 "#define PTRDIFF_MIN (-__STDINT_EXP(LONG_MAX) - 1L)\n"
3014                 "#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX)\n"
3015                 "#define UINT8_C(x) x##U\n"
3016                 "#define UINT16_C(x) x##U";
3017 };
3018
3019
3020 fix = {
3021     hackname  = newlib_stdint_2;
3022     files     = stdint-newlib.h, stdint.h;
3023     select    = "@todo - Add support for wint_t types";
3024     c_fix     = format;
3025     c_fix_arg = "#define INTMAX_MAX __INTMAX_MAX__\n"
3026                 "#define INTMAX_MIN (-INTMAX_MAX - 1)\n"
3027                 "#define UINTMAX_MAX __UINTMAX_MAX__\n"
3028                 "#define WCHAR_MAX __WCHAR_MAX__\n"
3029                 "#define WCHAR_MIN __WCHAR_MIN__\n"
3030                 "#define WINT_MAX __WINT_MAX__\n"
3031                 "#define WINT_MIN __WINT_MIN__\n\n"
3032                 "%0";
3033     c_fix_arg = '/\*\* Macros for minimum-width integer constant expressions \*/';
3034     test_text = "/* @todo - Add support for wint_t types. */\n"
3035                 "/** Macros for minimum-width integer constant expressions */";
3036 };
3037
3038
3039 /*
3040  *  NeXT 3.2 adds const prefix to some math functions.
3041  *  These conflict with the built-in functions.
3042  */
3043 fix = {
3044     hackname  = next_math_prefix;
3045     files     = ansi/math.h;
3046     select    = "^extern[ \t]+double[ \t]+__const__[ \t]";
3047
3048     c_fix     = format;
3049     c_fix_arg = "extern double %1(";
3050     c_fix_arg = "^extern[ \t]+double[ \t]+__const__[ \t]+([a-z]+)\\(";
3051
3052     test_text = "extern\tdouble\t__const__\tmumble();";
3053 };
3054
3055
3056 /*
3057  *  NeXT 3.2 uses the word "template" as a parameter for some
3058  *  functions. GCC reports an invalid use of a reserved key word
3059  *  with the built-in functions.
3060  */
3061 fix = {
3062     hackname = next_template;
3063     files    = bsd/libc.h;
3064     select   = "[ \t]template\\)";
3065
3066     c_fix     = format;
3067     c_fix_arg = "(%1)";
3068     c_fix_arg = "\\(([^)]*)[ \t]template\\)";
3069     test_text = "extern mumble( char * template); /* fix */";
3070 };
3071
3072
3073 /*
3074  *  NeXT 3.2 includes the keyword volatile in the abort() and  exit()
3075  *  function prototypes. That conflicts with the  built-in functions.
3076  */
3077 fix = {
3078     hackname = next_volitile;
3079     files    = ansi/stdlib.h;
3080     select   = "^extern[ \t]+volatile[ \t]+void[ \t]";
3081
3082     c_fix     = format;
3083     c_fix_arg = "extern void %1(";
3084     c_fix_arg = "^extern[ \t]+volatile[ \t]+void[ \t]+(exit|abort)\\(";
3085
3086     test_text = "extern\tvolatile\tvoid\tabort();";
3087 };
3088
3089
3090 /*
3091  *  NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
3092  *  Note that version 3 of the NeXT system has wait.h in a different directory,
3093  *  so that this code won't do anything.  But wait.h in version 3 has a
3094  *  conditional, so it doesn't need this fix.  So everything is okay.
3095  */
3096 fix = {
3097     hackname  = next_wait_union;
3098     files     = sys/wait.h;
3099
3100     select    = 'wait\(union wait';
3101     c_fix     = format;
3102     c_fix_arg = "wait(void";
3103     test_text = "extern pid_d wait(union wait*);";
3104 };
3105
3106
3107 /*
3108  *  a missing semi-colon at the end of the nodeent structure definition.
3109  */
3110 fix = {
3111     hackname  = nodeent_syntax;
3112     files     = netdnet/dnetdb.h;
3113     select    = "char[ \t]*\\*na_addr[ \t]*$";
3114     c_fix     = format;
3115     c_fix_arg = "%0;";
3116     test_text = "char *na_addr\t";
3117 };
3118
3119 /* 
3120  * Fix OpenBSD's NULL definition.
3121  */
3122 fix = {
3123   hackname  = openbsd_null_definition;
3124   mach      = "*-*-openbsd*";
3125   files     = locale.h, stddef.h, stdio.h, string.h,
3126   time.h, unistd.h, wchar.h, sys/param.h;
3127   select    = "__GNUG__";
3128   c_fix = format;
3129   c_fix_arg = "#ifndef NULL\n"
3130               "#ifdef __cplusplus\n"
3131               "#ifdef __GNUG__\n"
3132               "#define NULL\t__null\n"
3133               "#else\t /* ! __GNUG__  */\n"
3134               "#define NULL\t0L\n"
3135               "#endif\t /* __GNUG__  */\n"
3136               "#else\t /* ! __cplusplus  */\n"
3137               "#define NULL\t((void *)0)\n"
3138               "#endif\t /* __cplusplus  */\n"
3139               "#endif\t /* !NULL  */";
3140
3141   c_fix_arg = "^#ifndef[ \t]*NULL\n"
3142               "^#ifdef[ \t]*__GNUG__\n"
3143               "^#define[ \t]*NULL[ \t]*__null\n"
3144               "^#else\n"
3145               "^#define[ \t]*NULL[ \t]*0L\n"
3146               "^#endif\n"
3147               "^#endif";
3148   test_text = 
3149         "#ifndef NULL\n"
3150         "#ifdef  __GNUG__\n"
3151         "#define NULL    __null\n"
3152         "#else\n"
3153         "#define NULL    0L\n"
3154         "#endif\n"
3155         "#endif\n";
3156 };
3157
3158 /*
3159  *  obstack.h used casts as lvalues.
3160  *
3161  *  We need to change postincrements of casted pointers (which are
3162  *  then dereferenced and assigned into) of the form
3163  *
3164  *    *((TYPE*)PTRVAR)++ = (VALUE)
3165  *
3166  *  into expressions like
3167  *
3168  *    ((*((TYPE*)PTRVAR) = (VALUE)), (PTRVAR += sizeof (TYPE)))
3169  *
3170  *  which is correct for the cases used in obstack.h since PTRVAR is
3171  *  of type char * and the value of the expression is not used.
3172  */
3173 fix = {
3174     hackname  = obstack_lvalue_cast;
3175     files     = obstack.h;
3176     select    = '\*\(\(([^()]*)\*\)(.*)\)\+\+ = \(([^()]*)\)';
3177     c_fix     = format;
3178     c_fix_arg = "((*((%1*)%2) = (%3)), (%2 += sizeof (%1)))";
3179     test_text = "*((void **) (h)->next_free)++ = (aptr)";
3180 };
3181
3182 /* 
3183  * Fix OpenBSD's va_start define.
3184  */
3185 fix = {
3186   hackname  = openbsd_va_start;
3187   mach      = "*-*-openbsd*";
3188   files     = stdarg.h;
3189   select    = '__builtin_stdarg_start';
3190   c_fix     = format;
3191   c_fix_arg = __builtin_va_start;
3192
3193   test_text = "#define va_start(v,l)   __builtin_stdarg_start((v),l)";
3194 };
3195
3196 /*
3197  *  sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
3198  *  defining regex.h related types.  This causes libg++ build and usage
3199  *  failures.  Fixing this correctly requires checking and modifying 3 files.
3200  */
3201 fix = {
3202     hackname = osf_namespace_a;
3203     files    = reg_types.h;
3204     files    = sys/lc_core.h;
3205     test     = " -r reg_types.h";
3206     test     = " -r sys/lc_core.h";
3207     test     = " -n \"`grep '} regex_t;' reg_types.h`\"";
3208     test     = " -z \"`grep __regex_t regex.h`\"";
3209
3210     c_fix     = format;
3211     c_fix_arg = "__%0";
3212     c_fix_arg = "reg(ex|off|match)_t";
3213
3214     test_text = "`touch sys/lc_core.h`"
3215     "typedef struct {\n  int stuff, mo_suff;\n} regex_t;\n"
3216     "extern regex_t    re;\n"
3217     "extern regoff_t   ro;\n"
3218     "extern regmatch_t rm;\n";
3219 };
3220
3221 fix = {
3222     hackname = osf_namespace_c;
3223     files    = regex.h;
3224     test     = " -r reg_types.h";
3225     test     = " -r sys/lc_core.h";
3226     test     = " -n \"`grep '} regex_t;' reg_types.h`\"";
3227     test     = " -z \"`grep __regex_t regex.h`\"";
3228
3229     select    = "#include <reg_types\.h>.*";
3230     c_fix     = format;
3231     c_fix_arg = "%0\n"
3232                 "typedef __regex_t\tregex_t;\n"
3233                 "typedef __regoff_t\tregoff_t;\n"
3234                 "typedef __regmatch_t\tregmatch_t;";
3235
3236     test_text = "#include <reg_types.h>";
3237 };
3238
3239
3240 /*
3241  * On broken glibc-2.3.3 systems an array of incomplete structures is
3242  * passed to __sigsetjmp.  Fix that to take a pointer instead.
3243  */
3244 fix = {
3245     hackname  = pthread_incomplete_struct_argument;
3246     files     = pthread.h;
3247     select    = "struct __jmp_buf_tag";
3248     c_fix     = format;
3249     c_fix_arg = "%1 *%2%3";
3250     c_fix_arg = "^(extern int __sigsetjmp \\(struct __jmp_buf_tag) (__env)\\[1\\](.*)$";
3251     test_text = "extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask);";
3252 };
3253
3254 /*
3255  *  Fix return type of fread and fwrite on sysV68
3256  */
3257 fix = {
3258     hackname = read_ret_type;
3259     files    = stdio.h;
3260     select   = "extern int\t.*, fread\\(\\), fwrite\\(\\)";
3261     c_fix     = format;
3262     c_fix_arg = "extern unsigned int fread(), fwrite();\n%1%2";
3263     c_fix_arg = "(extern int\t.*), fread\\(\\), fwrite\\(\\)(.*)";
3264
3265     test_text = "extern int\tfclose(), fflush(), fread(), fwrite(), foo();";
3266 };
3267
3268
3269 /*
3270  *  Fix casts as lvalues in glibc's <rpc/xdr.h>.
3271  */
3272 fix = {
3273     hackname  = rpc_xdr_lvalue_cast_a;
3274     files     = rpc/xdr.h;
3275     select    = "#define[ \t]*IXDR_GET_LONG.*\\\\\n.*__extension__.*";
3276     c_fix     = format;
3277     c_fix_arg = "#define IXDR_GET_LONG(buf) ((long)IXDR_GET_U_INT32(buf))";
3278     test_text = "#define IXDR_GET_LONG(buf) \\\\\n"
3279                 "\t((long)ntohl((u_long)*__extension__((u_int32_t*)(buf))++))";
3280 };
3281
3282
3283 fix = {
3284     hackname  = rpc_xdr_lvalue_cast_b;
3285     files     = rpc/xdr.h;
3286     select    = "#define[ \t]*IXDR_PUT_LONG.*\\\\\n.*__extension__.*";
3287     c_fix     = format;
3288     c_fix_arg = "#define IXDR_PUT_LONG(buf, v) ((long)IXDR_PUT_INT32(buf, (long)(v)))";
3289     test_text = "#define IXDR_PUT_LONG(buf, v) \\\\\n"
3290                 "\t(*__extension__((u_int32_t*)(buf))++ = (long)htonl((u_long)(v)))";
3291 };
3292
3293
3294 /*
3295  *  function class(double x) conflicts with C++ keyword on rs/6000
3296  */
3297 fix = {
3298     hackname  = rs6000_double;
3299     files     = math.h;
3300     select    = '[^a-zA-Z_]class\(';
3301
3302     c_fix     = format;
3303     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
3304     c_fix_arg = '^.*[^a-zA-Z_]class\(.*';
3305
3306     test_text = "extern int class();";
3307 };
3308
3309
3310 /*
3311  *  Wrong fchmod prototype on RS/6000.
3312  */
3313 fix = {
3314     hackname  = rs6000_fchmod;
3315     files     = sys/stat.h;
3316     select    = 'fchmod\(char \*';
3317     c_fix     = format;
3318     c_fix_arg = "fchmod(int";
3319     test_text = "extern int fchmod(char *, mode_t);";
3320 };
3321
3322
3323 /*
3324  *  parameters conflict with C++ new on rs/6000
3325  */
3326 fix = {
3327     hackname  = rs6000_param;
3328     files     = "stdio.h";
3329     files     = "unistd.h";
3330
3331     select    = 'rename\(const char \*old, const char \*new\)';
3332     c_fix     = format;
3333     c_fix_arg = 'rename(const char *_old, const char *_new)';
3334
3335     test_text = 'extern int rename(const char *old, const char *new);';
3336 };
3337
3338
3339 /*
3340  *  Solaris 10+ <sys/feature_tests.h> defines _RESTRICT_KYWD as restrict
3341  *  for C99.  This is wrong for C++, which needs many C99 features, but
3342  *  only supports __restrict.
3343  */
3344 fix = {
3345     hackname  = solaris___restrict;
3346     files     = sys/feature_tests.h;
3347     select    = "#define[ \t]*_RESTRICT_KYWD[ \t]*restrict";
3348     mach      = "*-*-solaris2*";
3349     c_fix     = format;
3350     c_fix_arg = "#ifdef __cplusplus\n#define\t_RESTRICT_KYWD\t__restrict\n"
3351                 "#else\n%0\n#endif";
3352     test_text = "#define        _RESTRICT_KYWD  restrict";
3353 };
3354
3355
3356 /*
3357  * Solaris 10+ complex.h defines _Complex_I and _Imaginary_I in terms of
3358  * themselves, which are Sun Studio compiler intrinsics.  Remove _Imaginary_I
3359  * and imaginary definitions which are not supported by GCC.
3360  */
3361 fix = {
3362     hackname  = solaris_complex;
3363     mach      = "*-*-solaris2.*";
3364     files     = complex.h;
3365     select    = "#define[ \t]_Complex_I[ \t]_Complex_I";
3366     sed       = "s/#define[ \t]_Complex_I[ \t]_Complex_I/"
3367                 "#define\t_Complex_I\t(__extension__ 1.0iF)/";
3368     sed       = "/#define[ \t]_Imaginary_I[ \t]_Imaginary_I/d";
3369     sed       = "/#define[ \t]imaginary[ \t]_Imaginary/d";
3370     sed       = "s/#define[ \t]I[ \t]\\{1,\\}_Imaginary_I/#define\tI\t\t_Complex_I/";
3371     test_text = "#define        _Complex_I      _Complex_I\n"
3372                 "#define        complex         _Complex\n"
3373                 "#define        _Imaginary_I    _Imaginary_I\n"
3374                 "#define        imaginary       _Imaginary\n"
3375                 "#undef I\n"
3376                 "#define        I               _Imaginary_I";
3377 };
3378
3379
3380 /*
3381  * Solaris 10+ <complex.h> is wrapped in #ifndef __cplusplus.  Wrap in
3382  * extern "C" instead so libstdc++ can use it.
3383  */
3384 fix = {
3385     hackname  = solaris_complex_cxx;
3386     mach      = "*-*-solaris2.*";
3387     files     = complex.h;
3388     sed       = "/#if[ \t]*!defined(__cplusplus)/c\\\n"
3389                 "#ifdef\t__cplusplus\\\nextern \"C\" {\\\n#endif";
3390     sed       = "/#endif[ \t]*\\/\\* !defined(__cplusplus) \\*\\//c\\\n"
3391                 "#ifdef\t__cplusplus\\\n}\\\n#endif";
3392     test_text = "#if !defined(__cplusplus)\n"
3393                 "#endif /* !defined(__cplusplus) */";
3394 };
3395
3396
3397 /*
3398  * Solaris 8 PTHREAD_COND_INITIALIZER lacks the __pthread_cond_magic field.
3399  * COND_MAGIC is only defined in <synch.h> and pollutes the namespace, so
3400  * use the value literally instead.
3401  */
3402 fix = {
3403     hackname = solaris_cond_init;
3404     select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3405     files = pthread.h;
3406     mach = '*-*-solaris2.8';
3407     c_fix = format;
3408     c_fix_arg = "%1, 0x4356%2";
3409     c_fix_arg = "^(#define[ \t]+PTHREAD_COND_INITIALIZER[ \t]+"
3410                 "\\{.*0)(\\},[ \t]*0\\}.*)$";
3411     test_text =
3412     '#pragma ident      "@(#)pthread.h  1.29    01/07/07 SMI"'"\n"
3413     '#define    PTHREAD_COND_INITIALIZER        {{{0}, 0}, 0}   /* = DEFAULTCV */';
3414 };
3415
3416
3417 /*
3418  *  g++ rejects functions declared with both C and C++ linkage.
3419  */
3420 fix = {
3421     hackname  = solaris_cxx_linkage;
3422     mach      = '*-*-solaris2*';
3423     files     = "iso/stdlib_iso.h";
3424     select    = "(#if __cplusplus >= 199711L)\n"
3425                 "(extern \"C\\+\\+\" \\{\n)"
3426                 "(.*(bsearch|qsort).*)";
3427     c_fix     = format;
3428     c_fix_arg = "%1 && !__GNUG__\n%2%3";
3429
3430     test_text =
3431     "#if __cplusplus >= 199711L\n"
3432     "extern \"C++\" {\n"
3433     "   void *bsearch(const void *, const void *, size_t, size_t,";
3434 };
3435
3436
3437 /*
3438  *  Solaris <iso/stdio_iso.h> doesn't declare getc for C++ with
3439  *  _STRICT_STDC, but uses it.
3440  */
3441 fix = {
3442     hackname  = solaris_getc_strict_stdc;
3443     mach      = "*-*-solaris2*";
3444     files     = "iso/stdio_iso.h";
3445     select    = "(.*&& )!defined\\(_STRICT_STDC\\)(.*)";
3446     c_fix     = format;
3447     c_fix_arg = "%1(!defined(_STRICT_STDC) || (__cplusplus >= 199711L))%2";
3448
3449     test_text =
3450     "#if        !defined(_REENTRANT) && !defined(_LP64) && !defined(_STRICT_STDC)";
3451 };
3452
3453
3454 /*
3455  *  Before Solaris 10, <iso/setjmp_iso.h> doesn't mark longjump noreturn.
3456  */
3457 fix = {
3458     hackname  = solaris_longjmp_noreturn;
3459     mach      = "*-*-solaris2*";
3460     files     = "iso/setjmp_iso.h";
3461     bypass    = "__NORETURN";
3462     select    = "(.*longjmp\\(jmp_buf.*[^)]+\\));";
3463     c_fix     = format;
3464     c_fix_arg = "%1 __attribute__ ((__noreturn__));";
3465
3466     test_text = "extern void longjmp(jmp_buf, int);";
3467 };
3468
3469
3470 /*
3471  * Sun Solaris 10 defines several C99 math macros in terms of
3472  * builtins specific to the Studio compiler, in particular not
3473  * compatible with the GNU compiler.
3474  */
3475 fix = {
3476     hackname = solaris_math_1;
3477     select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3478     bypass = "__GNUC__";
3479     files = iso/math_c99.h;
3480     c_fix = format;
3481     c_fix_arg = "#define\tHUGE_VA%1\t(__builtin_huge_va%2())";
3482     c_fix_arg = "^#define[ \t]+HUGE_VA([LF]+)[ \t]+__builtin_huge_va([lf]+)";
3483     test_text =
3484     '#ident     "@(#)math_c99.h 1.9     04/11/01 SMI"'"\n"
3485     "#undef     HUGE_VAL\n"
3486     "#define    HUGE_VAL        __builtin_huge_val\n"
3487     "#undef     HUGE_VALF\n"
3488     "#define    HUGE_VALF       __builtin_huge_valf\n"
3489     "#undef     HUGE_VALL\n"
3490     "#define    HUGE_VALL       __builtin_huge_vall";
3491 };
3492
3493 fix = {
3494     hackname = solaris_math_2;
3495     select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3496     bypass = "__GNUC__";
3497     files = iso/math_c99.h;
3498     c_fix = format;
3499     c_fix_arg = "#define\tINFINITY\t(__builtin_inff())";
3500     c_fix_arg = "^#define[ \t]+INFINITY[ \t]+__builtin_infinity";
3501     test_text =
3502     '#ident     "@(#)math_c99.h 1.9     04/11/01 SMI"'"\n"
3503     "#undef     INFINITY\n"
3504     "#define    INFINITY        __builtin_infinity";
3505 };
3506
3507 fix = {
3508     hackname = solaris_math_3;
3509     select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3510     bypass = "__GNUC__";
3511     files = iso/math_c99.h;
3512     c_fix = format;
3513     c_fix_arg = "#define\tNAN\t\t(__builtin_nanf(\"\"))";
3514     c_fix_arg = "^#define[ \t]+NAN[ \t]+__builtin_nan";
3515     test_text =
3516     '#ident     "@(#)math_c99.h 1.9     04/11/01 SMI"'"\n"
3517     "#undef     NAN\n"
3518     "#define    NAN     __builtin_nan";
3519 };
3520
3521 fix = {
3522     hackname = solaris_math_4;
3523     select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3524     bypass = "__GNUC__";
3525     files = iso/math_c99.h;
3526     c_fix = format;
3527     c_fix_arg = "#define\tfpclassify(x) \\\n"
3528                 "  __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, (x))";
3529     c_fix_arg = "^#define[ \t]+fpclassify\\(x\\)[ \t]+__builtin_fpclassify\\(x\\)";
3530     test_text =
3531     '#ident     "@(#)math_c99.h 1.9     04/11/01 SMI"'"\n"
3532     "#undef     fpclassify\n"
3533     "#define    fpclassify(x)   __builtin_fpclassify(x)";
3534 };
3535
3536 fix = {
3537     hackname = solaris_math_8;
3538     select = '@\(#\)math_c99\.h' "[ \t]+1\\.[0-9]+[ \t]+[0-9/]+ SMI";
3539     bypass = "__GNUC__";
3540     files = iso/math_c99.h;
3541     c_fix = format;
3542     c_fix_arg = "#define\tsignbit(x)\t(sizeof(x) == sizeof(float) \\\n"
3543                 "\t\t\t   ? __builtin_signbitf(x) \\\n"
3544                 "\t\t\t   : sizeof(x) == sizeof(long double) \\\n"
3545                 "\t\t\t     ? __builtin_signbitl(x) \\\n"
3546                 "\t\t\t     : __builtin_signbit(x))";
3547     c_fix_arg = "^#define[ \t]+signbit\\(x\\)[ \t]+__builtin_signbit\\(x\\)";
3548     test_text = <<- _EOText_
3549         #ident  "@(#)math_c99.h 1.9     04/11/01 SMI"
3550         #undef  signbit
3551         #define signbit(x)      __builtin_signbit(x)
3552         _EOText_;
3553 };
3554
3555 fix = {
3556     hackname = solaris_math_9;
3557     select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3558     bypass = "__GNUC__";
3559     files = iso/math_c99.h;
3560     c_fix = format;
3561     c_fix_arg = "#define\t%1(x, y)%2__builtin_%1(x, y)";
3562     c_fix_arg = "^#define[ \t]+([a-z]+)\\(x, y\\)([ \t]+)\\(\\(x\\) __builtin_[a-z]+\\(y\\)\\)";
3563     test_text =
3564     '#ident     "@(#)math_c99.h 1.9     04/11/01 SMI"'"\n"
3565     "#undef     isgreater\n"
3566     "#define    isgreater(x, y)         ((x) __builtin_isgreater(y))\n"
3567     "#undef     isgreaterequal\n"
3568     "#define    isgreaterequal(x, y)    ((x) __builtin_isgreaterequal(y))\n"
3569     "#undef     isless\n"
3570     "#define    isless(x, y)            ((x) __builtin_isless(y))\n"
3571     "#undef     islessequal\n"
3572     "#define    islessequal(x, y)       ((x) __builtin_islessequal(y))\n"
3573     "#undef     islessgreater\n"
3574     "#define    islessgreater(x, y)     ((x) __builtin_islessgreater(y))\n"
3575     "#undef     isunordered\n"
3576     "#define    isunordered(x, y)       ((x) __builtin_isunordered(y))";
3577 };
3578
3579 /*
3580  * On Solaris 11, if you do isinf(NaN) you'll get a floating point
3581  * exception.  Provide an alternative using GCC's builtin.
3582  */
3583
3584 fix = {
3585     hackname  = solaris_math_10;
3586     select    = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3587     files     = iso/math_c99.h;
3588     c_fix     = format;
3589     c_fix_arg = "#define\tisinf(x) __builtin_isinf(x)";
3590     c_fix_arg = "^#define[ \t]+isinf\\(x\\)[ \t]+__extension__\\([ \t]*\\\\\n"
3591                 "[ \t]*\\{[ \t]*__typeof\\(x\\)[ \t]*__x_i[ \t]*=[ \t]*\\(x\\);[ \t]*\\\\\n"
3592                 "[ \t]*__x_i[ \t]*==[ \t]*\\(__typeof\\(__x_i\\)\\)[ \t]*INFINITY[ \t]*\\|\\|[ \t]*\\\\\n"
3593                 "[ \t]*__x_i[ \t]*==[ \t]*\\(__typeof\\(__x_i\\)\\)[ \t]*\\(-INFINITY\\);[ \t]*\\}\\)";
3594     test_text =
3595     '#pragma ident      "@(#)math_c99.h 1.12    07/01/21 SMI"'"\n"
3596     "#undef     isinf\n"
3597     "#define    isinf(x)        __extension__( \\\\\n"
3598     "                   { __typeof(x) __x_i = (x); \\\\\n"
3599     "                   __x_i == (__typeof(__x_i)) INFINITY || \\\\\n"
3600     "                   __x_i == (__typeof(__x_i)) (-INFINITY); })";
3601 };
3602
3603 /*
3604  * Sun Solaris defines PTHREAD_MUTEX_INITIALIZER with a trailing
3605  * "0" for the last field of the pthread_mutex_t structure, which is
3606  * of type upad64_t, which itself is typedef'd to int64_t, but with
3607  * __STDC__ defined (e.g. by -ansi) it is a union. So change the
3608  * initializer to "{0}" instead
3609  */
3610 fix = {
3611     hackname = solaris_mutex_init_2;
3612     select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3613     files = pthread.h;
3614     /*
3615      * On Solaris 10, this fix is unnecessary because upad64_t is
3616      * always defined correctly regardless of the definition of the
3617      * __STDC__ macro.  The first "mach" pattern matches up to
3618      * solaris9.  The second "mach" pattern will not match any two (or
3619      * more) digit solaris version, but it will match e.g. 2.5.1.
3620      */
3621     mach = '*-*-solaris2.[0-9]', '*-*-solaris2.[0-9][!0-9]*';
3622     c_fix = format;
3623     c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3624                 "%0\n"
3625                 "#else\n"
3626                 "%1, {0}}%4\n"
3627                 "#endif";
3628     c_fix_arg = "(^#define[ \t]+PTHREAD_(MUTEX|COND)_INITIALIZER[ \t]+"
3629                 "(|/\*.*\*/[ \t]*\\\\\n[ \t]*)\\{.*)"
3630                 ",[ \t]*0\\}" "(|[ \t].*)$";
3631     test_text =
3632     '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
3633     "#define PTHREAD_MUTEX_INITIALIZER\t{{{0},0}, {{{0}}}, 0}\n"
3634     "#define PTHREAD_COND_INITIALIZER\t{{{0}, 0}, 0}\t/* DEFAULTCV */\n"
3635     "#define    PTHREAD_MUTEX_INITIALIZER               /* = DEFAULTMUTEX */    \\\\\n"
3636     "   {{0, 0, 0, DEFAULT_TYPE, _MUTEX_MAGIC}, {{{0}}}, 0}\n"
3637     "#define    PTHREAD_COND_INITIALIZER                /* = DEFAULTCV */       \\\\\n"
3638     "   {{{0, 0, 0, 0}, DEFAULT_TYPE, _COND_MAGIC}, 0}";
3639 };
3640
3641
3642 /*
3643  *  The pow overloads with int were removed in C++ 2011.
3644  */
3645 fix = {
3646     hackname  = solaris_pow_int_overload;
3647     mach      = '*-*-solaris2*';
3648     files     = "iso/math_iso.h";
3649     select    = "^[ \t]*inline [a-z ]* pow\\([^()]*, int [^()]*\\)"
3650                 " *\\{[^{}]*\n[^{}]*\\}";
3651     c_fix     = format;
3652     c_fix_arg = "#ifndef __GXX_EXPERIMENTAL_CXX0X__\n%0\n#endif";
3653
3654     test_text =
3655     "   inline long double pow(long double __X, int __Y) { return\n"
3656     "           __powl(__X, (long double) (__Y)); }";
3657 };
3658
3659
3660 /*
3661  * Sun Solaris defines PTHREAD_RWLOCK_INITIALIZER with a "0" for some
3662  *  fields of the pthread_rwlock_t structure, which are of type
3663  *  upad64_t, which itself is typedef'd to int64_t, but with __STDC__
3664  *  defined (e.g. by -ansi) it is a union. So change the initializer
3665  *  to "{0}" instead.
3666  */
3667 fix = {
3668     hackname = solaris_rwlock_init_1;
3669     select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3670     files = pthread.h;
3671     mach = '*-*-solaris*';
3672     c_fix = format;
3673     c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3674                 "%0\n"
3675                 "#else\n"
3676                 "%1{0, 0, 0, {{0}, {0}, {0}}, {{0}, {0}}, {{0}, {0}}}\n"
3677                 "#endif";
3678     c_fix_arg = "(^#define[ \t]+PTHREAD_RWLOCK_INITIALIZER[ \t]+)"
3679                 "\\{0, 0, 0, \\{0, 0, 0\\}, \\{0, 0\\}, \\{0, 0\\}\\}[ \t]*$";
3680
3681     test_text =
3682     '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
3683     "#define PTHREAD_RWLOCK_INITIALIZER\t{0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}}";
3684 };
3685
3686
3687 /*
3688  * Sun Solaris defines PTHREAD_ONCE_INIT as an array containing a
3689  * structure.  As such, it need two levels of brackets, but only
3690  * contains one.  Wrap the macro definition in an extra layer.
3691  */
3692 fix = {
3693     hackname = solaris_once_init_1;
3694     select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3695     files = pthread.h;
3696     mach = '*-*-solaris*';
3697     c_fix = format;
3698     c_fix_arg = "%1{%2}%3";
3699     c_fix_arg = "(^#define[ \t]+PTHREAD_ONCE_INIT[ \t]+\\{)([^}]+)(\\})[ \t]*$";
3700     test_text =
3701     '#pragma ident      "@(#)pthread.h  1.37    04/09/28 SMI"'"\n"
3702     "#define PTHREAD_ONCE_INIT\t{0, 0, 0, PTHREAD_ONCE_NOTDONE}";
3703 };
3704
3705
3706 /*
3707  * Sun Solaris defines PTHREAD_ONCE_INIT with a "0" for some
3708  *  fields of the pthread_once_t structure, which are of type
3709  *  upad64_t, which itself is typedef'd to int64_t, but with __STDC__
3710  *  defined (e.g. by -ansi) it is a union. So change the initializer
3711  *  to "{0}" instead.  This test relies on solaris_once_init_1.
3712  */
3713 fix = {
3714     hackname = solaris_once_init_2;
3715     select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3716     files = pthread.h;
3717     /*
3718      * On Solaris 10, this fix is unnecessary because upad64_t is
3719      * always defined correctly regardless of the definition of the
3720      * __STDC__ macro.  The first "mach" pattern matches up to
3721      * solaris9.  The second "mach" pattern will not match any two (or
3722      * more) digit solaris version, but it will match e.g. 2.5.1.
3723      */
3724     mach = '*-*-solaris2.[0-9]', '*-*-solaris2.[0-9][!0-9]*';
3725     c_fix = format;
3726     c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3727                 "%0\n"
3728                 "#else\n"
3729                 "%1{0}, {0}, {0}, {%3}%4\n"
3730                 "#endif";
3731     c_fix_arg = "(^#define[ \t]+PTHREAD_ONCE_INIT[ \t]+\\{\\{)"
3732                 "(0, 0, 0, )(PTHREAD_[A-Z_]+)(\\}\\})[ \t]*$";
3733     test_text =
3734     '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
3735     "#define PTHREAD_ONCE_INIT\t{{0, 0, 0, PTHREAD_ONCE_NOTDONE}}\n";
3736 };
3737
3738
3739 /*
3740  * Sun Solaris 2 has a version of sys/int_const.h that defines
3741  * UINT8_C and UINT16_C to unsigned constants.
3742  */
3743 fix = {
3744     hackname  = solaris_int_const;
3745     files     = sys/int_const.h;
3746     mach      = '*-*-solaris2*';
3747     c_fix     = format;
3748     c_fix_arg = "#define\tUINT8_C(c)\t(c)\n"
3749                 "%1\n"
3750                 "#define\tUINT16_C(c)\t(c)";
3751     select    = "^#define[ \t]+UINT8_C\\(c\\)[ \t]+__CONCAT__.*\n"
3752                 "(/\*.*\*/)\n"
3753                 "#define[ \t]+UINT16_C\\(c\\)[ \t]+__CONCAT__.*";
3754     test_text =
3755     "#define    UINT8_C(c)      __CONCAT__(c,u)\n"
3756     "/* CSTYLED */\n"
3757     "#define    UINT16_C(c)     __CONCAT__(c,u)";
3758 };
3759
3760
3761 /*
3762  * Sun Solaris 2 has a version of sys/int_limits.h that defines
3763  * UINT8_MAX and UINT16_MAX to unsigned constants.
3764  */
3765 fix = {
3766     hackname  = solaris_int_limits_1;
3767     files     = sys/int_limits.h;
3768     mach      = '*-*-solaris2*';
3769     c_fix     = format;
3770     c_fix_arg = "#define\tUINT8_MAX\t(255)\n"
3771                 "#define\tUINT16_MAX\t(65535)";
3772     select    = "^#define[ \t]+UINT8_MAX[ \t]+\\(255U\\)\n"
3773                 "#define[ \t]+UINT16_MAX[ \t]+\\(65535U\\)";
3774     test_text =
3775     "#define    UINT8_MAX       (255U)\n"
3776     "#define    UINT16_MAX      (65535U)";
3777 };
3778
3779
3780 /*
3781  * Sun Solaris 2 has a version of sys/int_limits.h that defines
3782  * INT_FAST16 limits to wrong values for sys/int_types.h.
3783  */
3784 fix = {
3785     hackname  = solaris_int_limits_2;
3786     files     = sys/int_limits.h;
3787     mach      = '*-*-solaris2*';
3788     c_fix     = format;
3789     c_fix_arg = "#define\t%1_FAST16_%2 %132_%2";
3790     select    = "^#define[ \t]+(INT|UINT)_FAST16_(MAX|MIN)[ \t](INT|UINT)16.*";
3791     test_text =
3792     "#define    INT_FAST16_MAX INT16_MAX\n"
3793     "#define    UINT_FAST16_MAX UINT16_MAX\n"
3794     "#define    INT_FAST16_MIN  INT16_MIN";
3795 };
3796
3797
3798 /*
3799  * Sun Solaris 2 has a version of sys/int_limits.h that defines
3800  * SIZE_MAX as unsigned long.
3801  */
3802 fix = {
3803     hackname  = solaris_int_limits_3;
3804     files     = sys/int_limits.h;
3805     mach      = '*-*-solaris2*';
3806     c_fix     = format;
3807     c_fix_arg = "#define\tSIZE_MAX\t4294967295U";
3808     select    = "^#define[ \t]+SIZE_MAX[ \t]+4294967295UL";
3809     test_text =
3810     "#define    SIZE_MAX        4294967295UL";
3811 };
3812
3813
3814 /*
3815  * Sun Solaris up to 9 has a version of sys/int_types.h that forbids use
3816  * of Standard C99 64-bit types in 32-bit mode.
3817  */
3818 fix = {
3819     hackname  = solaris_int_types;
3820     select    = "__STDC__ - 0 == 0";
3821     bypass    = "_LONGLONG_TYPE";
3822     files     = sys/int_types.h;
3823     c_fix     = format;
3824     c_fix_arg =
3825     "(defined(_STDC_C99) || !defined(_STRICT_STDC) || defined(__GNUC__))";
3826     test_text =
3827     "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3828     "typedef    long long               int64_t;\n"
3829     "#endif\n\n"
3830     "#if defined(_LP64) || (__STDC__ - 0 == 0 && !defined(_NO_LONGLONG))\n"
3831     "typedef int64_t                    intmax_t;\n"
3832     "#endif";
3833 };
3834
3835
3836 /*
3837  * Solaris 10+ <spawn.h> uses char *const argv[_RESTRICT_KYWD] in the
3838  * posix_spawn declarations, which doesn't work with C++.
3839  */
3840 fix = {
3841     hackname  = solaris_posix_spawn_restrict;
3842     files     = spawn.h;
3843     mach      = '*-*-solaris2*';
3844     c_fix     = format;
3845     c_fix_arg = "%1*_RESTRICT_KYWD %2%3";
3846     select    = "(.*[ \t]+)([a-z]+)\\[_RESTRICT_KYWD\\](.*)";
3847     test_text =
3848     "char *const argv[_RESTRICT_KYWD],\n"
3849     "char *const envp[_RESTRICT_KYWD]);";
3850 };
3851
3852
3853 /*
3854  * Before Solaris 10, <stdio.h> lacks declarations of std::__filbuf and
3855  * std::__flsbuf, but <iso/stdio_iso.h> uses them.
3856  */
3857 fix = {
3858     hackname  = solaris_std___filbuf;
3859     files     = stdio.h;
3860     mach      = '*-*-solaris2*';
3861     bypass    = "using std::__filbuf";
3862     select    = "(using std::perror;\n)(#endif)";
3863     c_fix     = format;
3864     c_fix_arg = "%1#ifndef _LP64\n"
3865                 "using std::__filbuf;\n"
3866                 "using std::__flsbuf;\n"
3867                 "#endif\n%2";
3868
3869     test_text = "using std::perror;\n"
3870                 "#endif";
3871 };
3872
3873
3874 /*
3875  * Sun Solaris 8 has what appears to be some gross workaround for
3876  * some old version of their c++ compiler.  G++ doesn't want it
3877  * either, but doesn't want to be tied to SunPRO version numbers.
3878  */
3879 fix = {
3880     hackname = solaris_stdio_tag;
3881     files    = stdio_tag.h;
3882
3883     select   = '__cplusplus < 54321L';
3884     /* In Solaris 10, the code in stdio_tag.h is conditionalized on 
3885        "!defined(__GNUC__)" so we no longer need to fix it.  */
3886     bypass   = '__GNUC__';
3887     sed      = 's/defined(__cplusplus) && (__cplusplus < 54321L)/0/';
3888
3889     test_text = "#if\tdefined(__cplusplus) && (__cplusplus < 54321L)";
3890 };
3891
3892
3893 /*
3894  * On Solaris 8 and 9, __va_list needs to become a typedef for
3895  * __builtin_va_list to make -Wmissing-format-attribute work.
3896  */
3897 fix = {
3898     hackname = solaris_sys_va_list;
3899     files    = sys/va_list.h;
3900     mach     = '*-*-solaris2.[89]';
3901     select   = "#if.*__STDC__.*\n"
3902                "typedef void \\*__va_list;\n"
3903                "#else\n"
3904                "typedef char \\*__va_list;\n"
3905                "#endif";
3906
3907     c_fix    = format;
3908     c_fix_arg = "#ifdef __GNUC__\n"
3909                 "typedef __builtin_va_list __va_list;\n"
3910                 "#else\n"
3911                 "%0\n"
3912                 "#endif";
3913     test_text = "#if defined(__STDC__) && !defined(__ia64)\n"
3914                 "typedef void *__va_list;\n"
3915                 "#else\n"
3916                 "typedef char *__va_list;\n"
3917                 "#endif";
3918 };
3919
3920
3921 /*
3922  *  a missing semi-colon at the end of the statsswtch structure definition.
3923  */
3924 fix = {
3925     hackname  = statsswtch;
3926     files     = rpcsvc/rstat.h;
3927     select    = "boottime$";
3928     c_fix     = format;
3929     c_fix_arg = "boottime;";
3930     test_text = "struct statswtch {\n  int boottime\n};";
3931 };
3932
3933
3934 /*
3935  *  Arrange for stdio.h to use stdarg.h to define __gnuc_va_list.
3936  *  On 4BSD-derived systems, stdio.h defers to machine/ansi.h; that's
3937  *  OK too.
3938  */
3939 fix = {
3940     hackname = stdio_stdarg_h;
3941     files    = stdio.h;
3942     bypass   = "include.*(stdarg\.h|machine/ansi\.h)";
3943     /*
3944      * On Solaris 10, this fix is unncessary; <stdio.h> includes
3945      * <iso/stdio_iso.h>, which includes <sys/va_list.h>.
3946       */
3947     mach     = '*-*-solaris2.1[0-9]*';
3948     not_machine = true;
3949
3950     c_fix     = wrap;
3951
3952     c_fix_arg = "#define __need___va_list\n#include <stdarg.h>\n";
3953
3954     test_text = "";
3955 };
3956
3957
3958 /*
3959  *  Don't use or define the name va_list in stdio.h.  This is for
3960  *  ANSI.  Note _BSD_VA_LIST_ is dealt with elsewhere.  The presence
3961  *  of __gnuc_va_list, __DJ_va_list, or _G_va_list is taken to
3962  *  indicate that the header knows what it's doing -- under SUSv2,
3963  *  stdio.h is required to define va_list, and we shouldn't break
3964  *  that.  On IRIX 6.5, internal/wchar_core.h used to get its
3965  *  definition of va_list from stdio.h.  Since this doesn't happen any
3966  *  longer, use __gnuc_va_list there, too.
3967  */
3968 fix = {
3969     hackname = stdio_va_list;
3970     files    = stdio.h;
3971     files    = internal/stdio_core.h;
3972     files    = internal/wchar_core.h;
3973     bypass   = '__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list';
3974     /* 
3975      * On Solaris 10, the definition in 
3976      * <stdio.h> is guarded appropriately by the _XPG4 feature macro; 
3977      * there is therefore no need for this fix there.
3978      */
3979     mach = '*-*-solaris2.1[0-9]*';
3980     not_machine = true;
3981
3982     /*
3983      * Use __gnuc_va_list in arg types in place of va_list.
3984      * On 386BSD use __gnuc_va_list instead of _VA_LIST_.  On Tru64 UNIX V5.1A
3985      * use __gnuc_va_list instead of __VA_LIST__.  We're hoping the
3986      * trailing parentheses and semicolon save all other systems from this.
3987      * Define __not_va_list__ (something harmless and unused)
3988      * instead of va_list.
3989      * Don't claim to have defined va_list.
3990      */
3991     sed = "s@[ \t]va_list\\([ \t)]\\)@ __gnuc_va_list\\1@\n"
3992           "s@(va_list)&@(__gnuc_va_list)\\&@\n"
3993           "s@ _VA_LIST_));@ __gnuc_va_list));@\n"
3994           "s@ __VA_LIST__));@ __gnuc_va_list));@\n"
3995           "s@ va_list@ __not_va_list__@\n"
3996           "s@\\*va_list@*__not_va_list__@\n"
3997           "s@ __va_list)@ __gnuc_va_list)@\n"
3998           "s@typedef[ \t]\\(.*\\)[ \t]va_list[ \t]*;"
3999            "@typedef \\1 __not_va_list__;@\n"
4000           "s@typedef[ \t]*__va_list__@typedef __gnuc_va_list@\n"
4001           "s@GNUC_VA_LIST@GNUC_Va_LIST@\n"
4002           "s@_VA_LIST_DEFINED@_Va_LIST_DEFINED@\n"
4003           "s@_NEED___VA_LIST@_NEED___Va_LIST@\n"
4004           "s@VA_LIST@DUMMY_VA_LIST@\n"
4005           "s@_Va_LIST@_VA_LIST@";
4006     test_text = "extern void mumble( va_list);";
4007 };
4008
4009
4010 /*
4011  *  Fix headers that use va_list from stdio.h to use the updated
4012  *  va_list from the stdio_va_list change.  Note _BSD_VA_LIST_ is
4013  *  dealt with elsewhere.  The presence of __gnuc_va_list,
4014  *  __DJ_va_list, or _G_va_list is taken to indicate that the header
4015  *  knows what it's doing.
4016  */
4017 fix = {
4018     hackname = stdio_va_list_clients;
4019     files    = com_err.h;
4020     files    = cps.h;
4021     files    = curses.h;
4022     files    = krb5.h;
4023     files    = lc_core.h;
4024     files    = pfmt.h;
4025     files    = wchar.h;
4026     files    = curses_colr/curses.h;
4027     bypass   = '__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list';
4028     /* Don't fix, if we use va_list from stdarg.h, or if the use is
4029        otherwise protected.  */
4030     bypass   = 'include <stdarg\.h>|#ifdef va_start';
4031
4032     /*
4033      * Use __gnuc_va_list in arg types in place of va_list.
4034      * On 386BSD use __gnuc_va_list instead of _VA_LIST_.  On Tru64 UNIX V5.1A
4035      * use __gnuc_va_list instead of __VA_LIST__.  We're hoping the
4036      * trailing parentheses and semicolon save all other systems from this.
4037      * Define __not_va_list__ (something harmless and unused)
4038      * instead of va_list.
4039      * Don't claim to have defined va_list.
4040      */
4041     sed = "s@[ \t]va_list\\([ \t)]\\)@ __gnuc_va_list\\1@\n"
4042           "s@(va_list)&@(__gnuc_va_list)\\&@\n"
4043           "s@ _VA_LIST_));@ __gnuc_va_list));@\n"
4044           "s@ __VA_LIST__));@ __gnuc_va_list));@\n"
4045           "s@ va_list@ __not_va_list__@\n"
4046           "s@\\*va_list@*__not_va_list__@\n"
4047           "s@ __va_list)@ __gnuc_va_list)@\n"
4048           "s@typedef[ \t]\\(.*\\)[ \t]va_list[ \t]*;"
4049            "@typedef \\1 __not_va_list__;@\n"
4050           "s@typedef[ \t]*__va_list__@typedef __gnuc_va_list@\n"
4051           "s@GNUC_VA_LIST@GNUC_Va_LIST@\n"
4052           "s@_VA_LIST_DEFINED@_Va_LIST_DEFINED@\n"
4053           "s@_NEED___VA_LIST@_NEED___Va_LIST@\n"
4054           "s@VA_LIST@DUMMY_VA_LIST@\n"
4055           "s@_Va_LIST@_VA_LIST@";
4056     test_text = "extern void mumble( va_list);";
4057 };
4058
4059
4060 /*
4061  *  "!__STDC__" or "__STDC__==0" or "__STDC__!=1" or "__STDC__-0==0"
4062  *  is "!defined( __STRICT_ANSI__ )"
4063  */
4064 fix = {
4065     hackname = strict_ansi_not;
4066     select   = "^([ \t]*#[ \t]*if.*)"
4067                "(!__STDC__"
4068                "|__STDC__[ \t]*==[ \t]*0"
4069                "|__STDC__[ \t]*!=[ \t]*1"
4070                "|__STDC__[ \t]*-[ \t]*0[ \t]*==[ \t]*0)";
4071     /* Tru64 UNIX V4.0F/V5.1 <standards.h> supports GCC usage of __STDC__. */
4072     bypass = 'GNU and MIPS C compilers define __STDC__ differently';
4073     /* GNU gmp.h uses "__STDC__ != 1" only if __SCO_VERSION__, which
4074        is not defined by GCC, so it is safe.  */
4075     bypass = '__SCO_VERSION__.*__STDC__ != 1';
4076     c_test   = stdc_0_in_system_headers;
4077
4078     c_fix     = format;
4079     c_fix_arg = "%1 !defined(__STRICT_ANSI__)";
4080
4081     test_text = "#if !__STDC__ \n"
4082                 "#if __STDC__ == 0\n"
4083                 "#if __STDC__ != 1\n"
4084                 "#if __STDC__ - 0 == 0"
4085                "/* not std C */\nint foo;\n"
4086                "\n#end-end-end-end-if :-)";
4087 };
4088
4089 /*
4090  *  "__STDC__-0==0"
4091  *  is "!defined( __STRICT_ANSI__ )" on continued #if-s
4092  */
4093 fix = {
4094     hackname = strict_ansi_not_ctd;
4095     files    = math.h, limits.h, stdio.h, signal.h,
4096                stdlib.h, sys/signal.h, time.h;
4097     /*
4098      * Starting at the beginning of a line, skip white space and
4099      * a leading "(" or "&&" or "||".  One of those must be found.
4100      * Then, zero, one or more copies of a "defined(_FOO_BAR_) &&"
4101      * expression.  If these are nested, then they must accumulate
4102      * because we won't match any closing parentheses.  Finally,
4103      * after skipping over all that, we must then match our suspect
4104      * phrase:  "__STDC__-0==0" with or without white space.
4105      */
4106     select   = "^([ \t]*" '(\(|&&|\|\|)'
4107                "([ \t(]*!*[ \t]*defined\\([a-zA-Z_0-9]+\\)[ \t]*[|&][|&])*"
4108                "[ \t(]*)"
4109                "(__STDC__[ \t]*(|-[ \t]*0[ \t]*)==[ \t]*0)";
4110     c_test   = stdc_0_in_system_headers;
4111
4112     c_fix     = format;
4113     c_fix_arg = "%1 !defined(__STRICT_ANSI__)";
4114
4115     test_text = "#if 1 && \\\\\n"
4116                "&& defined(mumbling) |& (__STDC__ - 0 == 0) \\\\\n"
4117                "( __STDC__ == 0 && !defined(_XOPEN_SOURCE) \\\\\n"
4118                "|| __STDC__ - 0 == 0 ) /* not std C */\n"
4119                "int foo;\n#endif";
4120 };
4121
4122
4123 /*
4124  *  "__STDC__!=0" or "__STDC__==1" or "__STDC__-0==1"
4125  *  is "defined( __STRICT_ANSI__ )"
4126  */
4127 fix = {
4128     hackname = strict_ansi_only;
4129     select   = "^([ \t]*#[ \t]*if.*)"
4130                "(__STDC__[ \t]*!=[ \t]*0"
4131                "|__STDC__[ \t]*==[ \t]*1"
4132                "|__STDC__[ \t]*-[ \t]*0[ \t]*==[ \t]*1"
4133                "|__STDC__[ \t]*-[ \t]*0[ \t]*!=[ \t]*0)";
4134     c_test   = stdc_0_in_system_headers;
4135
4136     c_fix     = format;
4137     c_fix_arg = "%1 defined(__STRICT_ANSI__)";
4138
4139     test_text = "#if __STDC__ == 1 /* is std C\n */\nint foo;\n#endif";
4140 };
4141
4142
4143 /*
4144  *  IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s
4145  *  in prototype without previous definition.
4146  */
4147 fix = {
4148     hackname  = struct_file;
4149     files     = rpc/xdr.h;
4150     select    = '^.*xdrstdio_create.*struct __file_s';
4151     c_fix     = format;
4152     c_fix_arg = "struct __file_s;\n%0";
4153     test_text = "extern void xdrstdio_create( struct __file_s* );";
4154 };
4155
4156
4157 /*
4158  *  IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr
4159  *  in prototype without previous definition.
4160  *
4161  *  Don't fix OpenBSD, which uses struct sockaddr_in prototyping the same
4162  *  function, and does define it.
4163  */
4164 fix = {
4165     hackname  = struct_sockaddr;
4166     files     = rpc/auth.h;
4167     select    = "^.*authdes_create.*struct sockaddr[^_]";
4168     bypass    = "<sys/socket\.h>";
4169     bypass    = "struct sockaddr;\n";
4170     c_fix     = format;
4171     c_fix_arg = "struct sockaddr;\n%0";
4172     test_text = "extern AUTH* authdes_create( struct sockaddr* );";
4173 };
4174
4175
4176 /*
4177  *  Apply fix this to all OSs since this problem seems to effect
4178  *  more than just SunOS.
4179  */
4180 fix = {
4181     hackname = sun_auth_proto;
4182     files    = rpc/auth.h;
4183     files    = rpc/clnt.h;
4184     files    = rpc/svc.h;
4185     files    = rpc/xdr.h;
4186     bypass   = "__cplusplus";
4187     /*
4188      *  Select those files containing '(*name)()'.
4189      */
4190     select    = '\(\*[a-z][a-z_]*\)\(\)';
4191
4192     c_fix     = format;
4193     c_fix_arg = "#ifdef __cplusplus\n%1(...);%2\n"
4194                 "#else\n%1();%2\n#endif";
4195     c_fix_arg = '(.*\(\*[a-z][a-z_]*\))\(\);(.*)';
4196
4197     test_text =
4198     "struct auth_t {\n"
4199     "    int (*name)(); /* C++ bad */\n"
4200     "};";
4201 };
4202
4203
4204 /*
4205  *  Fix bogus #ifdef on SunOS 4.1.
4206  */
4207 fix = {
4208     hackname  = sun_bogus_ifdef;
4209     files     = "hsfs/hsfs_spec.h";
4210     files     = "hsfs/iso_spec.h";
4211     select    = '#ifdef(.*\|\|.*)';
4212     c_fix     = format;
4213     c_fix_arg = "#if%1";
4214
4215     test_text = "#ifdef  __i386__ || __vax__ || __sun4c__";
4216 };
4217
4218
4219 /*
4220  *  Fix the CAT macro in SunOS memvar.h.
4221  */
4222 fix = {
4223     hackname  = sun_catmacro;
4224     files     = pixrect/memvar.h;
4225     select    = "^#define[ \t]+CAT\\(a,b\\).*";
4226     c_fix     = format;
4227
4228     c_fix_arg =
4229     "#ifdef __STDC__\n"
4230     "#  define CAT(a,b) a##b\n"
4231     "#else\n%0\n#endif";
4232
4233     test_text =
4234     "#define CAT(a,b)\ta/**/b";
4235 };
4236
4237
4238 /*
4239  *  Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
4240  *  Also fix return type of {m,re}alloc in <malloc.h> on sysV68
4241  */
4242 fix = {
4243     hackname = sun_malloc;
4244     files    = malloc.h;
4245     bypass   = "_CLASSIC_ANSI_TYPES";
4246
4247     sed   = "s/typedef[ \t]char \\*\tmalloc_t/typedef void \\*\tmalloc_t/g";
4248     sed   = "s/int[ \t][ \t]*free/void\tfree/g";
4249     sed   = "s/char\\([ \t]*\\*[ \t]*malloc\\)/void\\1/g";
4250     sed   = "s/char\\([ \t]*\\*[ \t]*realloc\\)/void\\1/g";
4251     sed   = "s/char\\([ \t]*\\*[ \t]*calloc\\)/void\\1/g";
4252
4253     test_text =
4254     "typedef char *\tmalloc_t;\n"
4255     "int \tfree();\n"
4256     "char*\tmalloc();\n"
4257     "char*\tcalloc();\n"
4258     "char*\trealloc();";
4259 };
4260
4261
4262 /*
4263  *  Check for yet more missing ';' in struct (in SunOS 4.0.x)
4264  */
4265 fix = {
4266     hackname = sun_rusers_semi;
4267     files    = rpcsvc/rusers.h;
4268     select   = "_cnt$";
4269     sed      = "/^struct/,/^};/s/_cnt$/_cnt;/";
4270     test_text = "struct mumble\n  int _cnt\n};";
4271 };
4272
4273
4274 /*
4275  *  signal.h on SunOS defines signal using (),
4276  *  which causes trouble when compiling with g++ -pedantic.
4277  */
4278 fix = {
4279     hackname = sun_signal;
4280     files    = sys/signal.h;
4281     files    = signal.h;
4282     select   = "^void\t" '\(\*signal\(\)\)\(\);.*';
4283
4284     c_fix     = format;
4285     c_fix_arg =
4286           "#ifdef __cplusplus\n"
4287           "void\t(*signal(...))(...);\n"
4288           "#else\n%0\n#endif";
4289
4290     test_text = "void\t(*signal())();";
4291 };
4292
4293
4294 /*
4295  *  Correct the return type for strlen in strings.h in SunOS 4.
4296  */
4297 fix = {
4298     hackname = sunos_strlen;
4299     files    = strings.h;
4300     select   = "int[ \t]*strlen\\(\\);(.*)";
4301     c_fix     = format;
4302     c_fix_arg = "__SIZE_TYPE__ strlen();%1";
4303     test_text = " int\tstrlen(); /* string length */";
4304 };
4305
4306
4307 /*
4308  *  Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
4309  *  that is visible to any ANSI compiler using this include.  Simply
4310  *  delete the lines that #define some string functions to internal forms.
4311  */
4312 fix = {
4313     hackname = svr4_disable_opt;
4314     files    = string.h;
4315     select   = '#define.*__std_hdr_';
4316     sed      = '/#define.*__std_hdr_/d';
4317     test_text = "#define strlen __std_hdr_strlen\n";
4318 };
4319
4320
4321 /*
4322  *   Fix broken decl of getcwd present on some svr4 systems.
4323  */
4324 fix = {
4325     hackname = svr4_getcwd;
4326     files    = stdlib.h;
4327     files    = unistd.h;
4328     files    = prototypes.h;
4329     select   = 'getcwd\(char \*, int\)';
4330
4331     c_fix     = format;
4332     c_fix_arg = "getcwd(char *, size_t)";
4333
4334     test_text = "extern char* getcwd(char *, int);";
4335 };
4336
4337
4338 /*
4339  *   Fix broken decl of profil present on some svr4 systems.
4340  */
4341 fix = {
4342     hackname = svr4_profil;
4343     files    = stdlib.h;
4344     files    = unistd.h;
4345
4346     select    =
4347     'profil\(unsigned short \*, unsigned int, unsigned int, unsigned int\)';
4348     /* The fix is wrong on IRIX 5/6 and creates a conflict with another
4349        prototype in <sys/profil.h>.  */
4350     bypass    = 'Silicon Graphics';
4351     c_fix     = format;
4352     c_fix_arg = 'profil(unsigned short *, size_t, int, unsigned int)';
4353
4354     test_text =
4355     'profil(unsigned short *, unsigned int, unsigned int, unsigned int);';
4356 };
4357
4358
4359 /*
4360  * Correct types for signal handler constants like SIG_DFL; they might be
4361  * void (*) (), and should be void (*) (int).  C++ doesn't like the
4362  * old style.
4363  */
4364 fix = {
4365     hackname = svr4_sighandler_type;
4366     files = sys/signal.h;
4367     select = 'void *\(\*\)\(\)';
4368     c_fix = format;
4369     c_fix_arg = "void (*)(int)";
4370     test_text = "#define SIG_DFL (void(*)())0\n"
4371                 "#define SIG_IGN (void (*)())0\n";
4372 };
4373
4374
4375 /*
4376  *  Some SysV r4 systems, including Sequent's DYNIX/ptx, use the local
4377  *  function 'getrnge' in <regexp.h> before they declare it.  For these
4378  *  systems add a 'static int' declaration of 'getrnge' into <regexp.h>
4379  *  early on.
4380  *
4381  *  'getrnge' traditionally manipulates a file-scope global called 'size',
4382  *  so put the declaration right after the declaration of 'size'.
4383  *
4384  *  Don't do this if there is already a `static void getrnge' declaration
4385  *  present, since this would cause a redeclaration error.  Solaris 2.x has
4386  *  such a declaration.
4387  */
4388 fix = {
4389     hackname  = svr4_undeclared_getrnge;
4390     files     = regexp.h;
4391     select    = "getrnge";
4392     bypass    = "static void getrnge";
4393     c_fix     = format;
4394     c_fix_arg = "%0\n"
4395                 "static int getrnge ();";
4396     c_fix_arg = "^static int[ \t]+size;";
4397     test_text = "static int size;\n"
4398                 "/* stuff which calls getrnge() */\n"
4399                 "static getrnge()\n"
4400                 "{}";
4401 };
4402
4403
4404 /*
4405  *  Fix return value of mem{ccpy,chr,cpy,set} and str{len,spn,cspn}
4406  *  in string.h on sysV68
4407  *  Correct the return type for strlen in string.h on Lynx.
4408  *  Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
4409  *  Add missing const for strdup on OSF/1 V3.0.
4410  *  On sysV88 layout is slightly different.
4411  */
4412 fix = {
4413     hackname = sysv68_string;
4414     files    = testing.h;
4415     files    = string.h;
4416     bypass   = "_CLASSIC_ANSI_TYPES";
4417
4418     sed = "s/extern[ \t]*int[ \t]*strlen();/extern unsigned int strlen();/";
4419     sed = "s/extern[ \t]*int[ \t]*ffs[ \t]*(long);/extern int ffs(int);/";
4420     sed = "s/strdup(char \\*s1);/strdup(const char *s1);/";
4421
4422     sed = "/^extern char$/N";
4423     sed = "s/^extern char\\(\\n\t\\*memccpy(),\\)$/extern void\\1/";
4424
4425     sed = "/^extern int$/N";
4426     sed = "s/^extern int\\(\\n\tstrlen(),\\)/extern size_t\\1/";
4427
4428     sed = "/^\tstrncmp(),$/N";
4429     sed = 's/^\(' "\t" 'strncmp()\),\n\(' "\t" 'strlen(),\)$/'
4430             '\1;' "\\\nextern unsigned int\\\n\\2/";
4431
4432     test_text =
4433     "extern int strlen();\n"
4434
4435     "extern int ffs(long);\n"
4436
4437     "extern char\n"
4438     "\t*memccpy(),\n"
4439     "\tmemcpy();\n"
4440
4441     "extern int\n"
4442     "\tstrcmp(),\n"
4443     "\tstrncmp(),\n"
4444     "\tstrlen(),\n"
4445     "\tstrspn();\n"
4446
4447     "extern int\n"
4448     "\tstrlen(), strspn();";
4449 };
4450
4451
4452 /*
4453  *  Fix return type of calloc, malloc, realloc, bsearch and exit
4454  */
4455 fix = {
4456     hackname = sysz_stdlib_for_sun;
4457     files    = stdlib.h;
4458     bypass   = "_CLASSIC_ANSI_TYPES";
4459
4460     select    = "char[ \t]*\\*[ \t]*(calloc|malloc|realloc|bsearch)[ \t]*\\(";
4461     c_fix     = format;
4462     c_fix_arg = "void *\t%1(";
4463
4464     test_text =
4465     "extern char*\tcalloc(size_t);\n"
4466     "extern char*\tmalloc(size_t);\n"
4467     "extern char*\trealloc(void*,size_t);\n"
4468     "extern char*\tbsearch(void*,size_t,size_t);\n";
4469 };
4470
4471
4472 /*
4473  * __thread is now a keyword.
4474  */
4475 fix = {
4476     hackname  = thread_keyword;
4477     files     = "pthread.h";
4478     files     = "bits/sigthread.h";
4479     select    = "([* ])__thread([,)])";
4480     c_fix     = format;
4481     c_fix_arg = "%1__thr%2";
4482
4483     test_text =
4484         "extern int pthread_create (pthread_t *__restrict __thread,\n"
4485         "extern int pthread_kill (pthread_t __thread, int __signo);\n"
4486         "extern int pthread_cancel (pthread_t __thread);";
4487 };
4488
4489 /*
4490  *  if the #if says _cplusplus, not the double underscore __cplusplus
4491  *  that it should be
4492  */
4493 fix = {
4494     hackname = tinfo_cplusplus;
4495     files    = tinfo.h;
4496     select   = "[ \t]_cplusplus";
4497
4498     c_fix     = format;
4499     c_fix_arg = " __cplusplus";
4500     test_text = "#ifdef _cplusplus\nint bogus;\n#endif";
4501 };
4502
4503
4504 /*
4505  *  parameters not const on DECstation Ultrix V4.0 and OSF/1.
4506  */
4507 fix = {
4508     hackname  = ultrix_const;
4509     files     = stdio.h;
4510     select    = 'perror\( char \*';
4511
4512     c_fix     = format;
4513     c_fix_arg = "%1 const %3 *__";
4514     c_fix_arg = "([ \t*](perror|fputs|fwrite|scanf|fscanf)\\(.*)"
4515                 "[ \t]+(char|void) \\*__";
4516
4517     test_text =
4518     "extern void perror( char *__s );\n"
4519     "extern int fputs( char *__s, FILE *);\n"
4520     "extern size_t fwrite( void *__ptr, size_t, size_t, FILE *);\n"
4521     "extern int fscanf( FILE *__stream, char *__format, ...);\n"
4522     "extern int scanf( char *__format, ...);\n";
4523 };
4524
4525
4526 /*
4527  *  parameters not const on DECstation Ultrix V4.0 and OSF/1.
4528  */
4529 fix = {
4530     hackname  = ultrix_const2;
4531     files     = stdio.h;
4532
4533     select    = '\*fopen\( char \*';
4534     c_fix     = format;
4535     c_fix_arg = "%1( const char *%3, const char *";
4536     c_fix_arg = "([ \t*](fopen|sscanf|popen|tempnam))\\("
4537                "[ \t]*char[ \t]*\\*([^,]*),"
4538                "[ \t]*char[ \t]*\\*[ \t]*";
4539
4540     test_text =
4541     "extern FILE *fopen( char *__filename, char *__type );\n"
4542     "extern int sscanf( char *__s, char *__format, ...);\n"
4543     "extern FILE *popen(char *, char *);\n"
4544     "extern char *tempnam(char*,char*);\n";
4545 };
4546
4547
4548 /*
4549  *  Fix definitions of macros used by va-i960.h in VxWorks header file.
4550  */
4551 fix = {
4552     hackname  = va_i960_macro;
4553     files     = arch/i960/archI960.h;
4554     select    = "__(vsiz|vali|vpad|alignof__)";
4555
4556     c_fix     = format;
4557     c_fix_arg = "__vx%1";
4558
4559     test_text =
4560     "extern int __vsiz vsiz;\n"
4561     "extern int __vali vali;\n"
4562     "extern int __vpad vpad;\n"
4563     "#define __alignof__(x) ...";
4564 };
4565
4566
4567 /*
4568  *  Define __CAN_USE_EXTERN_PREFIX on vms.
4569  */
4570 fix = {
4571     hackname  = vms_define_can_use_extern_prefix;
4572     files     = "rtldef/decc$types.h";
4573     select    = "#[ \t]*else\n"
4574                 "#[ \t]*if defined\\(__DECCXX\\)\n"
4575                 "#[ \t]*define __CAN_USE_EXTERN_PREFIX 1\n";
4576     mach      = "*-*-*vms*";
4577     c_fix     = format;
4578
4579     c_fix_arg = "%0"
4580                 "#    elif defined (__GNUC__)\n"
4581                 "#\tdefine __CAN_USE_EXTERN_PREFIX 1\n";
4582
4583     test_text = "# else\n"
4584                 "#    if defined(__DECCXX)\n"
4585                 "#\tdefine __CAN_USE_EXTERN_PREFIX 1\n"
4586                 "#    endif\n"
4587                 "# endif\n";
4588 };
4589
4590 /*
4591  * On VMS, use pragma extern_model instead of VAX-C keywords.
4592  */
4593 fix = {
4594     hackname  = vms_use_pragma_extern_model;
4595     select    = "#if defined\\(__DECC\\) \\|\\| defined\\(__DECCXX\\)\n"
4596                 "# pragma extern_model __save\n";
4597     mach      = "*-*-*vms*";
4598     c_fix     = format;
4599
4600     c_fix_arg = "#if defined(__DECC) || defined(__DECCXX) || defined(__GNUC__)\n"
4601                 "# pragma extern_model __save\n";
4602
4603     test_text = "#if defined(__DECC) || defined(__DECCXX)\n"
4604                 "# pragma extern_model __save\n"
4605                 "# pragma extern_model strict_refdef\n"
4606                 "   extern struct x zz$yy;\n"
4607                 "# pragma extern_model __restore\n"
4608                 "#endif\n";
4609 };
4610
4611 /*
4612  * On VMS, disable the use of dec-c string builtins
4613  */
4614 fix = {
4615     hackname  = vms_disable_decc_string_builtins;
4616     select    = "#if !defined\\(__VAX\\)\n";
4617     mach      = "*-*-*vms*";
4618     files     = "rtldef/string.h";
4619     c_fix     = format;
4620
4621     c_fix_arg = "#if !defined(__VAX) && !defined(__GNUC__)\n";
4622
4623     test_text = "#if !defined(__VAX)\n";
4624 };
4625
4626 /*
4627  *  AIX and Interix headers define NULL to be cast to a void pointer,
4628  *  which is illegal in ANSI C++.
4629  */
4630 fix = {
4631     hackname  = void_null;
4632     files     = curses.h;
4633     files     = dbm.h;
4634     files     = locale.h;
4635     files     = stdio.h;
4636     files     = stdlib.h;
4637     files     = string.h;
4638     files     = time.h;
4639     files     = unistd.h;
4640     files     = sys/dir.h;
4641     files     = sys/param.h;
4642     files     = sys/types.h;
4643     /* avoid changing C++ friendly NULL */
4644     bypass    = __cplusplus;
4645     bypass    = __null;
4646     select    = "^#[ \t]*define[ \t]+NULL[ \t]+\\(\\(void[ \t]*\\*\\)0\\)";
4647     c_fix     = format;
4648     c_fix_arg = "#define NULL 0";
4649     test_text = "# define\tNULL \t((void *)0)  /* typed NULL */";
4650 };
4651
4652
4653 /*
4654  *  Make VxWorks header which is almost gcc ready fully gcc ready.
4655  */
4656 fix = {
4657     hackname = vxworks_gcc_problem;
4658     files    = types/vxTypesBase.h;
4659     select   = "__GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__";
4660
4661     sed = "s/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/"
4662           "#if 1/";
4663
4664     sed = "/[ \t]size_t/i\\\n"
4665         "#ifndef _GCC_SIZE_T\\\n"
4666         "#define _GCC_SIZE_T\n";
4667
4668     sed = "/[ \t]size_t/a\\\n"
4669         "#endif\n";
4670
4671     sed = "/[ \t]ptrdiff_t/i\\\n"
4672         "#ifndef _GCC_PTRDIFF_T\\\n"
4673         "#define _GCC_PTRDIFF_T\n";
4674
4675     sed = "/[ \t]ptrdiff_t/a\\\n"
4676         "#endif\n";
4677
4678     sed = "/[ \t]wchar_t/i\\\n"
4679         "#ifndef _GCC_WCHAR_T\\\n"
4680         "#define _GCC_WCHAR_T\n";
4681
4682     sed = "/[ \t]wchar_t/a\\\n"
4683         "#endif\n";
4684
4685     test_text =
4686     "#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__\n"
4687     "typedef unsigned int size_t;\n"
4688     "typedef long ptrdiff_t;\n"
4689     "typedef unsigned short wchar_t;\n"
4690     "#endif /* __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__ */\n";
4691 };
4692
4693
4694 /*
4695  *  Fix VxWorks <time.h> to not require including <vxTypes.h>.
4696  */
4697 fix = {
4698     hackname  = vxworks_needs_vxtypes;
4699     files     = time.h;
4700     select    = "uint_t([ \t]+_clocks_per_sec)";
4701     c_fix     = format;
4702     c_fix_arg = "unsigned int%1";
4703     test_text = "uint_t\t_clocks_per_sec;";
4704 };
4705
4706
4707 /*
4708  *  Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
4709  */
4710 fix = {
4711     hackname = vxworks_needs_vxworks;
4712     files    = sys/stat.h;
4713     test     = " -r types/vxTypesOld.h";
4714     test     = " -n \"`egrep '#include' $file`\"";
4715     test     = " -n \"`egrep ULONG $file`\"";
4716     select   = "#[ \t]define[ \t]+__INCstath";
4717
4718     sed = "/#[ \t]define[ \t][ \t]*__INCstath/a\\\n"
4719           "#include <types/vxTypesOld.h>\n";
4720
4721     test_text = "`touch types/vxTypesOld.h`"
4722     "#include </dev/null> /* ULONG */\n"
4723     "# define\t__INCstath <sys/stat.h>";
4724 };
4725
4726
4727 /*
4728  *  Another bad dependency in VxWorks 5.2 <time.h>.
4729  */
4730 fix = {
4731     hackname = vxworks_time;
4732     files    = time.h;
4733     test     = " -r vxWorks.h";
4734
4735     select    = "#[ \t]*define[ \t]+VOIDFUNCPTR[ \t].*";
4736     c_fix     = format;
4737
4738     c_fix_arg =
4739     "#ifndef __gcc_VOIDFUNCPTR_defined\n"
4740     "#ifdef __cplusplus\n"
4741     "typedef void (*__gcc_VOIDFUNCPTR) (...);\n"
4742     "#else\n"
4743     "typedef void (*__gcc_VOIDFUNCPTR) ();\n"
4744     "#endif\n"
4745     "#define __gcc_VOIDFUNCPTR_defined\n"
4746     "#endif\n"
4747     "#define VOIDFUNCPTR __gcc_VOIDFUNCPTR";
4748
4749     test_text = "`touch vxWorks.h`"
4750                 "#define VOIDFUNCPTR (void(*)())";
4751 };
4752
4753
4754 /*
4755  *  There are several name conflicts with C++ reserved words in X11 header
4756  *  files.  These are fixed in some versions, so don't do the fixes if
4757  *  we find __cplusplus in the file.  These were found on the RS/6000.
4758  */
4759 fix = {
4760     hackname  = x11_class;
4761     files     = X11/ShellP.h;
4762     bypass    = __cplusplus;
4763     select    = "^([ \t]*char \\*)class;(.*)";
4764     c_fix     = format;
4765     c_fix_arg = "#ifdef __cplusplus\n%1c_class;%2\n"
4766                 "#else\n%1class;%2\n#endif";
4767     test_text =
4768     "struct {\n"
4769     "   char *class;\n"
4770     "} mumble;\n";
4771 };
4772
4773
4774 /*
4775  *  class in Xm/BaseClassI.h
4776  */
4777 fix = {
4778     hackname = x11_class_usage;
4779     files    = Xm/BaseClassI.h;
4780     bypass   = "__cplusplus";
4781
4782     select    = " class\\)";
4783     c_fix     = format;
4784     c_fix_arg = " c_class)";
4785
4786     test_text = "extern mumble (int  class);\n";
4787 };
4788
4789
4790 /*
4791  *  new in Xm/Traversal.h
4792  */
4793 fix = {
4794     hackname = x11_new;
4795     files    = Xm/Traversal.h;
4796     bypass   = __cplusplus;
4797
4798     sed      = "/Widget\told, new;/i\\\n"
4799                    "#ifdef __cplusplus\\\n"
4800                    "\\\tWidget\told, c_new;\\\n"
4801                    "#else\n";
4802
4803     sed      = "/Widget\told, new;/a\\\n"
4804                    "#endif\n";
4805
4806     sed      = "s/Widget new,/Widget c_new,/g";
4807     test_text =
4808     "struct wedge {\n"
4809     "   Widget\told, new;\n"
4810     "};\nextern Wedged( Widget new, Widget old );";
4811 };
4812
4813
4814 /*
4815  *  Incorrect sprintf declaration in X11/Xmu.h
4816  */
4817 fix = {
4818     hackname = x11_sprintf;
4819     files    = X11/Xmu.h;
4820     files    = X11/Xmu/Xmu.h;
4821     select   = "^extern char \\*\tsprintf\\(\\);$";
4822
4823     c_fix     = format;
4824     c_fix_arg = "#ifndef __STDC__\n%0\n#endif /* !defined __STDC__ */";
4825
4826     test_text = "extern char *\tsprintf();";
4827 };
4828
4829 /*EOF*/