OSDN Git Service

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