2 * $Id: magics.c,v 1.11 2003-02-17 01:34:35 srittau 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>
24 int ps( infile, outfile, sat )
25 struct papfile *infile, *outfile;
26 struct sockaddr_at *sat;
29 int linelength, crlflength;
30 struct papd_comment *comment;
33 if ( (comment = compeek()) ) {
34 switch( (*comment->c_handler)( infile, outfile, sat )) {
46 switch ( markline( infile, &start, &linelength, &crlflength )) {
49 outfile->pf_state |= PF_EOF;
57 if ( infile->pf_state & PF_BOT ) {
58 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
60 continue; /* top of for (;;) */
62 infile->pf_state &= ~PF_BOT;
64 /* set up spool file */
65 if ( lp_open( outfile, sat ) < 0 ) {
66 LOG(log_error, logtype_papd, "lp_open failed" );
67 spoolerror( outfile, "Ignoring job." );
72 lp_write( start, linelength + crlflength );
73 CONSUME( infile, linelength + crlflength );
78 int cm_psquery( in, out, sat )
79 struct papfile *in, *out;
80 struct sockaddr_at *sat;
82 struct papd_comment *comment;
84 int linelength, crlflength;
87 switch ( markline( in, &start, &linelength, &crlflength )) {
90 out->pf_state |= PF_EOF;
98 if ( in->pf_state & PF_BOT ) {
99 in->pf_state &= ~PF_BOT;
101 if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
107 CONSUME( in, linelength + crlflength );
111 int cm_psadobe( in, out, sat )
112 struct papfile *in, *out;
113 struct sockaddr_at *sat;
116 int linelength, crlflength;
117 struct papd_comment *comment = compeek();
120 switch ( markline( in, &start, &linelength, &crlflength )) {
123 out->pf_state |= PF_EOF;
131 if ( in->pf_state & PF_BOT ) {
132 in->pf_state &= ~PF_BOT;
133 if ( lp_open( out, sat ) < 0 ) {
134 LOG(log_error, logtype_papd, "lp_open failed" );
135 spoolerror( out, "Ignoring job." );
138 if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
144 lp_write( start, linelength + crlflength );
145 CONSUME( in, linelength + crlflength );
149 char *Query = "Query";
151 int cm_psswitch( in, out, sat )
152 struct papfile *in, *out;
153 struct sockaddr_at *sat;
155 char *start, *stop, *p;
156 int linelength, crlflength;
158 switch ( markline( in, &start, &linelength, &crlflength )) {
161 out->pf_state |= PF_EOF;
169 stop = start + linelength;
170 for ( p = start; p < stop; p++ ) {
171 if ( *p == ' ' || *p == '\t' ) {
175 for ( ; p < stop; p++ ) {
176 if ( *p != ' ' && *p != '\t' ) {
181 if ( stop - p >= strlen( Query ) &&
182 strncmp( p, Query, strlen( Query )) == 0 ) {
183 if ( comswitch( magics, cm_psquery ) < 0 ) {
184 LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
188 if ( comswitch( magics, cm_psadobe ) < 0 ) {
189 LOG(log_error, logtype_papd, "cm_psswitch: can't find psadobe!" );
196 struct papd_comment magics[] = {
197 { "%!PS-Adobe-3.0 Query", 0, cm_psquery, C_FULL },
198 { "%!PS-Adobe-3.0", 0, cm_psadobe, C_FULL },
199 { "%!PS-Adobe-", 0, cm_psswitch, 0 },