2 * $Id: magics.c,v 1.14 2009-02-02 16:04:33 didg 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 static void parser_error(outfile)
27 struct papfile *outfile;
29 spoolerror( outfile, "Comments error, Ignoring job." );
30 outfile->pf_state |= PF_EOF;
34 int ps( infile, outfile, sat )
35 struct papfile *infile, *outfile;
36 struct sockaddr_at *sat;
39 int linelength, crlflength;
40 struct papd_comment *comment;
43 if ( infile->pf_state & PF_STW ) {
44 infile->pf_state &= ~PF_STW;
45 /* set up spool file */
46 if ( lp_open( outfile, sat ) < 0 && !state) {
47 LOG(log_error, logtype_papd, "lp_open failed" );
48 spoolerror( outfile, "Ignoring job." );
52 if ( (comment = compeek()) ) {
53 switch( (*comment->c_handler)( infile, outfile, sat )) {
61 parser_error(outfile);
68 switch ( markline( infile, &start, &linelength, &crlflength )) {
71 outfile->pf_state |= PF_EOF;
76 parser_error(outfile);
83 if ( infile->pf_state & PF_BOT ) {
84 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
86 continue; /* top of for (;;) */
89 infile->pf_state &= ~PF_BOT;
91 /* set up spool file */
92 if ( lp_open( outfile, sat ) < 0 ) {
93 LOG(log_error, logtype_papd, "lp_open failed" );
94 spoolerror( outfile, "Ignoring job." );
100 lp_write( infile, start, linelength + crlflength );
101 CONSUME( infile, linelength + crlflength );
106 int cm_psquery( in, out, sat )
107 struct papfile *in, *out;
108 struct sockaddr_at *sat _U_;
110 struct papd_comment *comment;
112 int linelength, crlflength;
115 switch ( markline( in, &start, &linelength, &crlflength )) {
118 out->pf_state |= PF_EOF;
129 if ( in->pf_state & PF_BOT ) {
130 in->pf_state &= ~PF_BOT;
132 if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
138 CONSUME( in, linelength + crlflength );
142 int cm_psadobe( in, out, sat )
143 struct papfile *in, *out;
144 struct sockaddr_at *sat _U_;
147 int linelength, crlflength;
148 struct papd_comment *comment = compeek();
151 switch ( markline( in, &start, &linelength, &crlflength )) {
154 out->pf_state |= PF_EOF;
164 if ( in->pf_state & PF_BOT ) {
165 in->pf_state &= ~PF_BOT;
167 if ( lp_open( out, sat ) < 0 ) {
168 LOG(log_error, logtype_papd, "lp_open failed" );
169 spoolerror( out, "Ignoring job." );
173 if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
179 lp_write( in, start, linelength + crlflength );
180 CONSUME( in, linelength + crlflength );
184 char *Query = "Query";
186 int cm_psswitch( in, out, sat )
187 struct papfile *in, *out;
188 struct sockaddr_at *sat _U_;
190 char *start, *stop, *p;
191 int linelength, crlflength;
193 switch ( markline( in, &start, &linelength, &crlflength )) {
196 out->pf_state |= PF_EOF;
207 stop = start + linelength;
208 for ( p = start; p < stop; p++ ) {
209 if ( *p == ' ' || *p == '\t' ) {
213 for ( ; p < stop; p++ ) {
214 if ( *p != ' ' && *p != '\t' ) {
219 if ( (size_t)(stop - p) >= strlen( Query ) &&
220 strncmp( p, Query, strlen( Query )) == 0 ) {
221 if ( comswitch( magics, cm_psquery ) < 0 ) {
222 LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
226 if ( comswitch( magics, cm_psadobe ) < 0 ) {
227 LOG(log_error, logtype_papd, "cm_psswitch: can't find psadobe!" );
235 struct papd_comment magics[] = {
236 { "%!PS-Adobe-3.0 Query", NULL, cm_psquery, C_FULL },
237 { "%!PS-Adobe-3.0", NULL, cm_psadobe, C_FULL },
238 { "%!PS-Adobe-", NULL, cm_psswitch, 0 },
239 { NULL, NULL, NULL, 0 },