🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #453

Re: ascii to ps printer

#453
From: Alfred Kayser
Date: Fri, 10 Apr 1992 07:45
58 lines
2211 bytes
dd@netlink.cts.com (Donna Druchunas) writes:
>I just wrote a little ASCII to PS converter for printing
>ASCII files on my PS printer.  I'm including the code in
>this message because it's fairly short and I thought some
>of you might be interested...and also because I'm having
>a couple of problems with the thing.  I've also neglected
>to include certain things which probably would be nice,
>but "oh well" <grins>!

Not particular nice a2ps code removed...
 
Inserted Obfusticated Ascii 2 PostScript filter:
#include <stdio.h>
FILE *fp=stdin;
char b[1024];
int c,l,lp,pl=0,p=0,fl=1;
#define P printf
void main(ac,av)int ac;char **av;{
	if(--ac)
		while(ac--)
			if(fp=fopen(*++av,"r"))
				Pf(),fclose(fp);
	else Pf();
	if(pl)P("%%Trailer\n%%Pages: %d\n\004",p);
	exit(0);}
Pf(){
	if(!pl){
		puts("%!PS-Adobe-1.0\n%%Pages: (atend)\n\/Courier findfont 10\n\
scalefont setfont\n/S{exch /L exch def 32 809 L 12 mul sub moveto show}bind def\n\
%%%%EndProlog");pl=1;}
	lp=l=0;
	while((c=getc(fp))!=EOF){
		if(c==9)do{b[lp++]=' ';}while(lp%8);
		else if(c==10)Nl();
		else if(c==12){Nl();Pp();}
		else{c&=0x7F;
			if(c<32){b[lp++]='^';c+='@';}
			b[lp++]=(char)c;}}
	Nl();if(l)Pp();}
Pl(p)char *p;{
	P("%d(",l++);
	for(;*p;p++){
		if(*p=='('||*p==')'||*p=='\\')putchar('\\');
		putchar(*p);}
	P(")S\n");}
Nl(){
	if(lp){
		b[lp]='\0';
		if(l>=65)Pp();
		if(fl)P("%%%%Page: %d %d\n",++p,p);
		Pl(b);fl=lp=0;}}
Pp(){
	P("showpage\n");
	l=0;fl=1;}
--
-- Ir. Alfred Kayser. PACS, OS/2, TCP/IP. --- Email: AKayser@et.tudelft.nl --
-- CARDIT, Delft University of Technology ------------ Tel: (31)-15-786179 --
-- P.O.Box 5031, 2600 GA Delft, The Netherlands ------ Fax: (31)-15-784898 --
Technical Details
Message-ID: <alfred.702891910@dutepp3>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!dutrun!donau!alfred
References: <g8oZiB2w164w@netlink.cts.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!dutrun!donau!alfred
From: AKayser@dnpap.et.tudelft.nl (Alfred Kayser)
Newsgroups: comp.lang.postscript
Subject: Re: ascii to ps printer
Message-ID: <alfred.702891910@dutepp3>
Date: 10 Apr 92 07:45:10 GMT
References: <g8oZiB2w164w@netlink.cts.com>
Sender: news@donau.et.tudelft.nl (UseNet News System)
Organization: Delft University of Technology, Dept. of Electrical Engineering
Lines: 58
Nntp-Posting-Host: dutepp3.et.tudelft.nl