LaserJet sources for BSD 4.2+

sources-request at panda.UUCP sources-request at panda.UUCP
Wed Sep 4 22:38:45 AEST 1985


Mod.sources:  Volume 3, Issue 9
Submitted by: ihnp4!psivax!friesen (Stanley Friesen)



	The following contains the filters and printcap entry which we
use to run a LaserJet printer as a spooled printer device under lpd.
It takes care of *most* of the funnies.  The worst problem is still
the buffer overflow, since even using LLITOUT UNIX does not stop
output fast enough after a ^S for the LaserJet. We have solved that
problem by sticking a Microbuffer external buffer between the computer
and the LaserJet, our system now works quite smoothly.
----------------------------------Cut Here--------------------------------
#! /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 the files:
#	hpf.c
#	lzcat.c
#	printcap
# This archive created: Tue Sep  3 10:17:46 1985
export PATH; PATH=/bin:$PATH
echo shar: extracting "'hpf.c'" '(1665 characters)'
if test -f 'hpf.c'
then
	echo shar: will not over-write existing file "'hpf.c'"
else
cat << \SHAR_EOF > 'hpf.c'
#include "stdio.h"
#include <signal.h>

int nomap = 0, is_of = 1;

main(ac, av)
int ac;
char **av;
{
    while(ac > 1 && av[1][0] == '-')
    {
	switch(av[1][1])
	{
	    case 'c':
		nomap = 1;
		break;
	    case 'n': case 'h':
		is_of = 0;
		break;
	    default: break;
	}
	ac--;
	av++;
    }

    lzinit();
    hpcat();
    exit(0);
}

#include <sgtty.h> 

lzinit()
{
    struct sgttyb nbuf;
    unsigned long lbits;

    setbuf(stdout, NULL);
    /* Work around to by-pass bug in terminal driver and force LITOUT */
    lbits = LMDMBUF|LLITOUT;
    ioctl(fileno(stdout), TIOCLSET, &lbits);
    ioctl(fileno(stdout), TIOCGETP, &nbuf);
    nbuf.sg_flags &= ~(ECHO|XTABS|CRMOD);  /* While we're at it, set the mode */
    ioctl(fileno(stdout), TIOCSETP, &nbuf);

    fputs("\033&k3G", stdout);	/* Set device to sane mode	*/
}

hpcat()
{
    register int c, cnt = 0;

    while((c = getchar()) != EOF)
    {

	if(c == '\t')
	{
	    do {
		delay();
		putchar(' ');
		cnt++;
	    } while(cnt%8 != 0);
	}
	else if(is_of && c == '\031')
	{
	    if(getchar() == '\001') kill(getpid(), SIGSTOP);
	}
	else
	{
	    delay();
	    putchar(c);
	    if(c == '\f' || c == '\n') 
	    {
		cnt = 0;
	    }
	    else cnt++;
	}
    }
}

#include <sys/time.h> 

struct timeval tm = {0, 1500};

delay()
{
    select(0, 0, 0, 0, &tm);
}

/*	Old version, hope to use again later
#include <sys/time.h> 
#include <signal.h>

int wakeup;

void nullfunc(){
    wakeup = 1;
}

struct itimerval tm = {{0, 0}, {0, 1500}};

delay()
{

    void nullfunc();

    signal(SIGALRM, nullfunc);
    wakeup = 0;
    if(setitimer(ITIMER_REAL, &tm, NULL)) exit(1);
    while(wakeup == 0) sigpause(0);
}
*/
SHAR_EOF
fi # end of overwriting check
echo shar: extracting "'lzcat.c'" '(695 characters)'
if test -f 'lzcat.c'
then
	echo shar: will not over-write existing file "'lzcat.c'"
else
cat << \SHAR_EOF > 'lzcat.c'
#include "stdio.h"

int nomap = 0;

main(ac, av)
int ac;
char **av;
{

    lzinit();
    lzcat();
    exit(0);
}

#include <sgtty.h> 

lzinit()
{
    struct sgttyb nbuf;
    unsigned long lbits;

    setbuf(stdout, NULL);
    /* Work around to by-pass bug in terminal driver and force LITOUT */
    lbits = LMDMBUF|LLITOUT;
    ioctl(fileno(stdout), TIOCLSET, &lbits);
    ioctl(fileno(stdout), TIOCGETP, &nbuf);
    nbuf.sg_flags &= ~(ECHO|XTABS|CRMOD);  /* While we're at it, set the mode */
    ioctl(fileno(stdout), TIOCSETP, &nbuf);

    fputs("\033&k3G", stdout);	/* Set device to sane mode	*/
}

lzcat()
{
    register int c;

    while((c = getchar()) != EOF)
    {
	putchar(c);
    }
}
SHAR_EOF
fi # end of overwriting check
echo shar: extracting "'printcap'" '(201 characters)'
if test -f 'printcap'
then
	echo shar: will not over-write existing file "'printcap'"
else
cat << \SHAR_EOF > 'printcap'
lz|laserjet|Hewlett-Packard Laserjet:\
	:lp=/dev/tty23:sd=/usr/spool/lqd:br#9600:pw#132:pl#60:\
	:xs#060:fc#0177477:lf=/usr/adm/lpd-errs:if=/usr/local/hpf:\
	:of=/usr/local/hpf:vf=/usr/local/lzcat:rs:
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0



More information about the Mod.sources mailing list