cgrind.c and lineprint.ps

Joseph P. Larson joe at dayton.UUCP
Fri Jun 2 02:12:00 AEST 1989


These are routines for printing C programs nicely and emulating a
line printer in PostScript.  See the Read.Me, the first file in the
below .shar, for a better description.

-Joe


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	Read.Me
#	cgrind.c
#	cgrind.h
#	stdtyp.h
#	land.ps
#	land2.ps
#	land4.ps
#	port.ps
#	port2.ps
#	port4.ps
#	showline.ps
# This archive created: Thu Jun  1 11:08:51 1989
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'Read.Me'
then
	echo shar: "will not over-write existing file 'Read.Me'"
else
cat << \SHAR_EOF > 'Read.Me'
Inclosed are several things.

	First off, we have "showline.ps".  Coupled with any one of the
	other .ps files, you have a PostScript program that reads files
	from the input and emulates a line printer.  The options are:

		port		Normal portrait
		land		Normal landscape
		port2/4		2-up or 4-up portrait
		land2/4		2-up or 4-up landscape

	(With the 2-up and 4-up, you may need to add a "lineprint" call
	to your input stream before sending the text to be printed.)

	Thus, the following should work to print fname.c:

		cat showline.ps land.ps fname.c > /dev/printertty

	
	Next, we have cgrind.c/h.  cgrind is a cute program that takes
	c programs and does stuff like bold reserved words and italicize
	comments.  It uses single characters recognized by the postscript
	programs above to enter/exit bold or italics mode.  Or turn italics
	off and pipe it through less.

We've been using cgrind and the .ps stuff for some time at our site.
My brain was hurting from looking at a graphics generator I'm working on,
so I figured I'd take a break to post this to the net.

Note that cgrind.c does a #include <dayton/stdtyp.h>.  You'll want to modify
this line to call the included stdtyp.h (which in turn includes <stdtyp.h>).
I got tired of defining these things in all my programs....
SHAR_EOF
fi
if test -f 'cgrind.c'
then
	echo shar: "will not over-write existing file 'cgrind.c'"
else
cat << \SHAR_EOF > 'cgrind.c'
#include <stdio.h>
#include <ctype.h>
#include <dayton/stdtyp.h>
#include "cgrind.h"

#define		CH_START_ITALICS	0x1c
#define		CH_START_UNDER		0x1d
#define		CH_START_BOLD		0x1e
#define		CH_END_ALL			0x1f

/*
 * cgrind -- take c programs and pretty them up with bolding and
 *			 such.
 *
 * cgrind [-s] [-i] [-tnn] [filelist]
 *
 *		-s -- output will go to a screen devices rather than one
 *				of our printers.  Implies -i.
 *		-i -- don't italics comments.
 *		-t -- tabstops.  -t0 to not perform tabbing.  Default is -t4.
 *
 * Revision History:
 *
 *		Sometime in 1987:
 *			Written by Joe Larson, DHDSC.  joe at dayton.dhdsc.mn.org
 */

extern int errno;

bool italics = TRUE;
bool screen_device = FALSE;
short	tabstops = 4;

main(argc,argv)
int argc;
char **argv;
{
	register short	i;
	FILE			*file;
	bool			did_file = FALSE;

	for (i = 1; i < argc; i++)
	{
		if (*argv[i] == '-')
		{
			if (argv[i][1] == 's')
			{
				screen_device = TRUE;
				italics = FALSE;
			}
			else if (argv[i][1] == 'i')
				italics = FALSE;
			else if (argv[i][1] == 't')
				tabstops = atoi(&argv[i][2]);
			else
			{
				usage(argv[i]);
				exit(0);
			}
		}
		else
		{
			if ((file = fopen(argv[i], "r")) == NULL)
			{
				perror(argv[i]);
				exit(errno);
			}
			dofile(file);
			fclose(file);
			did_file = TRUE;
		}
	}
	if (!did_file)
		dofile(stdin);
}

