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