--- /dev/null
+#!/bin/sh
+
+ROOT=`dirname $0`/..
+
+all_c=`echo *.c` #`find . -name '*.c' -print |LC_ALL=C sort`
+all_h=`echo *.h` #`find . -name '*.c' -print |LC_ALL=C sort`
+std_h=`find $ROOT/cross/usr/include -type f -name '*.h' -print |LC_ALL=C sort`
+
+if test -z "$1" || test "$1" = 0
+then
+ echo "===stage 0==="
+
+ rm -f *.[ch].allprotos #`find . -name '*.[ch].allprotos' -print`
+ rm -f *.[ch].nocomm #`find . -name '*.[ch].nocomm' -print`
+ rm -f *.[ch].oldprotos #`find . -name '*.[ch].oldprotos' -print`
+ rm -f *.[ch].protos #`find . -name '*.[ch].protos' -print`
+ rm -f *.[ch].protos.nocomm #`find . -name '*.[ch].protos.nocomm' -print`
+ rm -f *.[ch].usedby #`find . -name '*.[ch].usedby' -print`
+ rm -f *.[ch].uses #`find . -name '*.[ch].uses' -print`
+
+ rm -f `find $ROOT/cross/usr/include -name '*.h.nocomm' -print`
+ rm -f `find $ROOT/cross/usr/include -name '*.h.usedby' -print`
+ rm -rf `find $ROOT/cross/usr/include -name '.xify' -print`
+
+ rm -f a conflicts.temp oldprotos.txt oldprotos.temp xx*
+fi
+
+if test -z "$1" || test "$1" = 1
+then
+ echo "===stage 1==="
+
+ for i in $all_c $all_h
+ do
+ echo "i=$i"
+
+ grep -H '^[A-Za-z_][0-9A-Za-z_]*[^0-9A-Za-z_][^;]*[A-Za-z_][0-9A-Za-z_]*[ ]*([ ]*)[ ]*\(,[^;]*\)\?;' $i >>oldprotos.txt
+ sed -e 's/^[A-Za-z_][0-9A-Za-z_]*[^0-9A-Za-z_][^;]*[A-Za-z_][0-9A-Za-z_]*[ ]*([ ]*)[ ]*\(,[^;]*\)\?;/\/\*&\*\//' -i $i
+
+ sed -e 's/^\(#[ ]*\(else\|endif\)\)\([^0-9A-Za-z_].*\)\?/\1/' -i $i
+
+ rm -f xx*
+ csplit -b '%05d' -q $i '/^[ ]*{[ ]*$/' '{*}'
+ for j in xx*
+ do
+ :
+ done
+ for k in xx*
+ do
+ if test $k != xx00000
+ then
+ sed -ne '2,$p' -i $k
+ fi
+ if test $k != $j
+ then
+ sed -e '$s/$/ {/' -i $k
+ fi
+ done
+ cat xx* >$i
+ done
+
+ grep '\.h:' oldprotos.txt >oldprotos.temp
+
+ sed -e 's/^[A-Za-z_].*__P.*;$/\/\*AAA&\*\//' -i $std_h
+ touch $ROOT/cross/usr/include/stdarg.h
+ for i in $all_c
+ do
+ echo "i=$i"
+
+ group=
+ if test -f groups.txt
+ then
+ group=`sed -ne "s/^$i \\(.*\\)/\\1/p" groups.txt`
+ if test -n "$group"
+ then
+ touch $group
+ fi
+ fi
+ echo "group=$group"
+
+ $ROOT/cproto-4.6/cproto -i$ROOT/cross/usr/include -Dvax -t -H -s $i |sed -ne '2,$p' >$i.allprotos
+
+ grep "^static " <$i.allprotos >a
+ if test -s a
+ then
+ mv a $i.protos
+ fi
+
+ grep -v "^static " <$i.allprotos >a
+ if test -s a
+ then
+ if test -z "$group"
+ then
+ cp $i.allprotos $i.protos
+ else
+ (
+ cat <<EOF
+
+/* $i */
+EOF
+ cat a
+ ) >>$group.protos
+ fi
+
+ protos="`sed -ne 's/^.*[^0-9A-Za-z_]\([A-Za-z_][0-9A-Za-z_]*\) __P((.*));$/\1/p' a`"
+ echo "protos=$protos"
+
+ pattern=
+ prefix=
+ for j in $protos
+ do
+ pattern="$pattern$prefix$j"
+ prefix='\|'
+ done
+ echo "pattern=$pattern"
+
+ grep "[^0-9A-Za-z_]\\($pattern\\)[ ]*(" oldprotos.temp >a
+ if test -s a
+ then
+ mv a $i.oldprotos
+ grep -v "^$group:" $i.oldprotos
+ fi
+ fi
+ done
+ sed -e 's/^\/\*AAA\(.*\)\*\/$/\1/' -i $std_h
+ rm $ROOT/cross/usr/include/stdarg.h
+fi
+
+if test -z "$1" || test "$1" = 2
+then
+ echo "===stage 2==="
+
+ all_c_nocomm=
+ all_c_protos_nocomm=
+ for i in $all_c
+ do
+ $ROOT/scripts/nocomment <$i |$ROOT/scripts/nostring >$i.nocomm
+ all_c_nocomm="$all_c_nocomm $i.nocomm"
+ if test -f $i.protos
+ then
+ $ROOT/scripts/nocomment <$i.protos |$ROOT/scripts/nostring >$i.protos.nocomm
+ all_c_protos_nocomm="$all_c_protos_nocomm $i.protos.nocomm"
+ fi
+ done
+
+ all_h_nocomm=
+ all_h_protos_nocomm=
+ for i in $all_h
+ do
+ $ROOT/scripts/nocomment <$i |$ROOT/scripts/nostring >$i.nocomm
+ all_h_nocomm="$all_h_nocomm $i.nocomm"
+ if test -f $i.protos
+ then
+ $ROOT/scripts/nocomment <$i.protos |$ROOT/scripts/nostring >$i.protos.nocomm
+ all_h_protos_nocomm="$all_h_protos_nocomm $i.protos.nocomm"
+ fi
+ done
+
+ for i in $std_h
+ do
+ $ROOT/scripts/nocomment <$i |$ROOT/scripts/nostring >$i.nocomm
+ done
+
+ if test -f conflicts.txt
+ then
+ sed -e 's/^/:/;s/ /::/g;s/$/:/' <conflicts.txt >conflicts.temp
+ else
+ touch conflicts.temp
+ fi
+
+ for i in $all_h $std_h
+ do
+ echo "i=$i"
+ h=`echo $i |sed -e "s:^$ROOT/cross/usr/include/::"`
+ echo "h=$h"
+
+ macros="`sed -ne 's/^#[ ]*define[ ]\+\([A-Za-z_][0-9A-Za-z_]*\).*/\1/p' $i.nocomm |grep -v '^\(NULL\|__P\)$'`"
+ echo "macros=$macros"
+ 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`"
+ echo "typedefs=$typedefs"
+ structs="`sed -ne 's/^\(.*[^0-9A-Za-z_]\)\?struct[ ]\+\([A-Za-z_][0-9A-Za-z_]*\)[ ]*{.*/\2/p' $i.nocomm`"
+ echo "structs=$structs"
+ unions="`sed -ne 's/^\(.*[^0-9A-Za-z_]\)\?union[ ]\+\([A-Za-z_][0-9A-Za-z_]*\)[ ]*{.*/\2/p' $i.nocomm`"
+ echo "unions=$unions"
+ if test -f $i.protos.nocomm
+ then
+ protos="`sed -ne 's/^.*[^0-9A-Za-z_]\([A-Za-z_][0-9A-Za-z_]*\) __P((.*));$/\1/p' $i.nocomm $i.protos.nocomm`"
+ else
+ protos="`sed -ne 's/^.*[^0-9A-Za-z_]\([A-Za-z_][0-9A-Za-z_]*\) __P((.*));$/\1/p' $i.nocomm`"
+ fi
+ echo "protos=$protos"
+
+ rm -f $i.usedby
+
+ prefix0=
+ pattern0=
+
+ pattern1=
+ prefix1=
+ for j in $macros
+ do
+ pattern1="$pattern1$prefix1$j"
+ prefix1='\|'
+ done
+ for j in $typedefs
+ do
+ pattern1="$pattern1$prefix1$j"
+ prefix1='\|'
+ done
+ for j in $structs
+ do
+ pattern1="$pattern1${prefix1}struct[ ]\\+$j"
+ prefix1='\|'
+ done
+ for j in $unions
+ do
+ pattern1="$pattern1${prefix1}union[ ]\\+$j"
+ prefix1='\|'
+ done
+ echo "pattern1=$pattern1"
+ if test -n "$pattern1"
+ then
+ pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)\\([^0-9A-Za-z_].*\\)\\?"
+ prefix0='\|'
+ fi
+
+ pattern1=
+ prefix1=
+ for j in $protos
+ do
+ pattern1="$pattern1$prefix1$j"
+ prefix1='\|'
+ done
+ echo "pattern1=$pattern1"
+ if test -n "$pattern1"
+ then
+ pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)[ ]*(.*"
+ prefix0='\|'
+ fi
+
+ echo "pattern0=$pattern0"
+
+ if test -n "$pattern0"
+ then
+ grep -H "^\\($pattern0\\)$" $all_c_nocomm $all_c_protos_nocomm $all_h_protos_nocomm |grep -v "^$i\.protos.nocomm:" >a
+ if test -s a
+ then
+ cat a >>$i.usedby
+ for j in `sed -e 's/\.protos\.nocomm:.*//; s/\.nocomm:.*//' <a |sort |uniq`
+ do
+ echo "j=$j"
+ k=`echo $j |sed -e "s:^$ROOT/cross/usr/include/::"`
+ echo "k=$k"
+ if ! grep -q ":$h:.*:$k\\|:$k:.*:$h:" conflicts.temp
+ then
+ echo $i >>$j.uses
+ fi
+ done
+ fi
+ fi
+
+ pattern0=
+ prefix0=
+
+ pattern1=
+ prefix1=
+ for j in $macros
+ do
+ pattern1="$pattern1$prefix1$j"
+ prefix1='\|'
+ done
+ for j in $typedefs
+ do
+ pattern1="$pattern1$prefix1$j"
+ prefix1='\|'
+ done
+ echo "pattern1=$pattern1"
+ if test -n "$pattern1"
+ then
+ pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)\\([^0-9A-Za-z_].*\\)\\?"
+ prefix0='\|'
+ fi
+
+ pattern1=
+ prefix1=
+ for j in $structs
+ do
+ pattern1="$pattern1${prefix1}struct[ ]\\+$j"
+ prefix1='\|'
+ done
+ for j in $unions
+ do
+ pattern1="$pattern1${prefix1}union[ ]\\+$j"
+ prefix1='\|'
+ done
+ echo "pattern1=$pattern1"
+ if test -n "$pattern1"
+ then
+ pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)\\([^ *0-9A-Za-z_].*\\|[ ]\\+\\([^*].*\\)\\?\\)\\?"
+ prefix0='\|'
+ fi
+
+ pattern1=
+ prefix1=
+ for j in $protos
+ do
+ pattern1="$pattern1$prefix1$j"
+ prefix1='\|'
+ done
+ echo "pattern1=$pattern1"
+ if test -n "$pattern1"
+ then
+ pattern0="$pattern0$prefix0\\(.*[^0-9A-Za-z_]\\)\\?\\($pattern1\\)[ ]*(.*"
+ prefix0='\|'
+ fi
+
+ echo "pattern0=$pattern0"
+
+ if test -n "$pattern0"
+ then
+ grep -H "^\\($pattern0\\)$" $all_h_nocomm |grep -v "^$i\.nocomm:" >a
+ if test -s a
+ then
+ cat a >>$i.usedby
+ for j in `sed -e 's/\.nocomm:.*//' <a |sort |uniq`
+ do
+ echo "j=$j"
+ k=`echo $j |sed -e "s:^$ROOT/cross/usr/include/::"`
+ echo "k=$k"
+ if ! grep -q ":$h:.*:$k\\|:$k:.*:$h:" conflicts.temp
+ then
+ echo $i >>$j.uses
+ fi
+ done
+ fi
+ fi
+ done
+fi
+
+if test -z "$1" || test "$1" = 3
+then
+ echo "===stage 3==="
+
+ for i in $all_h
+ do
+ echo "i=$i"
+ rm -f xx*
+ csplit -b '%05d' -q $i '/^#/' '{*}'
+ if test -f xx00001 && ! $ROOT/scripts/nocomment <xx00000 |grep -q '[^ ]'
+ then
+ for j in xx*
+ do
+ :
+ done
+ echo "j=$j"
+ define="`sed -ne 's/^#[ ]*ifndef[ ]\+\([A-Za-z_][0-9A-Za-z_]*\).*/\1/p' xx00001`"
+ echo "define=$define"
+ if test -n "$define" && grep -q '^#[ ]*endif$' $j && ! grep -v "^#" $j |$ROOT/scripts/nocomment |grep -q '[^ ]'
+ then
+ sed -e "s/^#[ ]*ifndef[ ]\\+$define/\\/\\*&\\*\\//" -i xx00001
+ sed -e "s/^\\(#[ ]*define[ ]\\+$define\\)[ ]*$/\\/\\*\1\\*\\//" -i xx00002
+ sed -e 's/^#[ ]*endif$/\/\*&\*\//' -i $j
+ cat xx* >a
+ iflevel=0
+ for j in `sed -ne 's/^#[ ]*\(if\|ifdef\|ifndef\)[^0-9A-Za-z_].*/1/p; s/^#[ ]*endif$/-1/p' a`
+ do
+ iflevel=`expr $iflevel + $j`
+ if test $iflevel -lt 0
+ then
+ break
+ fi
+ done
+ echo "iflevel=$iflevel"
+ if test $iflevel -eq 0
+ then
+ mv a $i
+ fi
+ fi
+ fi
+ done
+
+ for i in $all_c $all_h
+ do
+ echo "i=$i"
+ rm -f xx*
+ csplit -b '%05d' -q $i '/^#[ ]*include[^0-9A-Za-z_]/' '{*}'
+ for j in xx*
+ do
+ sed -e 's/^#[ ]*include[ ]*\(<[^>]*>\|"[^"]*"\)/\/\*&\*\//' -i $j
+ if grep -v "^#[ ]*include[^0-9A-Za-z_]" $j |sed -e '/^#[ ]*if.*SCCS\|lint/,/^#[ ]*endif/s/.*//' |$ROOT/scripts/nocomment |grep -q '[^ ]'
+ then
+ break
+ fi
+ done
+ cat xx* >$i
+ done
+
+ for i in $all_c
+ do
+ echo "i=$i"
+
+ if test -s $i.protos
+ then
+ pattern="`sed -ne '1{s/\*/\\\*/g; s/ __P((.*));/(/p}' $i.allprotos`"
+ echo "pattern=$pattern"
+ rm -f xx*
+ csplit -q $i "/^$pattern/"
+ (
+ cat xx00
+ if test `wc -l <$i.protos` -ge `wc -l <$i.allprotos`
+ then
+ cat <<EOF
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+EOF
+ cat $i.protos
+ if test -f xx01
+ then
+ echo
+ cat xx01
+ fi
+ fi
+ ) >$i
+ fi
+
+ rm -f a
+ if test -s $i.uses
+ then
+ LC_ALL=C sort <$i.uses |uniq >a
+
+ pattern=
+ prefix=
+ for j in `sed -e "s:^$ROOT/cross/usr/include/::" a`
+ do
+ pattern="$pattern$prefix$j"
+ prefix='\|'
+ done
+ echo "pattern=$pattern"
+
+ sed -e "s:^#[ ]*include[ ]*\\(<\\($pattern\\)>\\|\"\\($pattern\\)\"\\):\\/\\*&\\*\\/:" -i $i
+ fi
+
+ (
+ if test -s a
+ then
+ sed -e "s:.*:#include \"&\":; s:\"$ROOT/cross/usr/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
+ echo
+ fi
+ sed -e 's/\([^0-9A-Za-z_]\)va_start(argp);/\1_va_start(argp, fmt);/' $i
+ ) |$ROOT/scripts/newline >b
+ mv b $i
+ done
+
+ for i in $all_h
+ do
+ echo "i=$i"
+ h=`echo $i |sed -e "s:^$ROOT/cross/usr/include/::"`
+ echo "h=$h"
+
+ rm -f a
+ if test -s $i.uses
+ then
+ LC_ALL=C sort <$i.uses |uniq >a
+
+ pattern=
+ prefix=
+ for j in `sed -e "s:^$ROOT/cross/usr/include/::" a`
+ do
+ pattern="$pattern$prefix$j"
+ prefix='\|'
+ done
+ echo "pattern=$pattern"
+
+ sed -e "s:^#[ ]*include[ ]*\\(<\\($pattern\\)>\\|\"\\($pattern\\)\"\\):\\/\\*&\\*\\/:" -i $i
+ fi
+
+ name=_`echo $h |tr '.\-/abcdefghijklmnopqrstuvwxyz' '___ABCDEFGHIJKLMNOPQRSTUVWXYZ'`_
+ echo "name=$name"
+ (
+ cat <<EOF
+#ifndef $name
+#define $name
+
+EOF
+ if test -s a
+ then
+# sed -e "s:.*:#include \"&\":; s:\"$ROOT/cross/usr/include/\\(.*\\)\":<\\1>:; s:^#include <varargs.h>$:#ifdef __STDC__\\n#include <stdarg.h>\\n#endif:" a
+ echo
+ fi
+ cat $i
+ if test -s $i.protos
+ then
+ cat <<EOF
+
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+EOF
+ cat $i.protos
+ fi
+ cat <<EOF
+
+#endif
+EOF
+ ) |$ROOT/scripts/newline >b
+ mv b $i
+ done
+fi
+
+if test -z "$1" || test "$1" = 4
+then
+ echo "===stage 4==="
+
+ # checking header loops
+ grep -H '^#include <[^>]*>' $all_h |\
+ sed -e "s:^\(.*\)\:#include <\(.*\)>:\1 \2:" |\
+ tsort >a
+
+ # removing useless extra header inclusions that are pulled in anyway
+ touch $ROOT/cross/usr/include/stdarg.h
+ rm -f a
+ for i in $all_h $std_h
+ do
+ echo "i=$i"
+ h=`echo $i |sed -e "s:^$ROOT/cross/usr/include/::"`
+ echo "h=$h"
+
+ pattern=
+ prefix=
+ cp $i temp.c
+ for j in `cpp -nostdinc -I$ROOT/cross/usr/include -Dvax -DNCMD=1 -DNRSP=1 -M temp.c`
+ do
+ case $j in
+ $ROOT/cross/usr/include/stdarg.h)
+ # system header files are not supposed to define stdarg.h, even if
+ # (like vfprintf etc) they have va_list paramters, it is silly and
+ # we ignore this restriction, but clients shouldn't rely on this
+ # (anyway, the above cpp command defines __STDC__ so we do not pick
+ # up any dependency on varargs.h, hence let's keep it symmetrical)
+ ;;
+ *.h)
+ k=`echo $j |sed -e "s:^$ROOT/cross/usr/include/::"`
+ echo "$h $k" >>a
+ pattern="$pattern$prefix$k"
+ prefix='\|'
+ ;;
+ esac
+ done
+ echo "pattern=$pattern"
+ if test -n "$pattern"
+ then
+ sed -e "s:^#include <\\($pattern\\)>$:/\\*& $h\\*/:" -i `grep -H "^#include <$h>$" $all_c $all_h |sed -e 's/:.*//'`
+ fi
+ done
+ rm -f $ROOT/cross/usr/include/stdarg.h temp.c
+ tsort <a >b
+fi