New scripts/ansify.sh, pre-ansification changes to bin/tp for data declarations
authorNick Downing <downing.nick@gmail.com>
Mon, 23 Jan 2017 15:06:43 +0000 (02:06 +1100)
committerNick Downing <downing.nick@gmail.com>
Mon, 23 Jan 2017 15:16:08 +0000 (02:16 +1100)
bin/tp/Makefile
bin/tp/groups.txt [new file with mode: 0644]
bin/tp/tp.h
bin/tp/tp0.c
bin/tp/tp_defs.h [deleted file]
lib/libc/o.sh
lib/libc/p.sh
lib/libc/q.sh
lib/libc/r.sh
scripts/ansify.sh [new file with mode: 0755]
scripts/make.sh [new file with mode: 0755]

index 6ea7638..ce50879 100644 (file)
@@ -1,7 +1,7 @@
 #      @(#)Makefile    4.1     12/18/82
 
 CFLAGS=-O
-h = tp.h tp_defs.h
+h = tp.h
 o  = tp0.o tp1.o tp2.o tp3.o
 
 tp :   $o
diff --git a/bin/tp/groups.txt b/bin/tp/groups.txt
new file mode 100644 (file)
index 0000000..e6163c8
--- /dev/null
@@ -0,0 +1,4 @@
+tp0.c tp.h
+tp1.c tp.h
+tp2.c tp.h
+tp3.c tp.h
index faefd12..093908f 100644 (file)
@@ -51,27 +51,27 @@ struct      dent {  /* in core version of tent with "unused" removed
        int     d_tapea;
 }  dir[MDIRENT];
 
-char   map[MAPSIZE];
-char   name[NAMELEN];
-char   name1[NAMELEN];
-extern char mt[];
-extern char tc[];
-char   *tname;
-extern char mheader[];
-extern char theader[];
+extern char    map[MAPSIZE];
+extern char    name[NAMELEN];
+extern char    name1[NAMELEN];
+extern char    mt[];
+extern char    tc[];
+extern char    *tname;
+extern char    mheader[];
+extern char    theader[];
 
-int    narg, rnarg;
-char   **parg;
-int    wseeka,rseeka;
-int    tapsiz;
-int    fio;
-short  ndirent, ndentb;
-struct dent    *edir;
-struct dent *lastd;            /* for improvement */
-char   *sbrk();
-char   *strcpy();
-long   lseek();
-int    (*command)();
+extern int     narg, rnarg;
+extern char    **parg;
+extern int     wseeka,rseeka;
+extern int     tapsiz;
+extern int     fio;
+extern short   ndirent, ndentb;
+extern struct  dent *edir;
+extern struct  dent *lastd;            /* for improvement */
+char *sbrk();
+char *strcpy();
+long lseek();
+int (*command)();
 
 extern int     flags;
 #define        flc     0001
index 3e009ce..9c6aefc 100644 (file)
@@ -3,4 +3,23 @@ static char sccsid[] = "@(#)tp0.c      4.1 12/18/82";
 #endif
 
 #include "tp.h"
-#include "tp_defs.h"
+
+int    flags   = flu;
+char   mt[]    = "/dev/rmt0";
+char   tc[]    = "/dev/tapx";
+char   mheader[] = "/usr/mdec/mboot";
+char   theader[] = "/usr/mdec/tboot";
+
+char   map[MAPSIZE];
+char   name[NAMELEN];
+char   name1[NAMELEN];
+char   *tname;
+
+int    narg, rnarg;
+char   **parg;
+int    wseeka,rseeka;
+int    tapsiz;
+int    fio;
+short  ndirent, ndentb;
+struct dent *edir;
+struct dent *lastd;            /* for improvement */
diff --git a/bin/tp/tp_defs.h b/bin/tp/tp_defs.h
deleted file mode 100644 (file)
index 64c013f..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/*     @(#)tp_defs.h   4.1     12/18/82        */
-
-char   mt[]    = "/dev/rmt0";
-char   tc[]    = "/dev/tapx";
-int    flags   = flu;
-char   mheader[] = "/usr/mdec/mboot";
-char   theader[] = "/usr/mdec/tboot";
index d8e8548..0c490b5 100755 (executable)
@@ -12,8 +12,6 @@ all_h=`find $ROOT/cross/usr/include -type f -name '*.h' -print |LC_ALL=C sort`
 
 rm -f oldprotos.txt
 
-find . -name '*.[ch]' -print |\
-sed -e 's:^\./::' |\
 for i in $all_c $all_h
 do
   echo "i=$i"
index 7881158..7b3c8c5 100755 (executable)
@@ -9,17 +9,16 @@ do
   all_c="$all_c $1"
 done <groups.txt
 all_h=`find $ROOT/cross/usr/include -type f -name '*.h' -print |LC_ALL=C sort`
-all_h_rev=`find $ROOT/cross/usr/include -type f -name '*.h' -print |LC_ALL=C sort -r`
 
 all_c_nocomm=
 all_c_protos_nocomm=
 for i in $all_c
 do
-  $ROOT/xify/nocomment <$i |$ROOT/xify/nostring >$i.nocomm
+  $ROOT/scripts/nocomment <$i |$ROOT/scripts/nostring >$i.nocomm
   all_c_nocomm="$all_c_nocomm $i.nocomm"
   if test -f $i.protos
   then
-    $ROOT/xify/nocomment <$i.protos |$ROOT/xify/nostring >$i.protos.nocomm
+    $ROOT/scripts/nocomment <$i.protos |$ROOT/scripts/nostring >$i.protos.nocomm
     all_c_protos_nocomm="$all_c_protos_nocomm $i.protos.nocomm"
   fi
 done
@@ -28,18 +27,18 @@ all_h_nocomm=
 all_h_protos_nocomm=
 for i in $all_h
 do
-  $ROOT/xify/nocomment <$i |$ROOT/xify/nostring >$i.nocomm
+  $ROOT/scripts/nocomment <$i |$ROOT/scripts/nostring >$i.nocomm
   all_h_nocomm="$all_h_nocomm $i.nocomm"
   if test -f $i.protos
   then
-    $ROOT/xify/nocomment <$i.protos |$ROOT/xify/nostring >$i.protos.nocomm
+    $ROOT/scripts/nocomment <$i.protos |$ROOT/scripts/nostring >$i.protos.nocomm
     all_h_protos_nocomm="$all_h_protos_nocomm $i.protos.nocomm"
   fi
 done
 
 sed -e 's/^/:/;s/ /::/g;s/$/:/' <conflicts.txt >conflicts.temp
 
-for i in $all_h_rev
+for i in $all_h
 do
   echo "i=$i"
   h=`echo $i |sed -e "s:^$ROOT/cross/usr/include/::"`
@@ -199,7 +198,6 @@ do
         echo "k=$k"
         if ! grep -q ":$h:.*:$k\\|:$k:.*:$h:" conflicts.temp
         then
-          echo "no conflicts"
           echo $h >>$j.uses
         fi
       done
index 90ccf90..7f262f9 100755 (executable)
@@ -15,7 +15,7 @@ do
   echo "i=$i"
   rm -f xx*
   csplit -b '%05d' -q $i '/^#/' '{*}'
-  if test -f xx00001 && ! $ROOT/xify/nocomment <xx00000 |grep -q '[^    ]'
+  if test -f xx00001 && ! $ROOT/scripts/nocomment <xx00000 |grep -q '[^         ]'
   then
     for j in xx*
     do
@@ -24,7 +24,7 @@ do
     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/xify/nocomment |grep -q '[^    ]'
+    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
@@ -55,9 +55,8 @@ do
   csplit -b '%05d' -q $i '/^#[  ]*include[^0-9A-Za-z_]/' '{*}'
   for j in xx*
   do
-    #sed -e 's/^#[      ]*include[      ]*\(<[^>]*>\|"[^"]*"\)/\/\*&\*\//' -i $j
-    sed -e 's/^#[       ]*include[      ]*<[^>]*>/\/\*&\*\//' -i $j
-    if grep -v "^#[     ]*include[^0-9A-Za-z_]" $j |sed -e '/^#[        ]*if.*SCCS/,/^#[        ]*endif/s/.*//' |$ROOT/xify/nocomment |grep -q '[^      ]'
+    sed -e 's/^#[       ]*include[      ]*\(<[^>]*>\|"[^"]*"\)/\/\*&\*\//' -i $j
+    if grep -v "^#[     ]*include[^0-9A-Za-z_]" $j |sed -e '/^#[        ]*if.*SCCS/,/^#[        ]*endif/s/.*//' |$ROOT/scripts/nocomment |grep -q '[^   ]'
     then
       break
     fi
@@ -109,7 +108,7 @@ do
       echo
     fi
     sed -e 's/\([^0-9A-Za-z_]\)va_start(argp);/\1_va_start(argp, fmt);/' $i
-  ) |$ROOT/xify/newline >b
+  ) |$ROOT/scripts/newline >b
   mv b $i
 done
 
@@ -172,6 +171,6 @@ EOF
 
 #endif
 EOF
-  ) |$ROOT/xify/newline >b
+  ) |$ROOT/scripts/newline >b
   mv b $i
 done
index f771a6f..2916f8e 100755 (executable)
@@ -32,7 +32,7 @@ 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 silly and
+      # (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)
diff --git a/scripts/ansify.sh b/scripts/ansify.sh
new file mode 100755 (executable)
index 0000000..04937e3
--- /dev/null
@@ -0,0 +1,566 @@
+#!/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
diff --git a/scripts/make.sh b/scripts/make.sh
new file mode 100755 (executable)
index 0000000..56b662b
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+ROOT=`dirname $0`/..
+make CC="$ROOT/cross/bin/hostcc -Dvax" LD="$ROOT/cross/bin/hostld" DESTDIR="$ROOT/cross" $@