OSDN Git Service

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