dofile(file)
FILE *file;
{
	register short	i, j, olen;
	register char	quoting = 0, comment = 0;
	short			oloc;
	char			line[256], oline[256];

	while (fgets(line, 255, file) > 0)
	{
		quoting = 0;
		olen = 0;
		oloc = 0;
		for (i = 0; line[i]; )
		{
			if (isspace(line[i]))
			{
				if (tabstops && (line[i] == '\t'))
				{
					i++;
					oline[olen++] = ' ';
					for ( ; (++oloc) % tabstops; )
						oline[olen++] = ' ';
				}
				else
				{
					oline[olen++] = line[i++];
					oloc++;
				}
				continue;
			}
			if (!comment && ((line[i] == 0x27) || (line[i] == 0x22)))
			{
				if (quoting == line[i])
					quoting = 0;
				else if (!quoting)
					quoting = line[i];
			}
			else if (!quoting)
			{
				if (!comment && !strncmp(&line[i], "\057\052", 2))
				{
					comment = TRUE;
					if (italics)
						oline[olen++] = CH_START_ITALICS;
					oline[olen++] = line[i++];
					oline[olen++] = line[i++];
					oloc += 2;
					continue;
				}
				else if (comment && !strncmp(&line[i], "\052\057", 2))
				{
					comment = 0;
					oline[olen++] = line[i++];
					oline[olen++] = line[i++];
					oloc += 2;
					if (italics)
						oline[olen++] = CH_END_ALL;
					continue;
				}
			}
			if (!quoting && !comment &&
					(isalpha(line[i]) || (line[i] == '#')))
			{
				for (j = i+1; isalpha(line[j]) || isdigit(line[j]) ||
						(line[j] == '_') || (line[j] == '$'); j++);
				if (isreserved(&line[i], j - i))
				{
					if (!screen_device)
					{
						oline[olen++] = CH_START_BOLD;
						for ( ; i < j; )
						{
							oline[olen++] = line[i++];
							oloc++;
						}
						oline[olen++] = CH_END_ALL;
					}
					else
						for ( ; i < j; )
						{
							oline[olen++] = line[i];
							oline[olen++] = '\b';
							oline[olen++] = line[i++];
							oloc++;
						}
					continue;
				}
			}
			oline[olen++] = line[i++];
			oloc++;
			if (isalpha(line[i-1]) || (line[i-1] == '_'))
			{
				while(isalpha(line[i]) || isdigit(line[i]) ||
						(line[i] == '_') || (line[i] == '$'))
				{
					oline[olen++] = line[i++];
					oloc++;
				}
			}
		}
		oline[olen] = 0;
		printf("%s", oline);
	}
	return(0);
}

isreserved(c, l)
char *c;
short l;
{
	register short i;

	for (i = 0; reslist[i] != NULL; i++)
	{
		if (!strncmp(reslist[i], c, l))
			if (!reslist[i][l])
				return(1);
	}
	return(0);
}


usage(arg)
char *arg;
{
	fprintf(stderr, "Usage: %s [-s] [-i] [-tnn] [filelist]\n", arg);
	fprintf(stderr, "	-s -- send output to a screen device.\n");
	fprintf(stderr, "	-i -- do not italicize comments.  Implied by -s.\n");
	fprintf(stderr, "	-t -- set tab stops. -t0 turns off detabing.\n");
	fprintf(stderr, "	      Default is -t4.\n");
}
SHAR_EOF
fi
if test -f 'cgrind.h'
then
	echo shar: "will not over-write existing file 'cgrind.h'"
else
cat << \SHAR_EOF > 'cgrind.h'
char *reslist[] =
{
/*
 * Compiler reserved words
 */
	"asm",
	"auto",
	"break",
	"case",
	"char",
	"continue",
	"default",
	"do",
	"double",
	"else",
	"enum",
	"extern",
	"float",
	"for",
	"fortran",
	"goto",
	"if",
	"int",
	"long",
	"register",
	"return",
	"short",
	"sizeof",
	"static",
	"struct",
	"switch",
	"typedef",
	"union",
	"unsigned",
	"void",
	"while",

/*
 * precompiler statements
 */
	"#define",
	"#undef",
	"#include",
	"#if",
	"define",
	"#ifdef",
	"#ifndef",
	"#else",
	"#endif",
	"#line",

	NULL
};
SHAR_EOF
fi
if test -f 'stdtyp.h'
then
	echo shar: "will not over-write existing file 'stdtyp.h'"
else
cat << \SHAR_EOF > 'stdtyp.h'
/*
 * Standard types and defines for Dayton-Hudson.
 * @(#)stdtyp.h	1.2 DHDSC - Release Date: 5/18/89  Compiled Date: 5/18/89
 */

#include	<stdtyp.h>

#ifndef		TRUE
#define		TRUE	(1)
#endif

