File: sendjob.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 (76 lines) | stat: -rw-r--r-- 1,890 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
/**************************************************************************
 * 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: sendjob.c,v 2.1 1997/01/05 18:41:45 papowell Exp $
 */

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

/*
 * send job to the remote printer
 */

void sendjob(fd, sockfd)
int    fd;
int    sockfd;
{
	int 	rdcnt;
	int i;
	char *s, *ps;
	int discard = 0;

	/* read an input line */
	log(9,"sendjob: reading input");
	/* set up the options using PJL.
     * Note: you may need to do this again in PCL or PostScript
	 */
	if( (rdcnt=file_readline(fd,sendline,sizeof(sendline)-1)) > 0){
		log(6,"sendjob: read %d '%s'", rdcnt,sendline);
		/* try to determine which mode you are in */
		if( literal || autodetect ){
			mode = LITERAL;
			job_page_set();
		} else {
			if( (ps = strstr(sendline, "%!" )) ){
				for( s = sendline; ps && s!=ps; ++s ){
					/* we must have a control char string */
					if( !iscntrl(*s) ) ps = 0;
				}
			}
			if( ps && cartridge ){
				mode = POSTSCRIPT ;
				job_page_set();
			} else {
				mode = PCL ;
				job_page_set();
				if( ps ){
					s = UNABLE;
					i = strlen(s);
					writecn(sockfd,s,i);
				}
			}
		}
		log(2,"Transferring file");
		if( !discard && rdcnt != writecn(sockfd, sendline, rdcnt) ){
			logerr_die(2,"Cannot write what read (%d bytes)",rdcnt);
		}
		log(4,"sendjob: wrote first line '%s'", sendline );
		/* now we read the rest of the file */
		if( !discard ){
			while( (rdcnt=read(fd,sendline,sizeof(sendline)-1)) > 0){
				log(4,"sendjob: next line '%s'", sendline );
				if( rdcnt != writecn(sockfd, sendline, rdcnt ) ){
					logerr_die(2,"Cannot write what read (%d bytes)",rdcnt);
				}
			}
		}
    }
	/* read an input line */
	log(2,"Finished transferring file");
}