OSDN Git Service

2f285f5205e235b17b6294b86138e12e5b80edbe
[pf3gnuchains/gcc-fork.git] / gcc / fixinc / 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 /*
24  *  This fixes __FD_ZERO bug for linux 2.x.y (x <= 2 && y <= some n)
25  */
26 fix = {
27     hackname = AAB_fd_zero_asm_posix_types_h;
28     files    = asm/posix_types.h;
29     mach     = 'i[34567]86-*-linux*';
30     bypass   = '} while';
31
32     /*
33      * Define _POSIX_TYPES_H_WRAPPER at the end of the wrapper, not
34      * the start, so that if #include_next gets another instance of
35      * the wrapper, this will follow the #include_next chain until
36      * we arrive at the real <asm/posix_types.h>.
37      */
38     replace  = <<-  _EndOfHeader_
39         /* This file fixes a bug in the __FD_ZERO macro
40            for older versions of the Linux kernel. */
41         #ifndef _POSIX_TYPES_H_WRAPPER
42         #include <features.h>
43          #include_next <asm/posix_types.h>
44         
45         #if defined(__FD_ZERO) && !defined(__GLIBC__)
46         #undef __FD_ZERO
47         #define __FD_ZERO(fdsetp) \
48           do { \
49             int __d0, __d1; \
50                         __asm__ __volatile__("cld ; rep ; stosl" \
51                                 : "=&c" (__d0), "=&D" (__d1) \
52                                 : "a" (0), "0" (__FDSET_LONGS), \
53                                   "1" ((__kernel_fd_set *) (fdsetp)) :"memory"); \
54           } while (0)
55         #endif
56         
57         #define _POSIX_TYPES_H_WRAPPER
58         #endif /* _POSIX_TYPES_H_WRAPPER */
59         _EndOfHeader_;
60 };
61
62
63 /*
64  *  This fixes __FD_ZERO bug for glibc-1.x
65  */
66 fix = {
67     hackname = AAB_fd_zero_gnu_types_h;
68     files    = gnu/types.h;
69     mach     = 'i[34567]86-*-linux*';
70
71     /*
72      * Define _TYPES_H_WRAPPER at the end of the wrapper, not
73      * the start, so that if #include_next gets another instance of
74      * the wrapper, this will follow the #include_next chain until
75      * we arrive at the real <gnu/types.h>.
76      */
77     replace  = <<-  _EndOfHeader_
78         /* This file fixes a bug in the __FD_ZERO macro present in glibc 1.x. */
79         #ifndef _TYPES_H_WRAPPER
80         #include <features.h>
81         #include_next <gnu/types.h>
82
83         #if defined(__FD_ZERO) && !defined(__GLIBC__)
84         #undef __FD_ZERO
85         # define __FD_ZERO(fdsetp) \\
86           do { \\
87             int __d0, __d1; \\
88                 __asm__ __volatile__("cld ; rep ; stosl" \\
89                 : "=&c" (__d0), "=&D" (__d1) \\
90                 : "a" (0), "0" (__FDSET_LONGS), \\
91                   "1" ((__fd_set *) (fdsetp)) :"memory"); \\
92           } while (0)
93         #endif
94
95         #define _TYPES_H_WRAPPER
96         #endif /* _TYPES_H_WRAPPER */
97         _EndOfHeader_;
98 };
99
100
101 /*
102  *  This fixes __FD_ZERO bug for glibc-2.0.x
103  */
104 fix = {
105     hackname = AAB_fd_zero_selectbits_h;
106     files    = selectbits.h;
107     mach     = 'i[34567]86-*-linux*';
108
109     /*
110      * Define _SELECTBITS_H_WRAPPER at the end of the wrapper, not
111      * the start, so that if #include_next gets another instance of
112      * the wrapper, this will follow the #include_next chain until
113      * we arrive at the real <selectbits.h>.
114      */
115     replace  = <<-  _EndOfHeader_
116         /* This file fixes a bug in the __FD_ZERO macro present in glibc 2.0.x. */
117         #ifndef _SELECTBITS_H_WRAPPER
118           #include <features.h>
119           #include_next <selectbits.h>
120
121           #if defined(__FD_ZERO) && defined(__GLIBC__) \\
122           && defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \\
123           && __GLIBC_MINOR__ == 0
124              #undef __FD_ZERO
125              #define __FD_ZERO(fdsetp) \\
126              do { \\
127                 int __d0, __d1; \\
128               __asm__ __volatile__ ("cld; rep; stosl" \\
129                         : "=&c" (__d0), "=&D" (__d1) \\
130                         : "a" (0), "0" (sizeof (__fd_set) \\
131                                         / sizeof (__fd_mask)), \\
132                           "1" ((__fd_mask *) (fdsetp)) \\
133                         : "memory"); \\
134               } while (0)
135           #endif
136
137           #define _SELECTBITS_H_WRAPPER
138         #endif /* _SELECTBITS_H_WRAPPER */
139         _EndOfHeader_;
140 };
141
142
143 /*
144  * Solaris <sys/varargs.h> is a DDK (aka kernel-land) header providing
145  * the same interface as <stdarg.h>.  No idea why they couldn't have just
146  * used the standard header.
147  */
148 fix = {
149     hackname = AAB_solaris_sys_varargs_h;
150     files    = "sys/varargs.h";
151     mach     = '*-*-solaris*';
152     replace  = <<-  _EndOfHeader_
153         #ifdef __STDC__
154           #include <stdarg.h>
155         #else
156           #include <varargs.h>
157         #endif
158         _EndOfHeader_;
159 };
160
161
162 /*
163  *  Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
164  *  declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
165  *  many other systems have similar text but correct versions of the file.
166  *  To ensure only Sun's is fixed, we grep for a likely unique string.
167  *  Fix also on sysV68 R3V7.1 (head/memory.h\t50.1\t )
168  */
169 fix = {
170     hackname = AAB_sun_memcpy;
171     files    = memory.h;
172     select   = "/\\*\t@\\(#\\)"
173              "(head/memory.h\t50.1\t "
174              "|memory\\.h 1\\.[2-4] 8./../.. SMI; from S5R2 1\\.2\t)\\*/";
175
176     replace = <<-  _EndOfHeader_
177         /* This file was generated by fixincludes */
178         #ifndef __memory_h__
179           #define __memory_h__
180
181           #ifdef __STDC__
182             extern void *memccpy();
183             extern void *memchr();
184             extern void *memcpy();
185             extern void *memset();
186           #else
187             extern char *memccpy();
188             extern char *memchr();
189             extern char *memcpy();
190             extern char *memset();
191           #endif /* __STDC__ */
192
193           extern int memcmp();
194
195         #endif /* __memory_h__ */
196         _EndOfHeader;
197 };
198
199
200 /*
201  *  Completely replace <sys/varargs.h> with a file that includes gcc's
202  *  stdarg.h or varargs.h files as appropriate.
203  */
204 #ifdef SVR4
205 fix = {
206     hackname = AAB_svr4_no_varargs;
207     files    = sys/varargs.h;
208     replace  = "/* This file was generated by fixincludes.  */\n"
209                "#ifndef _SYS_VARARGS_H\n"
210                "#define _SYS_VARARGS_H\n\n"
211
212                "#ifdef __STDC__\n"
213                "#include <stdarg.h>\n"
214                "#else\n"
215                "#include <varargs.h>\n"
216                "#endif\n\n"
217
218                "#endif  /* _SYS_VARARGS_H */\n";
219 };
220 #endif
221
222
223 /*
224  *  Completely replace <sys/byteorder.h> with a file that implements gcc's
225  *  optimized byteswapping.  (The original probably implemented some
226  *  incompatible optimized byteswapping.)
227  */
228 fix = {
229     hackname = AAB_svr4_replace_byteorder;
230     mach     = "*-*-sysv4*";
231     mach     = "i[34567]86-*-sysv5*";
232     mach     = "i[34567]86-*-sco3.2v5*";
233     mach     = "i[34567]86-*-udk*";
234     mach     = "i[34567]86-*-solaris2.[0-4]";
235     mach     = "powerpcle-*-solaris2.[0-4]";
236     mach     = "sparc-*-solaris2.[0-4]";
237     mach     = "i[34567]86-sequent-ptx*";
238     files    = sys/byteorder.h;
239     replace  = <<-  _EndOfHeader_
240         #ifndef _SYS_BYTEORDER_H
241         #define _SYS_BYTEORDER_H
242
243         /* Functions to convert `short' and `long' quantities from host byte order
244            to (internet) network byte order (i.e. big-endian).
245
246            Written by Ron Guilmette (rfg@ncd.com).
247
248            This isn't actually used by GCC.  It is installed by fixinc.svr4.
249
250            For big-endian machines these functions are essentially no-ops.
251
252            For little-endian machines, we define the functions using specialized
253            asm sequences in cases where doing so yields better code (e.g. i386).  */
254
255         #if !defined (__GNUC__) && !defined (__GNUG__)
256           #error You lose!  This file is only useful with GNU compilers.
257         #endif
258
259         #ifndef __BYTE_ORDER__
260           /* Byte order defines.  These are as defined on UnixWare 1.1, but with
261              double underscores added at the front and back.  */
262           #define __LITTLE_ENDIAN__   1234
263           #define __BIG_ENDIAN__      4321
264           #define __PDP_ENDIAN__      3412
265         #endif
266
267         #ifdef __STDC__
268           static __inline__ unsigned long htonl (unsigned long);
269           static __inline__ unsigned short htons (unsigned int);
270           static __inline__ unsigned long ntohl (unsigned long);
271           static __inline__ unsigned short ntohs (unsigned int);
272         #endif /* defined (__STDC__) */
273
274         #if defined (__i386__)
275
276           #ifndef __BYTE_ORDER__
277             #define __BYTE_ORDER__ __LITTLE_ENDIAN__
278           #endif
279
280           /* Convert a host long to a network long.  */
281
282           /* We must use a new-style function definition, so that this will also
283              be valid for C++.  */
284           static __inline__ unsigned long
285           htonl (unsigned long __arg)
286           {
287             register unsigned long __result;
288
289             __asm__ ("xchg%B0 %b0,%h0
290                   ror%L0 $16,%0
291                   xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
292             return __result;
293           }
294
295           /* Convert a host short to a network short.  */
296
297           static __inline__ unsigned short
298           htons (unsigned int __arg)
299           {
300             register unsigned short __result;
301
302             __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
303             return __result;
304           }
305
306         #elif (defined (__ns32k__) || defined (__vax__) || defined (__arm__))
307
308           #ifndef __BYTE_ORDER__
309             #define __BYTE_ORDER__ __LITTLE_ENDIAN__
310           #endif
311
312           /* For other little-endian machines, using C code is just as efficient as
313              using assembly code.  */
314
315           /* Convert a host long to a network long.  */
316
317           static __inline__ unsigned long
318           htonl (unsigned long __arg)
319           {
320             register unsigned long __result;
321
322             __result = (__arg >> 24) & 0x000000ff;
323             __result |= (__arg >> 8) & 0x0000ff00;
324             __result |= (__arg << 8) & 0x00ff0000;
325             __result |= (__arg << 24) & 0xff000000;
326             return __result;
327           }
328
329           /* Convert a host short to a network short.  */
330
331           static __inline__ unsigned short
332           htons (unsigned int __arg)
333           {
334             register unsigned short __result;
335
336             __result = (__arg << 8) & 0xff00;
337             __result |= (__arg >> 8) & 0x00ff;
338             return __result;
339           }
340
341         #else /* must be a big-endian machine */
342
343           #ifndef __BYTE_ORDER__
344             #define __BYTE_ORDER__ __BIG_ENDIAN__
345           #endif
346
347           /* Convert a host long to a network long.  */
348
349           static __inline__ unsigned long
350           htonl (unsigned long __arg)
351           {
352             return __arg;
353           }
354
355           /* Convert a host short to a network short.  */
356
357           static __inline__ unsigned short
358           htons (unsigned int __arg)
359           {
360             return __arg;
361           }
362
363         #endif /* big-endian */
364
365         /* Convert a network long to a host long.  */
366
367         static __inline__ unsigned long
368         ntohl (unsigned long __arg)
369         {
370           return htonl (__arg);
371         }
372
373         /* Convert a network short to a host short.  */
374
375         static __inline__ unsigned short
376         ntohs (unsigned int __arg)
377         {
378           return htons (__arg);
379         }
380         #endif
381         _EndOfHeader_;
382 };
383
384
385 /*
386  *  Cancel out ansi_compat.h on Ultrix.  Replace it with an empty file.
387  */
388 fix = {
389     hackname = AAB_ultrix_ansi_compat;
390     files    = ansi_compat.h;
391     select   = ULTRIX;
392     replace  = "/* This file intentionally left blank.  */\n";
393 };
394
395
396 /*
397  *  The Ultrix 4.3 file limits.h is a symbolic link to sys/limits.h.
398  *  Replace limits.h with a file that includes sys/limits.h.
399  */
400 fix = {
401     hackname = AAB_ultrix_limits;
402     files    = limits.h;
403     mach     = "*-*-ultrix4.3";
404     replace  = <<-  _EndOfHeader_
405         #ifndef _LIMITS_INCLUDED
406           #define _LIMITS_INCLUDED
407           #include <sys/limits.h>
408         #endif /* _LIMITS_INCLUDED */
409         _EndOfHeader_;
410 };
411
412
413 /*
414  *  The ULTRIX 4.3 version of memory.h duplicates definitions
415  *  present in strings.h.  Replace memory.h with a file that includes
416  *  strings.h to prevent problems from multiple inclusion.
417  */
418 fix = {
419     hackname = AAB_ultrix_memory;
420     files    = memory.h;
421     mach     = "*-*-ultrix4.3";
422     replace  = <<-  _EndOfHeader_
423         #ifndef _MEMORY_INCLUDED
424           #define _MEMORY_INCLUDED
425           #include <strings.h>
426         #endif /* _MEMORY_INCLUDED */
427         _EndOfHeader_;
428 };
429
430
431 /*
432  *  The Ultrix 4.3 file string.h is a symbolic link to strings.h.
433  *  Replace string.h link with a file that includes strings.h to prevent
434  *  problems from multiple inclusion.
435  */
436 fix = {
437     hackname = AAB_ultrix_string;
438     files    = string.h;
439     mach     = "*-*-ultrix4.3";
440     replace  = <<-  _EndOfHeader_
441         #ifndef _STRING_INCLUDED
442           #define _STRING_INCLUDED
443           #include <strings.h>
444         #endif /* _STRING_INCLUDED */
445         _EndOfHeader_;
446 };
447
448
449 /*
450  *  pthread.h on AIX 4.3.3 tries to define a macro without whitspace
451  *  which violates a requirement of ISO C.
452  */
453 fix = {
454     hackname  = aix_pthread;
455     files     = "pthread.h";
456     select    = "(#define [A-Za-z_0-9]+)(\\\\\n[^A-Za-z_0-9 \t\n(])";
457     c_fix     = format;
458     c_fix_arg = "%1 %2";
459     test_text = "#define PTHREAD_MUTEX_INITIALIZER\\\\\n"
460                 "{...init stuff...}";
461 };
462
463
464 /*
465  *  sys/machine.h on AIX 4.3.3 puts whitespace between a \ and a newline
466  *  in an otherwise harmless (and #ifed out) macro definition
467  */
468 fix = {
469     hackname  = aix_sysmachine;
470     files     = sys/machine.h;
471     select    = "\\\\ +\n";
472     c_fix     = format;
473     c_fix_arg = "\\\n";
474     test_text = "#define FOO \\\n"
475     " bar \\ \n baz \\ \n bat";
476 };
477
478
479 /*
480  *  sys/wait.h on AIX 3.2.5 puts the declaration of wait3 before the
481  *  definition of struct rusage, so the prototype added by fixproto fails.
482  */
483 fix = {
484     hackname  = aix_syswait;
485     files     = sys/wait.h;
486     select    = "^extern pid_t wait3\\(\\);\n";
487     select    = "bos325,";
488     c_fix     = format;
489     c_fix_arg = "struct rusage;\n%0";
490     test_text = "/* bos325, */\n"
491     "extern pid_t wait3();\n"
492     "\t/* pid_t wait3(int *, int, struct rusage *); */";
493 };
494
495
496 /*
497  *  sys/signal.h on some versions of AIX uses volatile in the typedef of
498  *  sig_atomic_t, which causes gcc to generate a warning about duplicate
499  *  volatile when a sig_atomic_t variable is declared volatile, as
500  *  required by ANSI C.
501  */
502 fix = {
503     hackname  = aix_volatile;
504     files     = sys/signal.h;
505     select    = "typedef volatile int sig_atomic_t";
506     c_fix     = format;
507     c_fix_arg = "typedef int sig_atomic_t";
508     test_text = "typedef volatile int sig_atomic_t;";
509 };
510
511
512 /*
513  *  Fix __assert declaration in assert.h on Alpha OSF/1.
514  */
515 fix = {
516     hackname  = alpha___assert;
517     files     = "assert.h";
518     select    = '__assert\(char \*, char \*, int\)';
519     c_fix     = format;
520     c_fix_arg = "__assert(const char *, const char *, int)";
521     test_text = 'extern void __assert(char *, char *, int);';
522 };
523
524
525 /*
526  *  Obey __PRAGMA_EXTERN_PREFIX for Tru64 UNIX V5 <sys/stat.h>.
527  */
528 fix = {
529     hackname  = alpha___extern_prefix;
530     files     = sys/stat.h;
531     select    = "#[ \t]*if[ \t]*defined\\(__DECC\\)";
532
533     mach      = "alpha*-dec-osf5*";
534     c_fix     = format;
535     c_fix_arg = "%0 || defined(__PRAGMA_EXTERN_PREFIX)";
536
537     test_text = "#   if defined(__DECC)";
538 };
539
540
541 /*
542  *  Fix assert macro in assert.h on Alpha OSF/1.
543  *  The superfluous int cast breaks C++.
544  */
545 fix = {
546     hackname  = alpha_assert;
547     files     = "assert.h";
548     select    = '(#define assert\(EX\).*)\(\(int\) \(EX\)\)';
549     c_fix     = format;
550     c_fix_arg = "%1(EX)";
551     test_text = '#define assert(EX) (((int) (EX)) ? (void)0 : __assert(#EX, __FILE__, __LINE__))';
552 };
553
554
555 /*
556  *  Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
557  */
558 fix = {
559     hackname  = alpha_getopt;
560     files     = "stdio.h";
561     files     = "stdlib.h";
562     select    = 'getopt\(int, char \*\[\], *char \*\)';
563     c_fix     = format;
564     c_fix_arg = "getopt(int, char *const[], const char *)";
565     test_text = 'extern int getopt(int, char *[], char *);';
566 };
567
568
569 /*
570  * Remove erroneous parentheses in sym.h on Alpha OSF/1.
571  */
572 fix = {
573     hackname  = alpha_parens;
574     files     = sym.h;
575     select    = '#ifndef\(__mips64\)';
576     c_fix     = format;
577     c_fix_arg = "#ifndef __mips64";
578     test_text = "#ifndef(__mips64) /* bogus */\nextern int foo;\n#endif";
579 };
580
581
582 /*
583  *  Obey __PRAGMA_EXTERN_PREFIX for Tru64 UNIX <pthread.h>.
584  */
585 fix = {
586     hackname  = alpha_pthread;
587     files     = pthread.h;
588     select    = "(#[ \t]*if defined \\(_PTHREAD_ENV_DECC\\) || defined \\(_PTHREAD_ENV_EPCC\\))\n"
589                 "(#[ \t]*define _PTHREAD_USE_PTDNAM_)";
590
591     mach      = "alpha*-dec-osf*";
592     c_fix     = format;
593     c_fix_arg = "%1 || defined (__PRAGMA_EXTERN_PREFIX)\n%2";
594
595     test_text = "#  if defined (_PTHREAD_ENV_DECC) || defined (_PTHREAD_ENV_EPCC)\n"
596                 "#   define _PTHREAD_USE_PTDNAM_\n"
597                 "#  endif";
598 };
599
600
601 /*
602  *  Recognize GCC in Tru64 UNIX V5.1B <pthread.h>.
603  */
604 fix = {
605     hackname  = alpha_pthread_gcc;
606     files     = pthread.h;
607     select    = "#else\n# error <pthread.h>: unrecognized compiler.";
608
609     mach      = "alpha*-dec-osf*";
610     c_fix     = format;
611     c_fix_arg = "#elif defined (__GNUC__)\n"
612                 "# define _PTHREAD_ENV_GCC\n"
613                 "%0";
614
615     test_text = "# define _PTHREAD_ENV_INTELC\n"
616                 "#else\n"
617                 "# error <pthread.h>: unrecognized compiler.\n"
618                 "#endif";
619 };
620
621
622 /*
623  *  Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
624  *  And OpenBSD.
625  */
626 fix = {
627     hackname = alpha_sbrk;
628     files    = unistd.h;
629     select   = "char[ \t]*\\*[\t ]*sbrk[ \t]*\\(";
630     c_fix     = format;
631     c_fix_arg = "void *sbrk(";
632     test_text = "extern char* sbrk(ptrdiff_t increment);";
633 };
634
635
636 /*
637  *  For C++, avoid any typedef or macro definition of bool,
638  *  and use the built in type instead.
639  *  HP/UX 10.20 also has it in curses_colr/curses.h.
640  */
641 fix = {
642     hackname  = avoid_bool_define;
643     files     = curses.h;
644     files     = curses_colr/curses.h;
645     files     = term.h;
646     files     = tinfo.h;
647
648     select    = "#[ \t]*define[ \t]+bool[ \t]";
649     bypass    = "__cplusplus";
650
651     c_fix     = format;
652     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
653     c_fix_arg = "^[ \t]*#[ \t]*define[ \t]+bool[ \t].*";
654
655     test_text = "# define bool\t char \n";
656 };
657
658
659 fix = {
660     hackname = avoid_bool_type;
661     files    = curses.h;
662     files    = curses_colr/curses.h;
663     files    = term.h;
664     files    = tinfo.h;
665
666     select    = "^[ \t]*typedef[ \t].*[ \t]bool[ \t]*;";
667     bypass    = "__cplusplus";
668
669     c_fix     = format;
670     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
671
672     test_text = "typedef unsigned int\tbool \t; /* bool\n type */";
673 };
674
675
676 /*
677  *  For C++, avoid any typedef definition of wchar_t,
678  *  and use the built in type instead.
679  *  Don't do this for headers that are smart enough to do the right
680  *  thing (recent [n]curses.h and Xlib.h).
681  *  Don't do it for <linux/nls.h> which is never used from C++ anyway,
682  *  and will be broken by the edit.
683  */
684
685 fix = {
686     hackname = avoid_wchar_t_type;
687
688     select    = "^[ \t]*typedef[ \t].*[ \t]wchar_t[ \t]*;";
689     bypass    = "__cplusplus";
690     bypass    = "_LINUX_NLS_H";
691     bypass    = "XFree86: xc/lib/X11/Xlib\\.h";
692
693     c_fix     = format;
694     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
695
696     test_text = "typedef unsigned short\twchar_t \t; /* wchar_t\n type */";
697 };
698
699
700 /*
701  *  Fix #defines under Alpha OSF/1:
702  *  The following files contain '#pragma extern_prefix "_FOO"' followed by
703  *  a '#define something(x,y,z) _FOOsomething(x,y,z)'.  The intent of these
704  *  statements is to reduce namespace pollution.  While these macros work
705  *  properly in most cases, they don't allow you to take a pointer to the
706  *  "something" being modified.  To get around this limitation, change these
707  *  statements to be of the form '#define something _FOOsomething'.
708  *
709  *  sed ain't egrep, lesson 2463:  sed can use self-referential
710  *  regular expressions.  In the substitute expression below,
711  *  "\\1" and "\\2" refer to subexpressions found earlier in the
712  *  same match.  So, we continue to use sed.  "extern_prefix" will
713  *  be a rare match anyway...
714  */
715 fix = {
716     hackname = bad_lval;
717
718     select   = "^[ \t]*#[ \t]*pragma[ \t]+extern_prefix";
719
720     files    = libgen.h;
721     files    = dirent.h;
722     files    = ftw.h;
723     files    = grp.h;
724     files    = ndbm.h;
725     files    = pthread.h;
726     files    = pwd.h;
727     files    = signal.h;
728     files    = standards.h;
729     files    = stdlib.h;
730     files    = string.h;
731     files    = stropts.h;
732     files    = time.h;
733     files    = unistd.h;
734
735     sed      =
736         "s/^[ \t]*#[ \t]*define[ \t][ \t]*\\([^(]*\\)\\(([^)]*)\\)[ \t]*"
737                "\\(_.*\\)\\1\\2[ \t]*$/#define \\1 \\3\\1/";
738
739     test_text = '#pragma extern_prefix "_FOO"'"\n"
740                 "#define something(x,y,z) _FOOsomething(x,y,z)\n"
741                 "#define mumble _FOOmumble";
742 };
743
744
745 /*
746  *  Fix `typedef struct term;' on hppa1.1-hp-hpux9.
747  */
748 fix = {
749     hackname  = bad_struct_term;
750     files     = curses.h;
751     select    = "^[ \t]*typedef[ \t]+struct[ \t]+term[ \t]*;";
752     c_fix     = format;
753     c_fix_arg = "struct term;";
754
755     test_text = 'typedef struct term;';
756 };
757
758
759 /*
760  *  Fix one other error in this file:
761  *  a mismatched quote not inside a C comment.
762  */
763 fix = {
764     hackname  = badquote;
765     files     = sundev/vuid_event.h;
766     select    = "doesn't";
767     c_fix     = format;
768     c_fix_arg = "does not";
769
770     test_text = "/* doesn't have matched single quotes */";
771 };
772
773
774 /*
775  *  check for broken assert.h that needs stdio.h
776  */
777 fix = {
778     hackname  = broken_assert_stdio;
779     files     = assert.h;
780     select    = stderr;
781     bypass    = "include.*stdio\\.h";
782     c_fix     = wrap;
783     c_fix_arg = "#include <stdio.h>\n";
784     test_text = "extern FILE* stderr;";
785 };
786
787
788 /*
789  *  check for broken assert.h that needs stdlib.h
790  */
791 fix = {
792     hackname  = broken_assert_stdlib;
793     files     = assert.h;
794     select    = 'exit *\(|abort *\(';
795     bypass    = "include.*stdlib\\.h";
796     c_fix     = wrap;
797     c_fix_arg = "#ifdef __cplusplus\n"
798                 "#include <stdlib.h>\n"
799                 "#endif\n";
800     test_text = "extern void exit ( int );";
801 };
802
803
804 /*
805  *  Remove `extern double cabs' declarations from math.h.
806  *  This conflicts with C99.  Discovered on AIX.
807  *  SunOS4 has its cabs() declaration followed by a comment which
808  *  terminates on the following line.
809  *  Darwin hides its broken cabs in architecture-specific subdirs.
810  */
811 fix = {
812     hackname = broken_cabs;
813     files    = "math.h";
814     files    = "architecture/ppc/math.h";
815     files    = "architecture/i386/math.h";
816     select   = '^extern[ \t]+double[ \t]+cabs';
817
818     c_fix     = format;
819     c_fix_arg = "";
820     c_fix_arg = "^extern[ \t]+double[ \t]+cabs[ \t]*\\([^\\)]*\\);";
821
822     test_text = "#ifdef __STDC__\n"
823                 "extern     double   cabs(struct dbl_hypot);\n"
824                 "#else\n"
825                 "extern     double   cabs();\n"
826                 "#endif\n"
827                 "extern double cabs ( _Complex z );\n"
828                 "extern double cabs(); /* This is a comment\n"
829                 "                         and it ends here. */";
830 };
831
832
833 /*
834  *  Various systems derived from BSD4.4 contain a macro definition
835  *  for vfscanf that interacts badly with requirements of builtin-attrs.def.
836  *  Known to be fixed in FreeBSD 5 system headers.
837  */
838 fix = {
839     hackname  = bsd_stdio_attrs_conflict;
840     mach      = *-*-*bsd*;
841     mach      = *-*-*darwin*;
842     files     = stdio.h;
843     select    = "^#define[ \t]*vfscanf[ \t]*__svfscanf[ \t]*$";
844     c_fix     = format;
845     c_fix_arg = '#define _BSD_STRING(_BSD_X) _BSD_STRINGX(_BSD_X)' "\n"
846                 '#define _BSD_STRINGX(_BSD_X) #_BSD_X' "\n"
847                 'int vfscanf(FILE *, const char *, __builtin_va_list) '
848                 '__asm__ (_BSD_STRING(__USER_LABEL_PREFIX__) "__svfscanf");';
849     test_text = '#define  vfscanf       __svfscanf';
850 };
851
852
853 /*
854  *  Fix various macros used to define ioctl numbers.
855  *  The traditional syntax was:
856  *
857  *    #define _CTRL(n, x) (('n'<<8)+x)
858  *    #define TCTRLCFOO _CTRL(T, 1)
859  *
860  *  but this does not work with the C standard, which disallows macro
861  *  expansion inside strings.  We have to rewrite it thus:
862  *
863  *    #define _CTRL(n, x) ((n<<8)+x)
864  *    #define TCTRLCFOO  _CTRL('T', 1)
865  *
866  *  The select expressions match too much, but the c_fix code is cautious.
867  *
868  *  CTRL might be: CTRL _CTRL ISCTRL BSD43_CTRL ...
869  */
870 fix = {
871     hackname  = ctrl_quotes_def;
872     select    = "define[ \t]+[A-Z0-9_]+CTRL\\([a-zA-Z][,)]";
873     c_fix     = char_macro_def;
874     c_fix_arg = "CTRL";
875
876     /*
877      *  This is two tests in order to ensure that the "CTRL(c)" can
878      *  be selected in isolation from the multi-arg format
879      */
880     test_text = "#define BSD43_CTRL(n, x) (('n'<<8)+x)\n";
881     test_text = "#define _CTRL(c) ('c'&037)";
882 };
883
884 fix = {
885     hackname  = ctrl_quotes_use;
886     select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
887     c_fix     = char_macro_use;
888     c_fix_arg = "CTRL";
889     test_text = "#define TCTRLFOO BSD43_CTRL(T, 1)";
890 };
891
892
893 /*
894  *  sys/mman.h on HP/UX is not C++ ready,
895  *  even though NO_IMPLICIT_EXTERN_C is defined on HP/UX.
896  *
897  *  rpc/types.h on OSF1/2.0 is not C++ ready,
898  *  even though NO_IMPLICIT_EXTERN_C is defined for the alpha.
899  *
900  *  The problem is the declaration of malloc.
901  */
902 fix = {
903     hackname = cxx_unready;
904     files    = sys/mman.h;
905     files    = rpc/types.h;
906     select   = '[^#]+malloc.*;';  /* Catch any form of declaration
907                                      not within a macro.  */
908     bypass   = '"C"|__BEGIN_DECLS';
909
910     c_fix     = wrap;
911     c_fix_arg = "#ifdef __cplusplus\n"
912                 "extern \"C\" {\n"
913                 "#endif\n";
914     c_fix_arg = "#ifdef __cplusplus\n"
915                 "}\n"
916                 "#endif\n";
917     test_text = "extern void* malloc( size_t );";
918 };
919
920
921 /*
922  *  Fix <c_asm.h> on Digital UNIX V4.0:
923  *  It contains a prototype for a DEC C internal asm() function,
924  *  clashing with gcc's asm keyword.  So protect this with __DECC.
925  */
926 fix = {
927     hackname = dec_intern_asm;
928     files    = c_asm.h;
929     sed = "/^[ \t]*float[ \t]*fasm/i\\\n#ifdef __DECC\n";
930     sed = "/^[ \t]*#[ \t]*pragma[ \t]*intrinsic([ \t]*dasm/a\\\n"
931           "#endif\n";
932     test_text =
933     "float fasm {\n"
934     "    ... asm stuff ...\n"
935     "};\n#pragma intrinsic( dasm )\n/* END ASM TEST*/";
936 };
937
938
939 /*
940  * Fix typo in <wchar.h> on DJGPP 2.03.
941  */
942 fix = {
943     hackname  = djgpp_wchar_h;
944     file      = wchar.h;
945     select    = "__DJ_wint_t";
946     bypass    = "sys/djtypes.h";
947     c_fix     = format;
948     c_fix_arg = "%0\n#include <sys/djtypes.h>";
949     c_fix_arg = "#include <stddef.h>";
950     test_text = "#include <stddef.h>\n"
951                 "extern __DJ_wint_t x;\n";
952 };
953
954
955 /*
956  * Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
957  */
958 fix = {
959     hackname  = ecd_cursor;
960     files     = "sunwindow/win_lock.h";
961     files     = "sunwindow/win_cursor.h";
962     select    = 'ecd\.cursor';
963     c_fix     = format;
964     c_fix_arg = 'ecd_cursor';
965
966     test_text = "#ifdef ecd.cursor\n#error bogus\n#endif /* ecd+cursor */";
967 };
968
969
970 /*
971  *  Between 8/24/1998 and 2/17/2001, FreeBSD system headers presume
972  *  neither the existence of GCC 3 nor its exact feature set yet break
973  *  (by design?) when __GNUC__ is set beyond 2.
974  */
975 fix = {
976     hackname  = freebsd_gcc3_breakage;
977     mach      = *-*-freebsd*;
978     files     = sys/cdefs.h;
979     select    = '^#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7$';
980     bypass    = '__GNUC__[ \t]*([>=]=[ \t]*[3-9]|>[ \t]*2)';
981     c_fix     = format;
982     c_fix_arg = '%0 || __GNUC__ >= 3';
983     test_text = '#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7';
984 };
985
986
987 /*
988  * Fix these files to use the types we think they should for
989  * ptrdiff_t, size_t, and wchar_t.
990  *
991  * This defines the types in terms of macros predefined by our 'cpp'.
992  * This is supposedly necessary for glibc's handling of these types.
993  * It's probably not necessary for anyone else, but it doesn't hurt.
994  */
995 fix = {
996     hackname  = gnu_types;
997     files  = "sys/types.h";
998     files  = "stdlib.h";
999     files  = "sys/stdtypes.h";
1000     files  = "stddef.h";
1001     files  = "memory.h";
1002     files  = "unistd.h";
1003     bypass    = '_GCC_(PTRDIFF|SIZE|WCHAR)_T';
1004     select    = "^[ \t]*typedef[ \t]+.*[ \t](ptrdiff|size|wchar)_t;";
1005     c_fix     = gnu_type;
1006
1007     test_text = "typedef long int ptrdiff_t; /* long int */\n"
1008                 "typedef uint_t size_t; /* uint_t */\n"
1009                 "typedef ushort_t wchar_t; /* ushort_t */";
1010 };
1011
1012
1013 /*
1014  *  Fix HP & Sony's use of "../machine/xxx.h"
1015  *  to refer to:  <machine/xxx.h>
1016  */
1017 fix = {
1018     hackname  = hp_inline;
1019     files     = sys/spinlock.h;
1020     files     = machine/machparam.h;
1021     select    = "[ \t]*#[ \t]*include[ \t]+"  '"\.\./machine/';
1022
1023     c_fix     = format;
1024     c_fix_arg = "%1<machine/%2.h>";
1025
1026     c_fix_arg = "([ \t]*#[ \t]*include[ \t]+)"  '"\.\./machine/'
1027                 '([a-z]+)\.h"';
1028
1029     test_text = ' # include "../machine/mumble.h"';
1030 };
1031
1032
1033 /*
1034  *  Check for (...) in C++ code in HP/UX sys/file.h.
1035  */
1036 fix = {
1037     hackname  = hp_sysfile;
1038     files     = sys/file.h;
1039     select    = "HPUX_SOURCE";
1040
1041     c_fix     = format;
1042     c_fix_arg = "(struct file *, ...)";
1043     c_fix_arg = '\(\.\.\.\)';
1044
1045     test_text = "extern void foo(...); /* HPUX_SOURCE - bad varargs */";
1046 };
1047
1048
1049 /*
1050  * Delete C++ double pow (double, int) inline function from HP-UX 10 & 11
1051  * math.h to prevent clash with define in c_std/bits/std_cmath.h.
1052  */
1053 fix = {
1054     hackname  = hpux10_cpp_pow_inline;
1055     files     = fixinc-test-limits.h, math.h;
1056     select    = <<-     END_POW_INLINE
1057         ^# +ifdef +__cplusplus
1058          +\}
1059          +inline +double +pow\(double +__d,int +__expon\) +\{
1060         [       ]+return +pow\(__d,\(double\)__expon\);
1061          +\}
1062          +extern +"C" +\{
1063         #else
1064         # +endif
1065         END_POW_INLINE;
1066  
1067     c_fix     = format;
1068     c_fix_arg = "";
1069
1070     test_text =
1071         "#    ifdef __cplusplus\n"
1072         "     }\n"
1073         "     inline double pow(double __d,int __expon) {\n"
1074         "\t return pow(__d,(double)__expon);\n"
1075         "     }\n"
1076         '     extern "C"' " {\n"
1077         "#else\n"
1078         "#    endif";
1079 };
1080
1081 fix = {
1082      hackname  = hpux11_cpp_pow_inline;
1083      files     = math.h;
1084      select    = " +inline double pow\\(double d,int expon\\) \\{\n"
1085                  " +return pow\\(d, \\(double\\)expon\\);\n"
1086                  " +\\}\n";
1087      c_fix     = format;
1088      c_fix_arg = "";
1089
1090      test_text =
1091             "   inline double pow(double d,int expon) {\n"
1092             "     return pow(d, (double)expon);\n"
1093             "   }\n";
1094 };
1095
1096
1097 /*
1098  *  Fix hpux 10.X missing ctype declarations 1
1099  */
1100 fix = {
1101     hackname = hpux10_ctype_declarations1;
1102     files    = ctype.h;
1103     select   = "^#[ \t]*define _toupper\\(__c\\)[ \t]*__toupper\\(__c\\)";
1104     bypass   = "^[ \t]*extern[ \t]*int[ \t]*__tolower[ \t]*\\(";
1105     c_fix     = format;
1106     c_fix_arg = "#ifdef _PROTOTYPES\n"
1107                 "extern int __tolower(int);\n"
1108                 "extern int __toupper(int);\n"
1109                 "#else /* NOT _PROTOTYPES */\n"
1110                 "extern int __tolower();\n"
1111                 "extern int __toupper();\n"
1112                 "#endif /* _PROTOTYPES */\n\n"
1113                 "%0\n";
1114
1115     test_text = "#  define _toupper(__c)         __toupper(__c)\n";
1116 };
1117
1118
1119 /*
1120  *  Fix hpux 10.X missing ctype declarations 2
1121  */
1122 fix = {
1123     hackname = hpux10_ctype_declarations2;
1124     files    = ctype.h;
1125     select   = "^#  if defined\\(_SB_CTYPE_MACROS\\) && \\!defined\\(__lint\\)";
1126     bypass   = "^[ \t]*extern[ \t]*int[ \t]*_isalnum[ \t]*\\(";
1127     c_fix     = format;
1128     c_fix_arg = "%0\n\n"
1129                 "#ifdef _PROTOTYPES\n"
1130                 "     extern int _isalnum(int);\n"
1131                 "     extern int _isalpha(int);\n"
1132                 "     extern int _iscntrl(int);\n"
1133                 "     extern int _isdigit(int);\n"
1134                 "     extern int _isgraph(int);\n"
1135                 "     extern int _islower(int);\n"
1136                 "     extern int _isprint(int);\n"
1137                 "     extern int _ispunct(int);\n"
1138                 "     extern int _isspace(int);\n"
1139                 "     extern int _isupper(int);\n"
1140                 "     extern int _isxdigit(int);\n"
1141                 "#  else /* not _PROTOTYPES */\n"
1142                 "     extern int _isalnum();\n"
1143                 "     extern int _isalpha();\n"
1144                 "     extern int _iscntrl();\n"
1145                 "     extern int _isdigit();\n"
1146                 "     extern int _isgraph();\n"
1147                 "     extern int _islower();\n"
1148                 "     extern int _isprint();\n"
1149                 "     extern int _ispunct();\n"
1150                 "     extern int _isspace();\n"
1151                 "     extern int _isupper();\n"
1152                 "     extern int _isxdigit();\n"
1153                 "#endif /* _PROTOTYPES */\n";
1154
1155     test_text = "#  if defined(_SB_CTYPE_MACROS) && !defined(__lint)\n"
1156                 "     extern unsigned int *__SB_masks;\n";
1157 };
1158
1159
1160 /*
1161  *  Make sure hpux defines abs in header.
1162  */
1163 fix = {
1164     hackname  = hpux11_abs;
1165     mach      = ia64-hp-hpux11*;
1166     files     = stdlib.h;
1167     select    = "ifndef _MATH_INCLUDED";
1168     c_fix     = format;
1169     c_fix_arg = "if !defined(_MATH_INCLUDED) || defined(__GNUG__)";
1170 //  sed       = "s/ifndef _MATH_INCLUDED/if !defined(_MATH_INCLUDED) || defined(__GNUG__)/";
1171     test_text = "#ifndef _MATH_INCLUDED";
1172 };
1173
1174
1175 /*
1176  *  Keep HP-UX 11 from stomping on C++ math namespace
1177  *  with defines for fabsf.
1178  */
1179 fix = {
1180     hackname  = hpux11_fabsf;
1181     files     = math.h;
1182     select    = "^[ \t]*#[ \t]*define[ \t]+fabsf\\(.*";
1183     bypass    = "__cplusplus";
1184
1185     c_fix     = format;
1186     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
1187
1188     test_text =
1189     "#ifdef _PA_RISC\n"
1190     "#  define fabsf(x) ((float)fabs((double)(float)(x)))\n"
1191     "#endif";
1192 };
1193
1194
1195 /*
1196  * Prevent HP-UX 11 from defining __size_t and preventing size_t from
1197  * being defined by having it define _hpux_size_t instead.
1198  */
1199 fix = {
1200     hackname  = hpux11_size_t;
1201     mach      = "*-hp-hpux11*";
1202     select    = "__size_t";
1203
1204     c_fix     = format;
1205     c_fix_arg = "_hpux_size_t";
1206
1207     test_text =
1208     "#define __size_t size_t\n"
1209     "       extern int getpwuid_r( char *, __size_t, struct passwd **);\n";
1210 };
1211
1212
1213 /*
1214  * In inttypes.h on HPUX 11, the use of __CONCAT__ in the definition
1215  * of UINT32_C has undefined behavior according to ISO/ANSI:
1216  * the arguments to __CONCAT__ are not macro expanded before the
1217  * concatination happens so the trailing ')' in the first argument
1218  * is concatinated with the 'l' in the second argument creating an
1219  * invalid pp token.  The behavior of invalid pp tokens is undefined.
1220  * GCC does not handle these invalid tokens the way the HP compiler does.
1221  * This problem will potentially occur anytime macros are used in the
1222  * arguments to __CONCAT__.  A general solution to this problem would be to
1223  * insert another layer of macro between __CONCAT__ and its use
1224  * in UINT32_C.  An example of this solution can be found in the C standard.
1225  * A more specific solution, the one used here, is to change the UINT32_C
1226  * macro to not used macros in the arguments to __CONCAT__.
1227  */
1228 fix = {
1229     hackname = hpux11_uint32_c;
1230     files    = inttypes.h;
1231     select   = "^#define UINT32_C\\(__c\\)[ \t]*"
1232                          "__CONCAT__\\(__CONCAT_U__\\(__c\\),l\\)";
1233     c_fix    = format;
1234     c_fix_arg = '#define UINT32_C(__c) __CONCAT__(__c,ul)';
1235     test_text =
1236     "#define CONCAT_U__(__c)\t__CONCAT__(__c,u)\n"
1237     "#define UINT32_C(__c)\t__CONCAT__(__CONCAT_U__(__c),l)";
1238 };
1239
1240
1241 /*
1242  *  Fix hpux 11.00 broken vsnprintf declaration
1243  */
1244 fix = {
1245     hackname = hpux11_vsnprintf;
1246     files    = stdio.h;
1247     select   = '(extern int vsnprintf\(char \*, _[hpux]*_size_t, '
1248                                      'const char \*,) __va__list\);';
1249     c_fix     = format;
1250     c_fix_arg = "%1 __va_list);";
1251
1252     test_text = 'extern int vsnprintf(char *, _hpux_size_t, const char *,'
1253                                      ' __va__list);';
1254 };
1255
1256
1257 /*
1258  *  Fix hpux 11.00 broken snprintf declaration
1259  *  (third argument is char *, needs to be const char * to prevent
1260  *  spurious warnings with -Wwrite-strings or in C++).
1261  */
1262 fix = {
1263     hackname = hpux11_snprintf;
1264     files    = stdio.h;
1265     select   = '(extern int snprintf *\(char *\*, *(|__|_hpux_)size_t,)'
1266                                     ' *(char *\*, *\.\.\.\);)';
1267     c_fix     = format;
1268     c_fix_arg = '%1 const %3';
1269
1270     test_text = "extern int snprintf(char *, size_t, char *, ...);\n"
1271                 "extern int snprintf(char *, __size_t, char *, ...);\n"
1272                 "extern int snprintf(char *, _hpux_size_t, char *, ...);";
1273 };
1274
1275
1276 /*
1277  *  get rid of bogus inline definitions in HP-UX 8.0
1278  */
1279 fix = {
1280     hackname = hpux8_bogus_inlines;
1281     files    = math.h;
1282     select   = inline;
1283     sed = "s@inline int abs(int [a-z][a-z]*) {.*}"
1284            "@extern \"C\" int abs(int);@";
1285     sed = "s@inline double abs(double [a-z][a-z]*) {.*}@@";
1286     sed = "s@inline int sqr(int [a-z][a-z]*) {.*}@@";
1287     sed = "s@inline double sqr(double [a-z][a-z]*) {.*}@@";
1288     test_text = "inline int abs(int v) { return (v>=0)?v:-v; }\n"
1289                 "inline double sqr(double v) { return v**0.5; }";
1290 };
1291
1292
1293 /*
1294  *  Fix hpux broken ctype macros
1295  */
1296 fix = {
1297     hackname = hpux_ctype_macros;
1298     files    = ctype.h;
1299     select   = '((: |\()__SB_masks \? )'
1300                '(__SB_masks\[__(alnum|c)\] & _IS)';
1301     c_fix     = format;
1302     c_fix_arg = "%1(int)%3";
1303
1304     test_text = ": __SB_masks ? __SB_masks[__alnum] & _ISCNTRL\n"
1305                 "# define isalpha(__c) (__SB_masks ? __SB_masks[__c] & _IS\n";
1306 };
1307
1308
1309 /*
1310  * HP-UX long_double
1311  */
1312 fix = {
1313     hackname  = hpux_long_double;
1314     files     = stdlib.h;
1315     select    = "extern[ \t]long_double[ \t]strtold";
1316     bypass    = "long_double_t";
1317     sed       = "/^#[ \t]*ifndef _LONG_DOUBLE/,/\\/\\* _LONG_DOUBLE \\*\\//D";
1318     sed       = "s/long_double/long double/g";
1319
1320     test_text = "#  ifndef _LONG_DOUBLE\n"
1321                 "#    define _LONG_DOUBLE\n"
1322                 "     typedef struct {\n"
1323                 "       unsigned int word1, word2, word3, word4;\n"
1324                 "     } long_double;\n"
1325                 "#  endif /* _LONG_DOUBLE */\n"
1326                 "extern long_double strtold(const char *, char **);\n";
1327 };
1328
1329
1330 /*
1331  *  HPUX 10.x sys/param.h defines MAXINT which clashes with values.h
1332  */
1333 fix = {
1334     hackname  = hpux_maxint;
1335     files     = sys/param.h;
1336     files     = values.h;
1337     select    = "^#[ \t]*define[ \t]+MAXINT[ \t]";
1338     bypass    = "^#[ \t]*ifndef[ \t]+MAXINT";
1339     test =
1340     "-n \"`egrep '#[ \t]*define[ \t]+MAXINT[ \t]' sys/param.h`\"";
1341
1342     c_fix     = format;
1343     c_fix_arg = "#ifndef MAXINT\n%0\n#endif";
1344     c_fix_arg = "^#[ \t]*define[ \t]+MAXINT[ \t].*";
1345
1346     test_text = '#define MAXINT 0x7FFFFFFF';
1347 };
1348
1349
1350 /*
1351  *  Fix hpux10.20 <sys/time.h> to avoid invalid forward decl
1352  */
1353 fix = {
1354     hackname = hpux_systime;
1355     files    = sys/time.h;
1356     select   = "^extern struct sigevent;";
1357
1358     c_fix     = format;
1359     c_fix_arg = "struct sigevent;";
1360
1361     test_text = 'extern struct sigevent;';
1362 };
1363
1364
1365 /*
1366  *  Fix return type of abort and free
1367  */
1368 fix = {
1369     hackname  = int_abort_free_and_exit;
1370     files     = stdlib.h;
1371     select    = "int[ \t]+(abort|free|exit)[ \t]*\\(";
1372
1373     c_fix     = format;
1374     c_fix_arg = "void\t%1(";
1375
1376     test_text = "extern int abort(int);\n"
1377                 "extern int free(void*);\n"
1378                 "extern int exit(void*);";
1379 };
1380
1381
1382 /*
1383  *  Fix various macros used to define ioctl numbers.
1384  *  The traditional syntax was:
1385  *
1386  *    #define _IO(n, x) (('n'<<8)+x)
1387  *    #define TIOCFOO _IO(T, 1)
1388  *
1389  *  but this does not work with the C standard, which disallows macro
1390  *  expansion inside strings.  We have to rewrite it thus:
1391  *
1392  *    #define _IO(n, x) ((n<<8)+x)
1393  *    #define TIOCFOO  _IO('T', 1)
1394  *
1395  *  The select expressions match too much, but the c_fix code is cautious.
1396  *
1397  *  _IO might be: _IO DESIO BSD43__IO with W, R, WR, C, ... suffixes.
1398  */
1399 fix = {
1400     hackname  = io_quotes_def;
1401     select    = "define[ \t]+[A-Z0-9_]+IO[A-Z]*\\([a-zA-Z][,)]";
1402     c_fix     = char_macro_def;
1403     c_fix_arg = "IO";
1404     test_text =
1405     "#define BSD43__IOWR(n, x) (('n'<<8)+x)\n"
1406     "#define _IOWN(x,y,t)  (_IOC_IN|(((t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)\n"
1407     "#define _IO(x,y)      ('x'<<8|y)";
1408     test_text =
1409     "#define XX_IO(x)        ('x'<<8|256)";
1410 };
1411
1412 fix = {
1413     hackname  = io_quotes_use;
1414     select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+IO[A-Z]*[ \t]*"
1415                 "\\( *[^,']";
1416     c_fix     = char_macro_use;
1417     c_fix_arg = "IO";
1418     test_text = "#define TIOCFOO BSD43__IOWR(T, 1)\n"
1419                 "#define TIOCFOO \\\\\n"
1420                 "BSD43__IOWR(T, 1) /* Some are multi-line */";
1421 };
1422
1423
1424 /*
1425  *  Check for missing ';' in struct
1426  */
1427 fix = {
1428     hackname = ip_missing_semi;
1429     files    = netinet/ip.h;
1430     select   = "}$";
1431     sed      = "/^struct/,/^};/s/}$/};/";
1432     test_text=
1433     "struct mumble {\n"
1434     "  union {\n"
1435     "    int x;\n"
1436     "  }\n"
1437     "}; /* mumbled struct */\n";
1438 };
1439
1440
1441 /*
1442  *  IRIX 6.5.1[89] <internal/sgimacros.h> unconditionally defines
1443  *  __restrict as restrict iff __c99.  This is wrong for C++, which
1444  *  needs many C99 features, but only supports __restrict.
1445  */
1446 fix = {
1447     hackname  = irix___restrict;
1448     files     = internal/sgimacros.h;
1449     select    = "(#ifdef __c99\n)(#[ \t]*define __restrict restrict)";
1450
1451     mach      = "mips-sgi-irix6.5";
1452     c_fix     = format;
1453     c_fix_arg = "%1"
1454                 "#  ifndef __cplusplus\n%2\n#  endif";
1455
1456     test_text = "#ifdef __c99\n#  define __restrict restrict";
1457 };
1458
1459 /*
1460  *  IRIX 5.2's <sys/asm.h> contains an asm comment with a contraction
1461  *  that causes the assembly preprocessor to complain about an
1462  *  unterminated character constant.
1463  */
1464 fix = {
1465     hackname  = irix_asm_apostrophe;
1466     files     = sys/asm.h;
1467
1468     select    = "^[ \t]*#.*[Ww]e're";
1469     c_fix     = format;
1470     c_fix_arg = "%1 are";
1471     c_fix_arg = "^([ \t]*#.*[Ww]e)'re";
1472     test_text = "\t# and we're on vacation";
1473 };
1474
1475
1476 /*
1477  *  Non-traditional "const" declaration in Irix's limits.h.
1478  */
1479 fix = {
1480     hackname    = irix_limits_const;
1481     files       = fixinc-test-limits.h, limits.h;
1482     select      = "^extern const ";
1483     c_fix       = format;
1484     c_fix_arg   = "extern __const ";
1485     test_text   = "extern const char limit; /* test limits */";
1486 };
1487
1488
1489 /*
1490  *  IRIX 6.5.1[78] <sys/socket.h> has a broken definition of socklen_t.
1491  *  Various socket function prototypes use different types instead,
1492  *  depending on the API in use (BSD, XPG4/5), but the socklen_t
1493  *  definition doesn't reflect this (SGI Bug Id 864477, fixed in
1494  *  IRIX 6.5.19).
1495  */
1496 fix = {
1497     hackname  = irix_socklen_t;
1498     files     = sys/socket.h;
1499     select    = "(#define _SOCKLEN_T\n)(typedef u_int32_t socklen_t;)";
1500
1501     mach      = "mips-sgi-irix6.5";
1502     c_fix     = format;
1503     c_fix_arg = "%1"
1504                 "#if _NO_XOPEN4 && _NO_XOPEN5\n"
1505                 "typedef int socklen_t;\n"
1506                 "#else\n"
1507                 "%2\n"
1508                 "#endif /* _NO_XOPEN4 && _NO_XOPEN5 */";
1509
1510     test_text = "#define _SOCKLEN_T\ntypedef u_int32_t socklen_t;";
1511 };
1512
1513 /*
1514  *  IRIX 5.x's stdio.h and IRIX 6.5's internal/stdio_core.h declare
1515  *  some functions that take a va_list as
1516  *  taking char *.  However, GCC uses void * for va_list, so
1517  *  calling vfprintf with a va_list fails in C++.  */
1518 fix = {
1519     hackname  = irix_stdio_va_list;
1520     files     = stdio.h;
1521     files     = internal/stdio_core.h;
1522
1523     select = '/\* va_list \*/ char \*';
1524     c_fix  = format;
1525     c_fix_arg = "__gnuc_va_list";
1526     test_text =
1527     "extern int printf( const char *, /* va_list */ char * );";
1528 };
1529
1530
1531 /*
1532  *  IRIX 6.5.19 <internal/wchar_core.h> provides the XPG4 variant of
1533  *  wcsftime by default.  ISO C99 requires the XPG5 variant instead.
1534  */
1535 fix = {
1536     hackname  = irix_wcsftime;
1537     files     = internal/wchar_core.h;
1538     select    = "#if _NO_XOPEN5\n(extern size_t[ \t]+wcsftime.*const char \*.*)";
1539
1540     mach      = "mips-sgi-irix6.5";
1541     c_fix     = format;
1542     c_fix_arg = "#if _NO_XOPEN5 && !defined(__c99)\n%1";
1543
1544     test_text = "#if _NO_XOPEN5\n"
1545                 "extern size_t          wcsftime(wchar_t *, __SGI_LIBC_NAMESPACE_QUALIFIER size_t, const char *, const struct tm *);";
1546 };
1547
1548 /*
1549  * Fixing ISC fmod declaration
1550  */
1551 fix = {
1552     hackname  = isc_fmod;
1553     files     = math.h;
1554     select    = 'fmod\(double\)';
1555     c_fix     = format;
1556     c_fix_arg = "fmod(double, double)";
1557     test_text = "extern double  fmod(double);";
1558 };
1559
1560
1561 /*
1562  *  On Interactive Unix 2.2, certain traditional Unix definitions
1563  *  (notably getc and putc in stdio.h) are omitted if __STDC__ is
1564  *  defined, not just if _POSIX_SOURCE is defined.  This makes it
1565  *  impossible to compile any nontrivial program except with -posix.
1566  */
1567 fix = {
1568     hackname = isc_omits_with_stdc;
1569
1570     files     = "stdio.h";
1571     files     = "math.h";
1572     files     = "ctype.h";
1573     files     = "sys/limits.h";
1574     files     = "sys/fcntl.h";
1575     files     = "sys/dirent.h";
1576
1577     select    = '!defined\(__STDC__\) && !defined\(_POSIX_SOURCE\)';
1578     c_fix     = format;
1579     c_fix_arg = '!defined(_POSIX_SOURCE)';
1580     test_text = "#if !defined(__STDC__) && !defined(_POSIX_SOURCE) /* ? ! */"
1581                 "\nint foo;\n#endif";
1582 };
1583
1584
1585 /*
1586  * These files in Sun OS 4.x and ARM/RISCiX and BSD4.3
1587  * use / * * / to concatenate tokens.
1588  */
1589 fix = {
1590     hackname = kandr_concat;
1591     files  = "sparc/asm_linkage.h";
1592     files  = "sun3/asm_linkage.h";
1593     files  = "sun3x/asm_linkage.h";
1594     files  = "sun4/asm_linkage.h";
1595     files  = "sun4c/asm_linkage.h";
1596     files  = "sun4m/asm_linkage.h";
1597     files  = "sun4c/debug/asm_linkage.h";
1598     files  = "sun4m/debug/asm_linkage.h";
1599     files  = "arm/as_support.h";
1600     files  = "arm/mc_type.h";
1601     files  = "arm/xcb.h";
1602     files  = "dev/chardefmac.h";
1603     files  = "dev/ps_irq.h";
1604     files  = "dev/screen.h";
1605     files  = "dev/scsi.h";
1606     files  = "sys/tty.h";
1607     files  = "Xm.acorn/XmP.h";
1608     files  = bsd43/bsd43_.h;
1609     select = '/\*\*/';
1610     c_fix     = format;
1611     c_fix_arg = '##';
1612     test_text = "#define __CONCAT__(a,b) a/**/b";
1613 };
1614
1615
1616 /*
1617  *  Fix libc1 _G_va_list definition, used in declarations of several
1618  *  more-or-less standard functions, for example vasprintf.
1619  */
1620 fix = {
1621     hackname = libc1_G_va_list;
1622     files    = _G_config.h;
1623     mach     = '*-*-linux*libc1';
1624     select   = 'typedef void \* _G_va_list;';
1625     c_fix     = format;
1626     c_fix_arg = "typedef __builtin_va_list _G_va_list;";
1627     test_text = 'typedef void * _G_va_list;';
1628 };
1629
1630
1631 /*
1632  *  GNU libc1 string.h does not prototype memcpy and memcmp for gcc
1633  *  versions > 1.  This fix will open up the declaration for all
1634  *  versions of GCC and for g++.
1635  */
1636 fix = {
1637     hackname  = libc1_ifdefd_memx;
1638
1639     /* The string.h result is overwritten by AAB_ultrix_string when doing
1640        "make check" and will fail.  Therefore, we add the following kludgery
1641        to insert the test_text into the special testing header.  :-}  */
1642     files     = testing.h;
1643     files     = string.h;
1644
1645     c_fix     = format;
1646     select    = "' is a built-in function for gcc 2\\.x\\. \\*/";
1647     bypass    = __cplusplus;
1648     c_fix_arg = "%1";
1649     c_fix_arg =
1650        '/\* `mem...\' is a built-in function for gcc 2\.x\. \*/' "\n"
1651        '#if defined\(__STDC__\) && __GNUC__ < 2'                 "\n"
1652        "(/\\* .* \\*/\n"
1653        "extern [a-z_]+ mem.*(\n[^#].*)*;)\n"
1654        "#endif";
1655
1656     test_text =
1657     "/* \\`memcpy' is a built-in function for gcc 2.x. */\n"
1658     "#if defined(__STDC__) && __GNUC__ < 2\n"
1659     "/* Copy N bytes of SRC to DEST.  */\n"
1660     "extern __ptr_t memcpy __P ((__ptr_t __dest, __const __ptr_t __src,\n"
1661     "                         size_t __n));\n"
1662     "#endif";
1663 };
1664
1665
1666 /*
1667  *  In limits.h, put #ifndefs around things that are supposed to be defined
1668  *  in float.h to avoid redefinition errors if float.h is included first.
1669  *  On HP/UX this patch does not work, because on HP/UX limits.h uses
1670  *  multi line comments and the inserted #endif winds up inside the
1671  *  comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1672  *  we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1673  *  are there, and we do not add them ourselves.
1674  *
1675  *  QNX Software Systems also guards the defines, but doesn't define
1676  *  FLT_MIN.  Therefore, bypass the fix for *either* guarded FLT_MIN
1677  *  or guarded FLT_MAX.
1678  */
1679 fix = {
1680     hackname = limits_ifndefs;
1681     files  = "sys/limits.h";
1682     files  = "limits.h";
1683     select = "^[ \t]*#[ \t]*define[ \t]+"
1684              "((FLT|DBL)_(MIN|MAX|DIG))[ \t].*";
1685     bypass = "ifndef[ \t]+FLT_(MIN|MAX)";
1686
1687     c_fix     = format;
1688     c_fix_arg = "#ifndef %1\n%0\n#endif";
1689     /* Second arg is select expression */
1690     test_text = " #\tdefine\tDBL_DIG \t 0  /* somthin' */";
1691 };
1692
1693
1694 /*
1695  * Apparently some SVR4 systems typedef longlong_t to long ?
1696  */
1697 #ifdef SVR4
1698 fix = {
1699     hackname  = longlong_t;
1700     select    = "typedef[ \t]+(unsigned[ \t]+)?long[ \t]+(u_)?longlong_t";
1701     c_fix     = format;
1702     c_fix_arg = "typedef %1long long %2longlong_t";
1703     test_text = "typedef long longlong_t\n"
1704                 "typedef unsigned long u_longlong_t";
1705 };
1706 #endif
1707
1708
1709 /*
1710  *  Delete the '#define void int' line from curses.h on Lynx
1711  */
1712 fix = {
1713     hackname  = lynx_void_int;
1714     files     = curses.h;
1715     select    = "#[ \t]*define[ \t]+void[ \t]+int[ \t]*";
1716     c_fix     = format;
1717     c_fix_arg = "";
1718     test_text = "# define\tvoid\tint \t/* curses foiled again */";
1719 };
1720
1721
1722 /*
1723  *  Fix fcntl prototype in fcntl.h on LynxOS.
1724  */
1725 fix = {
1726     hackname  = lynxos_fcntl_proto;
1727     files     = fcntl.h;
1728     select    = "fcntl[ \t]*" '\(int, int, int\)';
1729     c_fix     = format;
1730     c_fix_arg = '%1...)';
1731     c_fix_arg = "(fcntl[ \t]*" '\(int, int, )int\)';
1732     test_text = "extern int fcntl(int, int, int);";
1733 };
1734
1735
1736 /*
1737  * Fix BSD machine/ansi.h to use __builtin_va_list to define _BSD_VA_LIST_.
1738  *
1739  * On NetBSD, machine is a symbolic link to an architecture specific
1740  * directory name, so we can't match a specific file name here.
1741  */
1742 fix = {
1743     hackname = machine_ansi_h_va_list;
1744     select   = "define[ \t]+_BSD_VA_LIST_[ \t]";
1745     bypass   = '__builtin_va_list';
1746
1747     c_fix     = format;
1748     c_fix_arg = "%1__builtin_va_list";
1749     c_fix_arg = "(define[ \t]+_BSD_VA_LIST_[ \t]+).*";
1750
1751     test_text = " # define _BSD_VA_LIST_\tchar**";
1752 };
1753
1754
1755 /*
1756  *  Fix non-ansi machine name defines
1757  */
1758 fix = {
1759     hackname  = machine_name;
1760     c_test    = machine_name;
1761     c_fix     = machine_name;
1762
1763     test_text = "/* MACH_DIFF: */\n"
1764     "#if defined( i386 ) || defined( sparc ) || defined( vax )"
1765     "\n/* no uniform test, so be careful  :-) */";
1766 };
1767
1768
1769 /*
1770  *  Some math.h files define struct exception (it's in the System V
1771  *  Interface Definition), which conflicts with
1772  *  the class exception defined in the C++ file std/stdexcept.h.  We
1773  *  redefine it to __math_exception.  This is not a great fix, but I
1774  *  haven't been able to think of anything better.
1775  *  Note that we have to put the #ifdef/#endif blocks at beginning
1776  *  and end of file, because fixproto runs after us and may insert
1777  *  additional references to struct exception.
1778  */
1779 fix = {
1780     hackname  = math_exception;
1781     files     = math.h;
1782     select    = "struct exception";
1783     bypass    = '__cplusplus';
1784     c_fix     = wrap;
1785
1786     c_fix_arg = "#ifdef __cplusplus\n"
1787                 "#define exception __math_exception\n"
1788                 "#endif\n";
1789
1790     c_fix_arg = "#ifdef __cplusplus\n"
1791                 "#undef exception\n"
1792                 "#endif\n";
1793
1794     test_text = "typedef struct exception t_math_exception;";
1795 };
1796
1797
1798 /*
1799  *  This looks pretty broken to me.  ``dbl_max_def'' will contain
1800  *  "define DBL_MAX " at the start, when what we really want is just
1801  *  the value portion.  Can't figure out how to write a test case
1802  *  for this either  :-(
1803  */
1804 fix = {
1805     hackname = math_huge_val_from_dbl_max;
1806     files    = math.h;
1807
1808     /*
1809      * IF HUGE_VAL is defined to be DBL_MAX *and* DBL_MAX is _not_ defined
1810      * in math.h, this fix applies.
1811      */
1812     select   = "define[ \t]+HUGE_VAL[ \t]+DBL_MAX";
1813     bypass   = "define[ \t]+DBL_MAX";
1814
1815     shell    =
1816     /*
1817      *  See if we have a definition for DBL_MAX in float.h.
1818      *  If we do, we will replace the one in math.h with that one.
1819      */
1820
1821     "\tdbl_max_def=`egrep 'define[ \t]+DBL_MAX[ \t]+.*' float.h "
1822                    "| sed 's/.*DBL_MAX[ \t]*//' 2>/dev/null`\n\n"
1823
1824     "\tif ( test -n \"${dbl_max_def}\" ) > /dev/null 2>&1\n"
1825     "\tthen sed -e '/define[ \t]*HUGE_VAL[ \t]*DBL_MAX/"
1826                         "s@DBL_MAX@'\"$dbl_max_def@\"\n"
1827     "\telse cat\n"
1828     "\tfi";
1829
1830     test_text =
1831     "`echo '#define DBL_MAX\t3.1415e+9 /* really big */' >> float.h`\n"
1832     "#define HUGE_VAL DBL_MAX";
1833 };
1834
1835
1836 /*
1837  * In any case, put #ifndef .. #endif around #define HUGE_VAL in math.h.
1838  */
1839 fix = {
1840     hackname = math_huge_val_ifndef;
1841     files    = math.h;
1842     files    = math/math.h;
1843     select   = "define[ \t]+HUGE_VAL";
1844
1845     c_fix     = format;
1846     c_fix_arg = "#ifndef HUGE_VAL\n%0\n#endif";
1847     c_fix_arg = "^[ \t]*#[ \t]*define[ \t]+HUGE_VAL[ \t].*";
1848
1849     test_text = "# define\tHUGE_VAL 3.4e+40";
1850 };
1851
1852
1853 /*
1854  *  nested comment
1855  */
1856 fix = {
1857     hackname  = nested_auth_des;
1858     files     = rpc/rpc.h;
1859     select    = '(/\*.*rpc/auth_des\.h>.*)/\*';
1860     c_fix     = format;
1861     c_fix_arg = "%1*/ /*";
1862     test_text = "/*#include <rpc/auth_des.h> /* skip this */";
1863 };
1864
1865
1866 /*
1867  * Fix nested comments in Motorola's <limits.h> and <sys/limits.h>
1868  */
1869 fix = {
1870     hackname = nested_motorola;
1871     mach     = "m68k-motorola-sysv*";
1872     files    = sys/limits.h;
1873     files    = limits.h;
1874     select   = "max # bytes atomic in write|error value returned by Math lib";
1875
1876     sed = "s@^\\(#undef[ \t][ \t]*PIPE_BUF[ \t]*"
1877                    "/\\* max # bytes atomic in write to a\\)$@\\1 */@";
1878     sed = "s@\\(/\\*#define\tHUGE_VAL\t3.[0-9e+]* \\)"
1879           "\\(/\\*error value returned by Math lib\\*/\\)$@\\1*/ \\2@";
1880
1881     test_text =
1882     "#undef PIPE_BUF /* max # bytes atomic in write to a\n"
1883     "\t\t/* PIPE */\n"
1884     "/*#define\tHUGE_VAL\t3.9e+9 /*error value returned by Math lib*/";
1885 };
1886
1887
1888 /*
1889  * Fixing nested comments in ISC <sys/limits.h>
1890  */
1891 fix = {
1892     hackname = nested_sys_limits;
1893     files  = sys/limits.h;
1894     select = CHILD_MAX;
1895     sed    = "/CHILD_MAX/s,/\\* Max, Max,";
1896     sed    = "/OPEN_MAX/s,/\\* Max, Max,";
1897     test_text = "/*\n#define CHILD_MAX 20 /* Max, Max, ... */ /*\n"
1898                 "#define OPEN_MAX  20 /* Max, Max, ... */\n";
1899 };
1900
1901
1902 /*
1903  * NetBSD has a semicolon after the ending '}' for some extern "C".
1904  */
1905 fix = {
1906     hackname  = netbsd_extra_semicolon;
1907     mach      = *-*-netbsd*;
1908     files     = sys/cdefs.h;
1909     select    = "#define[ \t]*__END_DECLS[ \t]*};";
1910
1911     c_fix     = format;
1912     c_fix_arg = "#define __END_DECLS }";
1913
1914     test_text = "#define __END_DECLS };";
1915 };
1916
1917
1918 /*
1919  *  NeXT 3.2 adds const prefix to some math functions.
1920  *  These conflict with the built-in functions.
1921  */
1922 fix = {
1923     hackname  = next_math_prefix;
1924     files     = ansi/math.h;
1925     select    = "^extern[ \t]+double[ \t]+__const__[ \t]";
1926
1927     c_fix     = format;
1928     c_fix_arg = "extern double %1(";
1929     c_fix_arg = "^extern[ \t]+double[ \t]+__const__[ \t]+([a-z]+)\\(";
1930
1931     test_text = "extern\tdouble\t__const__\tmumble();";
1932 };
1933
1934
1935 /*
1936  *  NeXT 3.2 uses the word "template" as a parameter for some
1937  *  functions. GCC reports an invalid use of a reserved key word
1938  *  with the built-in functions.
1939  */
1940 fix = {
1941     hackname = next_template;
1942     files    = bsd/libc.h;
1943     select   = "[ \t]template\\)";
1944
1945     c_fix     = format;
1946     c_fix_arg = "(%1)";
1947     c_fix_arg = "\\(([^)]*)[ \t]template\\)";
1948     test_text = "extern mumble( char * template); /* fix */";
1949 };
1950
1951
1952 /*
1953  *  NeXT 3.2 includes the keyword volatile in the abort() and  exit()
1954  *  function prototypes. That conflicts with the  built-in functions.
1955  */
1956 fix = {
1957     hackname = next_volitile;
1958     files    = ansi/stdlib.h;
1959     select   = "^extern[ \t]+volatile[ \t]+void[ \t]";
1960
1961     c_fix     = format;
1962     c_fix_arg = "extern void %1(";
1963     c_fix_arg = "^extern[ \t]+volatile[ \t]+void[ \t]+(exit|abort)\\(";
1964
1965     test_text = "extern\tvolatile\tvoid\tabort();";
1966 };
1967
1968
1969 /*
1970  *  NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1971  *  Note that version 3 of the NeXT system has wait.h in a different directory,
1972  *  so that this code won't do anything.  But wait.h in version 3 has a
1973  *  conditional, so it doesn't need this fix.  So everything is okay.
1974  */
1975 fix = {
1976     hackname  = next_wait_union;
1977     files     = sys/wait.h;
1978
1979     select    = 'wait\(union wait';
1980     c_fix     = format;
1981     c_fix_arg = "wait(void";
1982     test_text = "extern pid_d wait(union wait*);";
1983 };
1984
1985
1986 /*
1987  *  a missing semi-colon at the end of the nodeent structure definition.
1988  */
1989 fix = {
1990     hackname  = nodeent_syntax;
1991     files     = netdnet/dnetdb.h;
1992     select    = "char[ \t]*\\*na_addr[ \t]*$";
1993     c_fix     = format;
1994     c_fix_arg = "%0;";
1995     test_text = "char *na_addr\t";
1996 };
1997
1998
1999 /*
2000  *  obstack.h used casts as lvalues.
2001  *
2002  *  We need to change postincrements of casted pointers (which are
2003  *  then dereferenced and assigned into) of the form
2004  *
2005  *    *((TYPE*)PTRVAR)++ = (VALUE)
2006  *
2007  *  into expressions like
2008  *
2009  *    ((*((TYPE*)PTRVAR) = (VALUE)), (PTRVAR += sizeof (TYPE)))
2010  *
2011  *  which is correct for the cases used in obstack.h since PTRVAR is
2012  *  of type char * and the value of the expression is not used.
2013  */
2014 fix = {
2015     hackname  = obstack_lvalue_cast;
2016     files     = obstack.h;
2017     select    = '\*\(\(([^()]*)\*\)(.*)\)\+\+ = \(([^()]*)\)';
2018     c_fix     = format;
2019     c_fix_arg = "((*((%1*)%2) = (%3)), (%2 += sizeof (%1)))";
2020     test_text = "*((void **) (h)->next_free)++ = (aptr)";
2021 };
2022
2023
2024 /*
2025  *  sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
2026  *  defining regex.h related types.  This causes libg++ build and usage
2027  *  failures.  Fixing this correctly requires checking and modifying 3 files.
2028  */
2029 fix = {
2030     hackname = osf_namespace_a;
2031     files    = reg_types.h;
2032     files    = sys/lc_core.h;
2033     test     = " -r reg_types.h";
2034     test     = " -r sys/lc_core.h";
2035     test     = " -n \"`grep '} regex_t;' reg_types.h`\"";
2036     test     = " -z \"`grep __regex_t regex.h`\"";
2037
2038     c_fix     = format;
2039     c_fix_arg = "__%0";
2040     c_fix_arg = "reg(ex|off|match)_t";
2041
2042     test_text = "`touch sys/lc_core.h`"
2043     "typedef struct {\n  int stuff, mo_suff;\n} regex_t;\n"
2044     "extern regex_t    re;\n"
2045     "extern regoff_t   ro;\n"
2046     "extern regmatch_t rm;\n";
2047 };
2048
2049 fix = {
2050     hackname = osf_namespace_c;
2051     files    = regex.h;
2052     test     = " -r reg_types.h";
2053     test     = " -r sys/lc_core.h";
2054     test     = " -n \"`grep '} regex_t;' reg_types.h`\"";
2055     test     = " -z \"`grep __regex_t regex.h`\"";
2056
2057     select    = "#include <reg_types\.h>.*";
2058     c_fix     = format;
2059     c_fix_arg = "%0\n"
2060                 "typedef __regex_t\tregex_t;\n"
2061                 "typedef __regoff_t\tregoff_t;\n"
2062                 "typedef __regmatch_t\tregmatch_t;";
2063
2064     test_text = "#include <reg_types.h>";
2065 };
2066
2067
2068 /*
2069  *  Fix __page_size* declarations in pthread.h AIX 4.1.[34].
2070  *  The original ones fail if uninitialized externs are not common.
2071  *  This is the default for all ANSI standard C++ compilers.
2072  */
2073 fix = {
2074     hackname  = pthread_page_size;
2075     files     = pthread.h;
2076     select    = "^int __page_size";
2077     c_fix     = format;
2078     c_fix_arg = "extern %0";
2079     test_text = "int __page_size;";
2080 };
2081
2082
2083 /*
2084  * On DYNIX/ptx, sys/mc_param.h has an embedded asm for the cpuid instruction
2085  * on the P5. This is not used by anything else so we ifdef it out.
2086  * Current GCC doesn't seem to complain about the asm, though.
2087  */
2088 #ifdef PTX
2089 fix = {
2090     hackname  = ptx_sys_mc_param_h;
2091     files     = sys/mc_param.h;
2092     sed       = "/__asm/,/}/{"
2093                   "/__asm/i\\\n"
2094                   "#if !defined (__GNUC__) && !defined (__GNUG__)\n"
2095                   "/}/a\\\n"
2096                   "#endif\n"
2097                 "}";
2098     test_text = "__asm\n"
2099                 "int _CPUID()\n"
2100                 "{\n"
2101                 "   non-GNU assembly here\n"
2102                 "}";
2103 };
2104 #endif
2105
2106
2107 /*
2108  *  Fix return type of fread and fwrite on sysV68
2109  */
2110 fix = {
2111     hackname = read_ret_type;
2112     files    = stdio.h;
2113     select   = "extern int\t.*, fread\\(\\), fwrite\\(\\)";
2114     c_fix     = format;
2115     c_fix_arg = "extern unsigned int fread(), fwrite();\n%1%2";
2116     c_fix_arg = "(extern int\t.*), fread\\(\\), fwrite\\(\\)(.*)";
2117
2118     test_text = "extern int\tfclose(), fflush(), fread(), fwrite(), foo();";
2119 };
2120
2121
2122 /*
2123  *  function class(double x) conflicts with C++ keyword on rs/6000
2124  */
2125 fix = {
2126     hackname  = rs6000_double;
2127     files     = math.h;
2128     select    = '[^a-zA-Z_]class\(';
2129
2130     c_fix     = format;
2131     c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
2132     c_fix_arg = '^.*[^a-zA-Z_]class\(.*';
2133
2134     test_text = "extern int class();";
2135 };
2136
2137
2138 /*
2139  *  Wrong fchmod prototype on RS/6000.
2140  */
2141 fix = {
2142     hackname  = rs6000_fchmod;
2143     files     = sys/stat.h;
2144     select    = 'fchmod\(char \*';
2145     c_fix     = format;
2146     c_fix_arg = "fchmod(int";
2147     test_text = "extern int fchmod(char *, mode_t);";
2148 };
2149
2150
2151 /*
2152  *  parameters conflict with C++ new on rs/6000
2153  */
2154 fix = {
2155     hackname  = rs6000_param;
2156     files     = "stdio.h";
2157     files     = "unistd.h";
2158
2159     select    = 'rename\(const char \*old, const char \*new\)';
2160     c_fix     = format;
2161     c_fix_arg = 'rename(const char *_old, const char *_new)';
2162
2163     test_text = 'extern int rename(const char *old, const char *new);';
2164 };
2165
2166
2167 /*
2168  *  On OpenServer and on UnixWare 7, <math.h> uses the native compiler
2169  *  __builtin_generic. We fix that usage to use the GCC equivalent.
2170  * It also has a plethora of inline functions that conflict with libstdc++.
2171  */
2172 fix = {
2173     hackname = sco_math;
2174     files    = math.h;
2175     files    = ansi/math.h;
2176     files    = posix/math.h;
2177     files    = xpg4/math.h;
2178     files    = xpg4v2/math.h;
2179     files    = xpg4plus/math.h;
2180     files    = ods_30_compat/math.h;
2181     files    = oldstyle/math.h;
2182     select   = "inline double abs";
2183     sed      = "/#define.*__fp_class(a) \\\\/i\\\n"
2184                "#ifndef __GNUC__\n";
2185     sed      =
2186 "/.*__builtin_generic/a\\\n"
2187 "#else\\\n"
2188 "#define __fp_class(a) \\\\\\\n"
2189 "  __builtin_choose_expr(__builtin_types_compatible_p(typeof(a),long double),\\\\\\\n"
2190 "   __fpclassifyl(a), \\\\\\\n"
2191 "    __builtin_choose_expr(__builtin_types_compatible_p(typeof(a), float), \\\\\\\n"
2192 "      __fpclassifyf(a),__fpclassify(a)))\\\n"
2193 "#endif";
2194
2195     sed      = "/extern \"C\\+\\+\"/N;"
2196                "/inline double abs/i\\\n"
2197                "#ifndef __GNUC__\n";
2198     sed      = "/inline long double trunc/N;"
2199                "/inline long double trunc.*}.*extern \"C\\+\\+\"/a\\\n"
2200                "#endif /* ! __GNUC__ */";
2201
2202     test_text =
2203     "#define __fp_class(a) \\\\\n"
2204     " __builtin_generic(a,\"ld:__fplcassifyl;f:__fpclassifyf;:__fpclassify\")\n";
2205
2206 };
2207
2208
2209 /*
2210  *  On SCO OpenServer prior to 5.0.7UP1, <sys/regset.h> and <ieeefp.h>
2211  *  have a clash on struct _fpstate and struct fpstate.
2212  */
2213 fix = {
2214     hackname = sco_regset;
2215     files    = sys/regset.h;
2216     mach     = "*-*-sco3.2v5*";
2217     select   = "(struct[ \t]+.*)fpstate";
2218     c_fix     = format;
2219     c_fix_arg = "%1rsfpstate";
2220
2221     test_text =
2222     "union u_fps {\n"
2223     "    struct\tfpstate\n"
2224     "    {\n"
2225     "       int whatever;\n"
2226     "    }\n"
2227     "};\n"
2228     "union _u_fps {\n"
2229     "    struct _fpstate\n"
2230     "    {\n"
2231     "       int whatever;\n"
2232     "    }\n"
2233     "};\n";
2234 };
2235
2236
2237 /*
2238  *  The static functions lstat() and fchmod() in <sys/stat.h>
2239  *  cause G++ grief since they're not wrapped in "if __cplusplus".
2240  *
2241  *  On SCO OpenServer 5.0.0 through (at least) 5.0.5 <sys/stat.h> contains
2242  *  tiny static wrappers that aren't C++ safe.
2243  */
2244 fix = {
2245     hackname = sco_static_func;
2246     files    = sys/stat.h;
2247     mach     = "i?86-*-sco3.2*";
2248     select   = "^static int";
2249
2250     sed      = "/^static int/i\\\n"
2251                "#if __cplusplus\\\n"
2252                "extern \"C\" {\\\n"
2253                "#endif /* __cplusplus */";
2254
2255     sed      = "/^}$/a\\\n"
2256                "#if __cplusplus\\\n"
2257                " }\\\n"
2258                "#endif /* __cplusplus */";
2259
2260     test_text =
2261     "#ifdef __STDC__\n"
2262     "static int\tstat(const char *__f, struct stat *__p) {\n"
2263     "\treturn __stat32(__f, __p);\n"
2264     "}\n\n#  else /* !__STDC__ THIS FAILS ON BSD SYSTEMS */\n"
2265
2266     "static int\tstat(__f, __p)\n"
2267     "\tchar *__f;\n"
2268     "\tstruct stat *__p;\n"
2269     "{\n"
2270     "\treturn __stat32(__f, __p);\n"
2271     "}\n"
2272     "#endif";
2273 };
2274
2275
2276 /*
2277  *  Fix prototype declaration of utime in sys/times.h.
2278  *  In 3.2v4.0 the const is missing.
2279  */
2280 fix = {
2281     hackname  = sco_utime;
2282     files     = sys/times.h;
2283     mach      = "i?86-*-sco3.2v4*";
2284
2285     select    = '\(const char \*, struct utimbuf \*\);';
2286     c_fix     = format;
2287     c_fix_arg = '(const char *, const struct utimbuf *);';
2288
2289     test_text = "extern int utime(const char *, struct utimbuf *);";
2290 };
2291
2292
2293 /*
2294  *  Sun Solaris 2.5.1, 2.6 defines PTHREAD_{MUTEX|COND}_INITIALIZER
2295  *  incorrectly, so we replace them with versions that correspond to
2296  *  the definition.  We also explicitly name this fix "1" and the next
2297  *  fix "2" because this one does not deal with the last field.  This
2298  *  fix needs to run before the next.
2299  */
2300 fix = {
2301     hackname = solaris_mutex_init_1;
2302     select = '@\(#\)pthread.h' "[ \t]+1.1[0-9][ \t]+9[567]/[0-9/]+ SMI";
2303     files = pthread.h;
2304     sed   = "/define[ \t]*PTHREAD_MUTEX_INI/s/{0, 0,/{{{0}, 0}, {{{0}}},/\n"
2305             "/define[ \t]*PTHREAD_COND_INI/s/{0,/{{{0},0},/";
2306     test_text =
2307     '#ident "@(#)pthread.h  1.16    97/05/05 SMI"'"\n"
2308     "#define PTHREAD_MUTEX_INITIALIZER\t{0, 0, 0}\n"
2309     "#define PTHREAD_COND_INITIALIZER\t{0, 0} /* */\n";
2310 };
2311
2312
2313 /*
2314  * Sun Solaris defines PTHREAD_MUTEX_INITIALIZER with a trailing
2315  * "0" for the last field of the pthread_mutex_t structure, which is
2316  * of type upad64_t, which itself is typedef'd to int64_t, but with
2317  * __STDC__ defined (e.g. by -ansi) it is a union. So change the
2318  * initializer to "{0}" instead
2319  */
2320 fix = {
2321     hackname = solaris_mutex_init_2;
2322     select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
2323     files = pthread.h;
2324     c_fix = format;
2325     c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
2326                 "%0\n"
2327                 "#else\n"
2328                 "%1, {0}}%3\n"
2329                 "#endif";
2330     c_fix_arg = "(^#define[ \t]+PTHREAD_(MUTEX|COND)_INITIALIZER[ \t]+\\{.*)"
2331                 ",[ \t]*0\\}" "(|[ \t].*)$";
2332     test_text =
2333     '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
2334     "#define PTHREAD_MUTEX_INITIALIZER\t{{{0},0}, {{{0}}}, 0}\n"
2335     "#define PTHREAD_COND_INITIALIZER\t{{{0}, 0}, 0}\t/* DEFAULTCV */\n"
2336     "#define PTHREAD_RWLOCK_INITIALIZER\t"
2337              "{0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}}";
2338 };
2339
2340
2341 /*
2342  * Solaris 2.5.1 and 2.6 use an outdated prototype for send & recv
2343  * in sys/socket.h.  This is corrected in Solaris 7 and up.
2344  */
2345 fix = {
2346     hackname = solaris_socket;
2347     files = sys/socket.h;
2348     select = '@\(#\)socket.h' "[ \t]+1.[123][0-9][ \t]+9[567]/[0-9/]+ SMI";
2349     c_fix = format;
2350     c_fix_arg = "extern int %1(int, %2void *, int, int);";
2351     c_fix_arg = '^extern int (recv|send)\(int,'
2352                 ' (const )*char '
2353                 '\*, int, int\);';
2354
2355     test_text = '#ident   "@(#)socket.h   1.30    97/01/20 SMI"'"\n"
2356                 "extern int recv(int, char *, int, int);\n"
2357                 "extern int send(int, const char *, int, int);";
2358 };
2359
2360
2361 /*
2362  * Solaris 2.8 has what appears to be some gross workaround for 
2363  * some old version of their c++ compiler.  G++ doesn't want it
2364  * either, but doesn't want to be tied to SunPRO version numbers.
2365  */
2366 fix = {
2367     hackname = solaris_stdio_tag;
2368     files    = stdio_tag.h;
2369
2370     select   = '__cplusplus < 54321L';
2371     sed      = 's/defined(__cplusplus) && (__cplusplus < 54321L)/0/';
2372
2373     test_text = "#if\tdefined(__cplusplus) && (__cplusplus < 54321L)";
2374 };
2375
2376
2377 /*
2378  * Sun Solaris 2.5.1 doesn't define 'getpagesize' in <unistd.h>, as is done
2379  * on Solaris 2.6 and up.
2380  */
2381 fix = {
2382     hackname  = solaris_unistd;
2383     files = unistd.h;
2384     select = '@\(#\)unistd.h' "[ \t]+1.3[0-9][ \t]+9[567]/[0-9/]+ SMI";
2385     bypass = "getpagesize";
2386     c_fix = format;
2387     c_fix_arg = "extern int getpagesize();\n%0";
2388     c_fix_arg = '^extern (pid_t|int) getpgid\(.*\);';
2389     test_text = '#ident "@(#)unistd.h   1.33    95/08/28 SMI"'"\n"
2390                 "extern pid_t getpgid(pid_t);\n"
2391                 "extern int getpgid();";
2392 };
2393
2394
2395 /*
2396  * <widec.h> until Solaris 2.5.1 defines macros for a couple of <wchar.h>
2397  * functions, breaking their prototypes if that file is included afterwards.
2398  * Include <wchar.h> early to avoid this issue, as is done on Solaris 2.6
2399  * and up.
2400  */
2401 fix = {
2402     hackname  = solaris_widec;
2403     files     = widec.h;
2404     mach      = '*-*-solaris2.[0-5]';
2405     mach      = '*-*-solaris2.[0-5].*';
2406     bypass    = "include.*wchar\\.h";
2407     select    = "#include <euc.h>";
2408     c_fix     = format;
2409     c_fix_arg = "%0\n#include <wchar.h>";
2410     test_text = "#include <euc.h>";
2411 };
2412
2413
2414 /*
2415  *  a missing semi-colon at the end of the statsswtch structure definition.
2416  */
2417 fix = {
2418     hackname  = statsswtch;
2419     files     = rpcsvc/rstat.h;
2420     select    = "boottime$";
2421     c_fix     = format;
2422     c_fix_arg = "boottime;";
2423     test_text = "struct statswtch {\n  int boottime\n};";
2424 };
2425
2426
2427 /*
2428  *  Arrange for stdio.h to use stdarg.h to define __gnuc_va_list.
2429  *  On 4BSD-derived systems, stdio.h defers to machine/ansi.h; that's
2430  *  OK too.
2431  */
2432 fix = {
2433     hackname = stdio_stdarg_h;
2434     files    = stdio.h;
2435     bypass   = "include.*(stdarg\.h|machine/ansi\.h)";
2436
2437     c_fix     = wrap;
2438
2439     c_fix_arg = "#define __need___va_list\n#include <stdarg.h>\n";
2440
2441     test_text = "";
2442 };
2443
2444
2445 /*
2446  *  Don't use or define the name va_list in stdio.h.
2447  *  This is for ANSI and also to interoperate properly with gcc's
2448  *  varargs.h.  Note _BSD_VA_LIST_ is dealt with elsewhere.  The
2449  *  presence of __gnuc_va_list, __DJ_va_list, or _G_va_list is taken
2450  *  to indicate that the header knows what it's doing -- under SUSv2,
2451  *  stdio.h is required to define va_list, and we shouldn't break that.
2452  *  On IRIX 6.5, internal/wchar_core.h used to get its definition of
2453  *  va_list from stdio.h.  Since this doesn't happen any longer, use
2454  *  __gnuc_va_list there, too.
2455  */
2456 fix = {
2457     hackname = stdio_va_list;
2458     files    = stdio.h;
2459     files    = internal/stdio_core.h;
2460     files    = internal/wchar_core.h;
2461     bypass   = '__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list';
2462
2463     /*
2464      * Use __gnuc_va_list in arg types in place of va_list.
2465      * On 386BSD use __gnuc_va_list instead of _VA_LIST_.  On Tru64 UNIX V5.1A
2466      * use __gnuc_va_list instead of __VA_LIST__.  We're hoping the
2467      * trailing parentheses and semicolon save all other systems from this.
2468      * Define __not_va_list__ (something harmless and unused)
2469      * instead of va_list.
2470      * Don't claim to have defined va_list.
2471      */
2472     sed = "s@ va_list @ __gnuc_va_list @\n"
2473           "s@ va_list)@ __gnuc_va_list)@\n"
2474           "s@(va_list)&@(__gnuc_va_list)\\&@\n"
2475           "s@ _VA_LIST_));@ __gnuc_va_list));@\n"
2476           "s@ __VA_LIST__));@ __gnuc_va_list));@\n"
2477           "s@ va_list@ __not_va_list__@\n"
2478           "s@\\*va_list@*__not_va_list__@\n"
2479           "s@ __va_list)@ __gnuc_va_list)@\n"
2480           "s@typedef[ \t]\\(.*\\)[ \t]va_list[ \t]*;"
2481            "@typedef \\1 __not_va_list__;@\n"
2482           "s@typedef[ \t]*__va_list__@typedef __gnuc_va_list@\n"
2483           "s@GNUC_VA_LIST@GNUC_Va_LIST@\n"
2484           "s@_VA_LIST_DEFINED@_Va_LIST_DEFINED@\n"
2485           "s@_NEED___VA_LIST@_NEED___Va_LIST@\n"
2486           "s@VA_LIST@DUMMY_VA_LIST@\n"
2487           "s@_Va_LIST@_VA_LIST@";
2488     test_text = "extern void mumble( va_list);";
2489 };
2490
2491
2492 /*
2493  *  "!__STDC__" or "__STDC__==0" or "__STDC__!=1" or "__STDC__-0==0"
2494  *  is "!defined( __STRICT_ANSI__ )"
2495  */
2496 fix = {
2497     hackname = strict_ansi_not;
2498     select   = "^([ \t]*#[ \t]*if.*)"
2499                "(!__STDC__"
2500                "|__STDC__[ \t]*==[ \t]*0"
2501                "|__STDC__[ \t]*!=[ \t]*1"
2502                "|__STDC__[ \t]*-[ \t]*0[ \t]*==[ \t]*0)";
2503     /* Tru64 UNIX V4.0F/V5.1 <standards.h> supports GCC usage of __STDC__. */
2504     bypass = 'GNU and MIPS C compilers define __STDC__ differently';
2505     /* GNU gmp.h uses "__STDC__ != 1" only if __SCO_VERSION__, which
2506        is not defined by GCC, so it is safe.  */
2507     bypass = '__SCO_VERSION__.*__STDC__ != 1';
2508     c_test   = stdc_0_in_system_headers;
2509
2510     c_fix     = format;
2511     c_fix_arg = "%1 !defined(__STRICT_ANSI__)";
2512
2513     test_text = "#if !__STDC__ \n"
2514                 "#if __STDC__ == 0\n"
2515                 "#if __STDC__ != 1\n"
2516                 "#if __STDC__ - 0 == 0"
2517                "/* not std C */\nint foo;\n"
2518                "\n#end-end-end-end-if :-)";
2519 };
2520
2521 /*
2522  *  "__STDC__-0==0"
2523  *  is "!defined( __STRICT_ANSI__ )" on continued #if-s
2524  */
2525 fix = {
2526     hackname = strict_ansi_not_ctd;
2527     files    = math.h, limits.h, stdio.h, signal.h,
2528                stdlib.h, sys/signal.h, time.h;
2529     /*
2530      * Starting at the beginning of a line, skip white space and
2531      * a leading "(" or "&&" or "||".  One of those must be found.
2532      * Then, zero, one or more copies of a "defined(_FOO_BAR_) &&"
2533      * expression.  If these are nested, then they must accumulate
2534      * because we won't match any closing parentheses.  Finally,
2535      * after skipping over all that, we must then match our suspect
2536      * phrase:  "__STDC__-0==0" with or without white space.
2537      */
2538     select   = "^([ \t]*" '(\(|&&|\|\|)'
2539                "([ \t(]*!*[ \t]*defined\\([a-zA-Z_0-9]+\\)[ \t]*[|&][|&])*"
2540                "[ \t(]*)"
2541                "(__STDC__[ \t]*(|-[ \t]*0[ \t]*)==[ \t]*0)";
2542     c_test   = stdc_0_in_system_headers;
2543
2544     c_fix     = format;
2545     c_fix_arg = "%1 !defined(__STRICT_ANSI__)";
2546
2547     test_text = "#if 1 && \\\\\n"
2548                "&& defined(mumbling) |& (__STDC__ - 0 == 0) \\\\\n"
2549                "( __STDC__ == 0 && !defined(_XOPEN_SOURCE) \\\\\n"
2550                "|| __STDC__ - 0 == 0 ) /* not std C */\n"
2551                "int foo;\n#endif";
2552 };
2553
2554
2555 /*
2556  *  "__STDC__!=0" or "__STDC__==1" or "__STDC__-0==1"
2557  *  is "defined( __STRICT_ANSI__ )"
2558  */
2559 fix = {
2560     hackname = strict_ansi_only;
2561     select   = "^([ \t]*#[ \t]*if.*)"
2562                "(__STDC__[ \t]*!=[ \t]*0"
2563                "|__STDC__[ \t]*==[ \t]*1"
2564                "|__STDC__[ \t]*-[ \t]*0[ \t]*==[ \t]*1"
2565                "|__STDC__[ \t]*-[ \t]*0[ \t]*!=[ \t]*0)";
2566     c_test   = stdc_0_in_system_headers;
2567
2568     c_fix     = format;
2569     c_fix_arg = "%1 defined(__STRICT_ANSI__)";
2570
2571     test_text = "#if __STDC__ == 1 /* is std C\n */\nint foo;\n#endif";
2572 };
2573
2574
2575 /*
2576  *  IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s
2577  *  in prototype without previous definition.
2578  */
2579 fix = {
2580     hackname  = struct_file;
2581     files     = rpc/xdr.h;
2582     select    = '^.*xdrstdio_create.*struct __file_s';
2583     c_fix     = format;
2584     c_fix_arg = "struct __file_s;\n%0";
2585     test_text = "extern void xdrstdio_create( struct __file_s* );";
2586 };
2587
2588
2589 /*
2590  *  IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr
2591  *  in prototype without previous definition.
2592  *
2593  *  Don't fix OpenBSD, which uses struct sockaddr_in prototyping the same
2594  *  function, and does define it.
2595  */
2596 fix = {
2597     hackname  = struct_sockaddr;
2598     files     = rpc/auth.h;
2599     select    = "^.*authdes_create.*struct sockaddr[^_]";
2600     bypass    = "<sys/socket\.h>";
2601     bypass    = "struct sockaddr;\n";
2602     c_fix     = format;
2603     c_fix_arg = "struct sockaddr;\n%0";
2604     test_text = "extern AUTH* authdes_create( struct sockaddr* );";
2605 };
2606
2607
2608 /*
2609  *  Apply fix this to all OSs since this problem seems to effect
2610  *  more than just SunOS.
2611  */
2612 fix = {
2613     hackname = sun_auth_proto;
2614     files    = rpc/auth.h;
2615     files    = rpc/clnt.h;
2616     files    = rpc/svc.h;
2617     files    = rpc/xdr.h;
2618     /*
2619      *  Select those files containing '(*name)()'.
2620      */
2621     select    = '\(\*[a-z][a-z_]*\)\(\)';
2622
2623     c_fix     = format;
2624     c_fix_arg = "#ifdef __cplusplus\n%1(...);%2\n"
2625                 "#else\n%1();%2\n#endif";
2626     c_fix_arg = '(.*\(\*[a-z][a-z_]*\))\(\);(.*)';
2627
2628     test_text =
2629     "struct auth_t {\n"
2630     "    int (*name)(); /* C++ bad */\n"
2631     "};";
2632 };
2633
2634
2635 /*
2636  *  Fix bogus #ifdef on SunOS 4.1.
2637  */
2638 fix = {
2639     hackname  = sun_bogus_ifdef;
2640     files     = "hsfs/hsfs_spec.h";
2641     files     = "hsfs/iso_spec.h";
2642     select    = '#ifdef(.*\|\|.*)';
2643     c_fix     = format;
2644     c_fix_arg = "#if%1";
2645
2646     test_text = "#ifdef  __i386__ || __vax__ || __sun4c__";
2647 };
2648
2649
2650 /*
2651  *  Fix the CAT macro in SunOS memvar.h.
2652  */
2653 fix = {
2654     hackname  = sun_catmacro;
2655     files     = pixrect/memvar.h;
2656     select    = "^#define[ \t]+CAT\\(a,b\\).*";
2657     c_fix     = format;
2658
2659     c_fix_arg =
2660     "#ifdef __STDC__\n"
2661     "#  define CAT(a,b) a##b\n"
2662     "#else\n%0\n#endif";
2663
2664     test_text =
2665     "#define CAT(a,b)\ta/**/b";
2666 };
2667
2668
2669 /*
2670  *  Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
2671  *  Also fix return type of {m,re}alloc in <malloc.h> on sysV68
2672  */
2673 fix = {
2674     hackname = sun_malloc;
2675     files    = malloc.h;
2676
2677     sed   = "s/typedef[ \t]char \\*\tmalloc_t/typedef void \\*\tmalloc_t/g";
2678     sed   = "s/int[ \t][ \t]*free/void\tfree/g";
2679     sed   = "s/char\\([ \t]*\\*[ \t]*malloc\\)/void\\1/g";
2680     sed   = "s/char\\([ \t]*\\*[ \t]*realloc\\)/void\\1/g";
2681     sed   = "s/char\\([ \t]*\\*[ \t]*calloc\\)/void\\1/g";
2682
2683     test_text =
2684     "typedef char *\tmalloc_t;\n"
2685     "int \tfree();\n"
2686     "char*\tmalloc();\n"
2687     "char*\tcalloc();\n"
2688     "char*\trealloc();";
2689 };
2690
2691
2692 /*
2693  *  Check for yet more missing ';' in struct (in SunOS 4.0.x)
2694  */
2695 fix = {
2696     hackname = sun_rusers_semi;
2697     files    = rpcsvc/rusers.h;
2698     select   = "_cnt$";
2699     sed      = "/^struct/,/^};/s/_cnt$/_cnt;/";
2700     test_text = "struct mumble\n  int _cnt\n};";
2701 };
2702
2703
2704 /*
2705  *  signal.h on SunOS defines signal using (),
2706  *  which causes trouble when compiling with g++ -pedantic.
2707  */
2708 fix = {
2709     hackname = sun_signal;
2710     files    = sys/signal.h;
2711     files    = signal.h;
2712     select   = "^void\t" '\(\*signal\(\)\)\(\);.*';
2713
2714     c_fix     = format;
2715     c_fix_arg =
2716           "#ifdef __cplusplus\n"
2717           "void\t(*signal(...))(...);\n"
2718           "#else\n%0\n#endif";
2719
2720     test_text = "void\t(*signal())();";
2721 };
2722
2723
2724 /*
2725  *  math.h on SunOS 4 puts the declaration of matherr before the definition
2726  *  of struct exception, so the prototype (added by fixproto) causes havoc.
2727  */
2728 fix = {
2729     hackname  = sunos_matherr_decl;
2730     files     = math.h;
2731
2732     /*  If matherr has a prototype already, the header needs no fix.  */
2733     bypass    = 'matherr.*(struct exception|__MATH_EXCEPTION)';
2734     select    = matherr;
2735
2736     c_fix     = wrap;
2737     c_fix_arg = "struct exception;\n";
2738
2739     test_text = "extern int matherr();";
2740 };
2741
2742
2743 /*
2744  *  Correct the return type for strlen in strings.h in SunOS 4.
2745  */
2746 fix = {
2747     hackname = sunos_strlen;
2748     files    = strings.h;
2749     select   = "int[ \t]*strlen\\(\\);(.*)";
2750     c_fix     = format;
2751     c_fix_arg = "__SIZE_TYPE__ strlen();%1";
2752     test_text = " int\tstrlen(); /* string length */";
2753 };
2754
2755
2756 /*
2757  *  Solaris math.h and floatingpoint.h define __P without protection,
2758  *  which conflicts with the fixproto definition.  The fixproto
2759  *  definition and the Solaris definition are used the same way.
2760  */
2761 fix = {
2762     hackname = svr4__p;
2763     files    = math.h;
2764     files    = floatingpoint.h;
2765     select   = "^#define[ \t]+__P.*";
2766     c_fix     = format;
2767     c_fix_arg = "#ifndef __P\n%0\n#endif";
2768
2769     test_text = "#define __P(a) a";
2770 };
2771
2772
2773 /*
2774  *  Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
2775  *  that is visible to any ANSI compiler using this include.  Simply
2776  *  delete the lines that #define some string functions to internal forms.
2777  */
2778 fix = {
2779     hackname = svr4_disable_opt;
2780     files    = string.h;
2781     select   = '#define.*__std_hdr_';
2782     sed      = '/#define.*__std_hdr_/d';
2783     test_text = "#define strlen __std_hdr_strlen\n";
2784 };
2785
2786
2787 /*
2788  *  Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
2789  *  On some systems (UnixWare 2, UnixWare 7), the file is byteorder.h
2790  *  but we still "hijack" it and redirect it to the GNU byteorder.h..
2791  */
2792 #ifdef SVR5
2793 fix = {
2794     hackname = svr4_endian;
2795     files    = sys/endian.h;
2796 #ifdef LATER
2797     /*
2798      * since we emit our own sys/byteorder.h,
2799      * this fix can never be applied to that file.
2800      */
2801     files    = sys/byteorder.h;
2802 #endif
2803     bypass   = '__GNUC__';
2804
2805     sed      = "/#\tifdef\t__STDC__/i\\\n"
2806                "#   if !defined (__GNUC__) && !defined (__GNUG__)\n";
2807
2808     sed      = "/#\t\tinclude\t<sys\\/byteorder.h>/s/\t\t/   /";
2809
2810     sed      = "/#   include\t<sys\\/byteorder.h>/i\\\n"
2811                "#   endif /* !defined (__GNUC__) && !defined (__GNUG__) */\n";
2812 };
2813 #endif /* SVR5 */
2814
2815
2816 /*
2817  *  Remove useless extern keyword from struct forward declarations
2818  *  in <sys/stream.h> and <sys/strsubr.h>
2819  */
2820 #ifdef SVR4
2821 fix = {
2822     hackname = svr4_extern_struct;
2823     files    = sys/stream.h;
2824     files    = sys/strsubr.h;
2825     select   = 'extern struct [a-z_]*;';
2826     sed      = 's/extern struct \([a-z][a-z_]*\)/struct \1/';
2827 };
2828 #endif
2829
2830 /*
2831  *  Fix declarations of `ftw' and `nftw' in <ftw.h>.  On some/most SVR4
2832  *  systems the file <ftw.h> contains extern declarations of these
2833  *  functions followed by explicitly `static' definitions of these
2834  *  functions... and that's not allowed according to ANSI C.  (Note
2835  *  however that on Solaris, this header file glitch has been pre-fixed by
2836  *  Sun.  In the Solaris version of <ftw.h> there are no static
2837  *  definitions of any function so we don't need to do any of this stuff
2838  *  when on Solaris.
2839  */
2840 #ifdef SVR4
2841 #ifndef SOLARIS
2842 fix = {
2843     hackname = svr4_ftw;
2844     files    = ftw.h;
2845     select   = '^extern int ftw\(const';
2846
2847     sed = '/^extern int ftw(const/i' "\\\n"
2848             "#if !defined(_STYPES)\\\n"
2849             "static\\\n"
2850             "#else\\\n"
2851             "extern\\\n"
2852             "#endif";
2853     sed = 's/extern \(int ftw(const.*\)$/\1/';
2854     sed = "/^extern int nftw/i\\\n"
2855             "#if defined(_STYPES)\\\n"
2856             "static\\\n"
2857             "#else\\\n"
2858             "extern\\\n"
2859             "#endif";
2860     sed = 's/extern \(int nftw.*\)$/\1/';
2861     sed = "/^extern int ftw(),/c\\\n"
2862             "#if !defined(_STYPES)\\\n"
2863             "static\\\n"
2864             "#else\\\n"
2865             "extern\\\n"
2866             "#endif\\\n"
2867             "  int ftw();\\\n"
2868             "#if defined(_STYPES)\\\n"
2869             "static\\\n"
2870             "#else\\\n"
2871             "extern\\\n"
2872             "#endif\\\n"
2873             "  int nftw();";
2874 };
2875 #endif
2876 #endif
2877
2878
2879 /*
2880  *   Fix broken decl of getcwd present on some svr4 systems.
2881  */
2882 fix = {
2883     hackname = svr4_getcwd;
2884     files    = stdlib.h;
2885     files    = unistd.h;
2886     files    = prototypes.h;
2887     select   = 'getcwd\(char \*, int\)';
2888
2889     c_fix     = format;
2890     c_fix_arg = "getcwd(char *, size_t)";
2891
2892     test_text = "extern char* getcwd(char *, int);";
2893 };
2894
2895
2896 /*
2897  *  Wrap some files on System V r4 and DYNIX/ptx systems with
2898  *  #ifdef _KERNEL, presumably to prevent kernel headers from
2899  *  leaking into userspace.  This may not be necessary at all,
2900  *  but it was in the old scripts, so it seems safest to keep it for now.
2901  */
2902 fix = {
2903     /* Can't name this with _kernel, or the test case will hit the bypass! */
2904     hackname = svr4_krnl;
2905     /* Since I'm rather unsure about the validity of this, limit it
2906      * to the specific systems it was operating on before.  It should
2907      * also be bypassed for i?86-*-sysv4.3uw2, by that rule, but I didn't
2908      * see an easy way to do that.  Hopefully it will be harmless
2909      * in any case. -- Nathanael */
2910     mach     = '*-*-sysv4*';
2911     mach     = 'i?86-sequent-ptx*';
2912     files    = fs/rfs/rf_cache.h;
2913     files    = sys/erec.h;
2914     files    = sys/err.h;
2915     files    = sys/char.h;
2916     files    = sys/getpages.h;
2917     files    = sys/map.h;
2918     files    = sys/cmn_err.h;
2919     files    = sys/kdebugger.h;
2920
2921     /* This bypass will match _KERNEL, __KERNEL, __KERNEL__, etc.
2922      * It will also match SVR4_KERNEL_CHECK, which means that the
2923      * testsuite case will always be bypassed.  Which is fine with me. */
2924     bypass   = '_KERNEL';
2925
2926     c_fix     = wrap;
2927     c_fix_arg = "#ifdef _KERNEL\n";
2928     c_fix_arg = "#endif /* _KERNEL */\n";
2929
2930     /* There's no reasonable test for this given that we don't know exactly
2931      * what problem inspired it in the first place. */
2932     test_text = "";
2933 };
2934
2935
2936 /*
2937  *  Delete any #defines of `__i386' which may be present in <ieeefp.h>.  They
2938  *  tend to conflict with the compiler's own definition of this symbol.  (We
2939  *  will use the compiler's definition.)
2940  *  Likewise __sparc, for Solaris, and __i860, and a few others
2941  *  (guessing it is necessary for all of them).
2942  */
2943 #ifdef SVR4
2944 fix = {
2945     hackname = svr4_mach_defines;
2946     files    = ieeefp.h;
2947     select   = "#define[ \t]*__(i386|mips|sparc|m88k|m68k)[ \t]";
2948     sed      = "/#define[ \t]*__\\(i386|mips|sparc|m88k|m68k\\)[ \t]/d";
2949 };
2950 #endif
2951
2952
2953 /*
2954  *  Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
2955  *  They are declared as non-static then immediately redeclared as static.
2956  */
2957 #ifdef SVR5
2958 fix = {
2959     hackname = svr4_mkdev;
2960     files    = sys/mkdev.h;
2961     select   = '^static';
2962
2963     sed      = "/^dev_t makedev(/s/^/static /";
2964     sed      = "/^major_t major(/s/^/static /";
2965     sed      = "/^minor_t minor(/s/^/static /";
2966 };
2967 #endif /* SVR5 */
2968
2969
2970 /*
2971  *  Fix reference to NC_NPI_RAW in <sys/netcspace.h>.
2972  *  Also fix types of array initializers.
2973  */
2974 #ifdef SVR4
2975 fix = {
2976     hackname = svr4_netcspace;
2977     files    = sys/netcspace.h;
2978     select   = 'NC_NPI_RAW';
2979     sed      = 's/NC_NPI_RAW/NC_TPI_RAW/g';
2980     sed      = 's/NC_/(unsigned long) NC_/';
2981 };
2982 #endif
2983
2984 /*
2985  *  Fix reference to NMSZ in <sys/adv.h>.
2986  */
2987 #ifdef SVR4
2988 fix = {
2989     hackname = svr4_nmsz;
2990     files    = sys/adv.h;
2991     select   = '\[NMSZ\]';
2992     sed      = 's/\[NMSZ\]/\[RFS_NMSZ\]/g';
2993 };
2994 #endif
2995
2996
2997 /*
2998  * Some SVR4 systems supposedly use these non-ANSI preprocessor directives.
2999  */
3000 #ifdef SVR4
3001 fix = {
3002     hackname  = svr4_preproc_lint_on;
3003     select    = '#lint\(on\)';
3004     c_fix     = format;
3005     c_fix_arg = 'defined(lint)';
3006     test_text = "#if #lint(on)";
3007 };
3008 fix = {
3009     hackname  = svr4_preproc_lint_off;
3010     select    = '#lint\(off\)';
3011     c_fix     = format;
3012     c_fix_arg = '!defined(lint)';
3013     test_text = "#if #lint(off)";
3014 };
3015 fix = {
3016     hackname  = svr4_preproc_machine;
3017     select    = '#(machine|system|cpu)\(([^)]*)\)';
3018     c_fix     = format;
3019     c_fix_arg = 'defined(__%1__)';
3020     test_text = "#if #machine(i386) || #system(vax) || #cpu(sparc)";
3021 };
3022 #endif
3023
3024
3025 /*
3026  *   Fix broken decl of profil present on some svr4 systems.
3027  */
3028 fix = {
3029     hackname = svr4_profil;
3030     files    = stdlib.h;
3031     files    = unistd.h;
3032
3033     select    =
3034     'profil\(unsigned short \*, unsigned int, unsigned int, unsigned int\)';
3035     c_fix     = format;
3036     c_fix_arg = 'profil(unsigned short *, size_t, int, unsigned int)';
3037
3038     test_text =
3039     'profil(unsigned short *, unsigned int, unsigned int, unsigned int);';
3040 };
3041
3042
3043 /*
3044  *  Convert functions to prototype form, and fix arg names in <sys/stat.h>.
3045  */
3046 #ifdef SVR4
3047 fix = {
3048     hackname = svr4_proto_form;
3049     files    = sys/stat.h;
3050     select   = 'const extern';
3051
3052     sed      = "/^stat([ \t]*[^c]/ {\nN\nN\n"
3053                    "s/(.*)\\n/( /\n"
3054                    "s/;\\n/, /\n"
3055                    "s/;$/)/\n"  "}";
3056
3057     sed      = "/^lstat([ \t]*[^c]/ {\nN\nN\n"
3058                    "s/(.*)\\n/( /\n"
3059                    "s/;\\n/, /\n"
3060                    "s/;$/)/\n"  "}";
3061
3062     sed      = "/^fstat([ \t]*[^i]/ {\nN\nN\n"
3063                    "s/(.*)\\n/( /\n"
3064                    "s/;\\n/, /\n"
3065                    "s/;$/)/\n"  "}";
3066
3067     sed      = "/^mknod([ \t]*[^c]/{\nN\nN\nN\n"
3068                    "s/(.*)\\n/( /\n"
3069                    "s/;\\n/, /g\n"
3070                    "s/;$/)/\n"  "}";
3071
3072     sed      = "1,$s/\\([^A-Za-z]\\)path\\([^A-Za-z]\\)/\\1__path\\2/g";
3073     sed      = "1,$s/\\([^A-Za-z]\\)buf\\([^A-Za-z]\\)/\\1__buf\\2/g";
3074     sed      = "1,$s/\\([^A-Za-z]\\)fd\\([^A-Za-z]\\)/\\1__fd\\2/g";
3075     sed      = "1,$s/ret\\([^u]\\)/__ret\\1/g";
3076     sed      = "1,$s/\\([^_]\\)mode\\([^_]\\)/\\1__mode\\2/g";
3077     sed      = "1,$s/\\([^_r]\\)dev\\([^_]\\)/\\1__dev\\2/g";
3078 };
3079 #endif
3080
3081 /*
3082  *  Add a prototyped declaration of mmap to <sys/mman.h>.
3083  */
3084 #ifdef SVR4
3085 fix = {
3086     hackname = svr4_proto_mmap;
3087     files    = sys/mman.h;
3088     select   = '^extern caddr_t mmap();$';
3089     sed = '/^extern caddr_t mmap();$/c' "\\\n"
3090           "#ifdef __STDC__\\\n"
3091           "extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\\\n"
3092           "#else /* !defined(__STDC__) */\\\n"
3093           "extern caddr_t mmap ();\\\n"
3094           "#endif /* !defined(__STDC__) */\\\n";
3095 };
3096 #endif
3097
3098 /*
3099  *  Add a #define of _SIGACTION_ into <sys/signal.h>.
3100  */
3101 #ifdef SVR4
3102 fix = {
3103     hackname = svr4_sigaction;
3104     files    = sys/signal.h;
3105     sed      = "/^struct sigaction {/i\\\n"
3106                "#define _SIGACTION_";
3107     sed      = 's/(void *(\*)())/(void (*)(int))/';
3108 };
3109 #endif
3110
3111
3112 /*
3113  * Correct types for signal handler constants like SIG_DFL; they might be
3114  * void (*) (), and should be void (*) (int).  C++ doesn't like the
3115  * old style.
3116  */
3117 fix = {
3118     hackname = svr4_sighandler_type;
3119     files = sys/signal.h;
3120     select = 'void *\(\*\)\(\)';
3121     c_fix = format;
3122     c_fix_arg = "void (*)(int)";
3123     test_text = "#define SIG_DFL (void(*)())0\n"
3124                 "#define SIG_IGN (void (*)())0\n";
3125 };
3126
3127 /*
3128  *  Put storage class at start of decl, to avoid warning.
3129  */
3130 #ifdef SVR4
3131 fix = {
3132     hackname = svr4_storage_class;
3133     files    = rpc/types.h;
3134     select   = 'const extern';
3135     sed      = 's/const extern/extern const/g';
3136 };
3137 #endif
3138
3139
3140 /*
3141  *  Some SysV r4 systems, including Sequent's DYNIX/ptx, use the local
3142  *  function 'getrnge' in <regexp.h> before they declare it.  For these
3143  *  systems add a 'static int' declaration of 'getrnge' into <regexp.h>
3144  *  early on.
3145  *
3146  *  'getrnge' traditionally manipulates a file-scope global called 'size',
3147  *  so put the declaration right after the declaration of 'size'.
3148  *
3149  *  Don't do this if there is already a `static void getrnge' declaration
3150  *  present, since this would cause a redeclaration error.  Solaris 2.x has
3151  *  such a declaration.
3152  */
3153 fix = {
3154     hackname  = svr4_undeclared_getrnge;
3155     files     = regexp.h;
3156     select    = "getrnge";
3157     bypass    = "static void getrnge";
3158     c_fix     = format;
3159     c_fix_arg = "%0\n"
3160                 "static int getrnge ();";
3161     c_fix_arg = "^static int[ \t]+size;";
3162     test_text = "static int size;\n"
3163                 "/* stuff which calls getrnge() */\n"
3164                 "static getrnge()\n"
3165                 "{}";
3166 };
3167
3168
3169 /*
3170  *  Like svr4_mach_defines, but with newfangled syntax.
3171  *  Source lines are of #define __i386 #machine(i386).   Delete them.
3172  */
3173 #ifdef SVR5
3174 fix = {
3175     hackname = svr5_mach_defines;
3176     files    = ieeefp.h;
3177     select   = "#define[ \t]*__i386.*\(i386\)";
3178     sed      = "/#define[ \t]*__i386.*/d";
3179 };
3180 #endif /*  SVR5 */
3181
3182
3183 /*
3184  *  Fix return value of mem{ccpy,chr,cpy,set} and str{len,spn,cspn}
3185  *  in string.h on sysV68
3186  *  Correct the return type for strlen in string.h on Lynx.
3187  *  Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
3188  *  Add missing const for strdup on OSF/1 V3.0.
3189  *  On sysV88 layout is slightly different.
3190  */
3191 fix = {
3192     hackname = sysv68_string;
3193     files    = testing.h;
3194     files    = string.h;
3195
3196     sed = "s/extern[ \t]*int[ \t]*strlen();/extern unsigned int strlen();/";
3197     sed = "s/extern[ \t]*int[ \t]*ffs[ \t]*(long);/extern int ffs(int);/";
3198     sed = "s/strdup(char \\*s1);/strdup(const char *s1);/";
3199
3200     sed = "/^extern char$/N";
3201     sed = "s/^extern char\\(\\n\t\\*memccpy(),\\)$/extern void\\1/";
3202
3203     sed = "/^extern int$/N";
3204     sed = "s/^extern int\\(\\n\tstrlen(),\\)/extern size_t\\1/";
3205
3206     sed = "/^\tstrncmp(),$/N";
3207     sed = 's/^\(' "\t" 'strncmp()\),\n\(' "\t" 'strlen(),\)$/'
3208             '\1;' "\\\nextern unsigned int\\\n\\2/";
3209
3210     test_text =
3211     "extern int strlen();\n"
3212
3213     "extern int ffs(long);\n"
3214
3215     "extern char\n"
3216     "\t*memccpy(),\n"
3217     "\tmemcpy();\n"
3218
3219     "extern int\n"
3220     "\tstrcmp(),\n"
3221     "\tstrncmp(),\n"
3222     "\tstrlen(),\n"
3223     "\tstrspn();\n"
3224
3225     "extern int\n"
3226     "\tstrlen(), strspn();";
3227 };
3228
3229
3230 /*
3231  *  Fix return type of calloc, malloc, realloc, bsearch and exit
3232  */
3233 fix = {
3234     hackname = sysz_stdlib_for_sun;
3235     files    = stdlib.h;
3236
3237     select    = "char[ \t]*\\*[ \t]*(calloc|malloc|realloc|bsearch)[ \t]*\\(";
3238     c_fix     = format;
3239     c_fix_arg = "void *\t%1(";
3240
3241     test_text =
3242     "extern char*\tcalloc(size_t);\n"
3243     "extern char*\tmalloc(size_t);\n"
3244     "extern char*\trealloc(void*,size_t);\n"
3245     "extern char*\tbsearch(void*,size_t,size_t);\n";
3246 };
3247
3248
3249 /*
3250  * __thread is now a keyword.
3251  */
3252 fix = {
3253     hackname  = thread_keyword;
3254     files     = "pthread.h";
3255     files     = "bits/sigthread.h";
3256     select    = "([* ])__thread([,)])";
3257     c_fix     = format;
3258     c_fix_arg = "%1__thr%2";
3259
3260     test_text =
3261         "extern int pthread_create (pthread_t *__restrict __thread,\n"
3262         "extern int pthread_kill (pthread_t __thread, int __signo);\n"
3263         "extern int pthread_cancel (pthread_t __thread);";
3264 };
3265
3266 /*
3267  *  if the #if says _cplusplus, not the double underscore __cplusplus
3268  *  that it should be
3269  */
3270 fix = {
3271     hackname = tinfo_cplusplus;
3272     files    = tinfo.h;
3273     select   = "[ \t]_cplusplus";
3274
3275     c_fix     = format;
3276     c_fix_arg = " __cplusplus";
3277     test_text = "#ifdef _cplusplus\nint bogus;\n#endif";
3278 };
3279
3280
3281 /*
3282  *  function parameter to atexit is missing "void" on VAX Ultrix 4.3.
3283  */
3284 fix = {
3285     hackname = ultrix_atexit_param;
3286     files    = stdlib.h;
3287     select   = 'atexit\(.*\(\)';
3288
3289     c_fix     = format;
3290     c_fix_arg = "atexit( void (*__func)( void )";
3291
3292     test_text = "int atexit( void (*__func)() );\n";
3293 };
3294
3295
3296 /*
3297  *  parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
3298  */
3299 fix = {
3300     hackname = ultrix_atof_param;
3301     files    = math.h;
3302     select   = "atof\\([ \t]*char";
3303
3304     c_fix     = format;
3305     c_fix_arg = "atof(const char";
3306
3307     test_text = "extern double atof( char *__nptr);\n";
3308 };
3309
3310
3311 /*
3312  *  parameters not const on DECstation Ultrix V4.0 and OSF/1.
3313  */
3314 fix = {
3315     hackname  = ultrix_const;
3316     files     = stdio.h;
3317     select    = 'perror\( char \*';
3318
3319     c_fix     = format;
3320     c_fix_arg = "%1 const %3 *__";
3321     c_fix_arg = "([ \t*](perror|fputs|fwrite|scanf|fscanf)\\(.*)"
3322                 "[ \t]+(char|void) \\*__";
3323
3324     test_text =
3325     "extern void perror( char *__s );\n"
3326     "extern int fputs( char *__s, FILE *);\n"
3327     "extern size_t fwrite( void *__ptr, size_t, size_t, FILE *);\n"
3328     "extern int fscanf( FILE *__stream, char *__format, ...);\n"
3329     "extern int scanf( char *__format, ...);\n";
3330 };
3331
3332
3333 /*
3334  *  parameters not const on DECstation Ultrix V4.0 and OSF/1.
3335  */
3336 fix = {
3337     hackname  = ultrix_const2;
3338     files     = stdio.h;
3339
3340     select    = '\*fopen\( char \*';
3341     c_fix     = format;
3342     c_fix_arg = "%1( const char *%3, const char *";
3343     c_fix_arg = "([ \t*](fopen|sscanf|popen|tempnam))\\("
3344                "[ \t]*char[ \t]*\\*([^,]*),"
3345                "[ \t]*char[ \t]*\\*[ \t]*";
3346
3347     test_text =
3348     "extern FILE *fopen( char *__filename, char *__type );\n"
3349     "extern int sscanf( char *__s, char *__format, ...);\n"
3350     "extern FILE *popen(char *, char *);\n"
3351     "extern char *tempnam(char*,char*);\n";
3352 };
3353
3354
3355 /*
3356  * Ultrix V4.[35] puts the declaration of uname before the definition
3357  * of struct utsname, so the prototype (added by fixproto) causes havoc.
3358  */
3359 fix = {
3360     hackname = ultrix_fix_fixproto;
3361     files    = sys/utsname.h;
3362     select   = ULTRIX;
3363
3364     c_fix     = format;
3365     c_fix_arg = "struct utsname;\n%0";
3366     c_fix_arg = "^[ \t]*extern[ \t]*int[ \t]*uname\\(\\);";
3367
3368     test_text =
3369     "/* ULTRIX's uname */\nextern\tint\tuname();";
3370 };
3371
3372
3373 /*
3374  *  Check for bad #ifdef line (in Ultrix 4.1)
3375  */
3376 fix = {
3377     hackname = ultrix_ifdef;
3378     select   = "^#ifdef KERNEL[ \t]+&&";
3379     files    = sys/file.h;
3380
3381     c_fix     = format;
3382     c_fix_arg = "#if defined(KERNEL) &&";
3383
3384     test_text =
3385     "#ifdef KERNEL\t&& defined( mumbojumbo )\nint oops;\n#endif";
3386 };
3387
3388
3389 /*
3390  * Strip "|| CC$gfloat" from Ultrix math headers.
3391  */
3392 fix = {
3393     hackname  = ultrix_math_ifdef;
3394     files     = sys/limits.h;
3395     files     = float.h;
3396     files     = math.h;
3397     select    = "^(#if.*)\\|\\|[ \t]+CC\\$[a-z]+";
3398     c_fix     = format;
3399     c_fix_arg = "%1";
3400
3401     test_text = '#if     defined(__GFLOAT) || CC\$gfloat';
3402 };
3403
3404
3405 /*
3406  *  Avoid nested comments on Ultrix 4.3.
3407  */
3408 fix = {
3409     hackname = ultrix_nested_ioctl;
3410     files    = sys/ioctl.h;
3411     select   = "^/\\* #define SIOCSCREEN";
3412     sed      = "/^\\/\\* #define SIOCSCREEN/s@/\\* screend@*//* screend@";
3413     test_text =
3414     "/* #define SIOCSCREENON _IOWR('i', 49, int)"
3415     "/* screend, net/gw_screen.h */\n";
3416 };
3417
3418
3419 fix = {
3420     hackname = ultrix_nested_svc;
3421     files    = rpc/svc.h;
3422     select   = "^ \\*[ \t]*int protocol;  */\\*";
3423     sed      = "s@^\\( \\*\tint protocol;  \\)/\\*@\\1*/ /*@";
3424     test_text =
3425     " *\tint protocol;  /* like TCP or UDP\n";
3426 };
3427
3428
3429 /*
3430  *  Add missing prototype for lstat and define for S_ISLNK
3431  *  in Ultrix V4.3 sys/stat.h.
3432  */
3433 fix = {
3434     hackname = ultrix_stat;
3435     files  = sys/stat.h;
3436     select = "@\\(#\\)stat\\.h.*6\\.1.*\\(ULTRIX\\)";
3437     sed    = "/^#define[ \t]S_IFPORT[ \t]*S_IFIFO$/a\\\n"
3438                 "\\\n"
3439                 "/* macro to test for symbolic link */\\\n"
3440                 "#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)\\\n"
3441                 "\n";
3442     sed    = "/^[ \t]*fstat(),$/a\\\n"
3443                 "\tlstat(),\n";
3444     test_text =
3445     "@(#)stat.h      6.1     (ULTRIX)\n"
3446     "#define S_IFPORT S_IFIFO\n"
3447     "\tfstat(),\n/* THE INSERTION LINE FAILS ON BSD SYSTEMS */";
3448 };
3449
3450
3451 /*
3452  *  Check for superfluous `static' (in Ultrix 4.2)
3453  *  On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
3454  */
3455 fix = {
3456     hackname = ultrix_static;
3457     files  = machine/cpu.h;
3458     select = '#include "r[34]_cpu';
3459     sed    = "s/^static struct tlb_pid_state/struct tlb_pid_state/";
3460     sed    = 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/';
3461     sed    = 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/';
3462     test_text =
3463     "static struct tlb_pid_state {\n"
3464     "#include \"r3_cpu.h\"\n";
3465 };
3466
3467
3468 /*
3469  *  Add once-only latch to Ultrix V4.3 strings.h.
3470  */
3471 fix = {
3472     hackname = ultrix_strings;
3473     files  = strings.h;
3474     select = "@\\(#\\)strings\\.h.*6\\.1.*\\(ULTRIX\\)";
3475     c_fix  = wrap;
3476     test_text =
3477     "@(#)strings.h   6.1     (ULTRIX)\n";
3478 };
3479
3480
3481 /*
3482  *  Fix multiple defines for NULL.  Sometimes, we stumble into \r\n
3483  *  terminated lines, so accommodate these.  Test both ways.
3484  *  Don't bother to reproduce the \r\n termination, as GCC has to
3485  *  recognize \n termination anyway.
3486  */
3487 fix = {
3488     hackname  = undefine_null;
3489     select    = "^#[ \t]*define[ \t]+NULL[ \t]";
3490     bypass    = "#[ \t]*(ifn|un)def[ \t]+NULL($|[ \t\r])";
3491
3492     c_fix     = format;
3493     c_fix_arg = "#ifndef NULL\n#define NULL%1\n#endif\n";
3494     c_fix_arg = "^#[ \t]*define[ \t]+NULL([^\r\n]+)[\r]*\n";
3495
3496     test_text = "#define NULL 0UL\r\n"
3497                 "#define NULL\t((void*)0)\n";
3498 };
3499
3500 /*
3501  * On Cray Unicos/Mk some standard headers use the C99 keyword "restrict"
3502  * which must be replaced by __restrict__ for GCC.
3503  */
3504 fix = {
3505     hackname = unicosmk_restrict;
3506     files    = stdio.h;
3507     files    = stdlib.h;
3508     files    = wchar.h;
3509     mach     = "*-*-unicosmk*";
3510     select   = "(\\*[ \t]*)restrict([ \t]+)";
3511
3512     c_fix     = format;
3513     c_fix_arg = "%1__restrict__%2";
3514
3515     test_text = "void f (char * restrict x);";
3516 };
3517
3518 /*
3519  * If arpa/inet.h prototypes are incompatible with the ones we just
3520  * installed in <sys/byteorder.h>, just remove the protos.
3521  * Because of this close association, this patch must be applied only
3522  * on those systems where the replacement byteorder header is installed.
3523  */
3524 fix = {
3525     hackname = uw7_byteorder_fix;
3526     files    = arpa/inet.h;
3527     select   = "in_port_t";
3528     test     = "-f sys/byteorder.h";
3529 #ifndef SVR5
3530         mach = "*-*-sysv4*";
3531         mach = "i?86-*-sysv5*";
3532         mach = "i?86-*-udk*";
3533         mach = "i?86-*-solaris2.[0-4]";
3534         mach = "powerpcle-*-solaris2.[0-4]";
3535         mach = "sparc-*-solaris2.[0-4]";
3536 #endif /* SVR5 */
3537
3538     c_fix     = format;
3539     c_fix_arg = "";
3540     c_fix_arg = "^extern.*[ \t](htons|ntohs).*\\(in_port_t\\).*;";
3541
3542     test_text = "extern in_port_t\thtons __P((in_port_t));\n"
3543                 "extern in_port_t\tntohs __P((in_port_t));"
3544                 "`[ ! -d $DESTDIR/sys ] && mkdir $DESTDIR/sys\n"
3545                 "echo '/* DUMMY */' >> sys/byteorder.h`";
3546 };
3547
3548
3549 /*
3550  *  Fix definitions of macros used by va-i960.h in VxWorks header file.
3551  */
3552 fix = {
3553     hackname  = va_i960_macro;
3554     files     = arch/i960/archI960.h;
3555     select    = "__(vsiz|vali|vpad|alignof__)";
3556
3557     c_fix     = format;
3558     c_fix_arg = "__vx%1";
3559
3560     test_text =
3561     "extern int __vsiz vsiz;\n"
3562     "extern int __vali vali;\n"
3563     "extern int __vpad vpad;\n"
3564     "#define __alignof__(x) ...";
3565 };
3566
3567
3568 /*
3569  *  AIX and Interix headers define NULL to be cast to a void pointer,
3570  *  which is illegal in ANSI C++.
3571  */
3572 fix = {
3573     hackname  = void_null;
3574     files     = curses.h;
3575     files     = dbm.h;
3576     files     = locale.h;
3577     files     = stdio.h;
3578     files     = stdlib.h;
3579     files     = string.h;
3580     files     = time.h;
3581     files     = unistd.h;
3582     files     = sys/dir.h;
3583     files     = sys/param.h;
3584     files     = sys/types.h;
3585     select    = "^#[ \t]*define[ \t]+NULL[ \t]+\\(\\(void[ \t]*\\*\\)0\\)";
3586     c_fix     = format;
3587     c_fix_arg = "#define NULL 0";
3588     test_text = "# define\tNULL \t((void *)0)  /* typed NULL */";
3589 };
3590
3591
3592 /*
3593  *  Make VxWorks header which is almost gcc ready fully gcc ready.
3594  */
3595 fix = {
3596     hackname = vxworks_gcc_problem;
3597     files    = types/vxTypesBase.h;
3598     select   = "__GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__";
3599
3600     sed = "s/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/"
3601           "#if 1/";
3602
3603     sed = "/[ \t]size_t/i\\\n"
3604         "#ifndef _GCC_SIZE_T\\\n"
3605         "#define _GCC_SIZE_T\n";
3606
3607     sed = "/[ \t]size_t/a\\\n"
3608         "#endif\n";
3609
3610     sed = "/[ \t]ptrdiff_t/i\\\n"
3611         "#ifndef _GCC_PTRDIFF_T\\\n"
3612         "#define _GCC_PTRDIFF_T\n";
3613
3614     sed = "/[ \t]ptrdiff_t/a\\\n"
3615         "#endif\n";
3616
3617     sed = "/[ \t]wchar_t/i\\\n"
3618         "#ifndef _GCC_WCHAR_T\\\n"
3619         "#define _GCC_WCHAR_T\n";
3620
3621     sed = "/[ \t]wchar_t/a\\\n"
3622         "#endif\n";
3623
3624     test_text =
3625     "#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__\n"
3626     "typedef unsigned int size_t;\n"
3627     "typedef long ptrdiff_t;\n"
3628     "typedef unsigned short wchar_t;\n"
3629     "#endif /* __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__ */\n";
3630 };
3631
3632
3633 /*
3634  *  Fix VxWorks <time.h> to not require including <vxTypes.h>.
3635  */
3636 fix = {
3637     hackname  = vxworks_needs_vxtypes;
3638     files     = time.h;
3639     select    = "uint_t([ \t]+_clocks_per_sec)";
3640     c_fix     = format;
3641     c_fix_arg = "unsigned int%1";
3642     test_text = "uint_t\t_clocks_per_sec;";
3643 };
3644
3645
3646 /*
3647  *  Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
3648  */
3649 fix = {
3650     hackname = vxworks_needs_vxworks;
3651     files    = sys/stat.h;
3652     test     = " -r types/vxTypesOld.h";
3653     test     = " -n \"`egrep '#include' $file`\"";
3654     test     = " -n \"`egrep ULONG $file`\"";
3655     select   = "#[ \t]define[ \t]+__INCstath";
3656
3657     sed = "/#[ \t]define[ \t][ \t]*__INCstath/a\\\n"
3658           "#include <types/vxTypesOld.h>\n";
3659
3660     test_text = "`touch types/vxTypesOld.h`"
3661     "#include </dev/null> /* ULONG */\n"
3662     "# define\t__INCstath <sys/stat.h>";
3663 };
3664
3665
3666 /*
3667  *  Another bad dependency in VxWorks 5.2 <time.h>.
3668  */
3669 fix = {
3670     hackname = vxworks_time;
3671     files    = time.h;
3672     test     = " -r vxWorks.h";
3673
3674     select    = "#[ \t]*define[ \t]+VOIDFUNCPTR[ \t].*";
3675     c_fix     = format;
3676
3677     c_fix_arg =
3678     "#ifndef __gcc_VOIDFUNCPTR_defined\n"
3679     "#ifdef __cplusplus\n"
3680     "typedef void (*__gcc_VOIDFUNCPTR) (...);\n"
3681     "#else\n"
3682     "typedef void (*__gcc_VOIDFUNCPTR) ();\n"
3683     "#endif\n"
3684     "#define __gcc_VOIDFUNCPTR_defined\n"
3685     "#endif\n"
3686     "#define VOIDFUNCPTR __gcc_VOIDFUNCPTR";
3687
3688     test_text = "`touch vxWorks.h`"
3689                 "#define VOIDFUNCPTR (void(*)())";
3690 };
3691
3692
3693 /* 
3694  * WindISS math.h headers include bogus extern declarations of 
3695  * numerous math functions that conflict with libstdc++-v3.
3696  */
3697 fix = {
3698     hackname  = windiss_math1;
3699     files     = math.h;
3700     mach      = "*-*-windiss";
3701     sed       = "s|inline long double cosl.*|#ifndef __GNUC__|";
3702
3703     test_text = "inline long double cosl(long double);";
3704 };
3705
3706 fix = {
3707     hackname  = windiss_math2;
3708     files     = math.h;
3709     mach      = "*-*-windiss";
3710     sed       = "s|/\\* long double declarations \\*/|"
3711                   "#endif /* __GNUC__ */|";
3712
3713     test_text = "/* long double declarations */";
3714 };
3715
3716 /*
3717  * WindISS headers include "diab/va_list.h" instead of "stdarg.h"
3718  */
3719 fix = {
3720     select    = '(#include.*)diab/va_list.h';
3721     hackname  = windiss_valist;
3722     sed       = "s|diab/va_list.h|stdarg.h|";
3723     mach      = "*-*-windiss";
3724
3725     test_text = "#include <diab/va_list.h>";
3726 };
3727
3728 /*
3729  *  There are several name conflicts with C++ reserved words in X11 header
3730  *  files.  These are fixed in some versions, so don't do the fixes if
3731  *  we find __cplusplus in the file.  These were found on the RS/6000.
3732  */
3733 fix = {
3734     hackname  = x11_class;
3735     files     = X11/ShellP.h;
3736     bypass    = __cplusplus;
3737     select    = "^([ \t]*char \\*)class;(.*)";
3738     c_fix     = format;
3739     c_fix_arg = "#ifdef __cplusplus\n%1c_class;%2\n"
3740                 "#else\n%1class;%2\n#endif";
3741     test_text =
3742     "struct {\n"
3743     "   char *class;\n"
3744     "} mumble;\n";
3745 };
3746
3747
3748 /*
3749  *  class in Xm/BaseClassI.h
3750  */
3751 fix = {
3752     hackname = x11_class_usage;
3753     files    = Xm/BaseClassI.h;
3754     bypass   = "__cplusplus";
3755
3756     select    = " class\\)";
3757     c_fix     = format;
3758     c_fix_arg = " c_class)";
3759
3760     test_text = "extern mumble (int  class);\n";
3761 };
3762
3763
3764 /*
3765  *  new in Xm/Traversal.h
3766  */
3767 fix = {
3768     hackname = x11_new;
3769     files    = Xm/Traversal.h;
3770     bypass   = __cplusplus;
3771
3772     sed      = "/Widget\told, new;/i\\\n"
3773                    "#ifdef __cplusplus\\\n"
3774                    "\tWidget\told, c_new;\\\n"
3775                    "#else\n";
3776
3777     sed      = "/Widget\told, new;/a\\\n"
3778                    "#endif\n";
3779
3780     sed      = "s/Widget new,/Widget c_new,/g";
3781     test_text =
3782     "struct wedge {\n"
3783     "   Widget\told, new; /* fixinc check FAILS ON BSD */\n"
3784     "};\nextern Wedged( Widget new, Widget old );";
3785 };
3786
3787
3788 /*
3789  *  Incorrect sprintf declaration in X11/Xmu.h
3790  */
3791 fix = {
3792     hackname = x11_sprintf;
3793     files    = X11/Xmu.h;
3794     files    = X11/Xmu/Xmu.h;
3795     select   = "^extern char \\*\tsprintf\\(\\);$";
3796
3797     c_fix     = format;
3798     c_fix_arg = "#ifndef __STDC__\n%0\n#endif /* !defined __STDC__ */";
3799
3800     test_text = "extern char *\tsprintf();";
3801 };
3802
3803 /*EOF*/