PPRINT -- Postscript pretty-printer for C/C++/Verilog and text

SourceForge.net Logo


PPRINT generates source code listings in postscript. It italicizes comments, boldfaces typedefs, and bold-italicizes keywords. It generates line numbers and a cross reference of all typedefs, static and global functions, listing both definitions and references. Definitions are in bold.

PPRINT manages print-outs of multiple files by producing both global and local page numbers. At the end of the run, it prints out a table of contents, and index, and a reference of all globally accessible typedefs and classes.

PPRINT works with C files, C++ files, Verilog files, and text files. It figures out which language based on extension:

Suffix Language
.c C
.cc C++
.cpp C++
.CPP C++
.C C++
.y Yacc
.h C or C++, depending on whether -h_is_cc flag is set
.h C++
.v Verilog
.vh Verilog
Other extensions are interpreted as straight text. This is useful for merging in ascii documentation, other languages, README files, etc.

C and C++ files can be parsed using the preprocessor, in order to see definitions hidden by macros, to suppress cross-referencing code that that is #ifdef'd out, and to cross reference typedefs that occur in include files that are not being printed in the same run of pprint. This is slower, of course, since it has to run the preprocessor, and requires that the user provide the include path (actually the whole call to the C preprocessor) as an argument.

Using the preprocessor is optional -- pprint can handle most C and C++ files directly -- it just won't cross-reference or boldface typedefs defined in includes, unless the include files are also printed in the same run. The preprocessor may be needed if a preprocessor-blind reading of the code would be syntactically invalid. This can occur when ifdefs are used to disable incomplete code, or when ifdefs are used inside function definitions, and ignoring them might cause parentheses or braces to appear unbalanced.


     pprint src1/*.h src1/*.h src2/*.c src2/*.h | lpr
     pprint +h_is_cc README *.doc *.h *.cc       \
         +preprocess -cpp "g++ -E -I../include"  \
     lpr src_code.ps
     pprint -line_numbers 0 text_file.txt | lpr
     pprint +landscape *.cc | lpr
     pprint +courier -size 5 *.cc | lpr
     pprint *.c -page_width 595 -page_height 842 | lpr -Pps_A4


Switch Default Description
-border <integer> 18 Border spacing to edge of page, in printer points
+clip (turn on), -clip (turn off) On Clip the text so it doesn't overrwrite the next column
-columns <integer> 2 Number of output columns
+courier (turn on), -courier (turn off) Off Print in landscape mode with a courier font, like a2ps, but with the cross-referencing, boldfacing, and italicizing.
-cpp <string> "gcc -E" Command to use to run the C Preprocessor. This should include all include directories, and be enclosed in double-quotes.
-expand <real number> 100 Expand or shrink the value of spaces in column alignment. The value is expressed as a percentage. 100 keeps it the same. 50 will cut columns in half, 200 will double them.
+h_is_cc (turn on), -h_is_cc (turn off) Off Interpret .h files as C++
-header_size <integer> 11 Size of line numbers in printer points
+landscape (turn on), -landscape (turn off) Off Print in landscape mode (sideways)
-line_numbers <integer> 5 Number of lines to skip in between printed line numbers A value of 0 means no line numbers are printed.
-linesep <real number> 0 Line-to-line separation in printer points
-loglevel <integer> 0 0=warnings only, 1=filenames, 2=pages
-npages <integer> 10000 Maximum number of pages to print (0 means infinite)
-number_size <integer> -2 Size of line numbers in printer points, relative to size
-offset <integer> 18 Distance between the source text, and the offset line numbers and line-wrap indicators, (+), in printer points
-page_height <integer> 792 Height of the page, in printers points (1/72 inch). See page_width.
-page_width <integer> 576 Width of the page, in printers points (1/72 inch). See page_height. Dimensions of common sizes (width x height): 
          Letter:        612 x 792    (default)
          Legal:         612 x 1008
          A5:            420 x 595
          A4:            595 x 842
          A3:            842 x 1190
+preprocess (turn on), -preprocess (turn off) Off Run the C or C++ preprocessor on appropriate input files. To specify a preprocessor program and options, use -cpp. You will need to use the preprocessor if the code you are printing hides a large amount of invalid syntax with ifdefs. Pprint will emit lots of parse error messages, which will go away if you use the preprocessor.
-size <integer> 7 Size of text in printer points
-start <integer> 1 Page number at which to start printing, starting at 1
-tab <integer> 8 Tab width of input files, in characters
+wrap (turn on), -wrap (turn off) On Wrap around long lines of text
-wrap_indent <integer> 0 Number of printer points to indent wrapped lines


Joshua Marantz (jmarantz@alum.mit.edu) Created 1/22/93

Last updated $Date: 2003/04/18 03:00:33 $



PPRINT is distributed in source code form. It has been tested on Linux, Suns, using SunOS 4.1.3 and Solaris 2.5, and HP-UX 9.07 and 10.x. It is written in C, but has only been compiled with gcc and the HP K&R compiler. Please send back any patches to make this compile in other environments.

There is one known Unix dependency in the source code, other than include file details, which is the use of "popen" to run the C preprocessor on input files. Apart from that, I believe a PC port would be straightforward, requiring only fixing the names of include files, etc.

Download (42k tar.gz file)

Download (45k zip file)


A2PS: A highly configurable, general purpose text-to-postscript converter

 GNU Enscript: a free replacement for Adobe's Enscript

 C2PS: Another cross-referencing pretty printer