OSDN Git Service

(do_include): Diagnose #import and #include_next if pedantic and if
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.svr4
1 #! /bin/sh
2 # Install modified versions of certain ANSI-incompatible
3 # native System V Release 4 system include files.
4 # Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
5 # Contributed by Ron Guilmette (rfg@monkeys.com).
6 #
7 # This file is part of GNU CC.
8
9 # GNU CC is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13
14 # GNU CC is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with GNU CC; see the file COPYING.  If not, write to
21 # the Free Software Foundation, 59 Temple Place - Suite 330,
22 # Boston, MA 02111-1307, USA.
23 #
24 #       This script munges the native include files provided with System V
25 #       Release 4 systems so as to remove things which are violations of the
26 #       ANSI C standard.  Once munged, the resulting new system include files
27 #       are placed in a directory that GNU C will search *before* searching
28 #       the /usr/include directory. This script should work properly for most
29 #       System V Release 4 systems.  For other types of systems, you should
30 #       use the `fixincludes' script instead.
31 #
32 #       See README-fixinc for more information.
33
34 # Directory containing the original header files.
35 INPUT=${2-${INPUT-/usr/include}}
36
37 # Fail if no arg to specify a directory for the output.
38 if [ x$1 = x ]
39 then echo fixincludes: no output directory specified
40 exit 1
41 fi
42
43 # Directory in which to store the results.
44 LIB=${1?"fixincludes: output directory not specified"}
45
46 # Make sure it exists.
47 if [ ! -d $LIB ]; then
48   mkdir $LIB || exit 1
49 fi
50
51 ORIG_DIR=`pwd`
52
53 # Make LIB absolute if it is relative.
54 # Don't do this if not necessary, since may screw up automounters.
55 case $LIB in
56 /*)
57         ;;
58 *)
59         LIB=$ORIG_DIR/$LIB
60         ;;
61 esac
62
63 echo 'Building fixincludes in ' ${LIB}
64
65 # Determine whether this filesystem has symbolic links.
66 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
67   rm -f $LIB/ShouldNotExist
68   LINKS=true
69 else
70   LINKS=false
71 fi
72
73 echo 'Making directories:'
74 cd ${INPUT}
75 if $LINKS; then
76   files=`find . -follow -type d -print 2>/dev/null | sed '/^.$/d'`
77 else
78   files=`find . -type d -print | sed '/^.$/d'`
79 fi
80 for file in $files; do
81   rm -rf $LIB/$file
82   if [ ! -d $LIB/$file ]
83   then mkdir $LIB/$file
84   fi
85 done
86
87 # treetops gets an alternating list
88 # of old directories to copy
89 # and the new directories to copy to.
90 treetops="${INPUT} ${LIB}"
91
92 if $LINKS; then
93   echo 'Making internal symbolic directory links'
94   for file in $files; do
95     dest=`ls -ld $file | sed -n 's/.*-> //p'`
96     if [ "$dest" ]; then    
97       cwd=`pwd`
98       # In case $dest is relative, get to $file's dir first.
99       cd ${INPUT}
100       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
101       rwd=`pwd`
102       # Check that the target directory exists.
103       # Redirections changed to avoid bug in sh on Ultrix.
104       (cd $dest) > /dev/null 2>&1
105       if [ $? = 0 ]; then
106         cd $dest
107         # X gets the dir that the link actually leads to.
108         x=`pwd`
109         # If link leads back into ${INPUT},
110         # make a similar link here.
111         if expr "$dest" : '[^/][^/]*' >/dev/null && [ ! -h $dest ]; then
112           echo $file '->'  $dest': Making link'
113           rm -fr ${LIB}/$file > /dev/null 2>&1
114           ln -s $dest ${LIB}/$file > /dev/null 2>&1
115         elif expr $x : "${INPUT}/.*" > /dev/null; then
116           # Y gets the actual target dir name, relative to ${INPUT}.
117           y=`echo $x | sed -n "s&${INPUT}/&&p"`
118           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
119           dots=`echo "$file" |
120             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
121           echo $file '->' $dots$y ': Making link'
122           rm -fr ${LIB}/$file > /dev/null 2>&1
123           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
124         elif expr $x : "${rwd}/.*" > /dev/null; then
125           # Y gets the actual target dir name, relative to the directory where the link is.
126           y=`echo $x | sed -n "s&${rwd}/&&p"`
127           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
128           dots=`echo "$file" |
129             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
130           echo $file '->' $dots$y ': Making link'
131           rm -fr ${LIB}/$file > /dev/null 2>&1
132           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
133         else
134           # If the link is to outside ${INPUT},
135           # treat this directory as if it actually contained the files.
136 # This line used to have $dest instead of $x.
137 # $dest seemed to be wrong for links found in subdirectories
138 # of ${INPUT}.  Does this change break anything?
139           treetops="$treetops $x ${LIB}/$file"
140         fi
141       fi
142       cd $cwd
143     fi
144   done
145 fi
146
147 set - $treetops
148 while [ $# != 0 ]; do
149   # $1 is an old directory to copy, and $2 is the new directory to copy to.
150   echo "Finding header files in $1:"
151   cd ${INPUT}
152   cd $1
153   files=`find . -name '*.h' -type f -print`
154   echo 'Checking header files:'
155   for file in $files; do
156       if [ -r $file ]; then
157         cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
158         chmod +w $2/$file
159         chmod a+r $2/$file
160
161 # The following have been removed from the sed command below
162 # because it is more useful to leave these things in.
163 # The only reason to remove them was for -pedantic,
164 # which isn't much of a reason. -- rms.
165 #         /^[   ]*#[    ]*ident/d
166
167 # This code makes Solaris SCSI fail, because it changes the
168 # alignment within some critical structures.  See <sys/scsi/impl/commands.h>.
169 #         s/u_char\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
170 # Disable these also, since they probably aren't safe either.
171 #         s/u_short\([  ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
172 #         s/ushort\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
173 #         s/evcm_t\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
174 #         s/Pbyte\([    ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*SEQSIZ\)/unsigned int\1/
175
176 # The change of u_char, etc, to u_int
177 # applies to bit fields.
178         sed -e '
179           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
180           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
181           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
182           s%^\([        ]*#[    ]*endif\)[      ]*[^/   ].*%\1%
183           s/#lint(on)/defined(lint)/g
184           s/#lint(off)/!defined(lint)/g
185           s/#machine(\([^)]*\))/defined(__\1__)/g
186           s/#system(\([^)]*\))/defined(__\1__)/g
187           s/#cpu(\([^)]*\))/defined(__\1__)/g
188           /#[a-z]*if.*[  (]m68k/                s/\([^_]\)m68k/\1__m68k__/g
189           /#[a-z]*if.*[  (]__i386\([^_]\)/      s/__i386/__i386__/g
190           /#[a-z]*if.*[  (]i386/                s/\([^_]\)i386/\1__i386__/g
191           /#[a-z]*if.*[  (!]__i860\([^_]\)/     s/__i860/__i860__/g
192           /#[a-z]*if.*[  (!]i860/               s/\([^_]\)i860/\1__i860__/g
193           /#[a-z]*if.*[  (]sparc/       s/\([^_]\)sparc/\1__sparc__/g
194           /#[a-z]*if.*[  (]mc68000/     s/\([^_]\)mc68000/\1__mc68000__/g
195           /#[a-z]*if.*[  (]vax/         s/\([^_]\)vax/\1__vax__/g
196           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
197           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
198           /#[a-z]*if.*[  (]ns32000/     s/\([^_]\)ns32000/\1__ns32000__/g
199           /#[a-z]*if.*[  (]pyr/         s/\([^_]\)pyr/\1__pyr__/g
200           /#[a-z]*if.*[  (]is68k/       s/\([^_]\)is68k/\1__is68k__/g
201           s/__STDC__[   ][      ]*==[   ][      ]*0/!defined (__STRICT_ANSI__)/g
202           s/__STDC__[   ][      ]*==[   ][      ]*1/defined (__STRICT_ANSI__)/g
203           s/__STDC__[   ][      ]*!=[   ][      ]*0/defined (__STRICT_ANSI__)/g
204           s/__STDC__[   ][      ]*!=[   ][      ]*1/!defined (__STRICT_ANSI__)/g
205           s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
206           /^typedef[    ][      ]*[unsigned     ]*long[         ][      ]*[u_]*longlong_t;/s/long/long long/
207         ' $2/$file > $2/$file.sed
208         mv $2/$file.sed $2/$file
209         if cmp $file $2/$file >/dev/null 2>&1; then
210            rm $2/$file
211         else
212            echo Fixed $file
213         fi
214       fi
215   done
216   shift; shift
217 done
218
219 # Install the proper definition of the three standard types in header files
220 # that they come from.
221 for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
222   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
223     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
224     chmod +w ${LIB}/$file 2>/dev/null
225     chmod a+r ${LIB}/$file 2>/dev/null
226   fi
227
228   if [ -r ${LIB}/$file ]; then
229     echo Fixing size_t, ptrdiff_t and wchar_t in $file
230     sed \
231       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
232 #ifndef __SIZE_TYPE__\
233 #define __SIZE_TYPE__ long unsigned int\
234 #endif
235 ' \
236       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef __SIZE_TYPE__ size_t/' \
237       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/i\
238 #ifndef __PTRDIFF_TYPE__\
239 #define __PTRDIFF_TYPE__ long int\
240 #endif
241 ' \
242       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
243       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]wchar_t/i\
244 #ifndef __WCHAR_TYPE__\
245 #define __WCHAR_TYPE__ int\
246 #endif
247 ' \
248       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
249       ${LIB}/$file > ${LIB}/${file}.sed
250     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
251     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
252       rm ${LIB}/$file
253     fi
254   fi
255 done
256
257 # Fix first broken decl of getcwd present on some svr4 systems.
258
259 file=stdlib.h
260 base=`basename $file`
261 if [ -r ${LIB}/$file ]; then
262   file_to_fix=${LIB}/$file
263 else
264   if [ -r ${INPUT}/$file ]; then
265     file_to_fix=${INPUT}/$file
266   else
267     file_to_fix=""
268   fi
269 fi
270 if [ \! -z "$file_to_fix" ]; then
271   echo Checking $file_to_fix
272   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
273   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
274     true
275   else
276     echo Fixed $file_to_fix
277     rm -f ${LIB}/$file
278     cp /tmp/$base ${LIB}/$file
279     chmod a+r ${LIB}/$file
280   fi
281   rm -f /tmp/$base
282 fi
283
284 # Fix second broken decl of getcwd present on some svr4 systems.  Also
285 # fix the incorrect decl of profil present on some svr4 systems.
286
287 file=unistd.h
288 base=`basename $file`
289 if [ -r ${LIB}/$file ]; then
290   file_to_fix=${LIB}/$file
291 else
292   if [ -r ${INPUT}/$file ]; then
293     file_to_fix=${INPUT}/$file
294   else
295     file_to_fix=""
296   fi
297 fi
298 if [ \! -z "$file_to_fix" ]; then
299   echo Checking $file_to_fix
300   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
301     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
302   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
303     true
304   else
305     echo Fixed $file_to_fix
306     rm -f ${LIB}/$file
307     cp /tmp/$base ${LIB}/$file
308     chmod a+r ${LIB}/$file
309   fi
310   rm -f /tmp/$base
311 fi
312
313 # Fix the definition of NULL in <sys/param.h> so that it is conditional
314 # and so that it is correct for both C and C++.
315
316 file=sys/param.h
317 base=`basename $file`
318 if [ -r ${LIB}/$file ]; then
319   file_to_fix=${LIB}/$file
320 else
321   if [ -r ${INPUT}/$file ]; then
322     file_to_fix=${INPUT}/$file
323   else
324     file_to_fix=""
325   fi
326 fi
327 if [ \! -z "$file_to_fix" ]; then
328   echo Checking $file_to_fix
329   cp $file_to_fix /tmp/$base
330   chmod +w /tmp/$base
331   chmod a+r /tmp/$base
332   sed -e '/^#define[    ]*NULL[         ]*0$/c\
333 #ifndef NULL\
334 #ifdef __cplusplus\
335 #define __NULL_TYPE\
336 #else /* !defined(__cplusplus) */\
337 #define __NULL_TYPE (void *)\
338 #endif /* !defined(__cplusplus) */\
339 #define NULL (__NULL_TYPE 0)\
340 #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
341   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
342     true
343   else
344     echo Fixed $file_to_fix
345     rm -f ${LIB}/$file
346     cp /tmp/$base.sed ${LIB}/$file
347     chmod a+r ${LIB}/$file
348   fi
349   rm -f /tmp/$base /tmp/$base.sed
350 fi
351
352 # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
353 # and so that it is correct for both C and C++.
354
355 file=stdio.h
356 base=`basename $file`
357 if [ -r ${LIB}/$file ]; then
358   file_to_fix=${LIB}/$file
359 else
360   if [ -r ${INPUT}/$file ]; then
361     file_to_fix=${INPUT}/$file
362   else
363     file_to_fix=""
364   fi
365 fi
366 if [ \! -z "$file_to_fix" ]; then
367   echo Checking $file_to_fix
368   cp $file_to_fix /tmp/$base
369   chmod +w /tmp/$base
370   sed -e '/^#define[    ]*NULL[         ]*0$/c\
371 #ifdef __cplusplus\
372 #define __NULL_TYPE\
373 #else /* !defined(__cplusplus) */\
374 #define __NULL_TYPE (void *)\
375 #endif /* !defined(__cplusplus) */\
376 #define NULL (__NULL_TYPE 0)' /tmp/$base > /tmp/$base.sed
377   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
378     true
379   else
380     echo Fixed $file_to_fix
381     rm -f ${LIB}/$file
382     cp /tmp/$base.sed ${LIB}/$file
383     chmod a+r ${LIB}/$file
384   fi
385   rm -f /tmp/$base /tmp/$base.sed
386 fi
387
388 # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
389 # and so that it is correct for both C and C++.
390
391 file=dbm.h
392 base=`basename $file`
393 if [ -r ${LIB}/$file ]; then
394   file_to_fix=${LIB}/$file
395 else
396   if [ -r ${INPUT}/$file ]; then
397     file_to_fix=${INPUT}/$file
398   else
399     file_to_fix=""
400   fi
401 fi
402 if [ \! -z "$file_to_fix" ]; then
403   echo Checking $file_to_fix
404   cp $file_to_fix /tmp/$base
405   chmod +w /tmp/$base
406   sed -e '/^#define[    ]*NULL[         ]*((char \*) 0)$/c\
407 #ifndef NULL\
408 #ifdef __cplusplus\
409 #define __NULL_TYPE\
410 #else /* !defined(__cplusplus) */\
411 #define __NULL_TYPE (void *)\
412 #endif /* !defined(__cplusplus) */\
413 #define NULL (__NULL_TYPE 0)\
414 #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
415   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
416     true
417   else
418     echo Fixed $file_to_fix
419     rm -f ${LIB}/$file
420     cp /tmp/$base.sed ${LIB}/$file
421     chmod a+r ${LIB}/$file
422   fi
423   rm -f /tmp/$base /tmp/$base.sed
424 fi
425
426 # Add a prototyped declaration of mmap to <sys/mman.h>.
427
428 file=sys/mman.h
429 base=`basename $file`
430 if [ -r ${LIB}/$file ]; then
431   file_to_fix=${LIB}/$file
432 else
433   if [ -r ${INPUT}/$file ]; then
434     file_to_fix=${INPUT}/$file
435   else
436     file_to_fix=""
437   fi
438 fi
439 if [ \! -z "$file_to_fix" ]; then
440   echo Checking $file_to_fix
441   cp $file_to_fix /tmp/$base
442   chmod +w /tmp/$base
443   sed -e '/^extern caddr_t mmap();$/c\
444 #ifdef __STDC__\
445 extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\
446 #else /* !defined(__STDC__) */\
447 extern caddr_t mmap ();\
448 #endif /* !defined(__STDC__) */' /tmp/$base > /tmp/$base.sed
449   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
450     true
451   else
452     echo Fixed $file_to_fix
453     rm -f ${LIB}/$file
454     cp /tmp/$base.sed ${LIB}/$file
455     chmod a+r ${LIB}/$file
456   fi
457   rm -f /tmp/$base /tmp/$base.sed
458 fi
459
460 # Fix declarations of `ftw' and `nftw' in <ftw.h>.  On some/most SVR4 systems
461 # the file <ftw.h> contains extern declarations of these functions followed
462 # by explicitly `static' definitions of these functions... and that's not
463 # allowed according to ANSI C.  (Note however that on Solaris, this header
464 # file glitch has been pre-fixed by Sun.  In the Solaris version of <ftw.h>
465 # there are no static definitions of any function so we don't need to do
466 # any of this stuff when on Solaris.
467
468 file=ftw.h
469 base=`basename $file`
470 if [ -r ${LIB}/$file ]; then
471   file_to_fix=${LIB}/$file
472 else
473   if [ -r ${INPUT}/$file ]; then
474     file_to_fix=${INPUT}/$file
475   else
476     file_to_fix=""
477   fi
478 fi
479 if test -z "$file_to_fix" || grep 'define       ftw' $file_to_fix > /dev/null; then
480 # Either we have no <ftw.h> file at all, or else we have the pre-fixed Solaris
481 # one.  Either way, we don't have to do anything.
482   true
483 else
484   echo Checking $file_to_fix
485   cp $file_to_fix /tmp/$base
486   chmod +w /tmp/$base
487   sed -e '/^extern int ftw(const/i\
488 #if !defined(_STYPES)\
489 static\
490 #else\
491 extern\
492 #endif
493 '\
494   -e 's/extern \(int ftw(const.*\)$/\1/' \
495   -e '/^extern int nftw/i\
496 #if defined(_STYPES)\
497 static\
498 #else\
499 extern\
500 #endif
501 '\
502   -e 's/extern \(int nftw.*\)$/\1/' \
503   -e '/^extern int ftw(),/c\
504 #if !defined(_STYPES)\
505 static\
506 #else\
507 extern\
508 #endif\
509   int ftw();\
510 #if defined(_STYPES)\
511 static\
512 #else\
513 extern\
514 #endif\
515   int nftw();' /tmp/$base > /tmp/$base.sed
516   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
517     true
518   else
519     echo Fixed $file_to_fix
520     rm -f ${LIB}/$file
521     cp /tmp/$base.sed ${LIB}/$file
522     chmod a+r ${LIB}/$file
523   fi
524   rm -f /tmp/$base /tmp/$base.sed
525 fi
526
527 # Avoid the definition of the bool type in the Solaris 2.x curses.h when using
528 # g++, since it's now an official type in the C++ language.
529 file=curses.h
530 base=`basename $file`
531 if [ -r ${LIB}/$file ]; then
532   file_to_fix=${LIB}/$file
533 else
534   if [ -r ${INPUT}/$file ]; then
535     file_to_fix=${INPUT}/$file
536   else
537     file_to_fix=""
538   fi
539 fi
540
541 if [ \! -z "$file_to_fix" ]; then
542   echo Checking $file_to_fix
543   cp $file_to_fix /tmp/$base
544   chmod +w /tmp/$base
545   sed -e 's,^typedef[   ]char[  ]bool;$,#ifndef __cplusplus\
546 typedef char bool;\
547 #endif /* !defined __cplusplus */,' /tmp/$base > /tmp/$base.sed
548   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
549     true
550   else
551     echo Fixed $file_to_fix
552     rm -f ${LIB}/$file
553     cp /tmp/$base.sed ${LIB}/$file
554     chmod a+r ${LIB}/$file
555   fi
556   rm -f /tmp/$base /tmp/$base.sed
557 fi
558
559 # Add a `static' declaration of `getrnge' into <regexp.h>.
560
561 # Don't do this if there is already a `static void getrnge' declaration
562 # present, since this would cause a redeclaration error.  Solaris 2.x has
563 # such a declaration.
564
565 file=regexp.h
566 base=`basename $file`
567 if [ -r ${LIB}/$file ]; then
568   file_to_fix=${LIB}/$file
569 else
570   if [ -r ${INPUT}/$file ]; then
571     file_to_fix=${INPUT}/$file
572   else
573     file_to_fix=""
574   fi
575 fi
576 if [ \! -z "$file_to_fix" ]; then
577   echo Checking $file_to_fix
578   if grep "static void getrnge" $file_to_fix > /dev/null; then
579     true
580   else
581     cp $file_to_fix /tmp/$base
582     chmod +w /tmp/$base
583     sed -e '/^static int[       ]*size;/c\
584 static int      size ;\
585 \
586 static int getrnge ();' /tmp/$base > /tmp/$base.sed
587     if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
588       true
589     else
590       echo Fixed $file_to_fix
591       rm -f ${LIB}/$file
592       cp /tmp/$base.sed ${LIB}/$file
593       chmod a+r ${LIB}/$file
594     fi
595   fi
596   rm -f /tmp/$base /tmp/$base.sed
597 fi
598
599 # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
600 # that is visible to any ANSI compiler using this include.  Simply
601 # delete the lines that #define some string functions to internal forms.
602
603 file=string.h
604 base=`basename $file`
605 if [ -r ${LIB}/$file ]; then
606   file_to_fix=${LIB}/$file
607 else
608   if [ -r ${INPUT}/$file ]; then
609     file_to_fix=${INPUT}/$file
610   else
611     file_to_fix=""
612   fi
613 fi
614 if [ \! -z "$file_to_fix" ]; then
615   echo Checking $file_to_fix
616   cp $file_to_fix /tmp/$base
617   chmod +w /tmp/$base
618   sed -e '/#define.*__std_hdr_/d' /tmp/$base > /tmp/$base.sed
619   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
620     true
621   else
622     echo Fixed $file_to_fix
623     rm -f ${LIB}/$file
624     cp /tmp/$base.sed ${LIB}/$file
625     chmod a+r ${LIB}/$file
626   fi
627   rm -f /tmp/$base /tmp/$base.sed
628 fi
629
630 # Delete any #defines of `__i386' which may be present in <ieeefp.h>.  They
631 # tend to conflict with the compiler's own definition of this symbol.  (We
632 # will use the compiler's definition.)
633 # Likewise __sparc, for Solaris, and __i860, and a few others
634 # (guessing it is necessary for all of them).
635
636 file=ieeefp.h
637 base=`basename $file`
638 if [ -r ${LIB}/$file ]; then
639   file_to_fix=${LIB}/$file
640 else
641   if [ -r ${INPUT}/$file ]; then
642     file_to_fix=${INPUT}/$file
643   else
644     file_to_fix=""
645   fi
646 fi
647 if [ \! -z "$file_to_fix" ]; then
648   echo Checking $file_to_fix
649   cp $file_to_fix /tmp/$base
650   chmod +w /tmp/$base
651   sed -e '/#define[     ]*__i386 /d' -e '/#define[      ]*__sparc /d' \
652       -e '/#define[     ]*__i860 /d' -e '/#define[      ]*__m88k /d' \
653       -e '/#define[     ]*__mips /d' -e '/#define[      ]*__m68k /d' \
654      /tmp/$base > /tmp/$base.sed
655   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
656     true
657   else
658     echo Fixed $file_to_fix 
659     rm -f ${LIB}/$file
660     cp /tmp/$base.sed ${LIB}/$file 
661     chmod a+r ${LIB}/$file
662   fi
663   rm -f /tmp/$base /tmp/$base.sed 
664 fi 
665
666 # Add a #define of _SIGACTION_ into <sys/signal.h>.
667 # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
668
669 file=sys/signal.h
670 base=`basename $file`
671 if [ -r ${LIB}/$file ]; then
672   file_to_fix=${LIB}/$file
673 else
674   if [ -r ${INPUT}/$file ]; then
675     file_to_fix=${INPUT}/$file
676   else
677     file_to_fix=""
678   fi
679 fi
680 if [ \! -z "$file_to_fix" ]; then
681   echo Checking $file_to_fix
682   cp $file_to_fix /tmp/$base
683   chmod +w /tmp/$base
684   sed -e '/^struct sigaction {/c\
685 #define _SIGACTION_\
686 struct  sigaction  {' \
687   -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp/$base > /tmp/$base.sed
688   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
689     true
690   else
691     echo Fixed $file_to_fix
692     rm -f ${LIB}/$file
693     cp /tmp/$base.sed ${LIB}/$file
694     chmod a+r ${LIB}/$file
695   fi
696   rm -f /tmp/$base /tmp/$base.sed
697 fi
698
699 # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
700
701 file=sys/mkdev.h
702 base=`basename $file`
703 if [ -r ${LIB}/$file ]; then
704   file_to_fix=${LIB}/$file
705 else
706   if [ -r ${INPUT}/$file ]; then
707     file_to_fix=${INPUT}/$file
708   else
709     file_to_fix=""
710   fi
711 fi
712 if [ \! -z "$file_to_fix" ]; then
713   echo Checking $file_to_fix
714   cp $file_to_fix /tmp/$base
715   chmod +w /tmp/$base
716   sed -e '/^dev_t makedev(const/c\
717 static dev_t makedev(const major_t, const minor_t);' \
718   -e '/^dev_t makedev()/c\
719 static dev_t makedev();' \
720   -e '/^major_t major(const/c\
721 static major_t major(const dev_t);' \
722   -e '/^major_t major()/c\
723 static major_t major();' \
724   -e '/^minor_t minor(const/c\
725 static minor_t minor(const dev_t);' \
726   -e '/^minor_t minor()/c\
727 static minor_t minor();' /tmp/$base > /tmp/$base.sed
728   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
729     true
730   else
731     echo Fixed $file_to_fix
732     rm -f ${LIB}/$file
733     cp /tmp/$base.sed ${LIB}/$file
734     chmod a+r ${LIB}/$file
735   fi
736   rm -f /tmp/$base /tmp/$base.sed
737 fi
738
739 # Fix reference to NMSZ in <sys/adv.h>.
740
741 file=sys/adv.h
742 base=`basename $file`
743 if [ -r ${LIB}/$file ]; then
744   file_to_fix=${LIB}/$file
745 else
746   if [ -r ${INPUT}/$file ]; then
747     file_to_fix=${INPUT}/$file
748   else
749     file_to_fix=""
750   fi
751 fi
752 if [ \! -z "$file_to_fix" ]; then
753   echo Checking $file_to_fix
754   sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
755   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
756     true
757   else
758     echo Fixed $file_to_fix
759     rm -f ${LIB}/$file
760     cp /tmp/$base ${LIB}/$file
761     chmod a+r ${LIB}/$file
762   fi
763   rm -f /tmp/$base
764 fi
765
766 # Fix reference to NC_NPI_RAW in <sys/netcspace.h>.  Also fix types of
767 # array initializers.
768
769 file=sys/netcspace.h
770 base=`basename $file`
771 if [ -r ${LIB}/$file ]; then
772   file_to_fix=${LIB}/$file
773 else
774   if [ -r ${INPUT}/$file ]; then
775     file_to_fix=${INPUT}/$file
776   else
777     file_to_fix=""
778   fi
779 fi
780 if [ \! -z "$file_to_fix" ]; then
781   echo Checking $file_to_fix
782   sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
783     | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
784   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
785     true
786   else
787     echo Fixed $file_to_fix
788     rm -f ${LIB}/$file
789     cp /tmp/$base ${LIB}/$file
790     chmod a+r ${LIB}/$file
791   fi
792   rm -f /tmp/$base
793 fi
794
795 # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
796
797 file=fs/rfs/rf_cache.h
798 base=`basename $file`
799 if [ -r ${LIB}/$file ]; then
800   file_to_fix=${LIB}/$file
801 else
802   if [ -r ${INPUT}/$file ]; then
803     file_to_fix=${INPUT}/$file
804   else
805     file_to_fix=""
806   fi
807 fi
808 if [ \! -z "$file_to_fix" ]; then
809   echo Checking $file_to_fix
810   if grep _KERNEL $file_to_fix > /dev/null; then
811     true
812   else
813     echo '#ifdef _KERNEL' > /tmp/$base
814     cat $file_to_fix >> /tmp/$base
815     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
816     echo Fixed $file_to_fix
817     rm -f ${LIB}/$file
818     cp /tmp/$base ${LIB}/$file
819     chmod a+r ${LIB}/$file
820     rm -f /tmp/$base
821   fi
822 fi
823
824 # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
825
826 file=sys/erec.h
827 base=`basename $file`
828 if [ -r ${LIB}/$file ]; then
829   file_to_fix=${LIB}/$file
830 else
831   if [ -r ${INPUT}/$file ]; then
832     file_to_fix=${INPUT}/$file
833   else
834     file_to_fix=""
835   fi
836 fi
837 if [ \! -z "$file_to_fix" ]; then
838   echo Checking $file_to_fix
839   if grep _KERNEL $file_to_fix > /dev/null; then
840     true
841   else
842     echo '#ifdef _KERNEL' > /tmp/$base
843     cat $file_to_fix >> /tmp/$base
844     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
845     echo Fixed $file_to_fix
846     rm -f ${LIB}/$file
847     cp /tmp/$base ${LIB}/$file
848     chmod a+r ${LIB}/$file
849     rm -f /tmp/$base
850   fi
851 fi
852
853 # Conditionalize all of <sys/err.h> on _KERNEL being defined.
854
855 file=sys/err.h
856 base=`basename $file`
857 if [ -r ${LIB}/$file ]; then
858   file_to_fix=${LIB}/$file
859 else
860   if [ -r ${INPUT}/$file ]; then
861     file_to_fix=${INPUT}/$file
862   else
863     file_to_fix=""
864   fi
865 fi
866 if [ \! -z "$file_to_fix" ]; then
867   echo Checking $file_to_fix
868   if grep _KERNEL $file_to_fix > /dev/null; then
869     true
870   else
871     echo '#ifdef _KERNEL' > /tmp/$base
872     cat $file_to_fix >> /tmp/$base
873     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
874     echo Fixed $file_to_fix
875     rm -f ${LIB}/$file
876     cp /tmp/$base ${LIB}/$file
877     chmod a+r ${LIB}/$file
878     rm -f /tmp/$base
879   fi
880 fi
881
882 # Conditionalize all of <sys/char.h> on _KERNEL being defined.
883
884 file=sys/char.h
885 base=`basename $file`
886 if [ -r ${LIB}/$file ]; then
887   file_to_fix=${LIB}/$file
888 else
889   if [ -r ${INPUT}/$file ]; then
890     file_to_fix=${INPUT}/$file
891   else
892     file_to_fix=""
893   fi
894 fi
895 if [ \! -z "$file_to_fix" ]; then
896   echo Checking $file_to_fix
897   if grep _KERNEL $file_to_fix > /dev/null; then
898     true
899   else
900     echo '#ifdef _KERNEL' > /tmp/$base
901     cat $file_to_fix >> /tmp/$base
902     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
903     echo Fixed $file_to_fix
904     rm -f ${LIB}/$file
905     cp /tmp/$base ${LIB}/$file
906     chmod a+r ${LIB}/$file
907     rm -f /tmp/$base
908   fi
909 fi
910
911 # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
912
913 file=sys/getpages.h
914 base=`basename $file`
915 if [ -r ${LIB}/$file ]; then
916   file_to_fix=${LIB}/$file
917 else
918   if [ -r ${INPUT}/$file ]; then
919     file_to_fix=${INPUT}/$file
920   else
921     file_to_fix=""
922   fi
923 fi
924 if [ \! -z "$file_to_fix" ]; then
925   echo Checking $file_to_fix
926   if grep _KERNEL $file_to_fix > /dev/null; then
927     true
928   else
929     echo '#ifdef _KERNEL' > /tmp/$base
930     cat $file_to_fix >> /tmp/$base
931     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
932     echo Fixed $file_to_fix
933     rm -f ${LIB}/$file
934     cp /tmp/$base ${LIB}/$file
935     chmod a+r ${LIB}/$file
936     rm -f /tmp/$base
937   fi
938 fi
939
940 # Conditionalize all of <sys/map.h> on _KERNEL being defined.
941
942 file=sys/map.h
943 base=`basename $file`
944 if [ -r ${LIB}/$file ]; then
945   file_to_fix=${LIB}/$file
946 else
947   if [ -r ${INPUT}/$file ]; then
948     file_to_fix=${INPUT}/$file
949   else
950     file_to_fix=""
951   fi
952 fi
953 if [ \! -z "$file_to_fix" ]; then
954   echo Checking $file_to_fix
955   if grep _KERNEL $file_to_fix > /dev/null; then
956     true
957   else
958     echo '#ifdef _KERNEL' > /tmp/$base
959     cat $file_to_fix >> /tmp/$base
960     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
961     echo Fixed $file_to_fix
962     rm -f ${LIB}/$file
963     cp /tmp/$base ${LIB}/$file
964     chmod a+r ${LIB}/$file
965     rm -f /tmp/$base
966   fi
967 fi
968
969 # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
970
971 file=sys/cmn_err.h
972 base=`basename $file`
973 if [ -r ${LIB}/$file ]; then
974   file_to_fix=${LIB}/$file
975 else
976   if [ -r ${INPUT}/$file ]; then
977     file_to_fix=${INPUT}/$file
978   else
979     file_to_fix=""
980   fi
981 fi
982 if [ \! -z "$file_to_fix" ]; then
983   echo Checking $file_to_fix
984   if grep _KERNEL $file_to_fix > /dev/null; then
985     true
986   else
987     echo '#ifdef _KERNEL' > /tmp/$base
988     cat $file_to_fix >> /tmp/$base
989     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
990     echo Fixed $file_to_fix
991     rm -f ${LIB}/$file
992     cp /tmp/$base ${LIB}/$file
993     chmod a+r ${LIB}/$file
994     rm -f /tmp/$base
995   fi
996 fi
997
998 # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
999
1000 file=sys/kdebugger.h
1001 base=`basename $file`
1002 if [ -r ${LIB}/$file ]; then
1003   file_to_fix=${LIB}/$file
1004 else
1005   if [ -r ${INPUT}/$file ]; then
1006     file_to_fix=${INPUT}/$file
1007   else
1008     file_to_fix=""
1009   fi
1010 fi
1011 if [ \! -z "$file_to_fix" ]; then
1012   echo Checking $file_to_fix
1013   if grep _KERNEL $file_to_fix > /dev/null; then
1014     true
1015   else
1016     echo '#ifdef _KERNEL' > /tmp/$base
1017     cat $file_to_fix >> /tmp/$base
1018     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
1019     echo Fixed $file_to_fix
1020     rm -f ${LIB}/$file
1021     cp /tmp/$base ${LIB}/$file
1022     chmod a+r ${LIB}/$file
1023     rm -f /tmp/$base
1024   fi
1025 fi
1026
1027 # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
1028 # This has been taken out because it breaks on some versions of
1029 # DYNIX/ptx, and it does not seem to do much good on any system.
1030 # file=netinet/in.h
1031 # base=`basename $file`
1032 # if [ -r ${LIB}/$file ]; then
1033 #   file_to_fix=${LIB}/$file
1034 # else
1035 #   if [ -r ${INPUT}/$file ]; then
1036 #     file_to_fix=${INPUT}/$file
1037 #   else
1038 #     file_to_fix=""
1039 #   fi
1040 # fi
1041 # if [ \! -z "$file_to_fix" ]; then
1042 #   echo Checking $file_to_fix
1043 #   if grep _KERNEL $file_to_fix > /dev/null; then
1044 #     true
1045 #   else
1046 #     sed -e '/#ifdef INKERNEL/i\
1047 # #ifdef _KERNEL
1048 # ' \
1049 #     -e '/#endif[      ]*\/\* INKERNEL \*\//a\
1050 # #endif /* _KERNEL */
1051 # ' \
1052 #     $file_to_fix > ${LIB}/${file}.sed
1053 #     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1054 #     echo Fixed $file_to_fix
1055 #   fi
1056 # fi
1057
1058 # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
1059
1060 file=sys/endian.h
1061 base=`basename $file`
1062 if [ -r ${LIB}/$file ]; then
1063   file_to_fix=${LIB}/$file
1064 else
1065   if [ -r ${INPUT}/$file ]; then
1066     file_to_fix=${INPUT}/$file
1067   else
1068     file_to_fix=""
1069   fi
1070 fi
1071 if [ \! -z "$file_to_fix" ]; then
1072   echo Checking $file_to_fix
1073   if grep __GNUC__ $file_to_fix > /dev/null; then
1074     true
1075   else
1076     sed -e '/#  ifdef   __STDC__/i\
1077 #   if !defined (__GNUC__) && !defined (__GNUG__)
1078 ' \
1079     -e '/#              include <sys\/byteorder.h>/s/           /   /'\
1080     -e '/#   include    <sys\/byteorder.h>/i\
1081 #   endif /* !defined (__GNUC__) && !defined (__GNUG__) */
1082 '\
1083     $file_to_fix > ${LIB}/${file}.sed
1084     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1085     echo Fixed $file_to_fix
1086   fi
1087 fi
1088
1089 # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
1090 # and the text in types.h is not erroneous.
1091 ## In sys/types.h, don't name the enum for booleans.
1092 #
1093 #file=sys/types.h
1094 #base=`basename $file`
1095 #if [ -r ${LIB}/$file ]; then
1096 #  file_to_fix=${LIB}/$file
1097 #else
1098 #  if [ -r ${INPUT}/$file ]; then
1099 #    file_to_fix=${INPUT}/$file
1100 #  else
1101 #    file_to_fix=""
1102 #  fi
1103 #fi
1104 #if [ \! -z "$file_to_fix" ]; then
1105 #  echo Checking $file_to_fix
1106 #  if grep "enum boolean" $file_to_fix > /dev/null; then
1107 #    sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
1108 #    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1109 #    echo Fixed $file_to_fix
1110 #  else
1111 #    true
1112 #  fi
1113 #fi
1114
1115 # Remove useless extern keyword from struct forward declarations in
1116 # <sys/stream.h> and <sys/strsubr.h>
1117
1118 file=sys/stream.h
1119 base=`basename $file`
1120 if [ -r ${LIB}/$file ]; then
1121   file_to_fix=${LIB}/$file
1122 else
1123   if [ -r ${INPUT}/$file ]; then
1124     file_to_fix=${INPUT}/$file
1125   else
1126     file_to_fix=""
1127   fi
1128 fi
1129 if [ \! -z "$file_to_fix" ]; then
1130   echo Checking $file_to_fix
1131   sed -e '
1132     s/extern struct stdata;/struct stdata;/g
1133     s/extern struct strevent;/struct strevent;/g
1134   ' $file_to_fix > /tmp/$base 
1135   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1136     true
1137   else
1138     echo Fixed $file_to_fix
1139     rm -f ${LIB}/$file
1140     cp /tmp/$base ${LIB}/$file
1141     chmod a+r ${LIB}/$file
1142   fi
1143   rm -f /tmp/$base
1144 fi
1145
1146 file=sys/strsubr.h
1147 base=`basename $file`
1148 if [ -r ${LIB}/$file ]; then
1149   file_to_fix=${LIB}/$file
1150 else
1151   if [ -r ${INPUT}/$file ]; then
1152     file_to_fix=${INPUT}/$file
1153   else
1154     file_to_fix=""
1155   fi
1156 fi
1157 if [ \! -z "$file_to_fix" ]; then
1158   echo Checking $file_to_fix
1159   sed -e '
1160     s/extern struct strbuf;/struct strbuf;/g
1161     s/extern struct uio;/struct uio;/g
1162     s/extern struct thread;/struct thread;/g
1163     s/extern struct proc;/struct proc;/g
1164   ' $file_to_fix > /tmp/$base 
1165   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1166     true
1167   else
1168     echo Fixed $file_to_fix
1169     rm -f ${LIB}/$file
1170     cp /tmp/$base ${LIB}/$file
1171     chmod a+r ${LIB}/$file
1172   fi
1173   rm -f /tmp/$base
1174 fi
1175
1176 # Put storage class at start of decl, to avoid warning.
1177 file=rpc/types.h
1178 base=`basename $file`
1179 if [ -r ${LIB}/$file ]; then
1180   file_to_fix=${LIB}/$file
1181 else
1182   if [ -r ${INPUT}/$file ]; then
1183     file_to_fix=${INPUT}/$file
1184   else
1185     file_to_fix=""
1186   fi
1187 fi
1188 if [ \! -z "$file_to_fix" ]; then
1189   echo Checking $file_to_fix
1190   sed -e '
1191     s/const extern/extern const/g
1192   ' $file_to_fix > /tmp/$base 
1193   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1194     true
1195   else
1196     echo Fixed $file_to_fix
1197     rm -f ${LIB}/$file
1198     cp /tmp/$base ${LIB}/$file
1199     chmod a+r ${LIB}/$file
1200   fi
1201   rm -f /tmp/$base
1202 fi
1203
1204 # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
1205
1206 file=sys/stat.h
1207 base=`basename $file`
1208 if [ -r ${LIB}/$file ]; then
1209   file_to_fix=${LIB}/$file
1210 else
1211   if [ -r ${INPUT}/$file ]; then
1212     file_to_fix=${INPUT}/$file
1213   else
1214     file_to_fix=""
1215   fi
1216 fi
1217 if [ \! -z "$file_to_fix" ]; then
1218   echo Checking $file_to_fix
1219   cp $file_to_fix /tmp/$base
1220   chmod +w /tmp/$base
1221   sed -e '/^stat([      ]*[^c]/{
1222 N
1223 N
1224 s/(.*)\n/( /
1225 s/;\n/, /
1226 s/;$/)/
1227 }' \
1228   -e '/^lstat([         ]*[^c]/{
1229 N
1230 N
1231 s/(.*)\n/( /
1232 s/;\n/, /
1233 s/;$/)/
1234 }' \
1235   -e '/^fstat([         ]*[^i]/{
1236 N
1237 N
1238 s/(.*)\n/( /
1239 s/;\n/, /
1240 s/;$/)/
1241 }' \
1242   -e '/^mknod([         ]*[^c]/{
1243 N
1244 N
1245 N
1246 s/(.*)\n/( /
1247 s/;\n/, /g
1248 s/;$/)/
1249 }' \
1250   -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
1251   -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
1252   -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
1253   -e '1,$s/ret\([^u]\)/__ret\1/g' \
1254   -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
1255   -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp/$base > /tmp/$base.sed
1256   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
1257     true
1258   else
1259     echo Fixed $file_to_fix
1260     rm -f ${LIB}/$file
1261     cp /tmp/$base.sed ${LIB}/$file
1262     chmod a+r ${LIB}/$file
1263   fi
1264   rm -f /tmp/$base /tmp/$base.sed
1265 fi
1266
1267 # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
1268
1269 if [ -x /bin/sony ]; then
1270   if /bin/sony; then
1271
1272     # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
1273
1274     file=stdio.h
1275     base=`basename $file`
1276     if [ -r ${LIB}/$file ]; then
1277       file_to_fix=${LIB}/$file
1278     else
1279       if [ -r ${INPUT}/$file ]; then
1280         file_to_fix=${INPUT}/$file
1281       else
1282         file_to_fix=""
1283       fi
1284     fi
1285     if [ \! -z "$file_to_fix" ]; then
1286       echo Checking $file_to_fix
1287       cp $file_to_fix /tmp/$base
1288       chmod +w /tmp/$base
1289       sed -e '
1290         s/__filbuf/_filbuf/g
1291         s/__flsbuf/_flsbuf/g
1292         s/__iob/_iob/g
1293       ' /tmp/$base > /tmp/$base.sed
1294       mv /tmp/$base.sed /tmp/$base
1295       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1296         true
1297       else
1298         echo Fixed $file_to_fix
1299         rm -f ${LIB}/$file
1300         cp /tmp/$base ${LIB}/$file
1301         chmod a+r ${LIB}/$file
1302       fi
1303       rm -f /tmp/$base
1304     fi
1305
1306     # Change <ctype.h> to not define __ctype
1307
1308     file=ctype.h
1309     base=`basename $file`
1310     if [ -r ${LIB}/$file ]; then
1311       file_to_fix=${LIB}/$file
1312     else
1313       if [ -r ${INPUT}/$file ]; then
1314         file_to_fix=${INPUT}/$file
1315       else
1316         file_to_fix=""
1317       fi
1318     fi
1319     if [ \! -z "$file_to_fix" ]; then
1320       echo Checking $file_to_fix
1321       cp $file_to_fix /tmp/$base
1322       chmod +w /tmp/$base
1323       sed -e '
1324         s/__ctype/_ctype/g
1325       ' /tmp/$base > /tmp/$base.sed
1326       mv /tmp/$base.sed /tmp/$base
1327       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1328         true
1329       else
1330         echo Fixed $file_to_fix
1331         rm -f ${LIB}/$file
1332         cp /tmp/$base ${LIB}/$file
1333         chmod a+r ${LIB}/$file
1334       fi
1335       rm -f /tmp/$base
1336     fi
1337   fi
1338 fi
1339
1340 # In limits.h, put #ifndefs around things that are supposed to be defined
1341 # in float.h to avoid redefinition errors if float.h is included first.
1342 # Solaris 2.1 has this problem.
1343
1344 file=limits.h
1345 base=`basename $file`
1346 if [ -r ${LIB}/$file ]; then
1347   file_to_fix=${LIB}/$file
1348 else
1349   if [ -r ${INPUT}/$file ]; then
1350     file_to_fix=${INPUT}/$file
1351   else
1352     file_to_fix=""
1353   fi
1354 fi
1355 if [ \! -z "$file_to_fix" ]; then
1356   echo Checking $file_to_fix
1357   sed -e '/[    ]FLT_MIN[       ]/i\
1358 #ifndef FLT_MIN
1359 '\
1360       -e '/[    ]FLT_MIN[       ]/a\
1361 #endif
1362 '\
1363       -e '/[    ]FLT_MAX[       ]/i\
1364 #ifndef FLT_MAX
1365 '\
1366       -e '/[    ]FLT_MAX[       ]/a\
1367 #endif
1368 '\
1369       -e '/[    ]FLT_DIG[       ]/i\
1370 #ifndef FLT_DIG
1371 '\
1372       -e '/[    ]FLT_DIG[       ]/a\
1373 #endif
1374 '\
1375       -e '/[    ]DBL_MIN[       ]/i\
1376 #ifndef DBL_MIN
1377 '\
1378       -e '/[    ]DBL_MIN[       ]/a\
1379 #endif
1380 '\
1381       -e '/[    ]DBL_MAX[       ]/i\
1382 #ifndef DBL_MAX
1383 '\
1384       -e '/[    ]DBL_MAX[       ]/a\
1385 #endif
1386 '\
1387       -e '/[    ]DBL_DIG[       ]/i\
1388 #ifndef DBL_DIG
1389 '\
1390       -e '/[    ]DBL_DIG[       ]/a\
1391 #endif
1392 ' $file_to_fix > /tmp/$base
1393   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1394     true
1395   else
1396     echo Fixed $file_to_fix
1397     rm -f ${LIB}/$file
1398     cp /tmp/$base ${LIB}/$file
1399     chmod a+r ${LIB}/$file
1400   fi
1401   rm -f /tmp/$base
1402 fi
1403
1404 # Completely replace <sys/varargs.h> with a file that includes gcc's
1405 # stdarg.h or varargs.h files as appropriate.
1406
1407 file=sys/varargs.h
1408 if [ -r ${INPUT}/$file ]; then
1409   echo Replacing $file
1410   cat > ${LIB}/$file << EOF
1411 /* This file was generated by fixincludes.  */
1412 #ifndef _SYS_VARARGS_H
1413 #define _SYS_VARARGS_H
1414
1415 #ifdef __STDC__
1416 #include <stdarg.h>
1417 #else
1418 #include <varargs.h>
1419 #endif
1420
1421 #endif  /* _SYS_VARARGS_H */
1422 EOF
1423   chmod a+r ${LIB}/$file
1424 fi
1425
1426 # In math.h, put #ifndefs around things that might be defined in a gcc
1427 # specific math-*.h file.
1428
1429 file=math.h
1430 base=`basename $file`
1431 if [ -r ${LIB}/$file ]; then
1432   file_to_fix=${LIB}/$file
1433 else
1434   if [ -r ${INPUT}/$file ]; then
1435     file_to_fix=${INPUT}/$file
1436   else
1437     file_to_fix=""
1438   fi
1439 fi
1440 if [ \! -z "$file_to_fix" ]; then
1441   echo Checking $file_to_fix
1442   sed -e '/define[      ]HUGE_VAL[      ]/i\
1443 #ifndef HUGE_VAL
1444 '\
1445       -e '/define[      ]HUGE_VAL[      ]/a\
1446 #endif
1447 ' $file_to_fix > /tmp/$base
1448   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1449     true
1450   else
1451     echo Fixed $file_to_fix
1452     rm -f ${LIB}/$file
1453     cp /tmp/$base ${LIB}/$file
1454     chmod a+r ${LIB}/$file
1455   fi
1456   rm -f /tmp/$base
1457 fi
1458
1459 # Solaris math.h and floatingpoint.h define __P without protection,
1460 # which conflicts with the fixproto definition.  The fixproto
1461 # definition and the Solaris definition are used the same way.
1462 for file in math.h floatingpoint.h; do
1463   base=`basename $file`
1464   if [ -r ${LIB}/$file ]; then
1465     file_to_fix=${LIB}/$file
1466   else
1467     if [ -r ${INPUT}/$file ]; then
1468       file_to_fix=${INPUT}/$file
1469     else
1470       file_to_fix=""
1471     fi
1472   fi
1473   if [ \! -z "$file_to_fix" ]; then
1474     echo Checking $file_to_fix
1475     sed -e '/^#define[  ]*__P/i\
1476 #ifndef __P
1477 '\
1478         -e '/^#define[  ]*__P/a\
1479 #endif
1480 ' $file_to_fix > /tmp/$base
1481     if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1482       true
1483     else
1484       echo Fixed $file_to_fix
1485       rm -f ${LIB}/$file
1486       cp /tmp/$base ${LIB}/$file
1487       chmod a+r ${LIB}/$file
1488     fi
1489    rm -f /tmp/$base
1490   fi
1491 done
1492
1493 # The Solaris math.h defines struct exception, which conflicts with
1494 # the class exception defined in the C++ file std/stdexcept.h.  We
1495 # redefine it to __math_exception.  This is not a great fix, but I
1496 # haven't been able to think of anything better.
1497 file=math.h
1498 base=`basename $file`
1499 if [ -r ${LIB}/$file ]; then
1500   file_to_fix=${LIB}/$file
1501 else
1502   if [ -r ${INPUT}/$file ]; then
1503     file_to_fix=${INPUT}/$file
1504   else
1505     file_to_fix=""
1506   fi
1507 fi
1508 if [ \! -z "$file_to_fix" ]; then
1509   echo Checking $file_to_fix
1510   sed -e '/struct exception/i\
1511 #ifdef __cplusplus\
1512 #define exception __math_exception\
1513 #endif'\
1514       -e '/struct exception/a\
1515 #ifdef __cplusplus\
1516 #undef exception\
1517 #endif' $file_to_fix > /tmp/$base
1518   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1519     true
1520   else
1521     echo Fixed $file_to_fix
1522     rm -f ${LIB}/$file
1523     cp /tmp/$base ${LIB}/$file
1524     chmod a+r ${LIB}/$file
1525   fi
1526   rm -f /tmp/$base
1527 fi
1528
1529 echo 'Removing unneeded directories:'
1530 cd $LIB
1531 files=`find . -type d -print | sort -r`
1532 for file in $files; do
1533   rmdir $LIB/$file > /dev/null 2>&1
1534 done
1535
1536 if $LINKS; then
1537   echo 'Making internal symbolic non-directory links'
1538   cd ${INPUT}
1539   files=`find . -type l -print`
1540   for file in $files; do
1541     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1542     if expr "$dest" : '[^/].*' > /dev/null; then    
1543       target=${LIB}/`echo $file | sed "s|[^/]*\$|$dest|"`
1544       if [ -f $target ]; then
1545         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1546       fi
1547     fi
1548   done
1549 fi
1550
1551 cd ${ORIG_DIR}
1552
1553 echo 'Replacing <sys/byteorder.h>'
1554 if [ \! -d $LIB/sys ]; then
1555   mkdir $LIB/sys
1556 fi
1557 rm -f ${LIB}/sys/byteorder.h
1558 cat <<'__EOF__' >${LIB}/sys/byteorder.h
1559 #ifndef _SYS_BYTEORDER_H
1560 #define _SYS_BYTEORDER_H
1561
1562 /* Functions to convert `short' and `long' quantities from host byte order
1563    to (internet) network byte order (i.e. big-endian).
1564
1565    Written by Ron Guilmette (rfg@ncd.com).
1566
1567    This isn't actually used by GCC.  It is installed by fixinc.svr4.
1568
1569    For big-endian machines these functions are essentially no-ops.
1570
1571    For little-endian machines, we define the functions using specialized
1572    asm sequences in cases where doing so yields better code (e.g. i386).  */
1573
1574 #if !defined (__GNUC__) && !defined (__GNUG__)
1575 #error You lose!  This file is only useful with GNU compilers.
1576 #endif
1577
1578 #ifndef __BYTE_ORDER__
1579 /* Byte order defines.  These are as defined on UnixWare 1.1, but with
1580    double underscores added at the front and back.  */
1581 #define __LITTLE_ENDIAN__   1234
1582 #define __BIG_ENDIAN__      4321
1583 #define __PDP_ENDIAN__      3412
1584 #endif
1585
1586 #ifdef __STDC__
1587 static __inline__ unsigned long htonl (unsigned long);
1588 static __inline__ unsigned short htons (unsigned int);
1589 static __inline__ unsigned long ntohl (unsigned long);
1590 static __inline__ unsigned short ntohs (unsigned int);
1591 #endif /* defined (__STDC__) */
1592
1593 #if defined (__i386__)
1594
1595 #ifndef __BYTE_ORDER__
1596 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1597 #endif
1598
1599 /* Convert a host long to a network long.  */
1600
1601 /* We must use a new-style function definition, so that this will also
1602    be valid for C++.  */
1603 static __inline__ unsigned long
1604 htonl (unsigned long __arg)
1605 {
1606   register unsigned long __result;
1607
1608   __asm__ ("xchg%B0 %b0,%h0\n\
1609         ror%L0 $16,%0\n\
1610         xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1611   return __result;
1612 }
1613
1614 /* Convert a host short to a network short.  */
1615
1616 static __inline__ unsigned short
1617 htons (unsigned int __arg)
1618 {
1619   register unsigned short __result;
1620
1621   __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1622   return __result;
1623 }
1624
1625 #elif ((defined (__i860__) && !defined (__i860_big_endian__))   \
1626        || defined (__ns32k__) || defined (__vax__)              \
1627        || defined (__spur__) || defined (__arm__))
1628
1629 #ifndef __BYTE_ORDER__
1630 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1631 #endif
1632
1633 /* For other little-endian machines, using C code is just as efficient as
1634    using assembly code.  */
1635
1636 /* Convert a host long to a network long.  */
1637
1638 static __inline__ unsigned long
1639 htonl (unsigned long __arg)
1640 {
1641   register unsigned long __result;
1642
1643   __result = (__arg >> 24) & 0x000000ff;
1644   __result |= (__arg >> 8) & 0x0000ff00;
1645   __result |= (__arg << 8) & 0x00ff0000;
1646   __result |= (__arg << 24) & 0xff000000;
1647   return __result;
1648 }
1649
1650 /* Convert a host short to a network short.  */
1651
1652 static __inline__ unsigned short
1653 htons (unsigned int __arg)
1654 {
1655   register unsigned short __result;
1656
1657   __result = (__arg << 8) & 0xff00;
1658   __result |= (__arg >> 8) & 0x00ff;
1659   return __result;
1660 }
1661
1662 #else /* must be a big-endian machine */
1663
1664 #ifndef __BYTE_ORDER__
1665 #define __BYTE_ORDER__ __BIG_ENDIAN__
1666 #endif
1667
1668 /* Convert a host long to a network long.  */
1669
1670 static __inline__ unsigned long
1671 htonl (unsigned long __arg)
1672 {
1673   return __arg;
1674 }
1675
1676 /* Convert a host short to a network short.  */
1677
1678 static __inline__ unsigned short
1679 htons (unsigned int __arg)
1680 {
1681   return __arg;
1682 }
1683
1684 #endif /* big-endian */
1685
1686 /* Convert a network long to a host long.  */
1687
1688 static __inline__ unsigned long
1689 ntohl (unsigned long __arg)
1690 {
1691   return htonl (__arg);
1692 }
1693
1694 /* Convert a network short to a host short.  */
1695
1696 static __inline__ unsigned short
1697 ntohs (unsigned int __arg)
1698 {
1699   return htons (__arg);
1700 }
1701
1702 __EOF__
1703
1704 if [ -r ${INPUT}/sys/byteorder.h ]; then
1705   if grep BYTE_ORDER ${INPUT}/sys/byteorder.h >/dev/null 2>/dev/null; then
1706     cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1707 #ifndef BYTE_ORDER
1708 #define LITTLE_ENDIAN __LITTLE_ENDIAN__
1709 #define BIG_ENDIAN __BIG_ENDIAN__
1710 #define PDP_ENDIAN __PDP_ENDIAN__
1711 #define BYTE_ORDER __BYTE_ORDER__
1712 #endif
1713
1714 __EOF__
1715   fi
1716 fi
1717
1718 cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1719 #endif /* !defined (_SYS_BYTEORDER_H) */
1720 __EOF__
1721
1722 chmod a+r ${LIB}/sys/byteorder.h
1723
1724 exit 0
1725