2 * $Id: magics.c,v 1.12 2005-04-28 20:49:49 bfernhomberg Exp $
4 * Copyright (c) 1990,1994 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
12 #include <atalk/logger.h>
13 #include <sys/param.h>
18 #include <netatalk/at.h>
26 int ps( infile, outfile, sat )
27 struct papfile *infile, *outfile;
28 struct sockaddr_at *sat;
31 int linelength, crlflength;
32 struct papd_comment *comment;
35 if ( infile->pf_state & PF_STW ) {
36 infile->pf_state &= ~PF_STW;
37 /* set up spool file */
38 if ( lp_open( outfile, sat ) < 0 && !state) {
39 LOG(log_error, logtype_papd, "lp_open failed" );
40 spoolerror( outfile, "Ignoring job." );
44 if ( (comment = compeek()) ) {
45 switch( (*comment->c_handler)( infile, outfile, sat )) {
56 switch ( markline( infile, &start, &linelength, &crlflength )) {
59 outfile->pf_state |= PF_EOF;
67 if ( infile->pf_state & PF_BOT ) {
68 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
70 continue; /* top of for (;;) */
73 infile->pf_state &= ~PF_BOT;
75 /* set up spool file */
76 if ( lp_open( outfile, sat ) < 0 ) {
77 LOG(log_error, logtype_papd, "lp_open failed" );
78 spoolerror( outfile, "Ignoring job." );
84 lp_write( infile, start, linelength + crlflength );
85 CONSUME( infile, linelength + crlflength );
90 int cm_psquery( in, out, sat )
91 struct papfile *in, *out;
92 struct sockaddr_at *sat _U_;
94 struct papd_comment *comment;
96 int linelength, crlflength;
99 switch ( markline( in, &start, &linelength, &crlflength )) {
102 out->pf_state |= PF_EOF;
110 if ( in->pf_state & PF_BOT ) {
111 in->pf_state &= ~PF_BOT;
113 if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
119 CONSUME( in, linelength + crlflength );
123 int cm_psadobe( in, out, sat )
124 struct papfile *in, *out;
125 struct sockaddr_at *sat _U_;
128 int linelength, crlflength;
129 struct papd_comment *comment = compeek();
132 switch ( markline( in, &start, &linelength, &crlflength )) {
135 out->pf_state |= PF_EOF;
142 if ( in->pf_state & PF_BOT ) {
143 in->pf_state &= ~PF_BOT;
145 if ( lp_open( out, sat ) < 0 ) {
146 LOG(log_error, logtype_papd, "lp_open failed" );
147 spoolerror( out, "Ignoring job." );
151 if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
157 lp_write( in, start, linelength + crlflength );
158 CONSUME( in, linelength + crlflength );
162 char *Query = "Query";
164 int cm_psswitch( in, out, sat )
165 struct papfile *in, *out;
166 struct sockaddr_at *sat _U_;
168 char *start, *stop, *p;
169 int linelength, crlflength;
171 switch ( markline( in, &start, &linelength, &crlflength )) {
174 out->pf_state |= PF_EOF;
182 stop = start + linelength;
183 for ( p = start; p < stop; p++ ) {
184 if ( *p == ' ' || *p == '\t' ) {
188 for ( ; p < stop; p++ ) {
189 if ( *p != ' ' && *p != '\t' ) {
194 if ( stop - p >= strlen( Query ) &&
195 strncmp( p, Query, strlen( Query )) == 0 ) {
196 if ( comswitch( magics, cm_psquery ) < 0 ) {
197 LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
201 if ( comswitch( magics, cm_psadobe ) < 0 ) {
202 LOG(log_error, logtype_papd, "cm_psswitch: can't find psadobe!" );
210 struct papd_comment magics[] = {
211 { "%!PS-Adobe-3.0 Query", NULL, cm_psquery, C_FULL },
212 { "%!PS-Adobe-3.0", NULL, cm_psadobe, C_FULL },
213 { "%!PS-Adobe-", NULL, cm_psswitch, 0 },
214 { NULL, NULL, NULL, 0 },