home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / gcc-2.6.0-src.lha / GNU / src / amiga / gcc-2.6.0 / fixinc.svr4 < prev    next >
Encoding:
Text File  |  1994-05-26  |  39.7 KB  |  1,620 lines

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