2 * $Id: headers.c,v 1.13 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 <sys/param.h>
17 #include <netatalk/at.h>
18 #include <atalk/logger.h>
24 int ch_title( struct papfile *, struct papfile * );
25 int ch_for( struct papfile *, struct papfile * );
27 static char *get_text(char *start, int linelength)
33 /* 1023 is arbitrary 255 max for comment but some may be escape \xxx and space and keyword */
35 if (linelength > 1023)
38 t = ret = calloc(1, linelength +1);
43 stop = start + linelength;
44 for ( p = start; p < stop; p++ ) {
51 for ( ; p < stop; p++ ) {
52 if (*p != ' ' && *p != '\t') {
57 if ( p < stop && *p == '(' ) {
59 /* start with ( then it's a <text> */
61 for ( q = p, count = 1; q < stop; q++, t++ ) {
65 else if ( *q == ')' ) {
76 for ( q = p; q < stop; q++, t++ ) {
83 int ch_for( struct papfile *in, struct papfile *out _U_)
86 int linelength, crlflength;
88 switch ( markline( in, &start, &linelength, &crlflength )) {
99 cmt = get_text(start, linelength);
106 in->pf_state |= PF_TRANSLATE;
107 lp_write( in, start, linelength + crlflength );
108 in->pf_state &= ~PF_TRANSLATE;
110 CONSUME( in, linelength + crlflength );
114 int ch_title( struct papfile *in, struct papfile *out _U_)
117 int linelength, crlflength;
119 switch ( markline( in, &start, &linelength, &crlflength )) {
131 LOG(log_debug, logtype_papd, "Parsing %%Title");
134 cmt = get_text(start, linelength);
141 in->pf_state |= PF_TRANSLATE;
142 lp_write( in, start, linelength + crlflength );
143 in->pf_state &= ~PF_TRANSLATE;
145 CONSUME( in, linelength + crlflength );
149 static int guess_creator ( char *creator )
151 if (strstr(creator, "LaserWriter"))
153 if (strstr(creator, "cgpdftops"))
160 int ch_creator( struct papfile *in, struct papfile *out _U_)
163 int linelength, crlflength;
165 switch ( markline( in, &start, &linelength, &crlflength )) {
176 cmt = get_text(start, linelength);
179 in->origin = guess_creator ( cmt );
181 lp_origin(in->origin);
184 in->pf_state |= PF_TRANSLATE;
185 lp_write( in, start, linelength + crlflength );
186 in->pf_state &= ~PF_TRANSLATE;
188 CONSUME( in, linelength + crlflength );
192 int ch_endcomm( struct papfile *in, struct papfile *out _U_)
195 int linelength, crlflength;
198 LOG(log_debug, logtype_papd, "End Comment");
200 in->pf_state |= PF_STW;
202 switch ( markline( in, &start, &linelength, &crlflength )) {
213 in->pf_state |= PF_TRANSLATE;
214 lp_write( in, start, linelength + crlflength );
215 in->pf_state &= ~PF_TRANSLATE;
217 CONSUME( in, linelength + crlflength );
221 int ch_starttranslate( struct papfile *in, struct papfile *out _U_)
224 int linelength, crlflength;
227 LOG(log_debug, logtype_papd, "Start translate");
230 switch ( markline( in, &start, &linelength, &crlflength )) {
241 in->pf_state |= PF_TRANSLATE;
242 lp_write( in, start, linelength + crlflength );
244 CONSUME( in, linelength + crlflength );
248 int ch_endtranslate(struct papfile *in, struct papfile *out _U_)
251 int linelength, crlflength;
254 LOG(log_debug, logtype_papd, "EndTranslate");
257 switch ( markline( in, &start, &linelength, &crlflength )) {
268 lp_write( in, start, linelength + crlflength );
269 in->pf_state &= ~PF_TRANSLATE;
271 CONSUME( in, linelength + crlflength );
275 int ch_translateone( struct papfile *in, struct papfile *out _U_)
278 int linelength, crlflength;
281 LOG(log_debug, logtype_papd, "TranslateOne");
284 switch ( markline( in, &start, &linelength, &crlflength )) {
295 in->pf_state |= PF_TRANSLATE;
296 lp_write( in, start, linelength + crlflength );
297 in->pf_state &= ~PF_TRANSLATE;
299 CONSUME( in, linelength + crlflength );
309 struct papd_comment headers[] = {
310 { "%%Title:", NULL, ch_title, 0 },
311 { "%%For:", NULL, ch_for, 0 },
312 { "%%Creator:", NULL, ch_creator, 0 },
313 { "%%EndComments", NULL, ch_endcomm, 0 },
314 { "%%BeginFeature", NULL, ch_starttranslate, 0 },
315 { "%%EndFeature", NULL, ch_endtranslate, 0 },
316 { "%%BeginPageSetup", NULL, ch_starttranslate, 0 },
317 { "%%EndPageSetup", NULL, ch_endtranslate, 0 },
319 { "%%BeginSetup", NULL, ch_translateone, 0 },
320 { "%%EndSetup", NULL, ch_translateone, 0 },
321 { "%%BeginProlog", NULL, ch_translateone, 0 },
322 { "%%EndProlog", NULL, ch_translateone, 0 },
323 { "%%Page:", NULL, ch_translateone, 0 },
324 { "%%PageTrailer", NULL, ch_translateone, 0 },
325 { "%%Trailer", NULL, ch_translateone, 0 },
326 { "%%EOF", NULL, ch_translateone, 0 },
328 { "%%", NULL, ch_translateone, 0 },
329 { NULL, NULL, NULL, 0 },