#ifndef		FALSE
#define		FALSE	(0)
#endif

#ifndef		UNSIGNED
#define		UNSIGNED	unsigned char
#endif

#ifndef FFCC
#include <dayton/spsdefs.h>
#endif

#ifndef ULONG
#define ULONG unsigned long
#endif

#ifndef USHORT
#define USHORT unsigned short
#endif

#ifndef UCHAR
#define UCHAR unsigned char
#endif
SHAR_EOF
fi
if test -f 'land.ps'
then
	echo shar: "will not over-write existing file 'land.ps'"
else
cat << \SHAR_EOF > 'land.ps'
%!

%
% Landscape Page Printer
%

/inch {72 mul} def
/pageheight 8.5 inch def
/pagewidth 11 inch def

/lmarg .3 inch def
/tmarg .7 inch def
/bmarg pageheight .7 inch sub def
/lincr 7.8 def

/x tmarg def
/y lmarg def
/xw 0 def
/yw 0 def
/i currentfile def
/s 1000 string def
/ones 1 string def
/lastFF 0 def
/page_text 0 def	% no text on this page

/undershow
%
% string undershow
%
%		do a "string show" then underline the string
%
{  
	currentlinewidth exch
    dup show   currentpoint 3 2 roll
    stringwidth neg
    2 0 rmoveto   rlineto 0.4 setlinewidth stroke
    moveto setlinewidth
} def


/doFF
%
% Takes 2 arguments:
%
%		Top: Type of FF encountered (0 = whatever 1=char 2=margin)
%		Next: Force showpage anyways?
%
{
	/curFF exch def
	1 eq
	{
		showpage
		/page_text 0 def
		/x tmarg def
		/y lmarg def
		/xw 0 def
		/yw 0 def
	}
	{
				%
				% if FF right after last line on page, ignore FF
				%
		curFF 1 eq				% This is FF?
		lastFF 2 eq				% Last was type 2 -- margin
		x tmarg eq				% Still at left margin
		y lmarg eq				% Still at top margin
		and and and false eq	% Do it if all the above is false
		{
			page_text 1 eq
				{ showpage } if
			/page_text 0 def
			/x tmarg def
			/y lmarg def
			/xw 0 def
			/yw 0 def
		} if
	} ifelse
	/lastFF curFF def
	x y moveto
} def

/normal-font /Courier findfont [0 9 -9 0 0 0] makefont def
/bold-font /Courier-Bold findfont [0 9 -9 0 0 0] makefont def
/italic-font /Courier-Oblique findfont [0 9 -9 0 0 0] makefont def
/bolditalic-font /Courier-BoldOblique findfont [0 9 -9 0 0 0] makefont def
/isbold 0 def
/isitalic 0 def

/lineprint
{
	normal-font setfont
    {i s readline
		{
			x y moveto
			showline
			/y lmarg def
			/x x lincr add def
			x bmarg gt
			{ 0 2 doFF } if
		}
		{
			page_text 1 eq
			{1 0 doFF} if
			exit
		} ifelse
	} loop
} def

lineprint
SHAR_EOF
fi
if test -f 'land2.ps'
then
	echo shar: "will not over-write existing file 'land2.ps'"
else
cat << \SHAR_EOF > 'land2.ps'
%!

%
% Two-Up Landscape Page Printer
%

/inch {72 mul} def
/pageheight 11 inch def
/pagewidth 8.5 inch def

/tp0 pageheight .3 inch sub def
/bp0 5.6 inch def
/tp1 5.4 inch def
/bp1 .3 inch def

/lmarg .2 inch def
/tmarg tp0 def
/bmarg bp0 def

/lincr 5.6 def

/x lmarg def
/y tmarg def
/pg 0 def

/xw 0 def
/yw 0 def
/i currentfile def
/s 1000 string def
/ones 1 string def
/lastFF 0 def
/page_text 0 def	% no text on this page

/undershow
{
	currentlinewidth exch
    dup show   currentpoint 3 2 roll
    stringwidth exch neg exch
    0 -1.5 rmoveto   rlineto 0.4 setlinewidth stroke
    moveto setlinewidth
} def

/dolines
{
	gsave
	.1 setlinewidth
	newpath
		.2 inch 5.5 inch moveto
		10.8 inch 5.5 inch lineto
		stroke
	grestore
} def


