2 * $Id: headers.c,v 1.10 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 <sys/param.h>
16 #include <netatalk/at.h>
17 #include <atalk/logger.h>
23 int ch_title( struct papfile *, struct papfile * );
24 int ch_for( struct papfile *, struct papfile * );
28 struct papfile *in, *out _U_;
30 char *start, *stop, *p, *q, c;
31 int linelength, crlflength;
33 switch ( markline( in, &start, &linelength, &crlflength )) {
41 stop = start + linelength;
42 for ( p = start; p < stop; p++ ) {
48 for ( ; p < stop; p++ ) {
54 for ( q = p; q < stop; q++ ) {
60 if ( q < stop && p < stop ) {
68 in->pf_state |= PF_TRANSLATE;
69 lp_write( in, start, linelength + crlflength );
70 in->pf_state &= ~PF_TRANSLATE;
72 CONSUME( in, linelength + crlflength );
76 int ch_title( in, out )
77 struct papfile *in, *out _U_;
79 char *start, *stop, *p, *q, c;
80 int linelength, crlflength;
82 switch ( markline( in, &start, &linelength, &crlflength )) {
91 LOG(log_debug, logtype_papd, "Parsing %%Title");
94 stop = start + linelength;
95 for ( p = start; p < stop; p++ ) {
101 for ( ; p < stop; p++ ) {
107 for ( q = p; q < stop; q++ ) {
113 if ( q < stop && p < stop ) {
121 in->pf_state |= PF_TRANSLATE;
122 lp_write( in, start, linelength + crlflength );
123 in->pf_state &= ~PF_TRANSLATE;
125 CONSUME( in, linelength + crlflength );
129 static int guess_creator ( char *creator )
131 if (strstr(creator, "LaserWriter"))
133 if (strstr(creator, "cgpdftops"))
140 int ch_creator( in, out )
141 struct papfile *in, *out _U_;
143 char *start, *stop, *p, *q, c;
144 int linelength, crlflength;
146 switch ( markline( in, &start, &linelength, &crlflength )) {
154 stop = start + linelength;
155 for ( p = start; p < stop; p++ ) {
161 for ( ; p < stop; p++ ) {
167 for ( q = p; q < stop; q++ ) {
173 if ( q < stop && p < stop ) {
177 in->origin = guess_creator ( p );
178 lp_origin(in->origin);
182 in->pf_state |= PF_TRANSLATE;
183 lp_write( in, start, linelength + crlflength );
184 in->pf_state &= ~PF_TRANSLATE;
186 CONSUME( in, linelength + crlflength );
190 int ch_endcomm( in, out )
191 struct papfile *in, *out _U_;
194 int linelength, crlflength;
197 LOG(log_debug, logtype_papd, "End Comment");
199 in->pf_state |= PF_STW;
201 switch ( markline( in, &start, &linelength, &crlflength )) {
209 in->pf_state |= PF_TRANSLATE;
210 lp_write( in, start, linelength + crlflength );
211 in->pf_state &= ~PF_TRANSLATE;
213 CONSUME( in, linelength + crlflength );
217 int ch_starttranslate(in,out)
218 struct papfile *in, *out _U_;
221 int linelength, crlflength;
224 LOG(log_debug, logtype_papd, "Start translate");
227 switch ( markline( in, &start, &linelength, &crlflength )) {
235 in->pf_state |= PF_TRANSLATE;
236 lp_write( in, start, linelength + crlflength );
238 CONSUME( in, linelength + crlflength );
242 int ch_endtranslate(in,out)
243 struct papfile *in, *out _U_;
246 int linelength, crlflength;
249 LOG(log_debug, logtype_papd, "EndTranslate");
252 switch ( markline( in, &start, &linelength, &crlflength )) {
260 lp_write( in, start, linelength + crlflength );
261 in->pf_state &= ~PF_TRANSLATE;
263 CONSUME( in, linelength + crlflength );
267 int ch_translateone(in,out)
268 struct papfile *in, *out _U_;
271 int linelength, crlflength;
274 LOG(log_debug, logtype_papd, "TranslateOne");
277 switch ( markline( in, &start, &linelength, &crlflength )) {
285 in->pf_state |= PF_TRANSLATE;
286 lp_write( in, start, linelength + crlflength );
287 in->pf_state &= ~PF_TRANSLATE;
289 CONSUME( in, linelength + crlflength );
299 struct papd_comment headers[] = {
300 { "%%Title:", NULL, ch_title, 0 },
301 { "%%For:", NULL, ch_for, 0 },
302 { "%%Creator:", NULL, ch_creator, 0 },
303 { "%%EndComments", NULL, ch_endcomm, 0 },
304 { "%%BeginFeature", NULL, ch_starttranslate, 0 },
305 { "%%EndFeature", NULL, ch_endtranslate, 0 },
306 { "%%BeginPageSetup", NULL, ch_starttranslate, 0 },
307 { "%%EndPageSetup", NULL, ch_endtranslate, 0 },
309 { "%%BeginSetup", NULL, ch_translateone, 0 },
310 { "%%EndSetup", NULL, ch_translateone, 0 },
311 { "%%BeginProlog", NULL, ch_translateone, 0 },
312 { "%%EndProlog", NULL, ch_translateone, 0 },
313 { "%%Page:", NULL, ch_translateone, 0 },
314 { "%%PageTrailer", NULL, ch_translateone, 0 },
315 { "%%Trailer", NULL, ch_translateone, 0 },
316 { "%%EOF", NULL, ch_translateone, 0 },
318 { "%%", NULL, ch_translateone, 0 },
319 { NULL, NULL, NULL, 0 },