2 * Copyright (c) 1990,1994 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
10 #include <sys/syslog.h>
11 #include <sys/param.h>
20 int ps( infile, outfile, sat )
21 struct papfile *infile, *outfile;
22 struct sockaddr_at *sat;
25 int linelength, crlflength;
26 struct papd_comment *comment;
29 if ( (comment = compeek()) ) {
30 switch( (*comment->c_handler)( infile, outfile, sat )) {
42 switch ( markline( infile, &start, &linelength, &crlflength )) {
45 outfile->pf_state |= PF_EOF;
53 if ( infile->pf_state & PF_BOT ) {
54 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
56 continue; /* top of for (;;) */
58 infile->pf_state &= ~PF_BOT;
60 /* set up spool file */
61 if ( lp_open( outfile, sat ) < 0 ) {
62 syslog( LOG_ERR, "lp_open failed" );
63 spoolerror( outfile, "Ignoring job." );
68 lp_write( start, linelength + crlflength );
69 CONSUME( infile, linelength + crlflength );
74 int cm_psquery( in, out, sat )
75 struct papfile *in, *out;
76 struct sockaddr_at *sat;
78 struct papd_comment *comment;
80 int linelength, crlflength;
83 switch ( markline( in, &start, &linelength, &crlflength )) {
86 out->pf_state |= PF_EOF;
94 if ( in->pf_state & PF_BOT ) {
95 in->pf_state &= ~PF_BOT;
97 if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
103 CONSUME( in, linelength + crlflength );
107 int cm_psadobe( in, out, sat )
108 struct papfile *in, *out;
109 struct sockaddr_at *sat;
112 int linelength, crlflength;
113 struct papd_comment *comment = compeek();
116 switch ( markline( in, &start, &linelength, &crlflength )) {
119 out->pf_state |= PF_EOF;
127 if ( in->pf_state & PF_BOT ) {
128 in->pf_state &= ~PF_BOT;
129 if ( lp_open( out, sat ) < 0 ) {
130 syslog( LOG_ERR, "lp_open failed" );
131 spoolerror( out, "Ignoring job." );
134 if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
140 lp_write( start, linelength + crlflength );
141 CONSUME( in, linelength + crlflength );
145 char *Query = "Query";
147 int cm_psswitch( in, out, sat )
148 struct papfile *in, *out;
149 struct sockaddr_at *sat;
151 char *start, *stop, *p;
152 int linelength, crlflength;
153 struct papd_comment *comment = compeek();
155 switch ( markline( in, &start, &linelength, &crlflength )) {
158 out->pf_state |= PF_EOF;
166 stop = start + linelength;
167 for ( p = start; p < stop; p++ ) {
168 if ( *p == ' ' || *p == '\t' ) {
172 for ( ; p < stop; p++ ) {
173 if ( *p != ' ' && *p != '\t' ) {
178 if ( stop - p >= strlen( Query ) &&
179 strncmp( p, Query, strlen( Query )) == 0 ) {
180 if ( comswitch( magics, cm_psquery ) < 0 ) {
181 syslog( LOG_ERR, "cm_psswitch: can't find psquery!" );
185 if ( comswitch( magics, cm_psadobe ) < 0 ) {
186 syslog( LOG_ERR, "cm_psswitch: can't find psadobe!" );
193 struct papd_comment magics[] = {
194 { "%!PS-Adobe-3.0 Query", 0, cm_psquery, C_FULL },
195 { "%!PS-Adobe-3.0", 0, cm_psadobe, C_FULL },
196 { "%!PS-Adobe-", 0, cm_psswitch, 0 },