/doFF
%
% Takes 2 arguments:
%
%		Top: Type of FF encountered (0 = whatever 1=char 2=margin)
%		Next: Force showpage anyways?
%
{
	/curFF exch def
	1 eq
	{
		dolines
		showpage
		/page_text 0 def
		/x lmarg def
		/y tmarg def
		/xw 0 def
		/yw 0 def
	}
	{
				%
				% if FF right after last line on page, ignore FF
				%
		curFF 1 eq				% This is FF?
		lastFF 2 eq				% Last was type 2 -- margin
		x lmarg eq				% Still at left margin
		y tmarg eq				% Still at top margin
		and and and false eq	% Do it if all the above is false
		{
			pg 0 eq
			{
				/pg 1 def
				/tmarg tp1 def
				/bmarg bp1 def
			}
			{
				dolines
				showpage
				/page_text 0 def
				/pg 0 def
				/tmarg tp0 def
				/bmarg bp0 def
			} ifelse
			/x lmarg def
			/y tmarg def
			/xw 0 def
			/yw 0 def
		} if
	} ifelse
	x y moveto
	/lastFF curFF def
} def

/normal-font /Courier findfont 7 scalefont def
/bold-font /Courier-Bold findfont 7 scalefont def
/italic-font /Courier-Oblique findfont 7 scalefont def
/bolditalic-font /Courier-BoldOblique findfont 7 scalefont def
/isbold 0 def
/isitalic 0 def

/lineprint
{
	normal-font setfont
    {i s readline
		{
			x y moveto
			showline
			/x lmarg def
			/y y lincr sub def
			y bmarg lt
			{ 0 2 doFF } if
		}
		{
			page_text 1 eq
			{1 0 doFF} if
			exit
		} ifelse
	} loop
} def

% lineprint
SHAR_EOF
fi
if test -f 'land4.ps'
then
	echo shar: "will not over-write existing file 'land4.ps'"
else
cat << \SHAR_EOF > 'land4.ps'
%!

%
% Four-Up Landscape Page Printer
%

/inch {72 mul} def
/pageheight 8.5 inch def
/pagewidth 11 inch def

/ttop .3 inch def
/tbot 4.15 inch def
/btop 4.35 inch def
/bbot 8.2 inch def

/lleft .25 inch def
/rleft 5.58 inch def

/lmarg lleft def
/tmarg ttop def
/bmarg tbot def

/lincr 4.25 def

/x tmarg def
/y lmarg def
/pg 0 def
/xw 0 def
/i currentfile def
/s 1000 string def
/ones 1 string def
/lastFF 0 def
/page_text 0 def	% no text on this page

/undershow
{
	currentlinewidth exch
    dup show   currentpoint 3 2 roll
    stringwidth neg
    1 0 rmoveto   rlineto 0.4 setlinewidth stroke
    moveto setlinewidth
} def


/dolines
{
	gsave
	.1 setlinewidth
	newpath
		.2 inch 5.55 inch moveto
		8.3 inch 5.55 inch lineto
		4.25 inch .2 inch moveto
		4.25 inch 10.8 inch lineto
		stroke
	grestore
} def


/doFF
%
% Takes 2 arguments:
%
%		Top: Type of FF encountered (0 = whatever 1=char 2=margin)
%		Next: Force showpage anyways?
%
{
	/curFF exch def
	1 eq
	{
		dolines
		showpage
		/page_text 0 def
		/x tmarg def
		/y lmarg def
		/xw 0 def
		/yw 0 def
	}
	{
				%
				% if FF right after last line on page, ignore FF
				%
		curFF 1 eq				% This is FF?
		lastFF 2 eq				% Last was type 2 -- margin
		x tmarg eq				% Still at left margin
		y lmarg eq				% Still at top margin
		and and and false eq	% Do it if all the above is false
		{
			pg 0 eq
			{
				/pg 1 def
				/lmarg rleft def
				/tmarg ttop def
				/bmarg tbot def
			}
			{
				pg 1 eq
				{
					/pg 2 def
					/lmarg lleft def
					/tmarg btop def
					/bmarg bbot def
				}
				{
					pg 2 eq
					{
						/pg 3 def
						/lmarg rleft def
						/tmarg btop def
						/bmarg bbot def
					}
					{
						dolines
						showpage
						/page_text 0 def
						/pg 0 def
						/lmarg lleft def
						/tmarg ttop def
						/bmarg tbot def
					} ifelse
				} ifelse
			} ifelse
			/x tmarg def
			/y lmarg def
			/xw 0 def
			/yw 0 def
		} if
	} ifelse
	/lastFF curFF def
} def

