Cover V04, I04
Article
Listing 1
Listing 2
Listing 3
Sidebar 1

jul95.tar


Listing 3: lpjthin.c--Sets the line style to the thinnest width

/*
lpjthin.c

DM Brown
8 February 1991

This is an output filter for the HP PaintJet to be
used in conjunction with the HP/GL2 cartridge and
AutoCAD on the Sun.  AutoCAD is set up to create HP/GL
plot files through the HP7550 plot driver.  Each plot
made includes an IN; statement as the first HP/GL
statement (after some apparent device init. commands).
This filter does nothing more than search the first
MAXCOUNT bytes for the IN; command then includes a
PW0; command to set the pen width to the absolute
smallest it can be.  The rest of the plot file is sent
to the plotter without any changes.

To use this filter on the command line, use the
following syntax:

lpjthin < infile > outfile
or
cat infile | lpjthin | print

Compile with:

cc lpjthin.c -o lpjthin

*/

#include <stdio.h>

#define BUFSIZE 4
#define MAXCOUNT 50
#define NUL '\0'
#define INITSTR "\033%-1B"
#define RESETSTR "\033%A"

static char buf[BUFSIZE];

main()
{
int c, j, count;

/* switch to HP-GL/2 mode */
fputs(INITSTR, stdout);

for(count = 0;
(c = getchar()) != EOF && count < MAXCOUNT;
count++)
{
if (c == 'I')
{
for (buf[0] = c,j=1;
(j < 3) &&
((buf[j] = getchar()) != EOF); j++) ;
buf[j] = NUL;
fputs(buf,stdout);
if (!strcmp(buf,"IN;"))
{
fputs("PW0;",stdout);
break;
}
else continue;
}
putchar(c);
}

while ((c = getchar()) != EOF)
putchar(c);

/* switch back to PCL mode */
fputs(RESETSTR, stdout);

fflush(stdout);

exit(0);
}