File: check_job.c

package info (click to toggle)
cti-ifhp 2.1.8-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 932 kB
  • ctags: 845
  • sloc: ansic: 6,036; sh: 1,524; makefile: 318
file content (59 lines) | stat: -rw-r--r-- 1,645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**************************************************************************
 * LPRng IFHP Filter
 * Copyright 1994-1997 Patrick Powell, San Diego, CA <papowell@sdsu.edu>
 *
 * Based on the CTI printer filters.
 *  See COPYRIGHT for details.
 *
 * $Id: check_job.c,v 2.2 1997/01/06 21:59:46 papowell Exp $
 */

#include "portable.h"
#include "common.h"
#include "hp4.h"


void check_job_end()
{
	int fftries = 0;
	int timeout = 16;
	int n, err;
	char buf[MAXLINE+1];
	int i;

	log(2,"Checking printer for job end");

	/*
	 * the printer may be tied up doing postscript or offline;
	 * it is also possible that somebody turned the printer off;
	 * Looking for the end of job string may not work if
	 * somebody screwed up by sending a bad PJL language print job
	 * We look for idle printer OR echo job string;  in fact we may not
	 * get either of these if somebody sent a bad 'change personality'
	 * command to the printer.  I suspect that by clever use of
	 * embedded printer job language commands in a file somebody could
	 * appear to have terminated their job while in actual fact it
	 * was still printing.
	 * we try to end the job when the printer is idle
	 */

	i = 0;
	query[i++]= UELPJL ;
	plp_snprintf(buf,sizeof(buf)-1,"@PJL EOJ %s\r\n", job_end);
	query[i++] = buf;
	query[i++]= UEL;
	query[i]= 0;
	do{
		pr_query(STDOUT, i);
		if( timeout < 256 ){
			timeout += timeout; /* double it each time */
		}
		err = readpipe(&n,timeout);
		if( err < 0 ){
			log(2, "EOF reading from printer");
			fexit(FILTABORT);
		}
		log(4, "check_job_end: fftries=%d, code %d, job_ended %d",
			++fftries, n, job_ended );
	} while( !job_ended );
}