/normal-font /Courier findfont [0 4.8 -4.8 0 0 0] makefont def
/bold-font /Courier-Bold findfont [0 4.8 -4.8 0 0 0] makefont def
/italic-font /Courier-Oblique findfont [0 4.8 -4.8 0 0 0] makefont def
/bolditalic-font /Courier-BoldOblique findfont [0 4.8 -4.8 0 0 0] makefont def
/isbold 0 def
/isitalic 0 def

/lineprint
{
	normal-font setfont
    {i s readline
		{
			x y moveto
			showline
			/y lmarg def
			/x x lincr add def
			x bmarg gt
			{ 0 2 doFF } if
		}
		{
			page_text 1 eq
			{1 0 doFF} if
			exit
		} ifelse
	} loop
} def

% lineprint
SHAR_EOF
fi
if test -f 'port.ps'
then
	echo shar: "will not over-write existing file 'port.ps'"
else
cat << \SHAR_EOF > 'port.ps'
%!

%
% Portrait Page Printer
%

/inch {72 mul} def
/pageheight 11 inch def
/pagewidth 8.5 inch def

/lmarg .2 inch def
/bmarg .3 inch def
/tmarg pageheight .4 inch sub def
/lincr 11.4 def

/x lmarg def
/y tmarg def
/xw 0 def
/yw 0 def
/i currentfile def
/s 1000 string def
/ones 1 string def

/lastFF 0 def		% last type of form-feed
/page_text 0 def	% no text yet

/undershow
{   currentlinewidth exch
    dup show   currentpoint 3 2 roll
    stringwidth exch neg exch
    0 -2 rmoveto   rlineto 0.6 setlinewidth stroke
    moveto setlinewidth
} def


/doFF
%
% Takes 2 arguments.
%  Top: type of FF encountered, be it a reall FF, bottom of page,
%       or what-not.
%  Next: force the FF or only if stuff on page.
%
{
	/curFF exch def
	1 eq
	{
		showpage
		/page_text 0 def
		/x lmarg def
		/y tmarg def
		/xw 0 def
		x y moveto
	}
	{
				%
				% if FF right after last line on page, ignore FF
				%
		curFF 1 eq				% This is FF?
		lastFF 2 eq				% Last was type 2 -- margin
		x lmarg eq				% Still at left margin
		y tmarg eq				% Still at top margin
		and and and false eq	% Do it if all the above is false
		{
			page_text 1 eq
				{ showpage } if
			/page_text 0 def
			/x lmarg def
			/y tmarg def
			/xw 0 def
			x y moveto
		} if
	} ifelse
	/lastFF curFF def
} def

/normal-font /Courier findfont 12 scalefont def
/bold-font /Courier-Bold findfont 12 scalefont def
/italic-font /Courier-Oblique findfont 12 scalefont def
/bolditalic-font /Courier-BoldOblique findfont 12 scalefont def
/isbold 0 def
/isitalic 0 def

/lineprint
{
	normal-font setfont
    {i s readline
		{	x y moveto
			showline
			/x lmarg def
			/y y lincr sub def
			y bmarg lt
			{0 2 doFF } if
		}
		{
			page_text 1 eq
			{1 0 doFF} if
			exit
		} ifelse
	} loop
} def

lineprint
SHAR_EOF
fi
if test -f 'port2.ps'
then
	echo shar: "will not over-write existing file 'port2.ps'"
else
cat << \SHAR_EOF > 'port2.ps'
%!

%
% Two-Up Portrait Page Printer
%

/inch {72 mul} def
/pageheight 8.5 inch def
/pagewidth 11 inch def

/p0 .2 inch def
/p1 5.54 inch def
/pg 0 def

/lmarg p0 def
/tmarg .3 inch def
/bmarg pageheight .3 inch sub def
/lincr 8.7 def

/x tmarg def
/y lmarg def
/xw 0 def
/yw 0 def
/i currentfile def
/s 1000 string def
/ones 1 string def

/lastFF 0 def
/page_text 0 def	% no text on this page

/undershow
{   currentlinewidth exch
    dup show   currentpoint 3 2 roll
    stringwidth neg
    2 0 rmoveto   rlineto 0.4 setlinewidth stroke
    moveto setlinewidth
} def

