Tue, 01 Jan 2002 06:11:43 +0000
add support for PDF file attributes: author, creator, title, etc.
parser.y | file | annotate | diff | revisions | |
scanner.l | file | annotate | diff | revisions | |
semantics.c | file | annotate | diff | revisions | |
semantics.h | file | annotate | diff | revisions | |
t2p.c | file | annotate | diff | revisions | |
t2p.h | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions | |
tumble.h | file | annotate | diff | revisions |
1.1 --- a/parser.y Tue Jan 01 05:41:03 2002 +0000 1.2 +++ b/parser.y Tue Jan 01 06:11:43 2002 +0000 1.3 @@ -47,6 +47,12 @@ 1.4 %token BOOKMARK 1.5 %token OUTPUT 1.6 1.7 +%token AUTHOR 1.8 +%token CREATOR 1.9 +%token TITLE 1.10 +%token SUBJECT 1.11 +%token KEYWORDS 1.12 + 1.13 %type <range> range 1.14 %type <range> image_ranges 1.15 %type <range> page_ranges 1.16 @@ -151,8 +157,21 @@ 1.17 input_statement: 1.18 INPUT input_clauses ; 1.19 1.20 +pdf_file_attribute: 1.21 + AUTHOR STRING { output_set_author ($2); } 1.22 + | CREATOR STRING { output_set_creator ($2); } 1.23 + | TITLE STRING { output_set_title ($2); } 1.24 + | SUBJECT STRING { output_set_subject ($2); } 1.25 + | KEYWORDS STRING { output_set_keywords ($2); } ; 1.26 + 1.27 +pdf_file_attributes: 1.28 + /* empty */ 1.29 + | pdf_file_attribute 1.30 + | pdf_file_attributes pdf_file_attribute ; 1.31 + 1.32 output_file_clause: 1.33 - FILE_KEYWORD STRING ';' { output_set_file ($2) } ; 1.34 + FILE_KEYWORD STRING { output_set_file ($2); } 1.35 + pdf_file_attributes ';' 1.36 1.37 label_clause: 1.38 LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
2.1 --- a/scanner.l Tue Jan 01 05:41:03 2002 +0000 2.2 +++ b/scanner.l Tue Jan 01 06:11:43 2002 +0000 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 -$Id: scanner.l,v 1.12 2001/12/31 19:46:08 eric Exp $ 2.6 +$Id: scanner.l,v 1.13 2001/12/31 22:11:43 eric Exp $ 2.7 */ 2.8 2.9 %option case-insensitive 2.10 @@ -49,8 +49,10 @@ 2.11 return (PAGE_SIZE); } 2.12 2.13 all { return (ALL); } 2.14 +author { return (AUTHOR); } 2.15 bookmark { return (BOOKMARK); } 2.16 cm { return (CM); } 2.17 +creator { return (CREATOR); } 2.18 crop { return (CROP); } 2.19 even { return (EVEN); } 2.20 file { return (FILE_KEYWORD); } 2.21 @@ -58,6 +60,7 @@ 2.22 images { return (IMAGES); } 2.23 inch { return (INCH); } 2.24 input { return (INPUT); } 2.25 +keywords { return (KEYWORDS); } 2.26 label { return (LABEL); } 2.27 landscape { return (LANDSCAPE); } 2.28 odd { return (ODD); } 2.29 @@ -68,6 +71,8 @@ 2.30 resolution { return (RESOLUTION) ; } 2.31 rotate { return (ROTATE); } 2.32 size { return (SIZE); } 2.33 +subject { return (SUBJECT); } 2.34 +title { return (TITLE); } 2.35 2.36 '[^\n']' { 2.37 yylval.character = yytext [1];
3.1 --- a/semantics.c Tue Jan 01 05:41:03 2002 +0000 3.2 +++ b/semantics.c Tue Jan 01 06:11:43 2002 +0000 3.3 @@ -52,6 +52,8 @@ 3.4 including those from subcontexts */ 3.5 3.6 char *output_file; 3.7 + pdf_file_attributes_t file_attributes; 3.8 + 3.9 bookmark_t *first_bookmark; 3.10 bookmark_t *last_bookmark; 3.11 3.12 @@ -285,8 +287,38 @@ 3.13 { 3.14 output_clone (); 3.15 last_output_context->output_file = name; 3.16 + last_output_context->file_attributes.author = NULL; 3.17 + last_output_context->file_attributes.creator = NULL; 3.18 + last_output_context->file_attributes.title = NULL; 3.19 + last_output_context->file_attributes.subject = NULL; 3.20 + last_output_context->file_attributes.keywords = NULL; 3.21 }; 3.22 3.23 +void output_set_author (char *author) 3.24 +{ 3.25 + last_output_context->file_attributes.author = author; 3.26 +} 3.27 + 3.28 +void output_set_creator (char *creator) 3.29 +{ 3.30 + last_output_context->file_attributes.creator = creator; 3.31 +} 3.32 + 3.33 +void output_set_title (char *title) 3.34 +{ 3.35 + last_output_context->file_attributes.title = title; 3.36 +} 3.37 + 3.38 +void output_set_subject (char *subject) 3.39 +{ 3.40 + last_output_context->file_attributes.subject = subject; 3.41 +} 3.42 + 3.43 +void output_set_keywords (char *keywords) 3.44 +{ 3.45 + last_output_context->file_attributes.keywords = keywords; 3.46 +} 3.47 + 3.48 void output_set_bookmark (char *name) 3.49 { 3.50 bookmark_t *new_bookmark; 3.51 @@ -408,7 +440,16 @@ 3.52 for (; context; context = context->parent) 3.53 if (context->output_file) 3.54 return (context->output_file); 3.55 - fprintf (stderr, "no output file name found\n"); 3.56 + fprintf (stderr, "no output file found\n"); 3.57 + exit (2); 3.58 +} 3.59 + 3.60 +static pdf_file_attributes_t *get_output_file_attributes (output_context_t *context) 3.61 +{ 3.62 + for (; context; context = context->parent) 3.63 + if (context->output_file) 3.64 + return (& context->file_attributes); 3.65 + fprintf (stderr, "no output file found\n"); 3.66 exit (2); 3.67 } 3.68 3.69 @@ -557,7 +598,8 @@ 3.70 else 3.71 page = first_output_page; 3.72 p = 0; 3.73 - if (! open_pdf_output_file (get_output_file (page->output_context))) 3.74 + if (! open_pdf_output_file (get_output_file (page->output_context), 3.75 + get_output_file_attributes (page->output_context))) 3.76 return (0); 3.77 page_label = get_output_page_label (page->output_context); 3.78 process_page_numbers (page_index,
4.1 --- a/semantics.h Tue Jan 01 05:41:03 2002 +0000 4.2 +++ b/semantics.h Tue Jan 01 06:11:43 2002 +0000 4.3 @@ -57,7 +57,14 @@ 4.4 /* semantic routines for output statements */ 4.5 void output_push_context (void); 4.6 void output_pop_context (void); 4.7 + 4.8 void output_set_file (char *name); 4.9 +void output_set_author (char *author); 4.10 +void output_set_creator (char *creator); 4.11 +void output_set_title (char *title); 4.12 +void output_set_subject (char *subject); 4.13 +void output_set_keywords (char *keywords); 4.14 + 4.15 void output_set_bookmark (char *name); 4.16 void output_set_page_label (page_label_t label); 4.17 void output_pages (range_t range);
5.1 --- a/t2p.c Tue Jan 01 05:41:03 2002 +0000 5.2 +++ b/t2p.c Tue Jan 01 06:11:43 2002 +0000 5.3 @@ -5,7 +5,7 @@ 5.4 * encoding. 5.5 * 5.6 * Main program 5.7 - * $Id: t2p.c,v 1.10 2001/12/31 21:41:03 eric Exp $ 5.8 + * $Id: t2p.c,v 1.11 2001/12/31 22:11:43 eric Exp $ 5.9 * Copyright 2001 Eric Smith <eric@brouhaha.com> 5.10 * 5.11 * This program is free software; you can redistribute it and/or modify 5.12 @@ -114,7 +114,8 @@ 5.13 return (1); 5.14 } 5.15 5.16 -boolean open_pdf_output_file (char *name) 5.17 +boolean open_pdf_output_file (char *name, 5.18 + pdf_file_attributes_t *attributes) 5.19 { 5.20 output_file_t *o; 5.21 5.22 @@ -150,6 +151,17 @@ 5.23 return (0); 5.24 } 5.25 5.26 + if (attributes->author) 5.27 + panda_setauthor (o->pdf, attributes->author); 5.28 + if (attributes->creator) 5.29 + panda_setcreator (o->pdf, attributes->creator); 5.30 + if (attributes->title) 5.31 + panda_settitle (o->pdf, attributes->title); 5.32 + if (attributes->subject) 5.33 + panda_setsubject (o->pdf, attributes->subject); 5.34 + if (attributes->keywords) 5.35 + panda_setkeywords (o->pdf, attributes->keywords); 5.36 + 5.37 /* prepend new output file onto list */ 5.38 o->next = output_files; 5.39 output_files = o;
6.1 --- a/t2p.h Tue Jan 01 05:41:03 2002 +0000 6.2 +++ b/t2p.h Tue Jan 01 06:11:43 2002 +0000 6.3 @@ -8,7 +8,19 @@ 6.4 boolean open_tiff_input_file (char *name); 6.5 boolean close_tiff_input_file (void); 6.6 6.7 -boolean open_pdf_output_file (char *name); 6.8 + 6.9 +typedef struct 6.10 +{ 6.11 + char *author; 6.12 + char *creator; 6.13 + char *title; 6.14 + char *subject; 6.15 + char *keywords; 6.16 +} pdf_file_attributes_t; 6.17 + 6.18 +boolean open_pdf_output_file (char *name, 6.19 + pdf_file_attributes_t *attributes); 6.20 + 6.21 6.22 void process_page_numbers (int page_index, 6.23 int count,
7.1 --- a/tumble.c Tue Jan 01 05:41:03 2002 +0000 7.2 +++ b/tumble.c Tue Jan 01 06:11:43 2002 +0000 7.3 @@ -5,7 +5,7 @@ 7.4 * encoding. 7.5 * 7.6 * Main program 7.7 - * $Id: tumble.c,v 1.10 2001/12/31 21:41:03 eric Exp $ 7.8 + * $Id: tumble.c,v 1.11 2001/12/31 22:11:43 eric Exp $ 7.9 * Copyright 2001 Eric Smith <eric@brouhaha.com> 7.10 * 7.11 * This program is free software; you can redistribute it and/or modify 7.12 @@ -114,7 +114,8 @@ 7.13 return (1); 7.14 } 7.15 7.16 -boolean open_pdf_output_file (char *name) 7.17 +boolean open_pdf_output_file (char *name, 7.18 + pdf_file_attributes_t *attributes) 7.19 { 7.20 output_file_t *o; 7.21 7.22 @@ -150,6 +151,17 @@ 7.23 return (0); 7.24 } 7.25 7.26 + if (attributes->author) 7.27 + panda_setauthor (o->pdf, attributes->author); 7.28 + if (attributes->creator) 7.29 + panda_setcreator (o->pdf, attributes->creator); 7.30 + if (attributes->title) 7.31 + panda_settitle (o->pdf, attributes->title); 7.32 + if (attributes->subject) 7.33 + panda_setsubject (o->pdf, attributes->subject); 7.34 + if (attributes->keywords) 7.35 + panda_setkeywords (o->pdf, attributes->keywords); 7.36 + 7.37 /* prepend new output file onto list */ 7.38 o->next = output_files; 7.39 output_files = o;
8.1 --- a/tumble.h Tue Jan 01 05:41:03 2002 +0000 8.2 +++ b/tumble.h Tue Jan 01 06:11:43 2002 +0000 8.3 @@ -8,7 +8,19 @@ 8.4 boolean open_tiff_input_file (char *name); 8.5 boolean close_tiff_input_file (void); 8.6 8.7 -boolean open_pdf_output_file (char *name); 8.8 + 8.9 +typedef struct 8.10 +{ 8.11 + char *author; 8.12 + char *creator; 8.13 + char *title; 8.14 + char *subject; 8.15 + char *keywords; 8.16 +} pdf_file_attributes_t; 8.17 + 8.18 +boolean open_pdf_output_file (char *name, 8.19 + pdf_file_attributes_t *attributes); 8.20 + 8.21 8.22 void process_page_numbers (int page_index, 8.23 int count,