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

line=100
output=$(tempfile)
while read; do
  case $REPLY in
    \#*) # skip commented lines
        ;;
    ?*) # skip blank lines, too
        echo "$REPLY"
        enscript -o - -G2rE -C"$line" "$REPLY" >> "$output"
        line=$((line + $(wc -l < "$REPLY")))
        # round up to nearest multiple of 50
        line=$(((line+49)/50 * 50))
        ;;
  esac
done < runoff.list
#psmerge "$output" | ps2pdf - enscripted.pdf
ps2pdf "$output" enscripted.pdf
#rm "$output"
echo "$output"
