OSDN Git Service

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