File: ifhp.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 (119 lines) | stat: -rw-r--r-- 2,915 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**************************************************************************
 * 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: ifhp.c,v 2.4 1997/01/21 04:14:51 papowell Exp $
 */

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

static const char *const idallf = "@(#) Computer Technology Institute, CTI-Print Project";
static const char *const idhp4 = "@(#)       Filter for HP LaserJet 4, V 1.2 \n" ;
static const char *const idifhp4 = "@(#) ifhp4.c 95/08/23 - V 1.15" ;

int main(argc,argv,envp)
int argc;
char *argv[];
char *envp[];
{
	int acnt_fd;
	unsigned long starttime, endtime;
	int elapsed;

	Envp = envp;
	debug = 2;

	/* save the PID */
	starttime = time( (void *)0 );
	filterpid = getpid();

	acnt_fd = Accounting_fd = dup(3);
	if( Accounting_fd >= 0 ){
		close( Accounting_fd );
		Accounting_fd = 3;
	}
	getargs( argc, argv );

	get_info();
	errorcode = FILTABORT;
	plp_snprintf(job_start,sizeof(job_start)-1,
		"NAME=\"Start of CTI-Print Job: %d\"",getpid());
	plp_snprintf(job_end,sizeof(job_start)-1,
		"NAME=\"End of CTI-Print Job: %d\"", getpid() );


	(void)signal(SIGINT, cleanup);
	(void)signal(SIGHUP, cleanup);
	(void)signal(SIGTERM, cleanup);
	(void)signal(SIGQUIT, cleanup);
	(void)signal(SIGPIPE, SIG_IGN);

	/* open device if specified */
	if( device ) open_device();

	log(4,"ifhp: get_status %d", get_status );
#if defined(F_GETFL)
	if( get_status ){
		int status;
		log(4,"ifhp: trying fcntl" );
		status = fcntl( 1, F_GETFL );
		log(4,"ifhp: fcntl returned 0x%x, O_RDWR = 0x%x", status, O_RDWR );
		if( (status & O_RDWR) == 0 ){
			log(4,"ifhp: cannot read stdout, not getting status" );
			get_status = 0;
		}
	}
#endif

	/* set up the initialization of the printer, and start monitoring */
	do_monitor();

	if( of_filter ){
		log(2,"Starting of_filter actions");
		do_of_stream(stdin, STDOUT );
	} else {
		sendjob(0, STDOUT );
	}

	/* terminate job */
	header_info();

	if( monitpid > 0 ) {
		int pid, status;
		log(3,"stopping monitor %d", monitpid);
		kill(monitpid,SIGTERM);
		kill(monitpid,SIGCONT);
		pid = waitpid( monitpid, &status, 0 );
		log(3,"ifhp: monitor %d exit status %d", pid, status );
	}

	/* get the status and end of job */
	if( get_status ){
		if( sync_printer ) check_job_end();
		if( pagecount ){
			npages = pr_pagecount(STDOUT);
			if( npages == 0 ){
				log (2, "Pagecount 0 using PJL INFO.");
			}
		}
		if (npages == 0 || forcepagecount ) {
			npages = pr_pspagecount(STDOUT);
			if (npages == 0)  {
				log (2, "Pagecount 0 using PostScript");
			}
		}
	}
	endtime = time( (void *)0 );
	elapsed = endtime - starttime;
	log(2,"Initial page count %d, final %d, Total pages = %d, elapsed time %d secs",
		initialpagecount, npages, npages - initialpagecount, elapsed );
	doaccnt(0);

	fexit(FILTSUCC);
	return( 0 );
}