xv6-65oo2/runoff

234 lines
4.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
echo This script takes a minute to run. Be patient. 1>&2
2007-08-08 09:29:18 +00:00
LC_CTYPE=C export LC_CTYPE
# pad stdin to multiple of 120 lines
pad()
{
awk '{print} END{for(; NR%120!=0; NR++) print ""}'
}
# create formatted (numbered) files
mkdir -p fmt
2006-09-08 14:40:59 +00:00
rm -f fmt/*
cp README fmt
files=`grep -v '^#' runoff.list | awk '{print $1}'`
n=99
for i in $files
do
2007-08-24 14:56:17 +00:00
./runoff1 -n $n $i >fmt/$i
2006-09-07 13:07:29 +00:00
nn=`tail -1 fmt/$i | sed 's/ .*//; s/^0*//'`
if [ "x$nn" != x ]; then
n=$nn
fi
done
# create table of contents
2006-09-08 13:53:18 +00:00
cat toc.hdr >fmt/toc
pr -e8 -t runoff.list | awk '
2006-09-08 13:53:18 +00:00
/^[a-z0-9]/ {
s=$0
f="fmt/"$1
getline<f
close(f)
n=$1
printf("%02d %s\n", n/100, s);
2007-08-14 18:42:34 +00:00
printf("TOC: %04d %s\n", n, s) >"fmt/tocdata"
next
}
{
print
2006-09-08 13:53:18 +00:00
}' | pr -3 -t >>fmt/toc
cat toc.ftr >>fmt/toc
2007-08-14 18:42:34 +00:00
# check for bad alignments
perl -e '
$leftwarn = 0;
2007-08-14 18:42:34 +00:00
while(<>){
chomp;
s!#.*!!;
s!\s+! !g;
s! +$!!;
next if /^$/;
if(/TOC: (\d+) (.*)/){
$toc{$2} = $1;
next;
}
if(/even: (.*)/){
$file = $1;
if(!defined($toc{$file})){
print STDERR "Have no toc for $file\n";
next;
}
if($toc{$file} =~ /^\d\d[^0]/){
print STDERR "$file does not start on a fresh page.\n";
}
next;
}
if(/odd: (.*)/){
$file = $1;
if(!defined($toc{$file})){
print STDERR "Have no toc for $file\n";
next;
}
if($toc{$file} !~ /^\d\d5/){
2007-08-14 18:42:34 +00:00
print STDERR "$file does not start on a second half page.\n";
}
next;
}
if(/(left|right): (.*)/){
$what = $1;
$file = $2;
if(!defined($toc{$file})){
print STDERR "Have no toc for $file\n";
next;
}
# this assumes that sheet 1 of code is a left page
# double-check the PDF
if(!$leftwarn++) {
print STDERR "assuming that sheet 1 is a left page. double-check!\n";
}
if($what eq "left" && !($toc{$file} =~ /^\d[13579]0/)){
print STDERR "$file does not start on a fresh left page [$toc{$file}]\n";
}
# why does this not work if I inline $x in the if?
$x = ($toc{$file} =~ /^\d[02468]0/);
if($what eq "right" && !$x){
print STDERR "$file does not start on a fresh right page [$toc{$file}] [$x]\n";
}
next;
}
2007-08-14 18:42:34 +00:00
print STDERR "Unknown spec: $_\n";
}
' fmt/tocdata runoff.spec
# make definition list
cd fmt
2006-09-06 19:43:59 +00:00
perl -e '
while(<>) {
chomp;
s!//.*!!;
s!/\*([^*]|[*][^/])*\*/!!g;
s!\s! !g;
s! +$!!;
# look for declarations like char* x;
if (/^[0-9]+ typedef .* u(int|short|long|char);/) {
next;
}
2006-09-06 19:43:59 +00:00
if (/^[0-9]+ extern/) {
next;
}
if (/^[0-9]+ struct [a-zA-Z0-9_]+;/) {
next;
}
2007-08-08 09:29:18 +00:00
if (/^([0-9]+) #define +([A-za-z0-9_]+) +?\(.*/) {
2006-09-06 19:43:59 +00:00
print "$1 $2\n"
}
2007-08-08 09:29:18 +00:00
elsif (/^([0-9]+) #define +([A-Za-z0-9_]+) +([^ ]+)/) {
2006-09-06 19:43:59 +00:00
print "$1 $2 $3\n";
}
elsif (/^([0-9]+) #define +([A-Za-z0-9_]+)/) {
print "$1 $2\n";
}
2007-08-28 19:25:04 +00:00
if(/^^([0-9]+) \.globl ([a-zA-Z0-9_]+)/){
$isglobl{$2} = 1;
}
if(/^^([0-9]+) ([a-zA-Z0-9_]+):$/ && $isglobl{$2}){
print "$1 $2\n";
}
2007-08-08 09:29:18 +00:00
if (/\(/) {
next;
}
if (/^([0-9]+) (((static|struct|extern|union|enum) +)*([A-Za-z0-9_]+))( .*)? +([A-Za-z_][A-Za-z0-9_]*)(,|;|=| =)/) {
print "$1 $7\n";
2007-08-08 09:29:18 +00:00
}
2006-09-06 19:43:59 +00:00
elsif(/^([0-9]+) (enum|struct|union) +([A-Za-z0-9_]+) +{/){
print "$1 $3\n";
}
# TODO: enum members
}
' $files >defs
2006-09-06 19:22:24 +00:00
2007-08-28 18:23:48 +00:00
(for i in $files
do
case "$i" in
*.S)
cat $i | sed 's;#.*;;; s;//.*;;;'
;;
*)
cat $i | sed 's;//.*;;; s;"([^"\\]|\\.)*";;;'
esac
done
) >alltext
perl -n -e 'print if s/^([0-9]+ [a-zA-Z0-9_]+)\(.*$/\1/;' alltext |
2008-10-12 19:54:11 +00:00
egrep -v ' (STUB|usage|main|if|for)$' >>defs
#perl -n -e 'print if s/^([0-9]+) STUB\(([a-zA-Z0-9_]+)\)$/\1 \2/;' alltext \
# >>defs
(
>s.defs
# make reference list
for i in `awk '{print $2}' defs | sort -f | uniq`
do
defs=`egrep '^[0-9]+ '$i'( |$)' defs | awk '{print $1}'`
echo $i $defs >>s.defs
2007-08-28 18:23:48 +00:00
uses=`egrep -h '([^a-zA-Z_0-9])'$i'($|[^a-zA-Z_0-9])' alltext | awk '{print $1}'`
if [ "x$defs" != "x$uses" ]; then
echo $i $defs
echo $uses |fmt -24 | sed 's/^/ /'
fi
done
) >refs
# build defs list
awk '
{
printf("%04d %s\n", $2, $1);
for(i=3; i<=NF; i++)
printf("%04d \" \n", $i);
}
' s.defs > t.defs
# format the whole thing
(
2006-09-08 13:53:18 +00:00
../pr.pl README
../pr.pl -h "table of contents" toc
# pr -t -2 t.defs | ../pr.pl -h "definitions" | pad
pr -t -l50 -2 refs | ../pr.pl -h "cross-references" | pad
# pr.pl -h "definitions" -2 t.defs | pad
# pr.pl -h "cross-references" -2 refs | pad
2006-09-06 19:43:59 +00:00
for i in $files
do
2006-09-08 13:53:18 +00:00
../pr.pl -h "xv6/$i" $i
2006-09-06 19:43:59 +00:00
done
) | mpage -m50t50b -o -bLetter -T -t -2 -FCourier -L60 >all.ps
grep Pages: all.ps
# if we have the nice font, use it
2008-08-20 18:00:24 +00:00
nicefont=../LucidaSans-Typewriter83
if [ -f $nicefont ]
then
2008-08-20 18:00:24 +00:00
echo nicefont
(sed 1q all.ps; cat $nicefont; sed '1d; s/Courier/LucidaSans-Typewriter83/' all.ps) >allf.ps
else
2008-08-20 18:00:24 +00:00
echo ugly font!
cp all.ps allf.ps
fi
ps2pdf allf.ps ../xv6.pdf
2007-08-30 14:12:19 +00:00
cd ..
pdftops xv6.pdf xv6.ps