diff --git a/pdf.c b/pdf.c index df57b4dae5700290a208f83158a029701309413e..678788d039042d77fefc99416a206fb7a25fa76a 100644 --- a/pdf.c +++ b/pdf.c @@ -17,6 +17,12 @@ #define IN(STR) h_in((const uint8_t *)(STR), sizeof(STR) - 1) #define NOT_IN(STR) h_not_in((const uint8_t *)(STR), sizeof(STR) - 1) +#ifdef LOG +#define WARN(P,MSG) h_action(P, act_warn, (char *) MSG) +#else +#define WARN(P,MSG) P +#endif + /* * some helpers @@ -29,6 +35,14 @@ HParser *p_return_1; /* a combinator to parse a given character but return a different value */ +HParsedToken * +act_warn(const HParseResult *p, void *warnstring) +{ + fprintf(stderr, "WARNING: %s\n", (char *) warnstring); + return (HParsedToken *) p->ast; +} + + HParsedToken * act_return_uint(const HParseResult *p, void *u) { @@ -667,7 +681,8 @@ init_parser(struct Env *aux) // NB: lws before xref offset is allowed, cf. p.48 (example 4) H_RULE(xr_td, SEQ(xrefs, KW("trailer"), ws, dict)); - H_RULE(junk, h_many1(h_butnot(h_ch_range(0, 255), objdef))); + H_RULE(hdr_junk, WARN(h_many1(h_butnot(h_ch_range(0, 255), objdef)), + "Junk after header")); H_RULE(tail, SEQ(body, h_optional(xr_td), startxr)); // XXX the real world likes to omit 'startxr' from all but the // last trailer. we should accept-and-warn in that case.