6 INCLUDE=$ROOT/stage0/usr/include
10 if test "$all_c" = "*.c"
14 #all_c=`find . -type f -name '*.c' -print |sed -e 's:^\./::' |LC_ALL=C sort`
15 #all_c=`find . -type f -name '*.c' -print |sed -e 's:^\./::' |grep -v '^vax/' |LC_ALL=C sort`
18 if test "$all_h" = "*.h"
22 #all_h=`find . -type f -name '*.h' -print |sed -e 's:^\./::' |LC_ALL=C sort`
23 #all_h=`find $INCLUDE -type f -name '*.h' -print |LC_ALL=C sort`
27 if test -z "$1" || test $1 -eq 0
31 rm -f *.[ch].allprotos
34 rm -f *.[ch].oldprotos
36 rm -f *.[ch].protos.nocomm
40 #rm -f `find . -name '*.[ch].allprotos' -print`
41 #rm -f `find . -name '*.[ch].cproto' -print`
42 #rm -f `find . -name '*.[ch].nocomm' -print`
43 #rm -f `find . -name '*.[ch].oldprotos' -print`
44 #rm -f `find . -name '*.[ch].protos' -print`
45 #rm -f `find . -name '*.[ch].protos.nocomm' -print`
46 #rm -f `find . -name '*.[ch].usedby' -print`
47 #rm -f `find . -name '*.[ch].uses' -print`
48 #rm -rf `find . -name .xify -print`
50 #rm -f `find $INCLUDE -name '*.h.allprotos' -print`
51 rm -f `find $INCLUDE -name '*.h.nocomm' -print`
52 #rm -f `find $INCLUDE -name '*.h.oldprotos' -print`
53 #rm -f `find $INCLUDE -name '*.h.protos' -print`
54 #rm -f `find $INCLUDE -name '*.h.protos.nocomm' -print`
55 rm -f `find $INCLUDE -name '*.h.usedby' -print`
56 #rm -f `find $INCLUDE -name '*.h.uses' -print`
57 rm -rf `find $INCLUDE -name .xify -print`
59 rm -f a b conflicts.temp oldprotos.txt oldprotos.temp xx*
63 git checkout $all_c $all_h
64 #rm -rf $ROOT/include $ROOT/sys
65 #git checkout $ROOT/include $ROOT/sys $all_c
68 #(cd $ROOT/include && $SCRIPTS/make.sh SHARED=copies install)
73 if test "$all_c" = "*.c"
77 #all_c=`find . -type f -name '*.c' -print |sed -e 's:^\./::' |LC_ALL=C sort`
78 #all_c=`find . -type f -name '*.c' -print |sed -e 's:^\./::' |grep -v '^vax/' |LC_ALL=C sort`
81 if test "$all_h" = "*.h"
85 #all_h=`find . -type f -name '*.h' -print |sed -e 's:^\./::' |LC_ALL=C sort`
86 #all_h=`find $INCLUDE -type f -name '*.h' -print |LC_ALL=C sort`
88 std_h=`find $INCLUDE -type f -name '*.h' -print |grep -v "^$INCLUDE/\(stand\|vaxif\|vaxmba\|vaxuba\)/" |LC_ALL=C sort`
91 if test -z "$1" || test $1 -eq 1
95 if test -f uniqify.sed
97 sed -f uniqify.sed -i $all_c $all_h
100 for i in $all_c $all_h
104 grep -H '^[A-Za-z_][0-9A-Za-z_]*[^0-9A-Za-z_][^;]*[A-Za-z_][0-9A-Za-z_]*[ ]*([ ]*)[ ]*\(,[^;]*\)\?;' $i >>oldprotos.txt
105 sed -e 's/^[A-Za-z_][0-9A-Za-z_]*[^0-9A-Za-z_][^;]*[A-Za-z_][0-9A-Za-z_]*[ ]*([ ]*)[ ]*\(,[^;]*\)\?;/\/\*&\*\//' -i $i
107 sed -e 's/^\(#[ ]*\(else\|endif\)\)\([^0-9A-Za-z_].*\)\?/\1/' -i $i
110 csplit -b '%05d' -q $i '/^#[ ]*if.*\(SCCS\|lint\)/' '{*}'
113 if test $j != xx00000 && sed -ne '2p' $j |grep -q 'char[ ]*\(copyright[ ]*\[[ ]*\]\|\*[ ]*copyright\)[ ]*='
115 sed -e 's/^\(#[ ]*if\).*\(SCCS\|lint\).*$/\1 defined(DOCOPYRIGHT) \&\& !defined(lint)/' -i $j
117 if test $j != xx00000 && sed -ne '2p' $j |grep -q 'char[ ]*\(sccsid[ ]*\[[ ]*\]\|\*[ ]*sccsid\)[ ]*='
119 sed -e 's/^\(#[ ]*if\).*\(SCCS\|lint\).*$/\1 defined(DOSCCS) \&\& !defined(lint)/' -i $j
121 sed -e 's/^.*char[ ]*\(sccsid[ ]*\[[ ]*\]\|\*[ ]*sccsid\)[ ]*=.*$/#if defined(DOSCCS) \&\& !defined(lint)\n&\n#endif/' -i $j
127 csplit -b '%05d' -q $i '/^[ ]*{[ ]*$/' '{*}'
131 if test -n "$prev" && ! sed -ne '$p' $prev |grep -q '^#'
133 sed -e '$s/$/ {/' -i $prev
141 grep '\.h:' oldprotos.txt >oldprotos.temp
143 sed -e 's/^[A-Za-z_].*__P.*;$/\/\*AAA&\*\//' -i $std_h
144 if ! test -f $INCLUDE/setjmp.h.save
146 mv $INCLUDE/setjmp.h $INCLUDE/setjmp.h.save
147 mv $INCLUDE/stdarg.h $INCLUDE/stdarg.h.save
148 mv $INCLUDE/stdint.h $INCLUDE/stdint.h.save
149 mv $INCLUDE/varargs.h $INCLUDE/varargs.h.save
151 cat <<EOF >$INCLUDE/setjmp.h
157 # cat <<EOF >$INCLUDE/stdarg.h
160 #typedef int va_list;
163 touch $INCLUDE/stdarg.h
164 # cat <<EOF >$INCLUDE/stdint.h
168 #typedef int int16_t;
169 #typedef int int32_t;
170 #typedef int int64_t;
171 #typedef int intptr_t;
172 #typedef int ssize_t;
173 #typedef int uint8_t;
174 #typedef int uint16_t;
175 #typedef int uint32_t;
176 #typedef int uint64_t;
177 #typedef int uintptr_t;
181 touch $INCLUDE/stdint.h
182 cat <<EOF >$INCLUDE/varargs.h
193 #group=$INCLUDE/`dirname $i`.h
195 if test -f groups.txt
197 j=`sed -ne "s:^$i \\(.*\\):\\1:p" groups.txt`
201 #echo $j >>$group.uses
209 $ROOT/cproto-4.6/cproto -i$INCLUDE -Dvax -t -H -s $i |sed -ne '2,$p' >$i.allprotos
210 if ! grep -qv '^int main __P((' $i.allprotos
212 echo -n >$i.allprotos
215 grep "^static " <$i.allprotos >a
221 grep -v "^static " <$i.allprotos >a
226 cp $i.allprotos $i.protos
237 protos="`sed -ne 's/^.*[^0-9A-Za-z_]\([A-Za-z_][0-9A-Za-z_]*\) __P((.*))\\( NORETURN\\)\\?;$/\1/p' a`"
238 echo "protos=$protos"
244 pattern="$pattern$prefix$j"
247 echo "pattern=$pattern"
249 grep "[^0-9A-Za-z_]\\($pattern\\)[ ]*(" oldprotos.temp >a
253 grep -v "^$group:" $i.oldprotos >&2
257 mv $INCLUDE/setjmp.h.save $INCLUDE/setjmp.h
258 mv $INCLUDE/stdarg.h.save $INCLUDE/stdarg.h
259 mv $INCLUDE/stdint.h.save $INCLUDE/stdint.h
260 mv $INCLUDE/varargs.h.save $INCLUDE/varargs.h
261 sed -e 's/^\/\*AAA\(.*\)\*\/$/\1/' -i $std_h
265 if test "$all_h" = "*.h"
269 #all_h=`find . -type f -name '*.h' -print |sed -e 's:^\./::' |LC_ALL=C sort`
270 #all_h=`find $INCLUDE -type f -name '*.h' -print |LC_ALL=C sort`
272 if test -z "$1" || test $1 -eq 2
280 $SCRIPTS/nocomment <$i |$SCRIPTS/nostring >$i.nocomm
281 all_c_nocomm="$all_c_nocomm $i.nocomm"
284 $SCRIPTS/nocomment <$i.protos |$SCRIPTS/nostring >$i.protos.nocomm
285 all_c_protos_nocomm="$all_c_protos_nocomm $i.protos.nocomm"
293 $SCRIPTS/nocomment <$i |$SCRIPTS/nostring >$i.nocomm
294 all_h_nocomm="$all_h_nocomm $i.nocomm"
297 $SCRIPTS/nocomment <$i.protos |$SCRIPTS/nostring >$i.protos.nocomm
298 all_h_protos_nocomm="$all_h_protos_nocomm $i.protos.nocomm"
302 if ! test -f $INCLUDE/setjmp.h.save
304 mv $INCLUDE/setjmp.h $INCLUDE/setjmp.h.save
305 mv $INCLUDE/stdarg.h $INCLUDE/stdarg.h.save
306 mv $INCLUDE/stdint.h $INCLUDE/stdint.h.save
307 mv $INCLUDE/varargs.h $INCLUDE/varargs.h.save
309 cat <<EOF >$INCLUDE/setjmp.h
315 # cat <<EOF >$INCLUDE/stdarg.h
318 #typedef int va_list;
321 touch $INCLUDE/stdarg.h
322 # cat <<EOF >$INCLUDE/stdint.h
326 #typedef int int16_t;
327 #typedef int int32_t;
328 #typedef int int64_t;
329 #typedef int intptr_t;
330 #typedef int ssize_t;
331 #typedef int uint8_t;
332 #typedef int uint16_t;
333 #typedef int uint32_t;
334 #typedef int uint64_t;
335 #typedef int uintptr_t;
339 touch $INCLUDE/stdint.h
340 cat <<EOF >$INCLUDE/varargs.h
348 $SCRIPTS/nocomment <$i |$SCRIPTS/nostring >$i.nocomm
350 mv $INCLUDE/setjmp.h.save $INCLUDE/setjmp.h
351 mv $INCLUDE/stdarg.h.save $INCLUDE/stdarg.h
352 mv $INCLUDE/stdint.h.save $INCLUDE/stdint.h
353 mv $INCLUDE/varargs.h.save $INCLUDE/varargs.h
355 if test -f conflicts.txt
357 sed -e 's/^/:/;s/ /::/g;s/$/:/' <conflicts.txt >conflicts.temp
362 for i in $all_h $std_h
365 h=`echo $i |sed -e "s:^$INCLUDE/::"`
368 macros="`sed -ne 's/^#[ ]*define[ ]\+\([A-Za-z_][0-9A-Za-z_]*\).*/\1/p' $i.nocomm |grep -v '^\(NULL\|__P\)$'`"
369 echo "macros=$macros"
370 typedefs="`sed -ne 's/^\(.*[^0-9A-Za-z_]\)\?typedef[^0-9A-Za-z_]\(.*[^0-9A-Za-z_]\)\?\([A-Za-z_][0-9A-Za-z_]*\)[ ]*\(\[[ 0-9]*\][ ]*\)\?;.*/\3/p' $i.nocomm; sed -ne 's/^}[ ]*\([A-Za-z_][0-9A-Za-z_]*\)[ ]*;.*/\1/p' $i.nocomm`"
371 echo "typedefs=$typedefs"
372 structs="`sed -ne 's/^\(.*[^0-9A-Za-z_]\)\?struct[ ]\+\([A-Za-z_][0-9A-Za-z_]*\)[ ]*{.*/\2/p' $i.nocomm`"
373 echo "structs=$structs"
374 unions="`sed -ne 's/^\(.*[^0-9A-Za-z_]\)\?union[ ]\+\([A-Za-z_][0-9A-Za-z_]*\)[ ]*{.*/\2/p' $i.nocomm`"
375 echo "unions=$unions"
376 if test -f $i.protos.nocomm
378 protos="`sed -ne 's/^.*[^0-9A-Za-z_]\([A-Za-z_][0-9A-Za-z_]*\) __P((.*))\\( NORETURN\\)\\?;$/\1/p' $i.nocomm $i.protos.nocomm`"
380 protos="`sed -ne 's/^.*[^0-9A-Za-z_]\([A-Za-z_][0-9A-Za-z_]*\) __P((.*))\\( NORETURN\\)\\?;$/\1/p' $i.nocomm`"
382 echo "protos=$protos"
393 pattern1="$pattern1$prefix1$j"
398 pattern1="$pattern1$prefix1$j"
403 pattern1="$pattern1${prefix1}struct[ ]\\+$j"
408 pattern1="$pattern1${prefix1}union[ ]\\+$j"
411 echo "pattern1=$pattern1"
412 if test -n "$pattern1"
414 pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)\\([^0-9A-Za-z_].*\\)\\?"
422 pattern1="$pattern1$prefix1$j"
425 echo "pattern1=$pattern1"
426 if test -n "$pattern1"
428 pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)[ ]*(.*"
432 echo "pattern0=$pattern0"
434 if test -n "$pattern0" && test -n "$all_c_nocomm$all_c_protos_nocomm$all_h_protos_nocomm"
436 grep -H "^\\($pattern0\\)$" $all_c_nocomm $all_c_protos_nocomm $all_h_protos_nocomm |grep -v "^$i\.protos.nocomm:" >a
440 for j in `sed -e 's/\.protos\.nocomm:.*//; s/\.nocomm:.*//' <a |sort |uniq`
443 k=`echo $j |sed -e "s:^$INCLUDE/::"`
445 if ! grep -q ":$h:.*:$k:\\|:$k:.*:$h:" conflicts.temp
460 pattern1="$pattern1$prefix1$j"
465 pattern1="$pattern1$prefix1$j"
468 echo "pattern1=$pattern1"
469 if test -n "$pattern1"
471 pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)\\([^0-9A-Za-z_].*\\)\\?"
479 pattern1="$pattern1${prefix1}struct[ ]\\+$j"
484 pattern1="$pattern1${prefix1}union[ ]\\+$j"
487 echo "pattern1=$pattern1"
488 if test -n "$pattern1"
490 pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)\\([^ *0-9A-Za-z_].*\\|[ ]\\+\\([^*].*\\)\\?\\)\\?"
498 pattern1="$pattern1$prefix1$j"
501 echo "pattern1=$pattern1"
502 if test -n "$pattern1"
504 pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)[ ]*(.*"
508 echo "pattern0=$pattern0"
510 if test -n "$pattern0" && test -n "$all_h_nocomm"
512 grep -H "^\\($pattern0\\)$" $all_h_nocomm |grep -v "^$i\.nocomm:" >a
516 for j in `sed -e 's/\.nocomm:.*//' <a |sort |uniq`
519 k=`echo $j |sed -e "s:^$INCLUDE/::"`
521 if ! grep -q ":$h:.*:$k:\\|:$k:.*:$h:" conflicts.temp
531 if test -z "$1" || test $1 -eq 3
539 csplit -b '%05d' -q $i '/^#/' '{*}'
540 if test -f xx00001 && ! $SCRIPTS/nocomment <xx00000 |grep -q '[^ ]'
547 define="`sed -ne 's/^#[ ]*ifndef[ ]\+\([A-Za-z_][0-9A-Za-z_]*\).*/\1/p' xx00001`"
548 echo "define=$define"
549 if test -n "$define" && grep -q '^#[ ]*endif$' $j && ! grep -v "^#" $j |$SCRIPTS/nocomment |grep -q '[^ ]'
551 sed -e "s/^#[ ]*ifndef[ ]\\+$define/\\/\\*&\\*\\//" -i xx00001
552 sed -e "s/^\\(#[ ]*define[ ]\\+$define\\)[ ]*$/\\/\\*\1\\*\\//" -i xx00002
553 sed -e 's/^#[ ]*endif$/\/\*&\*\//' -i $j
556 for j in `sed -ne 's/^#[ ]*\(if\|ifdef\|ifndef\)[^0-9A-Za-z_].*/1/p; s/^#[ ]*endif$/-1/p' a`
558 iflevel=`expr $iflevel + $j`
559 if test $iflevel -lt 0
564 echo "iflevel=$iflevel"
565 if test $iflevel -eq 0
573 for i in $all_c $all_h
577 csplit -b '%05d' -q $i '/^#[ ]*include[^0-9A-Za-z_]/' '{*}'
580 sed -e 's/^#[ ]*include[ ]*\(<[^>]*>\|"[^"]*"\)/\/\*&\*\//' -i $j
581 if grep -v "^#[ ]*include[^0-9A-Za-z_]" $j |sed -e '/^#[ ]*if.*\(SCCS\|lint\)/,/^#[ ]*endif/s/.*//' |$SCRIPTS/nocomment |grep -q '[^ ]'
595 pattern="`sed -ne '1{s/\*/\\\*/g; s/ __P((.*));/(/p}' $i.allprotos`"
596 echo "pattern=$pattern"
598 csplit -q $i "/^$pattern/"
601 if test `wc -l <$i.protos` -ge `wc -l <$i.allprotos`
606 #define __P(args) args
626 LC_ALL=C sort <$i.uses |uniq >a
630 for j in `sed -e "s:^$INCLUDE/::" a`
632 pattern="$pattern$prefix$j"
635 echo "pattern=$pattern"
637 sed -e "s:^#[ ]*include[ ]*\\(<\\($pattern\\)>\\|\"\\($pattern\\)\"\\):\\/\\*&\\*\\/:" -i $i
638 #sed -e "s:^#[ ]*include[ ]*<\\($pattern\\)>:\\/\\*&\\*\\/:" -i $i
644 sed -e "s:.*:#include \"&\":; s:\"$INCLUDE/\\(.*\\)\":<\\1>:; s:^#include <varargs.h>$:#ifdef __STDC__\\n#include <stdarg.h>\\n#define _va_start(argp, arg) va_start(argp, arg)\\n#else\\n#include <varargs.h>\\n#define _va_start(argp, arg) va_start(argp)\\n#endif:" a
647 sed -e 's/\([^0-9A-Za-z_]\)va_start(argp);/\1_va_start(argp, fmt);/' $i
648 ) |$SCRIPTS/newline >b
655 h=`echo $i |sed -e "s:^$INCLUDE/::"`
661 LC_ALL=C sort <$i.uses |uniq >a
665 for j in `sed -e "s:^$INCLUDE/::" a`
667 pattern="$pattern$prefix$j"
670 echo "pattern=$pattern"
672 sed -e "s:^#[ ]*include[ ]*\\(<\\($pattern\\)>\\|\"\\($pattern\\)\"\\):\\/\\*&\\*\\/:" -i $i
673 #sed -e "s:^#[ ]*include[ ]*<\\($pattern\\)>:\\/\\*&\\*\\/:" -i $i
676 name=_`echo $h |tr '.\-/abcdefghijklmnopqrstuvwxyz' '___ABCDEFGHIJKLMNOPQRSTUVWXYZ'`_
686 sed -e "s:.*:#include \"&\":; s:\"$INCLUDE/\\(.*\\)\":<\\1>:; s:^#include <varargs.h>$:#ifdef __STDC__\\n#include <stdarg.h>\\n#endif:" a
693 #if echo $h |grep -q '^\(net\|netimp\|netinet\|netns\|sys\|vax\|vaxif\|vaxmba\|vaxuba\)/'
695 # echo "#ifndef KERNEL"
700 #define __P(args) args
707 #if echo $h |grep -q '^\(net\|netimp\|netinet\|netns\|sys\|vax\|vaxif\|vaxmba\|vaxuba\)/'
716 ) |$SCRIPTS/newline >b
721 if test -z "$1" || test $1 -eq 4
725 # checking header loops
728 grep -H '^#include \(<[^>]*>\|"[^"]*"\)' $all_h |\
729 sed -e 's:^\(.*\)\:#include \(<\([^>]*\)>\|"\([^"]*\)"\):\1 \3\4:' |\
731 #grep -H '^#include <[^>]*>' $all_h |\
732 #sed -e "s:^$INCLUDE/::; s:^\\(.*\\)\\:#include <\\([^>]*\\)>:\1 \2:" |\
736 # removing useless extra header inclusions that are pulled in anyway
738 for i in $all_h $std_h
741 h=`echo $i |sed -e "s:^$INCLUDE/::"`
747 for j in `cpp -nostdinc -I$INCLUDE -Dvax -DNCMD=1 -DNRSP=1 -M temp.c`
752 # system header files are not supposed to define stdarg.h, even if
753 # (like vfprintf etc) they have va_list paramters, it is silly and
754 # we ignore this restriction, but clients shouldn't rely on this
755 # (anyway, the above cpp command defines __STDC__ so we do not pick
756 # up any dependency on varargs.h, hence let's keep it symmetrical)
759 k=`echo $j |sed -e "s:^$INCLUDE/::"`
762 pattern="$pattern$prefix$k"
767 echo "pattern=$pattern"
768 if test -n "$pattern"
770 grep -H "^#include \\(<$h>\\|\"$h\"\\)$" $all_c $all_h >b
773 sed -e "s:^#include \\(<\\($pattern\\)>\\|\"\\($pattern\\)\"\\)$:/\\*& $h\\*/:" -i `sed -e 's/:.*//' b`
774 #sed -e "s:^#include <\\($pattern\\)>$:/\\*& $h\\*/:" -i `sed -e 's/:.*//' b`
782 #if test -z "$1" || test $1 -eq 5
784 # echo "===stage 5==="
785 # for i in . arpa protocols
788 # for j in $ROOT/include/$i/*.h
791 # cp $INCLUDE/$i/`basename $j` $ROOT/include/$i
794 # for i in compat-4.1 compat-sys5 gen inet net ns stdio sys
797 # cp $INCLUDE/$i.h $ROOT/include
799 # for i in net netimp netinet netns vax vaxif vaxmba vaxuba
802 # for j in $ROOT/sys/$i/*.h
805 # cp $INCLUDE/$i/`basename $j` $ROOT/sys/$i
808 # for i in $ROOT/sys/h/*.h
811 # cp $INCLUDE/sys/`basename $i` $ROOT/sys/h