2 * Copyright (c) 1990,1994 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
6 #include <sys/syslog.h>
14 ps( infile, outfile, sat )
15 struct papfile *infile, *outfile;
16 struct sockaddr_at *sat;
19 int linelength, crlflength;
20 struct comment *comment;
23 if ( comment = compeek()) {
24 switch( (*comment->c_handler)( infile, outfile, sat )) {
36 switch ( markline( infile, &start, &linelength, &crlflength )) {
39 outfile->pf_state |= PF_EOF;
47 if ( infile->pf_state & PF_BOT ) {
48 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
50 continue; /* top of for (;;) */
52 infile->pf_state &= ~PF_BOT;
54 /* set up spool file */
55 if ( lp_open( outfile, sat ) < 0 ) {
56 syslog( LOG_ERR, "lp_open failed" );
57 spoolerror( outfile, "Ignoring job." );
62 lp_write( start, linelength + crlflength );
63 CONSUME( infile, linelength + crlflength );
68 cm_psquery( in, out, sat )
69 struct papfile *in, *out;
70 struct sockaddr_at *sat;
72 struct comment *comment;
74 int linelength, crlflength;
77 switch ( markline( in, &start, &linelength, &crlflength )) {
80 out->pf_state |= PF_EOF;
88 if ( in->pf_state & PF_BOT ) {
89 in->pf_state &= ~PF_BOT;
91 if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
97 CONSUME( in, linelength + crlflength );
101 cm_psadobe( in, out, sat )
102 struct papfile *in, *out;
103 struct sockaddr_at *sat;
106 int linelength, crlflength;
107 struct comment *comment = compeek();
110 switch ( markline( in, &start, &linelength, &crlflength )) {
113 out->pf_state |= PF_EOF;
121 if ( in->pf_state & PF_BOT ) {
122 in->pf_state &= ~PF_BOT;
123 if ( lp_open( out, sat ) < 0 ) {
124 syslog( LOG_ERR, "lp_open failed" );
125 spoolerror( out, "Ignoring job." );
128 if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
134 lp_write( start, linelength + crlflength );
135 CONSUME( in, linelength + crlflength );
139 char *Query = "Query";
141 cm_psswitch( in, out, sat )
142 struct papfile *in, *out;
143 struct sockaddr_at *sat;
145 char *start, *stop, *p;
146 int linelength, crlflength;
147 struct comment *comment = compeek();
149 switch ( markline( in, &start, &linelength, &crlflength )) {
152 out->pf_state |= PF_EOF;
160 stop = start + linelength;
161 for ( p = start; p < stop; p++ ) {
162 if ( *p == ' ' || *p == '\t' ) {
166 for ( ; p < stop; p++ ) {
167 if ( *p != ' ' && *p != '\t' ) {
172 if ( stop - p >= strlen( Query ) &&
173 strncmp( p, Query, strlen( Query )) == 0 ) {
174 if ( comswitch( magics, cm_psquery ) < 0 ) {
175 syslog( LOG_ERR, "cm_psswitch: can't find psquery!" );
179 if ( comswitch( magics, cm_psadobe ) < 0 ) {
180 syslog( LOG_ERR, "cm_psswitch: can't find psadobe!" );
187 struct comment magics[] = {
188 { "%!PS-Adobe-3.0 Query", 0, cm_psquery, C_FULL },
189 { "%!PS-Adobe-3.0", 0, cm_psadobe, C_FULL },
190 { "%!PS-Adobe-", 0, cm_psswitch, 0 },