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