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>
18 ps( infile, outfile, sat )
19 struct papfile *infile, *outfile;
20 struct sockaddr_at *sat;
23 int linelength, crlflength;
24 struct papd_comment *comment;
27 if ( comment = compeek()) {
28 switch( (*comment->c_handler)( infile, outfile, sat )) {
40 switch ( markline( infile, &start, &linelength, &crlflength )) {
43 outfile->pf_state |= PF_EOF;
51 if ( infile->pf_state & PF_BOT ) {
52 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
54 continue; /* top of for (;;) */
56 infile->pf_state &= ~PF_BOT;
58 /* set up spool file */
59 if ( lp_open( outfile, sat ) < 0 ) {
60 syslog( LOG_ERR, "lp_open failed" );
61 spoolerror( outfile, "Ignoring job." );
66 lp_write( start, linelength + crlflength );
67 CONSUME( infile, linelength + crlflength );
72 cm_psquery( in, out, sat )
73 struct papfile *in, *out;
74 struct sockaddr_at *sat;
76 struct papd_comment *comment;
78 int linelength, crlflength;
81 switch ( markline( in, &start, &linelength, &crlflength )) {
84 out->pf_state |= PF_EOF;
92 if ( in->pf_state & PF_BOT ) {
93 in->pf_state &= ~PF_BOT;
95 if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
101 CONSUME( in, linelength + crlflength );
105 cm_psadobe( in, out, sat )
106 struct papfile *in, *out;
107 struct sockaddr_at *sat;
110 int linelength, crlflength;
111 struct comment *comment = compeek();
114 switch ( markline( in, &start, &linelength, &crlflength )) {
117 out->pf_state |= PF_EOF;
125 if ( in->pf_state & PF_BOT ) {
126 in->pf_state &= ~PF_BOT;
127 if ( lp_open( out, sat ) < 0 ) {
128 syslog( LOG_ERR, "lp_open failed" );
129 spoolerror( out, "Ignoring job." );
132 if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
138 lp_write( start, linelength + crlflength );
139 CONSUME( in, linelength + crlflength );
143 char *Query = "Query";
145 cm_psswitch( in, out, sat )
146 struct papfile *in, *out;
147 struct sockaddr_at *sat;
149 char *start, *stop, *p;
150 int linelength, crlflength;
151 struct papd_comment *comment = compeek();
153 switch ( markline( in, &start, &linelength, &crlflength )) {
156 out->pf_state |= PF_EOF;
164 stop = start + linelength;
165 for ( p = start; p < stop; p++ ) {
166 if ( *p == ' ' || *p == '\t' ) {
170 for ( ; p < stop; p++ ) {
171 if ( *p != ' ' && *p != '\t' ) {
176 if ( stop - p >= strlen( Query ) &&
177 strncmp( p, Query, strlen( Query )) == 0 ) {
178 if ( comswitch( magics, cm_psquery ) < 0 ) {
179 syslog( LOG_ERR, "cm_psswitch: can't find psquery!" );
183 if ( comswitch( magics, cm_psadobe ) < 0 ) {
184 syslog( LOG_ERR, "cm_psswitch: can't find psadobe!" );
191 struct papd_comment magics[] = {
192 { "%!PS-Adobe-3.0 Query", 0, cm_psquery, C_FULL },
193 { "%!PS-Adobe-3.0", 0, cm_psadobe, C_FULL },
194 { "%!PS-Adobe-", 0, cm_psswitch, 0 },