/dolines
{
	gsave
	.1 setlinewidth
	newpath
		.2 inch 5.5 inch moveto
		8.3 inch 5.5 inch lineto
		stroke
	grestore
} def

/doFF
{
%
% Takes 2 arguments.
%  Top: type of FF encountered, be it a reall FF, bottom of page,
%       or what-not.
%  Next: force the FF or only if stuff on page.
%
	/curFF exch def
	1 eq
	{
		dolines
		showpage
		/page_text 0 def
	}
	{
%
% if FF right after last line on page, ignore FF
%
		curFF 1 eq				% This is FF?
		lastFF 2 eq				% Last was type 2 -- margin
		x tmarg eq				% Still at left margin
		y lmarg eq				% Still at top margin
		and and and false eq	% Do it if all the above is false
		{
			pg 0 eq
			{
				/pg 1 def
				/lmarg p1 def
			}
			{
				/pg 0 def
				/lmarg p0 def
				dolines
				showpage
				/page_text 0 def
			} ifelse
		} if
	} ifelse
	/x tmarg def
	/y lmarg def
	/xw 0 def
	/lastFF curFF def
} def

/normal-font /Courier findfont [0 7.75 -7.75 0 0 0] makefont def
/bold-font /Courier-Bold findfont [0 7.75 -7.75 0 0 0] makefont def
/italic-font /Courier-Oblique findfont [0 7.75 -7.75 0 0 0] makefont def
/bolditalic-font /Courier-BoldOblique findfont [0 7.75 -7.75 0 0 0]
				makefont def
/isbold 0 def
/isitalic 0 def

/lineprint
{
	normal-font setfont
	5 setlinewidth
    {i s readline
		{
			x y moveto
			showline
			/y lmarg def
			/x x lincr add def
			x bmarg gt
			{ 0 2 doFF } if
		}
		{
			page_text 1 eq
			{1 0 doFF} if
			exit
		} ifelse
	} loop
} def

% lineprint
SHAR_EOF
fi
if test -f 'port4.ps'
then
	echo shar: "will not over-write existing file 'port4.ps'"
else
cat << \SHAR_EOF > 'port4.ps'
%!

%
% Four-Up Portrait Page Printer
%

/inch {72 mul} def
/pageheight 11 inch def
/pagewidth 8.5 inch def

/ttop 10.7 inch def
/tbot 5.6 inch def
/btop 5.4 inch def
/bbot .3 inch def

/lleft .3 inch def
/rleft 4.35 inch def

/lmarg lleft def
/tmarg ttop def
/bmarg tbot def

/lincr 5.6 def

/x lmarg def
/y tmarg def
/pg 0 def
/xw 0 def
/yw 0 def
/i currentfile def
/s 1000 string def
/ones 1 string def

/lastFF 0 def
/page_text 0 def	% no text on this page

/undershow
{   currentlinewidth exch
    dup show   currentpoint 3 2 roll
    stringwidth exch neg exch
    0 -2 rmoveto   rlineto 0.4 setlinewidth stroke
    moveto setlinewidth
} def


/dolines
{
	gsave
	.1 setlinewidth
	newpath
		.2 inch 5.5 inch moveto
		8.3 inch 5.5 inch lineto
		4.33 inch .2 inch moveto
		4.33 inch 10.8 inch lineto
		stroke
	grestore
} def


/doFF
{
%
% Takes 2 arguments.
%  Top: type of FF encountered, be it a reall FF, bottom of page,
%       or what-not.
%  Next: force the FF or only if stuff on page.
%
	/curFF exch def
	1 eq
	{
		dolines
		showpage
		/page_text 0 def
	}
	{
%
% if FF right after last line on page, ignore FF
%
		curFF 1 eq				% This is FF?
		lastFF 2 eq				% Last was type 2 -- margin
		x lmarg eq				% Still at left margin
		y tmarg eq				% Still at top margin
		and and and false eq	% Do it if all the above is false
		{
			pg 0 eq
			{
				/pg 1 def
				/lmarg lleft def
				/tmarg btop def
				/bmarg bbot def
			}
			{
				pg 1 eq
				{
					/pg 2 def
					/lmarg rleft def
					/tmarg ttop def
					/bmarg tbot def
				}
				{
					pg 2 eq
					{
						/pg 3 def
						/lmarg rleft def
						/tmarg btop def
						/bmarg bbot def
					}
					{
						dolines
						showpage
						/page_text 0 def
						/pg 0 def
						/lmarg lleft def
						/tmarg ttop def
						/bmarg tbot def
					} ifelse
				} ifelse
			} ifelse
		} if
	} ifelse
	/lastFF curFF def

	/x lmarg def
	/y tmarg def
	/xw 0 def
	x y moveto
} def

