[ale] Printing Source Code

John Mills jmmills at telocity.com
Tue Mar 19 21:45:47 EST 2002


Hello, Chris -

We had to print about 2,000 pages of source listings in Ada, and I (with
much help from this list) ended up with a runoff script I like a lot.

You hand-edit some headers and footers, and other items like the date are
put in automatically (unless you inactivate them). You can work
sectionally: this means you can print a hundred or so pages at a time,
from a partial list of the files to print, so you can re-do a smaller
fileset if the job scr*ws up. I didn't work it that way, but PostScript
output could be captured rather than sent to the printer.

There is a bit of filtering source constructs which get confused with
'nroff' commands - you may want to tune that a bit for the language you're
printing. I remember it as pretty clean for Ada, generally OK for C/C++,
and a "really hurtin' turkey" for LaTex [source].

It is driven by a list of filenames, provided in a file. (It also runs
happily in a pipe, as in:

# ls <dir_path> | list_runoff -

It reads the list, saves it to a temporary file, and can optionally sort
the list before printing those files.

Try a few files and see how it acts.

You'll probably see some improvements once you have the idea: consider it
a starting point and send me back any changes you make for better 'C'
handling or cool features.

On Tue, 19 Mar 2002, Chris Fowler wrote:

> Hello,
> 
> I need to print about 50,000 lines of C source code.  I want to print on
> both sides of the paper, punch, and bind.
> I've determined that pr -o 8 -n *.c will number, pagenate, and head each
> page.  I'm trying to
> decide what is the best way to print them.  I thought about converting to
> DOS (unix2dos) format and taking
> to Kinko's to finish.  Has anyone else had to print a pile of source before?
> I've determined that to print all the source that I've
> written over the last 5 months would require 1 ream of paper.  That is
> printed front and back. Thankfully I created a standard library otherwise
> that would have been 2 reams of paper.

 - John Mills


#!/bin/sh

#! conditionally set parameters
FIRSTPAGE=1
LISTNAMES=''
DOCNAME=''
PROJNAME=''
SECTNAME=''
PRINT_DATE=`date '+%d %b %Y'`
TEMPFILE='/tmp/printorder.'$$

if [ $# -ge 1 ]
then
  LISTNAMES=$1
else
  echo "usage: list_runoff <filelist> [initial page_no]" >&2
  exit
fi

if [ $# -ge 2 ]
then
  FIRSTPAGE=$2
fi
 
#! alphabetize list for correct output pagination
sort -o $TEMPFILE -f $LISTNAMES

echo printing from \'$LISTNAMES\' with pages starting from $FIRSTPAGE, on $PRINT_DATE >&2

#! print each file's prefix and text to groff
for FILENAME in `cat $TEMPFILE`
do
  if [ -f $FILENAME ]
  then
    cat - << MARKER
.nr PS 10
.R
.P1
.nr PO 1.25i
.nr LT 6.5i
.nr LL 6.5i
.nr HM 1.25i
.nr FM 0.5i
.pl 702p
.ds LH \fBFILE:  $FILENAME\fP
.ds CH
.ds RH \fB$DOCNAME\fP
.ds LF \fB$PROJNAME\fP
.ds CF \fB$SECTNAME%\fP
.ds RF \fB$PRINT_DATE\fP
.ND
.LP
.bp
.nf
.CW
MARKER
    sed 's/\\/&e/g' < $FILENAME
  fi
done |groff -mgs -n$FIRSTPAGE -Tps |lpr
# to supress burst-sheet:
# done |groff -mgs -n$FIRSTPAGE -Tps |lpr -h
if [ -f $TEMPFILE ]
  then
   rm $TEMPFILE
fi



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.




More information about the Ale mailing list