Debian Codegraph @

src/gutenprintui2/printrcy.y

raw
1 /*
2 *
3 * Test pattern generator for Gutenprint
4 *
5 * Copyright 2001 Robert Krawitz <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 %{
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <gutenprint/gutenprint-intl-internal.h>
28 #include <gutenprintui2/gutenprintui.h>
29 #include "gutenprintui-internal.h"
30 #include "printrc.h"
31
32 #include <string.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 extern int mylineno;
37
38 extern int yylex(void);
39 char *quotestrip(const char *i);
40 char *endstrip(const char *i);
41
42 extern char* yytext;
43
44 static int yyerror( const char *s )
45 {
46 fprintf(stderr,"stdin:%d: %s before '%s'\n", mylineno, s, yytext);
47 return 0;
48 }
49
50 static stpui_plist_t *current_printer = NULL;
51
52 %}
53
54 %token <dval> tNUMBER
55 %token <sval> tBOOLEAN
56 %token <sval> tSTRING
57 %token <sval> tWORD
58 %token <sval> tGSWORD
59
60 %token CURRENT_PRINTER
61 %token SHOW_ALL_PAPER_SIZES
62 %token PRINTER
63 %token DESTINATION
64 %token SCALING
65 %token ORIENTATION
66 %token AUTOSIZE_ROLL_PAPER
67 %token UNIT
68 %token DRIVER
69 %token LEFT
70 %token TOP
71 %token CUSTOM_PAGE_WIDTH
72 %token CUSTOM_PAGE_HEIGHT
73 %token OUTPUT_TYPE
74 %token PRINTRC_HDR
75 %token PARAMETER
76 %token QUEUE_NAME
77 %token OUTPUT_FILENAME
78 %token EXTRA_PRINTER_OPTIONS
79 %token CUSTOM_COMMAND
80 %token COMMAND_TYPE
81 %token GLOBAL_SETTINGS
82 %token GLOBAL
83 %token END_GLOBAL_SETTINGS
84 %token pINT
85 %token pSTRING_LIST
86 %token pFILE
87 %token pDOUBLE
88 %token pDIMENSION
89 %token pBOOLEAN
90 %token pCURVE
91
92 %start Thing
93
94 %%
95
96 Printer: PRINTER tSTRING tSTRING
97 {
98 current_printer = stpui_plist_create($2, $3);
99 g_free($2);
100 g_free($3);
101 }
102 ;
103
104 /*
105 * Destination is obsolete; ignore it.
106 */
107 Destination: DESTINATION tSTRING
108 {
109 if ($2)
110 g_free($2);
111 }
112 ;
113
114 Queue_Name: QUEUE_NAME tSTRING
115 {
116 if (current_printer && $2)
117 {
118 stpui_plist_set_queue_name(current_printer, $2);
119 g_free($2);
120 }
121 }
122 ;
123
124 Output_Filename: OUTPUT_FILENAME tSTRING
125 {
126 if (current_printer && $2)
127 {
128 stpui_plist_set_output_filename(current_printer, $2);
129 g_free($2);
130 }
131 }
132 ;
133
134 Extra_Printer_Options: EXTRA_PRINTER_OPTIONS tSTRING
135 {
136 if (current_printer && $2)
137 {
138 stpui_plist_set_extra_printer_options(current_printer, $2);
139 g_free($2);
140 }
141 }
142 ;
143
144 Custom_Command: CUSTOM_COMMAND tSTRING
145 {
146 if (current_printer && $2)
147 {
148 stpui_plist_set_custom_command(current_printer, $2);
149 g_free($2);
150 }
151 }
152 ;
153
154 Command_Type: COMMAND_TYPE tNUMBER
155 {
156 if (current_printer)
157 stpui_plist_set_command_type(current_printer, (int) $2);
158 }
159 ;
160
161 Scaling: SCALING tNUMBER
162 {
163 if (current_printer)
164 current_printer->scaling = $2;
165 }
166 ;
167
168 Orientation: ORIENTATION tNUMBER
169 {
170 if (current_printer)
171 current_printer->orientation = (int) $2;
172 }
173 ;
174
175 Autosize_Roll_Paper: AUTOSIZE_ROLL_PAPER tNUMBER
176 {
177 if (current_printer)
178 current_printer->auto_size_roll_feed_paper = (int) $2;
179 }
180 ;
181
182 Unit: UNIT tNUMBER
183 {
184 if (current_printer)
185 current_printer->unit = (int) $2;
186 }
187 ;
188
189 Left: LEFT tNUMBER
190 {
191 if (current_printer)
192 stp_set_left(current_printer->v, $2);
193 }
194 ;
195
196 Top: TOP tNUMBER
197 {
198 if (current_printer)
199 stp_set_top(current_printer->v, $2);
200 }
201 ;
202
203 Output_Type: OUTPUT_TYPE tNUMBER
204 {
205 if (current_printer)
206 {
207 switch ((int) $2)
208 {
209 case 0:
210 stp_set_string_parameter
211 (current_printer->v, "PrintingMode", "BW");
212 break;
213 case 1:
214 case 2:
215 default:
216 stp_set_string_parameter
217 (current_printer->v, "PrintingMode", "Color");
218 break;
219 }
220 }
221 }
222 ;
223
224 Custom_Page_Width: CUSTOM_PAGE_WIDTH tNUMBER
225 {
226 if (current_printer)
227 stp_set_page_width(current_printer->v, $2);
228 }
229 ;
230
231 Custom_Page_Height: CUSTOM_PAGE_HEIGHT tNUMBER
232 {
233 if (current_printer)
234 stp_set_page_height(current_printer->v, $2);
235 }
236 ;
237
238 Empty:
239 ;
240
241 Int_Param: tWORD pINT tBOOLEAN tNUMBER
242 {
243 if (current_printer)
244 {
245 stp_set_int_parameter(current_printer->v, $1, (int) $4);
246 if (strcmp($3, "False") == 0)
247 stp_set_int_parameter_active(current_printer->v, $1,
248 STP_PARAMETER_INACTIVE);
249 else
250 stp_set_int_parameter_active(current_printer->v, $1,
251 STP_PARAMETER_ACTIVE);
252 }
253 g_free($1);
254 g_free($3);
255 }
256 ;
257
258 String_List_Param: tWORD pSTRING_LIST tBOOLEAN tSTRING
259 {
260 if (current_printer)
261 {
262 stp_set_string_parameter(current_printer->v, $1, $4);
263 if (strcmp($3, "False") == 0)
264 stp_set_string_parameter_active(current_printer->v, $1,
265 STP_PARAMETER_INACTIVE);
266 else
267 stp_set_string_parameter_active(current_printer->v, $1,
268 STP_PARAMETER_ACTIVE);
269 }
270 g_free($1);
271 g_free($3);
272 g_free($4);
273 }
274 ;
275
276 File_Param: tWORD pFILE tBOOLEAN tSTRING
277 {
278 if (current_printer)
279 {
280 stp_set_file_parameter(current_printer->v, $1, $4);
281 if (strcmp($3, "False") == 0)
282 stp_set_file_parameter_active(current_printer->v, $1,
283 STP_PARAMETER_INACTIVE);
284 else
285 stp_set_file_parameter_active(current_printer->v, $1,
286 STP_PARAMETER_ACTIVE);
287 }
288 g_free($1);
289 g_free($3);
290 g_free($4);
291 }
292 ;
293
294 Double_Param: tWORD pDOUBLE tBOOLEAN tNUMBER
295 {
296 if (current_printer)
297 {
298 stp_set_float_parameter(current_printer->v, $1, $4);
299 if (strcmp($3, "False") == 0)
300 stp_set_float_parameter_active(current_printer->v, $1,
301 STP_PARAMETER_INACTIVE);
302 else
303 stp_set_float_parameter_active(current_printer->v, $1,
304 STP_PARAMETER_ACTIVE);
305 }
306 g_free($1);
307 g_free($3);
308 }
309 ;
310
311 Dimension_Param: tWORD pDIMENSION tBOOLEAN tNUMBER
312 {
313 if (current_printer)
314 {
315 stp_set_dimension_parameter(current_printer->v, $1, $4);
316 if (strcmp($3, "False") == 0)
317 stp_set_dimension_parameter_active(current_printer->v, $1,
318 STP_PARAMETER_INACTIVE);
319 else
320 stp_set_dimension_parameter_active(current_printer->v, $1,
321 STP_PARAMETER_ACTIVE);
322 }
323 g_free($1);
324 g_free($3);
325 }
326 ;
327
328 Boolean_Param: tWORD pBOOLEAN tBOOLEAN tBOOLEAN
329 {
330 if (current_printer)
331 {
332 if (strcmp($4, "False") == 0)
333 stp_set_boolean_parameter(current_printer->v, $1, 0);
334 else
335 stp_set_boolean_parameter(current_printer->v, $1, 1);
336 if (strcmp($3, "False") == 0)
337 stp_set_boolean_parameter_active(current_printer->v, $1,
338 STP_PARAMETER_INACTIVE);
339 else
340 stp_set_boolean_parameter_active(current_printer->v, $1,
341 STP_PARAMETER_ACTIVE);
342 }
343 g_free($1);
344 g_free($3);
345 g_free($4);
346 }
347 ;
348
349 Curve_Param: tWORD pCURVE tBOOLEAN tSTRING
350 {
351 if (current_printer)
352 {
353 stp_curve_t *curve = stp_curve_create_from_string($4);
354 if (curve)
355 {
356 stp_set_curve_parameter(current_printer->v, $1, curve);
357 if (strcmp($3, "False") == 0)
358 stp_set_curve_parameter_active(current_printer->v, $1,
359 STP_PARAMETER_INACTIVE);
360 else
361 stp_set_curve_parameter_active(current_printer->v, $1,
362 STP_PARAMETER_ACTIVE);
363 stp_curve_destroy(curve);
364 }
365 }
366 g_free($1);
367 g_free($3);
368 g_free($4);
369 }
370 ;
371
372 Typed_Param: Int_Param | String_List_Param | File_Param | Double_Param
373 | Boolean_Param | Curve_Param | Dimension_Param
374 ;
375
376 Parameter: PARAMETER Typed_Param
377 ;
378
379 Parameters: Parameters Parameter | Empty
380 ;
381
382 Standard_Value: Destination | Scaling | Orientation | Autosize_Roll_Paper |
383 Unit | Left | Top | Custom_Page_Width | Custom_Page_Height |
384 Output_Type | Queue_Name | Output_Filename | Extra_Printer_Options |
385 Custom_Command | Command_Type
386 ;
387
388 Standard_Values: Standard_Values Standard_Value | Empty
389 ;
390
391 A_Printer: Printer Standard_Values Parameters
392 ;
393
394 Printers: Printers A_Printer | Empty
395 ;
396
397 Current_Printer: CURRENT_PRINTER tSTRING
398 { stpui_printrc_current_printer = $2; }
399 ;
400
401 Show_All_Paper_Sizes: SHOW_ALL_PAPER_SIZES tBOOLEAN
402 {
403 if (strcmp($2, "True") == 0)
404 stpui_show_all_paper_sizes = 1;
405 else
406 stpui_show_all_paper_sizes = 0;
407 g_free($2);
408 }
409 ;
410
411 Global: Current_Printer | Show_All_Paper_Sizes
412 ;
413
414 Old_Globals: Current_Printer Show_All_Paper_Sizes
415 ;
416
417 New_Global_Setting: tWORD tSTRING
418 {
419 if ($2)
420 {
421 stpui_set_global_parameter($1, $2);
422 g_free($2);
423 }
424 g_free($1);
425 }
426 ;
427
428 Global_Setting: Global | New_Global_Setting
429 ;
430
431 Global_Settings: Global_Settings Global_Setting | Empty
432 ;
433
434 Global_Subblock: GLOBAL_SETTINGS Global_Settings END_GLOBAL_SETTINGS
435 ;
436
437 Global_Block: Global_Subblock | Old_Globals | Empty
438 ;
439
440 Thing: PRINTRC_HDR Global_Block Printers
441 ;
442
443 %%