2 * $Id: headers.c,v 1.12 2009-02-02 10:31:32 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++ ) {
84 struct papfile *in, *out _U_;
87 int linelength, crlflength;
89 switch ( markline( in, &start, &linelength, &crlflength )) {
100 cmt = get_text(start, linelength);
107 in->pf_state |= PF_TRANSLATE;
108 lp_write( in, start, linelength + crlflength );
109 in->pf_state &= ~PF_TRANSLATE;
111 CONSUME( in, linelength + crlflength );
115 int ch_title( in, out )
116 struct papfile *in, *out _U_;
119 int linelength, crlflength;
121 switch ( markline( in, &start, &linelength, &crlflength )) {
133 LOG(log_debug, logtype_papd, "Parsing %%Title");
136 cmt = get_text(start, linelength);
143 in->pf_state |= PF_TRANSLATE;
144 lp_write( in, start, linelength + crlflength );
145 in->pf_state &= ~PF_TRANSLATE;
147 CONSUME( in, linelength + crlflength );
151 static int guess_creator ( char *creator )
153 if (strstr(creator, "LaserWriter"))
155 if (strstr(creator, "cgpdftops"))
162 int ch_creator( in, out )
163 struct papfile *in, *out _U_;
166 int linelength, crlflength;
168 switch ( markline( in, &start, &linelength, &crlflength )) {
179 cmt = get_text(start, linelength);
182 in->origin = guess_creator ( cmt );
184 lp_origin(in->origin);
187 in->pf_state |= PF_TRANSLATE;
188 lp_write( in, start, linelength + crlflength );
189 in->pf_state &= ~PF_TRANSLATE;
191 CONSUME( in, linelength + crlflength );
195 int ch_endcomm( in, out )
196 struct papfile *in, *out _U_;
199 int linelength, crlflength;
202 LOG(log_debug, logtype_papd, "End Comment");
204 in->pf_state |= PF_STW;
206 switch ( markline( in, &start, &linelength, &crlflength )) {
217 in->pf_state |= PF_TRANSLATE;
218 lp_write( in, start, linelength + crlflength );
219 in->pf_state &= ~PF_TRANSLATE;
221 CONSUME( in, linelength + crlflength );
225 int ch_starttranslate(in,out)
226 struct papfile *in, *out _U_;
229 int linelength, crlflength;
232 LOG(log_debug, logtype_papd, "Start translate");
235 switch ( markline( in, &start, &linelength, &crlflength )) {
246 in->pf_state |= PF_TRANSLATE;
247 lp_write( in, start, linelength + crlflength );
249 CONSUME( in, linelength + crlflength );
253 int ch_endtranslate(in,out)
254 struct papfile *in, *out _U_;
257 int linelength, crlflength;
260 LOG(log_debug, logtype_papd, "EndTranslate");
263 switch ( markline( in, &start, &linelength, &crlflength )) {
274 lp_write( in, start, linelength + crlflength );
275 in->pf_state &= ~PF_TRANSLATE;
277 CONSUME( in, linelength + crlflength );
281 int ch_translateone(in,out)
282 struct papfile *in, *out _U_;
285 int linelength, crlflength;
288 LOG(log_debug, logtype_papd, "TranslateOne");
291 switch ( markline( in, &start, &linelength, &crlflength )) {
302 in->pf_state |= PF_TRANSLATE;
303 lp_write( in, start, linelength + crlflength );
304 in->pf_state &= ~PF_TRANSLATE;
306 CONSUME( in, linelength + crlflength );
316 struct papd_comment headers[] = {
317 { "%%Title:", NULL, ch_title, 0 },
318 { "%%For:", NULL, ch_for, 0 },
319 { "%%Creator:", NULL, ch_creator, 0 },
320 { "%%EndComments", NULL, ch_endcomm, 0 },
321 { "%%BeginFeature", NULL, ch_starttranslate, 0 },
322 { "%%EndFeature", NULL, ch_endtranslate, 0 },
323 { "%%BeginPageSetup", NULL, ch_starttranslate, 0 },
324 { "%%EndPageSetup", NULL, ch_endtranslate, 0 },
326 { "%%BeginSetup", NULL, ch_translateone, 0 },
327 { "%%EndSetup", NULL, ch_translateone, 0 },
328 { "%%BeginProlog", NULL, ch_translateone, 0 },
329 { "%%EndProlog", NULL, ch_translateone, 0 },
330 { "%%Page:", NULL, ch_translateone, 0 },
331 { "%%PageTrailer", NULL, ch_translateone, 0 },
332 { "%%Trailer", NULL, ch_translateone, 0 },
333 { "%%EOF", NULL, ch_translateone, 0 },
335 { "%%", NULL, ch_translateone, 0 },
336 { NULL, NULL, NULL, 0 },