OSDN Git Service

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