Article View: comp.lang.postscript
Article #444ascii to ps printer
From: Donna Druchunas
Date: Fri, 10 Apr 1992 00:43
Date: Fri, 10 Apr 1992 00:43
137 lines
4980 bytes
4980 bytes
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>!
1. The file basically works but I've hard coded at 8
space tab replacement into it because I couldn't get my
PS printer to do anything with a \t. It recognized the \t
as a special character but didn't do a right shift to
compensate for it. What *DOES* the PS interpreter do with
a \t?
2. If I choose prn: or LPT1 as the output file name, the
"working" light on my printer blinks like crazy but
nothing ever prints. However, if I use an actual file
for the output it prints fine (via DOS). Any guesses on
what's happening (before I start printing out PS errors)?
It's actually a VERY simple program but it was fun to do
because it combines C and PS syntax(es?) in one project.
Now I need to modify it so you can choose fonts,
justification, etc. and supply the input and output
filenames optionally at the command line as parameters.
<laff>
***************** CODE BEGINS HERE ******************
/* program to convert an ASCII text */
/* file to a PostScript printer file */
#include <stdio.h>
FILE *in, *out;
char text_file[13]="untitled.txt",
ps_file[13]="untitled.ps",
line[81];
int x=72, y=730, i=0, character;
/* ******** function to get file names to convert from user ******** */
void get_file_names() {
printf ("This program will convert an ASCII text file to\n");
printf ("a printable PostScript (not-encapsulated) file.\n\n");
printf ("Enter source file name: ");
scanf ("%s", text_file);
printf ("Enter output file name: ");
scanf ("%s", ps_file);
}
/* ******** function to creat PS header including font selection ******* */
void ps_header() {
fprintf (out, "/Courier findfont 10 scalefont setfont\n");
fprintf (out, "72 730 moveto\n");
}
/* ******** function to read in a line from the ASCII text file ******** */
int read_line() {
int done=0, i=0;
do {
if ((character = getc(in)) != EOF) {
if (character != '\n' && i < 81) {
line[i]=character;
i++;
}
}
else
done =1;
} while (!done && character != '\n' && i<81 );
return (done);
}
/* ******* function to write one line of text to PS file w/ show ******** */
void write_line() {
int count;
unsigned len;
count = (strlen(line)-1);
fprintf (out, "(");
for (i=0; i<count; i++) {
if (line[i] == '\051')
fprintf (out, "\\)");
else if (line[i] == '\050')
fprintf (out, "\\(");
else if (line [i] == '\134')
fprintf (out, "\\\\");
else if (line [i] == '\11')
fprintf (out, " ");
else
putc (line[i], out);
}
fprintf (out, ") show\n");
y-=12;
if (y<=36) {
fprintf (out, "showpage 72 730 moveto\n");
y = 730;
}
else
fprintf (out, "72 %d moveto\n", y);
for (i=0; i<81; ++i)
line[i]='\0'; /* clear out array for next line */
}
/* ****** main function for converting ASCII to PostScript ********* */
void main() {
int done=0;
get_file_names();
if ((in=fopen(text_file, "r")) == NULL)
printf ("Cannot open %s for reading.\n", text_file);
else if ((out=fopen(ps_file, "w")) == NULL)
printf ("Cannot open %s for writing.\n", ps_file);
else {
ps_header();
do {
(done=read_line());
write_line();
} while (!done);
fprintf (out, "showpage");
}
fclose (in);
fclose (out);
}
********************* CODE ENDS HERE ************************
Thanks for any input. Please reply via e-mail as I haven't had the time
lately to keep up with all the message traffic.
--
INTERNET: dd@netlink.cts.com (Donna Druchunas)
UUCP: ...!nosc!ryptyde!netlink!dd
NetLink Online Communications * Public Access in San Diego, CA (619) 435-6181
Technical Details
Message-ID:
<g8oZiB2w164w@netlink.cts.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!dog.ee.lbl.gov!nosc!ryptyde!ddShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!dog.ee.lbl.gov!nosc!ryptyde!dd From: dd@netlink.cts.com (Donna Druchunas) Newsgroups: comp.lang.postscript Subject: ascii to ps printer Message-ID: <g8oZiB2w164w@netlink.cts.com> Date: 10 Apr 92 00:43:39 GMT Article-I.D.: netlink.g8oZiB2w164w Organization: NetLink Online Communications, San Diego CA Lines: 137