runoff
来自「美国mit操作系统课程所用的一个教学操作系统xv6」· 代码 · 共 209 行
TXT
209 行
#!/bin/shecho This script takes a minute to run. Be patient. 1>&2LC_CTYPE=C export LC_CTYPE# pad stdin to multiple of 120 linespad(){ awk '{print} END{for(; NR%120!=0; NR++) print ""}'}# create formatted (numbered) filesmkdir -p fmtrm -f fmt/*cp README fmtfiles=`grep -v '^#' runoff.list | awk '{print $1}'`n=99for i in $filesdo ./runoff1 -n $n $i >fmt/$i nn=`tail -1 fmt/$i | sed 's/ .*//; s/^0*//'` if [ "x$nn" != x ]; then n=$nn fidone# create table of contentscat toc.hdr >fmt/tocpr -e8 -t runoff.list | awk '/^[a-z0-9]/ { s=$0 f="fmt/"$1 getline<f close(f) n=$1 printf("%02d %s\n", n/100, s); printf("TOC: %04d %s\n", n, s) >"fmt/tocdata" next}{ print}' | pr -3 -t >>fmt/toccat toc.ftr >>fmt/toc# check for bad alignmentsperl -e ' 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\d[^5]/){ print STDERR "$file does not start on a second half page.\n"; } next; } print STDERR "Unknown spec: $_\n"; }' fmt/tocdata runoff.spec# make definition listcd fmtperl -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; } if (/^[0-9]+ extern/) { next; } if (/^[0-9]+ struct [a-zA-Z0-9_]+;/) { next; } if (/^([0-9]+) #define +([A-za-z0-9_]+) +?\(.*/) { print "$1 $2\n" } elsif (/^([0-9]+) #define +([A-Za-z0-9_]+) +([^ ]+)/) { print "$1 $2 $3\n"; } elsif (/^([0-9]+) #define +([A-Za-z0-9_]+)/) { print "$1 $2\n"; } if(/^^([0-9]+) \.globl ([a-zA-Z0-9_]+)/){ $isglobl{$2} = 1; } if(/^^([0-9]+) ([a-zA-Z0-9_]+):$/ && $isglobl{$2}){ print "$1 $2\n"; } 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" } elsif(/^([0-9]+) (enum|struct|union) +([A-Za-z0-9_]+) +{/){ print "$1 $3\n"; } # TODO: enum members }' $files >defs(for i in $filesdo case "$i" in *.S) cat $i | sed 's;#.*;;; s;//.*;;;' ;; *) cat $i | sed 's;//.*;;; s;"([^"\\]|\\.)*";;;' esacdone) >alltextperl -n -e 'print if s/^([0-9]+ [a-zA-Z0-9_]+)\(.*$/\1/;' alltext | egrep -v ' (usage|main|if|for)$' >>defs(>s.defs# make reference listfor i in `awk '{print $2}' defs | sort -fu`do defs=`egrep '^[0-9]+ '$i'( |$)' defs | awk '{print $1}'` echo $i $defs >>s.defs 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/^/ /' fidone) >refs# build defs listawk '{ printf("%04d %s\n", $2, $1); for(i=3; i<=NF; i++) printf("%04d \" \n", $i);}' s.defs > t.defs# format the whole thing( ../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 for i in $files do ../pr.pl -h "xv6/$i" $i done) | mpage -m50t50b -o -bLetter -T -t -2 -FCourier -L60 >all.psgrep Pages: all.ps# if we have the nice font, use itnicefont=../LucidaSans-Typewriter83if [ -f $nicefont ]then echo nicefont (sed 1q all.ps; cat $nicefont; sed '1d; s/Courier/LucidaSans-Typewriter83/' all.ps) >allf.pselse echo ugly font! cp all.ps allf.psfips2pdf allf.ps ../xv6.pdfcd ..pdftops xv6.pdf xv6.ps
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?