/normal-font /Courier findfont 6 scalefont def
/bold-font /Courier-Bold findfont 6 scalefont def
/italic-font /Courier-Oblique findfont 6 scalefont def
/bolditalic-font /Courier-BoldOblique findfont 6 scalefont def
/isbold 0 def
/isitalic 0 def

/lineprint
{
	normal-font setfont
	x y moveto
    {i s readline
		{
			x y moveto				% go to start of line
			showline				% show the line on the stack
			/x lmarg def			% reset x to left margin
			/y y lincr sub def		% increment line
			y bmarg lt				% new page if end of page?
			{ 0 2 doFF } if
		}
		{
			page_text 1 eq
			{1 0 doFF} if
			exit
		} ifelse
	} loop
} def

% lineprint
SHAR_EOF
fi
if test -f 'showline.ps'
then
	echo shar: "will not over-write existing file 'showline.ps'"
else
cat << \SHAR_EOF > 'showline.ps'
%
% showline -- display the top line on the stack.
%
% assumes we have access to:
%
%		doFF			handle a form-feed (2 arguments)
%		/x				current x location
%		/y				current y location
%		/normal-font	regular, unbolded font
%		/bold-font		bolded version of /normal
%		/italic-font	italics version of /normal
%		/page_text		set to 1 if text on this page, 0 otherwise
%


/underline 0 def

/showline
{
%
% We have a string -- look for any special characters.
%
	/spec 0 def
	dup
	{
		32 lt
		{
			/spec 1 def
			exit
		} if
	} forall
%
% If no special characters, just show the line
%
	spec 0 eq
	{
		x y moveto
		show
		/page_text 1 def
	}
%
% Special characters -- do it the hard way, char by char.
%
	{
		{
			dup 32 lt
			{
				dup 28 lt					% If char not FS..US
				{
					dup 12 eq				% If char is a FF
					{
						pop
						0 1 doFF			% Let doFF do it all
					}
					{
						8 eq			% If char is a BS
						{
							/x x xw sub def	% Just decrement x
							/y y yw sub def	% Just decrement y
							x y moveto
						} if
					} ifelse
				}
				{							% This is a FS..US
					dup 31 eq
					{						% US - turns off
						pop
						normal-font setfont	% Return to normal font
						/underline 0 def	% Turn off underlining
						/isbold 0 def		% Remember not bold mode
						/isitalic 0 def		% Remember not italics mode
					}
					{						% turn bold, under or italics on
						dup 30 eq
						{					% - turns on bolding
							pop
							isitalic 0 eq
							{
								bold-font setfont
							}
							{
								bolditalic-font setfont
							} ifelse
							/isbold 1 def	% Remember bold mode
						}
						{
							29 eq
							{				% -- turn on underscoring
								/underline 1 def
							}
							{				% -- turn on italics
								/isitalic 1 def	% Remember italics mode
								isbold 0 eq
								{
									italic-font setfont
								}
								{
									bolditalic-font setfont
								} ifelse
							} ifelse
						} ifelse
					} ifelse
				} ifelse
			}
%
% Otherwise -- character is printable
%
			{
				ones 0 3 -1 roll put	% Make our substring
				x y moveto
				underline 1 eq
				{
					ones undershow		% Show the string
				}
				{
					ones show			% Show the string
				} ifelse
				/xw						% Prepare to update xw
				ones stringwidth		% new xw and yw now on stack
				/yw exch def def		% defines new xw and yw
				/x x xw add def			% Increment x
				/y y yw add def			% Increment y
				/page_text 1 def
			} ifelse
		} forall
	} ifelse
} def
SHAR_EOF
fi
exit 0
#	End of shell archive
-- 
Life is a cabaret (old chum).
UUCP: rutgers!dayton!joe   (Picts 1-13 are   DHDSC - Joe Larson/MIS 1060
ATT : (612) 375-3537       now ready.)       700 on the Mall, Mpls, Mn. 55402



More information about the Alt.sources mailing list