OSDN Git Service

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