<< Sun Settled With Microsoft, Shouldn't You? | Home | Boolean.getBoolean() >>

Pretty Printed Code Listings in Cygwin

Been doing a lot of code reviews lately. Aside from turning into a mean person ("Too many 'return's!", "Indentation is wrong!"), I also experienced the non-uniformness of the code printouts various developers bring to the table. While IntelliJ IDEA, Eclipse, Together, JBuilder and NetBeans all have their own pretty print facilities, they all left something to be desired.

In my opinion, the GNU Enscript program generates the best quality code printouts when used with appropriate switches. The magic switch I use is "-G2rE -C -M Letter", which I set as the ENSCRIPT environment variable so that enscript picks it up automatically.

On Linux systems, enscript is hooked up directly to the default printer, so a simple command like:

[weiqi@gao] $ enscript Foo.java

will do.

On Windows, I use Cygwin to accomplish what I want. Things are not as automatic as on Linux, but all the ingredients are there. I can use GNU Enscript to turn source files into PostScript files, use GhostScript to turn PostScript files into the format for my printer (which happens to be an HP LaserJet 8150 PCL), and then use Lpr to send the PCL to the printer. Here's the script I use to print code in Cygwin (enscript, gs, and lpr are all distributed with the Net version of Cygwin):

#!/bin/bash
#
# print-code
#
# Generate a filename based on the current date/time
FILENAME=`date +%Y%m%d%H%M`
#
# Generate PostScript
enscript $1 -o $FILENAME.ps
#
# Generate PCL
gs -sDEVICE=ljet4 \
   -sOutputFile=$FILENAME.pcl \
   -dNOPAUSE \
   -dBATCH \
   -q $FILENAME.ps
#
# Send PCL to printer
lpr -l $FILENAME.pcl
#
# Remove temporary files
\rm $FILENAME.ps $FILENAME.pcl

Now I can do things like:

[weiqi@gao] $ print-code Foo.java

and

[weiqi@gao] $ for x in *.java; do print-code $x; done

to have my Java files printed.

Tags :



Add a comment Send a TrackBack