#!/bin/sh
#
# to run (if called headerize): headerize <text> < in_file > out_file
# e.g.: if heading is: "a heading", source file is sfile.ps, destination
#       file is dfile.ps, then use:
#
#       headerize a heading < sfile.ps > dfile.ps
# or
#       headerize "a heading" < sfile.ps > dfile.ps
#
gawk -v MYHEADING="$*" '
    BEGIN{
        begin=1
    }
    begin==1 && $1 !~ /^%.*/ {
        begin=0
        printf "save\n"
        printf "gsave\n"
        printf "/Times-Italic findfont 9 scalefont setfont\n"
        printf "72 750 moveto (%s) show\n", MYHEADING
        printf "grestore\n"
        printf "restore\n"
    }
    {
        print
    }
    '

