]> arthur.barton.de Git - netatalk.git/blob - etc/papd/magics.c
Set pkgconfdir explicitly.
[netatalk.git] / etc / papd / magics.c
1 /*
2  * Copyright (c) 1990,1994 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <sys/syslog.h>
11 #include <sys/param.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15
16 #include "file.h"
17 #include "comment.h"
18 #include "lp.h"
19
20 int ps( infile, outfile, sat )
21     struct papfile      *infile, *outfile;
22     struct sockaddr_at  *sat;
23 {
24     char                        *start;
25     int                         linelength, crlflength;
26     struct papd_comment         *comment;
27
28     for (;;) {
29         if ( (comment = compeek()) ) {
30             switch( (*comment->c_handler)( infile, outfile, sat )) {
31             case CH_DONE :
32                 continue;
33
34             case CH_MORE :
35                 return( CH_MORE );
36
37             default :
38                 return( CH_ERROR );
39             }
40
41         } else {
42             switch ( markline( infile, &start, &linelength, &crlflength )) {
43             case 0 :
44                 /* eof on infile */
45                 outfile->pf_state |= PF_EOF;
46                 lp_close();
47                 return( 0 );
48
49             case -1 :
50                 return( 0 );
51             }
52
53             if ( infile->pf_state & PF_BOT ) {
54                 if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
55                     compush( comment );
56                     continue;   /* top of for (;;) */
57                 }
58                 infile->pf_state &= ~PF_BOT;
59
60                 /* set up spool file */
61                 if ( lp_open( outfile, sat ) < 0 ) {
62                     syslog( LOG_ERR, "lp_open failed" );
63                     spoolerror( outfile, "Ignoring job." );
64                 }
65             }
66
67             /* write to file */
68             lp_write( start, linelength + crlflength );
69             CONSUME( infile, linelength + crlflength );
70         }
71     }
72 }
73
74 int cm_psquery( in, out, sat )
75     struct papfile      *in, *out;
76     struct sockaddr_at  *sat;
77 {
78     struct papd_comment *comment;
79     char                *start;
80     int                 linelength, crlflength;
81
82     for (;;) {
83         switch ( markline( in, &start, &linelength, &crlflength )) {
84         case 0 :
85             /* eof on infile */
86             out->pf_state |= PF_EOF;
87             compop();
88             return( CH_DONE );
89
90         case -1 :
91             return( CH_MORE );
92         }
93
94         if ( in->pf_state & PF_BOT ) {
95             in->pf_state &= ~PF_BOT;
96         } else {
97             if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
98                 compush( comment );
99                 return( CH_DONE );
100             }
101         }
102
103         CONSUME( in, linelength + crlflength );
104     }
105 }
106
107 int cm_psadobe( in, out, sat )
108     struct papfile      *in, *out;
109     struct sockaddr_at  *sat;
110 {
111     char                *start;
112     int                 linelength, crlflength;
113     struct papd_comment *comment = compeek();
114
115     for (;;) {
116         switch ( markline( in, &start, &linelength, &crlflength )) {
117         case 0 :
118             /* eof on infile */
119             out->pf_state |= PF_EOF;
120             compop();
121             return( CH_DONE );
122
123         case -1 :
124             return( CH_MORE );
125         }
126
127         if ( in->pf_state & PF_BOT ) {
128             in->pf_state &= ~PF_BOT;
129             if ( lp_open( out, sat ) < 0 ) {
130                 syslog( LOG_ERR, "lp_open failed" );
131                 spoolerror( out, "Ignoring job." );
132             }
133         } else {
134             if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
135                 compush( comment );
136                 return( CH_DONE );
137             }
138         }
139
140         lp_write( start, linelength + crlflength );
141         CONSUME( in, linelength + crlflength );
142     }
143 }
144
145 char    *Query = "Query";
146
147 int cm_psswitch( in, out, sat )
148     struct papfile      *in, *out;
149     struct sockaddr_at  *sat;
150 {
151     char                *start, *stop, *p;
152     int                 linelength, crlflength;
153     struct papd_comment *comment = compeek();
154
155     switch ( markline( in, &start, &linelength, &crlflength )) {
156     case 0 :
157         /* eof on infile */
158         out->pf_state |= PF_EOF;
159         compop();
160         return( 0 );
161
162     case -1 :
163         return( CH_MORE );
164     }
165
166     stop = start + linelength;
167     for ( p = start; p < stop; p++ ) {
168         if ( *p == ' ' || *p == '\t' ) {
169             break;
170         }
171     }
172     for ( ; p < stop; p++ ) {
173         if ( *p != ' ' && *p != '\t' ) {
174             break;
175         }
176     }
177
178     if ( stop - p >= strlen( Query ) &&
179             strncmp( p, Query, strlen( Query )) == 0 ) {
180         if ( comswitch( magics, cm_psquery ) < 0 ) {
181             syslog( LOG_ERR, "cm_psswitch: can't find psquery!" );
182             exit( 1 );
183         }
184     } else {
185         if ( comswitch( magics, cm_psadobe ) < 0 ) {
186             syslog( LOG_ERR, "cm_psswitch: can't find psadobe!" );
187             exit( 1 );
188         }
189     }
190     return( CH_DONE );
191 }
192
193 struct papd_comment     magics[] = {
194     { "%!PS-Adobe-3.0 Query",   0,                      cm_psquery, C_FULL },
195     { "%!PS-Adobe-3.0",         0,                      cm_psadobe, C_FULL },
196     { "%!PS-Adobe-",            0,                      cm_psswitch,    0 },
197     { 0 },
198 };