2 * $Id: headers.c,v 1.11 2008-08-14 19:57:52 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 )) {
97 cmt = get_text(start, linelength);
104 in->pf_state |= PF_TRANSLATE;
105 lp_write( in, start, linelength + crlflength );
106 in->pf_state &= ~PF_TRANSLATE;
108 CONSUME( in, linelength + crlflength );
112 int ch_title( in, out )
113 struct papfile *in, *out _U_;
116 int linelength, crlflength;
118 switch ( markline( in, &start, &linelength, &crlflength )) {
127 LOG(log_debug, logtype_papd, "Parsing %%Title");
130 cmt = get_text(start, linelength);
137 in->pf_state |= PF_TRANSLATE;
138 lp_write( in, start, linelength + crlflength );
139 in->pf_state &= ~PF_TRANSLATE;
141 CONSUME( in, linelength + crlflength );
145 static int guess_creator ( char *creator )
147 if (strstr(creator, "LaserWriter"))
149 if (strstr(creator, "cgpdftops"))
156 int ch_creator( in, out )
157 struct papfile *in, *out _U_;
160 int linelength, crlflength;
162 switch ( markline( in, &start, &linelength, &crlflength )) {
170 cmt = get_text(start, linelength);
173 in->origin = guess_creator ( cmt );
175 lp_origin(in->origin);
178 in->pf_state |= PF_TRANSLATE;
179 lp_write( in, start, linelength + crlflength );
180 in->pf_state &= ~PF_TRANSLATE;
182 CONSUME( in, linelength + crlflength );
186 int ch_endcomm( in, out )
187 struct papfile *in, *out _U_;
190 int linelength, crlflength;
193 LOG(log_debug, logtype_papd, "End Comment");
195 in->pf_state |= PF_STW;
197 switch ( markline( in, &start, &linelength, &crlflength )) {
205 in->pf_state |= PF_TRANSLATE;
206 lp_write( in, start, linelength + crlflength );
207 in->pf_state &= ~PF_TRANSLATE;
209 CONSUME( in, linelength + crlflength );
213 int ch_starttranslate(in,out)
214 struct papfile *in, *out _U_;
217 int linelength, crlflength;
220 LOG(log_debug, logtype_papd, "Start translate");
223 switch ( markline( in, &start, &linelength, &crlflength )) {
231 in->pf_state |= PF_TRANSLATE;
232 lp_write( in, start, linelength + crlflength );
234 CONSUME( in, linelength + crlflength );
238 int ch_endtranslate(in,out)
239 struct papfile *in, *out _U_;
242 int linelength, crlflength;
245 LOG(log_debug, logtype_papd, "EndTranslate");
248 switch ( markline( in, &start, &linelength, &crlflength )) {
256 lp_write( in, start, linelength + crlflength );
257 in->pf_state &= ~PF_TRANSLATE;
259 CONSUME( in, linelength + crlflength );
263 int ch_translateone(in,out)
264 struct papfile *in, *out _U_;
267 int linelength, crlflength;
270 LOG(log_debug, logtype_papd, "TranslateOne");
273 switch ( markline( in, &start, &linelength, &crlflength )) {
281 in->pf_state |= PF_TRANSLATE;
282 lp_write( in, start, linelength + crlflength );
283 in->pf_state &= ~PF_TRANSLATE;
285 CONSUME( in, linelength + crlflength );
295 struct papd_comment headers[] = {
296 { "%%Title:", NULL, ch_title, 0 },
297 { "%%For:", NULL, ch_for, 0 },
298 { "%%Creator:", NULL, ch_creator, 0 },
299 { "%%EndComments", NULL, ch_endcomm, 0 },
300 { "%%BeginFeature", NULL, ch_starttranslate, 0 },
301 { "%%EndFeature", NULL, ch_endtranslate, 0 },
302 { "%%BeginPageSetup", NULL, ch_starttranslate, 0 },
303 { "%%EndPageSetup", NULL, ch_endtranslate, 0 },
305 { "%%BeginSetup", NULL, ch_translateone, 0 },
306 { "%%EndSetup", NULL, ch_translateone, 0 },
307 { "%%BeginProlog", NULL, ch_translateone, 0 },
308 { "%%EndProlog", NULL, ch_translateone, 0 },
309 { "%%Page:", NULL, ch_translateone, 0 },
310 { "%%PageTrailer", NULL, ch_translateone, 0 },
311 { "%%Trailer", NULL, ch_translateone, 0 },
312 { "%%EOF", NULL, ch_translateone, 0 },
314 { "%%", NULL, ch_translateone, 0 },
315 { NULL, NULL, NULL, 0 },