Flushing printer output in VP/ix


Sun Jan 20 11:23:51 AEST 1991


Since there have been a slew of people sending me mail on the solution that
I had for kicking VP/ix into printing (without exiting VP/ix or explicitly
flushing the print buffer), I offer vplp.

The line in your $HOME/vpix/vpix.cnf file should be changed to use the
vplp interface instead of lp.  If, for example, you're using a laser
printer on tty1a, then you could use:

LPT1		/usr/local/bin/vplp /dev/tty1a

I originally had a flavor that popen()'d lp, but this caused problems
under heavy printing because some spooled jobs interleaved with the
VP/ix output.  I agree that the lpshut and lpsched is like using a sledge-
hammer to kill a housefly, but it was a quick and dirty solution.
Perhaps when I have 5 minutes to myself, I write something more elegant. :-)

---[ cut here ]-------------------------------------------------------------

/*      @(#)vplp.c      1.3 91/01/14 flush printer output in VP/ix
        Written by Mike Stefanik

	This program is offered for public consumption, and is offered
	without warranty of any kind.  If you choose to use it, then
	you get to support it.
*/

#include <stdio.h>
#include <fcntl.h>
#include <termio.h>
#include <signal.h>
#include <sys/types.h>

#define BUFSIZE 256     /* buffer size for dumping to the device */
#define TIMEOUT 10      /* buffer read timeout after 1 second */

main(argc,argv)
int     argc;
char    *argv[];
{
int             fd, bytes;
char            buf[BUFSIZE];
struct termio   old, new;

	/* ignore some signals that may be fired at me */

        signal(SIGHUP,SIG_IGN);
        signal(SIGTERM,SIG_IGN);
        signal(SIGINT,SIG_IGN);

        if ( argc != 2 ) {
                fprintf(stderr,"Usage: %s device\n",argv[0]);
                exit(1);
                }

	system("/usr/lib/lpshut");

	/* put stdin into "raw" mode, reading a character at a time,
	   with a timeout of 1 second */

        ioctl(0,TCGETA,&old);
        ioctl(0,TCGETA,&new);

        new.c_lflag &= ~ECHO;
        new.c_lflag &= ~ICANON;
        new.c_lflag &= ~ISIG;
        new.c_cc[VMIN] = BUFSIZ;
        new.c_cc[VTIME] = TIMEOUT; 

        ioctl(0,TCSETA,&new);

	/* here we are reading in the output from VP/ix, and shoving
	   it out the door, insuring that it is "flushed" by closing
	   and re-opening the device */

        while ( (bytes = read(0,buf,BUFSIZE)) > 0 ) {
                if ( (fd = open(argv[1],O_WRONLY|O_APPEND)) == -1 ) {
                        ioctl(0,TCSETA,&old);
                        fprintf(stderr,"%s: cannot open %s\n",argv[0],argv[1]);
                        exit(1);
                        }
                write(fd,buf,bytes);
                close(fd);
                }

	/* put stdin back to the way it was, and restart the scheduler */

        ioctl(0,TCSETA,&old);
	system("/usr/lib/lpsched");
        exit(0);
}
-- 
Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation
UUCP: ...!uunet!bria!mike
--
technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly
found to be saying things like "Well, it works on my DOS machine ..."



More information about the Comp.unix.xenix.sco mailing list