#!/bin/bash
#
# Uses enscript to format the xv6 source code in a way that keeps line numbers
# faithful to the runoff script's result.

output=$(tempfile)
mkdir -p enscripted
while read; do
  case $REPLY in
    \#*) # skip commented lines
        ;;
    ?*) # skip blank lines, too
        cut -c6- "fmt/$REPLY" > "enscripted/$REPLY"
        line=$(head -1 "fmt/$REPLY" | cut -c1-4)
        (cd enscripted; enscript -o - -GE -C"$line" "$REPLY") >> "$output"
        # round up to nearest multiple of 50
        ;;
  esac
done < runoff.list
#psmerge "$output" | ps2pdf - enscripted.pdf
ps2pdf "$output" enscripted.pdf
#rm "$output"
echo "$output"
