2 * $Id: magics.c,v 1.15 2009-10-13 22:55:37 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(struct papfile *outfile)
28 spoolerror( outfile, "Comments error, Ignoring job." );
29 outfile->pf_state |= PF_EOF;
33 int ps( struct papfile *infile, struct papfile *outfile, struct sockaddr_at *sat)
36 int linelength, crlflength;
37 struct papd_comment *comment;
40 if ( infile->pf_state & PF_STW ) {
41 infile->pf_state &= ~PF_STW;
42 /* set up spool file */
43 if ( lp_open( outfile, sat ) < 0 && !state) {
44 LOG(log_error, logtype_papd, "lp_open failed" );
45 spoolerror( outfile, "Ignoring job." );
49 if ( (comment = compeek()) ) {
50 switch( (*comment->c_handler)( infile, outfile, sat )) {
58 parser_error(outfile);
65 switch ( markline( infile, &start, &linelength, &crlflength )) {
68 outfile->pf_state |= PF_EOF;
73 parser_error(outfile);
80 if ( infile->pf_state & PF_BOT ) {
81 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
83 continue; /* top of for (;;) */
86 infile->pf_state &= ~PF_BOT;
88 /* set up spool file */
89 if ( lp_open( outfile, sat ) < 0 ) {
90 LOG(log_error, logtype_papd, "lp_open failed" );
91 spoolerror( outfile, "Ignoring job." );
97 lp_write( infile, start, linelength + crlflength );
98 CONSUME( infile, linelength + crlflength );
103 int cm_psquery( struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
105 struct papd_comment *comment;
107 int linelength, crlflength;
110 switch ( markline( in, &start, &linelength, &crlflength )) {
113 out->pf_state |= PF_EOF;
124 if ( in->pf_state & PF_BOT ) {
125 in->pf_state &= ~PF_BOT;
127 if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
133 CONSUME( in, linelength + crlflength );
137 int cm_psadobe( struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
140 int linelength, crlflength;
141 struct papd_comment *comment = compeek();
144 switch ( markline( in, &start, &linelength, &crlflength )) {
147 out->pf_state |= PF_EOF;
157 if ( in->pf_state & PF_BOT ) {
158 in->pf_state &= ~PF_BOT;
160 if ( lp_open( out, sat ) < 0 ) {
161 LOG(log_error, logtype_papd, "lp_open failed" );
162 spoolerror( out, "Ignoring job." );
166 if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
172 lp_write( in, start, linelength + crlflength );
173 CONSUME( in, linelength + crlflength );
177 char *Query = "Query";
179 int cm_psswitch(struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
181 char *start, *stop, *p;
182 int linelength, crlflength;
184 switch ( markline( in, &start, &linelength, &crlflength )) {
187 out->pf_state |= PF_EOF;
198 stop = start + linelength;
199 for ( p = start; p < stop; p++ ) {
200 if ( *p == ' ' || *p == '\t' ) {
204 for ( ; p < stop; p++ ) {
205 if ( *p != ' ' && *p != '\t' ) {
210 if ( (size_t)(stop - p) >= strlen( Query ) &&
211 strncmp( p, Query, strlen( Query )) == 0 ) {
212 if ( comswitch( magics, cm_psquery ) < 0 ) {
213 LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
217 if ( comswitch( magics, cm_psadobe ) < 0 ) {
218 LOG(log_error, logtype_papd, "cm_psswitch: can't find psadobe!" );
226 struct papd_comment magics[] = {
227 { "%!PS-Adobe-3.0 Query", NULL, cm_psquery, C_FULL },
228 { "%!PS-Adobe-3.0", NULL, cm_psadobe, C_FULL },
229 { "%!PS-Adobe-", NULL, cm_psswitch, 0 },
230 { NULL, NULL, NULL, 0 },