Fri, 21 Feb 2003 08:49:11 +0000
GPL.
eric@63 | 1 | /* |
eric@63 | 2 | * t2p: Create a PDF file from the contents of one or more TIFF |
eric@63 | 3 | * bilevel image files. The images in the resulting PDF file |
eric@63 | 4 | * will be compressed using ITU-T T.6 (G4) fax encoding. |
eric@63 | 5 | * |
eric@63 | 6 | * Parser |
eric@63 | 7 | * $Id: parser.y,v 1.17 2003/02/21 00:49:11 eric Exp $ |
eric@63 | 8 | * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> |
eric@63 | 9 | * |
eric@63 | 10 | * This program is free software; you can redistribute it and/or modify |
eric@63 | 11 | * it under the terms of the GNU General Public License version 2 as |
eric@63 | 12 | * published by the Free Software Foundation. Note that permission is |
eric@63 | 13 | * not granted to redistribute this program under the terms of any |
eric@63 | 14 | * other version of the General Public License. |
eric@63 | 15 | * |
eric@63 | 16 | * This program is distributed in the hope that it will be useful, |
eric@63 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
eric@63 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eric@63 | 19 | * GNU General Public License for more details. |
eric@63 | 20 | * |
eric@63 | 21 | * You should have received a copy of the GNU General Public License |
eric@63 | 22 | * along with this program; if not, write to the Free Software |
eric@63 | 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA |
eric@63 | 24 | */ |
eric@63 | 25 | |
eric@5 | 26 | %{ |
eric@48 | 27 | #include <stdbool.h> |
eric@48 | 28 | #include <stdint.h> |
eric@11 | 29 | #include <stdio.h> |
eric@17 | 30 | #include "semantics.h" |
eric@5 | 31 | %} |
eric@5 | 32 | |
eric@5 | 33 | %union { |
eric@5 | 34 | int integer; |
eric@27 | 35 | char character; |
eric@5 | 36 | double fp; |
eric@5 | 37 | char *string; |
eric@18 | 38 | page_size_t size; |
eric@18 | 39 | range_t range; |
eric@27 | 40 | page_label_t page_label; |
eric@5 | 41 | } |
eric@5 | 42 | |
eric@5 | 43 | %token <integer> INTEGER |
eric@5 | 44 | %token <fp> FLOAT |
eric@5 | 45 | %token <string> STRING |
eric@27 | 46 | %token <character> CHARACTER |
eric@9 | 47 | %token <size> PAGE_SIZE |
eric@5 | 48 | |
eric@7 | 49 | %token ELIPSIS |
eric@7 | 50 | |
eric@9 | 51 | %token CM |
eric@9 | 52 | %token INCH |
eric@9 | 53 | |
eric@5 | 54 | %token EVEN |
eric@5 | 55 | %token ODD |
eric@5 | 56 | %token ALL |
eric@5 | 57 | |
eric@9 | 58 | %token PORTRAIT |
eric@9 | 59 | %token LANDSCAPE |
eric@9 | 60 | |
eric@11 | 61 | %token FILE_KEYWORD |
eric@5 | 62 | %token IMAGE |
eric@9 | 63 | %token IMAGES |
eric@5 | 64 | %token ROTATE |
eric@5 | 65 | %token CROP |
eric@5 | 66 | %token SIZE |
eric@11 | 67 | %token RESOLUTION |
eric@5 | 68 | %token INPUT |
eric@5 | 69 | |
eric@27 | 70 | %token LABEL |
eric@5 | 71 | %token PAGE |
eric@8 | 72 | %token PAGES |
eric@5 | 73 | %token BOOKMARK |
eric@5 | 74 | %token OUTPUT |
eric@5 | 75 | |
eric@30 | 76 | %token AUTHOR |
eric@30 | 77 | %token CREATOR |
eric@30 | 78 | %token TITLE |
eric@30 | 79 | %token SUBJECT |
eric@30 | 80 | %token KEYWORDS |
eric@30 | 81 | |
eric@11 | 82 | %type <range> range |
eric@11 | 83 | %type <range> image_ranges |
eric@11 | 84 | %type <range> page_ranges |
eric@11 | 85 | |
eric@11 | 86 | %type <fp> unit |
eric@11 | 87 | |
eric@32 | 88 | %type <fp> length |
eric@9 | 89 | |
eric@32 | 90 | %type <integer> orientation |
eric@32 | 91 | |
eric@32 | 92 | %type <size> page_size |
eric@5 | 93 | |
eric@5 | 94 | %% |
eric@5 | 95 | |
eric@9 | 96 | statements: |
eric@9 | 97 | statement |
eric@9 | 98 | | statements statement ; |
eric@5 | 99 | |
eric@9 | 100 | statement: |
eric@9 | 101 | input_statement |
eric@9 | 102 | | output_statement ; |
eric@5 | 103 | |
eric@5 | 104 | |
eric@11 | 105 | range: |
eric@11 | 106 | INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; } |
eric@11 | 107 | | INTEGER { $$.first = $1; $$.last = $1; } ; |
eric@5 | 108 | |
eric@9 | 109 | image_ranges: |
eric@20 | 110 | range { input_images ($1); } |
eric@20 | 111 | | image_ranges ',' range { input_images ($3); } ; |
eric@5 | 112 | |
eric@5 | 113 | |
eric@12 | 114 | input_file_clause: |
eric@17 | 115 | FILE_KEYWORD STRING ';' { input_set_file ($2) } ; |
eric@5 | 116 | |
eric@5 | 117 | image_clause: |
eric@20 | 118 | IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ; |
eric@9 | 119 | |
eric@9 | 120 | images_clause: |
eric@19 | 121 | IMAGES image_ranges ';' ; |
eric@5 | 122 | |
eric@5 | 123 | rotate_clause: |
eric@20 | 124 | ROTATE INTEGER ';' { input_set_rotation ($2) } ; |
eric@5 | 125 | |
eric@9 | 126 | unit: |
eric@32 | 127 | /* empty */ /* default to INCH */ { $$ = 1.0; } |
eric@32 | 128 | | CM { $$ = (1.0 / 25.4); } |
eric@32 | 129 | | INCH { $$ = 1.0; } ; |
eric@9 | 130 | |
eric@9 | 131 | length: |
eric@11 | 132 | FLOAT unit { $$ = $1 * $2; } ; |
eric@9 | 133 | |
eric@5 | 134 | crop_clause: |
eric@9 | 135 | CROP PAGE_SIZE ';' |
eric@9 | 136 | | CROP PAGE_SIZE orientation ';' |
eric@9 | 137 | | CROP length ',' length ';' |
eric@9 | 138 | | CROP length ',' length ',' length ',' length ';' ; |
eric@9 | 139 | |
eric@9 | 140 | orientation: |
eric@32 | 141 | PORTRAIT { $$ = 0; } |
eric@32 | 142 | | LANDSCAPE { $$ = 1; } ; |
eric@32 | 143 | |
eric@32 | 144 | page_size: |
eric@32 | 145 | PAGE_SIZE { $$ = $1; } |
eric@32 | 146 | | PAGE_SIZE orientation { if ($2) |
eric@32 | 147 | { |
eric@32 | 148 | $$.width = $1.height; |
eric@32 | 149 | $$.height = $1.width; |
eric@32 | 150 | } |
eric@32 | 151 | else |
eric@32 | 152 | $$ = $1; |
eric@32 | 153 | } |
eric@32 | 154 | | length ',' length { $$.width = $1; $$.height = $3; } ; |
eric@5 | 155 | |
eric@5 | 156 | size_clause: |
eric@32 | 157 | SIZE page_size ';' { input_set_page_size ($2); } ; |
eric@9 | 158 | |
eric@11 | 159 | resolution_clause: |
eric@11 | 160 | RESOLUTION FLOAT unit ; |
eric@11 | 161 | |
eric@9 | 162 | modifier_clause: |
eric@11 | 163 | rotate_clause | crop_clause | size_clause | resolution_clause; |
eric@9 | 164 | |
eric@9 | 165 | modifier_clauses: |
eric@9 | 166 | modifier_clause |
eric@9 | 167 | | modifier_clauses modifier_clause; |
eric@9 | 168 | |
eric@9 | 169 | modifier_clause_list: |
eric@9 | 170 | '{' modifier_clauses '}' ; |
eric@5 | 171 | |
eric@5 | 172 | part_clause: |
eric@19 | 173 | ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); } |
eric@19 | 174 | modifier_clause_list ';' |
eric@19 | 175 | { input_set_modifier_context (INPUT_MODIFIER_ALL); } |
eric@20 | 176 | | EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); } |
eric@19 | 177 | modifier_clause_list ';' |
eric@19 | 178 | { input_set_modifier_context (INPUT_MODIFIER_ALL); } ; |
eric@5 | 179 | |
eric@5 | 180 | input_clause: |
eric@12 | 181 | input_file_clause |
eric@9 | 182 | | image_clause |
eric@9 | 183 | | images_clause |
eric@19 | 184 | | part_clause |
eric@9 | 185 | | modifier_clause |
eric@7 | 186 | | input_clause_list ; |
eric@5 | 187 | |
eric@5 | 188 | input_clauses: |
eric@5 | 189 | input_clause |
eric@7 | 190 | | input_clauses input_clause ; |
eric@7 | 191 | |
eric@7 | 192 | input_clause_list: |
eric@7 | 193 | '{' input_clauses '}' ; |
eric@5 | 194 | |
eric@5 | 195 | input_statement: |
eric@8 | 196 | INPUT input_clauses ; |
eric@5 | 197 | |
eric@30 | 198 | pdf_file_attribute: |
eric@30 | 199 | AUTHOR STRING { output_set_author ($2); } |
eric@30 | 200 | | CREATOR STRING { output_set_creator ($2); } |
eric@30 | 201 | | TITLE STRING { output_set_title ($2); } |
eric@30 | 202 | | SUBJECT STRING { output_set_subject ($2); } |
eric@30 | 203 | | KEYWORDS STRING { output_set_keywords ($2); } ; |
eric@30 | 204 | |
eric@31 | 205 | pdf_file_attribute_list: |
eric@31 | 206 | pdf_file_attribute |
eric@31 | 207 | | pdf_file_attribute_list pdf_file_attribute ; |
eric@31 | 208 | |
eric@30 | 209 | pdf_file_attributes: |
eric@30 | 210 | /* empty */ |
eric@31 | 211 | | pdf_file_attribute_list ; |
eric@30 | 212 | |
eric@12 | 213 | output_file_clause: |
eric@30 | 214 | FILE_KEYWORD STRING { output_set_file ($2); } |
eric@48 | 215 | pdf_file_attributes ';' ; |
eric@12 | 216 | |
eric@27 | 217 | label_clause: |
eric@27 | 218 | LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); } |
eric@27 | 219 | | LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); } |
eric@27 | 220 | | LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); } |
eric@27 | 221 | | LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ; |
eric@20 | 222 | |
eric@9 | 223 | page_ranges: |
eric@20 | 224 | range { output_pages ($1); } |
eric@20 | 225 | | page_ranges ',' range { output_pages ($3); } ; |
eric@9 | 226 | |
eric@5 | 227 | page_clause: |
eric@20 | 228 | PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ; |
eric@8 | 229 | |
eric@8 | 230 | pages_clause: |
eric@20 | 231 | PAGES page_ranges ';' ; |
eric@20 | 232 | |
eric@20 | 233 | bookmark_name: |
eric@20 | 234 | STRING { output_set_bookmark ($1); } ; |
eric@20 | 235 | |
eric@20 | 236 | bookmark_name_list: |
eric@20 | 237 | bookmark_name |
eric@20 | 238 | | bookmark_name_list ',' bookmark_name ; |
eric@5 | 239 | |
eric@5 | 240 | bookmark_clause: |
eric@27 | 241 | BOOKMARK { output_push_context (); bookmark_level++; } |
eric@20 | 242 | bookmark_name_list |
eric@27 | 243 | output_clause_list ';' { bookmark_level--; output_pop_context (); } ; |
eric@5 | 244 | |
eric@5 | 245 | output_clause: |
eric@12 | 246 | output_file_clause |
eric@27 | 247 | | label_clause |
eric@12 | 248 | | page_clause | pages_clause |
eric@12 | 249 | | bookmark_clause |
eric@7 | 250 | | output_clause_list ; |
eric@5 | 251 | |
eric@5 | 252 | output_clauses: |
eric@5 | 253 | output_clause |
eric@7 | 254 | | output_clauses output_clause ; |
eric@7 | 255 | |
eric@7 | 256 | output_clause_list: |
eric@20 | 257 | '{' { output_push_context (); } |
eric@20 | 258 | output_clauses '}' { output_pop_context (); } ; |
eric@5 | 259 | |
eric@5 | 260 | output_statement: |
eric@8 | 261 | OUTPUT output_clauses ; |