1 /*
2 * "$Id: printdefy.y,v 1.7.4.1 2003/10/01 20:35:27 rleigh Exp $"
3 *
4 * Parse printer definition pseudo-XML
5 *
6 * Copyright 2000 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 #include <string.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "printdef.h"
29
30 extern int mylineno;
31 stp_printer_t thePrinter;
32 char *quotestrip(const char *i);
33 char *endstrip(const char *i);
34
35 extern int yylex(void);
36 void initialize_the_printer(const char *name, const char *driver);
37 void output_the_printer(void);
38 static int yyerror(const char *s);
39
40 const char *printfuncs[] =
41 {
42 "canon",
43 "escp2",
44 "pcl",
45 "ps",
46 "lexmark"
47 };
48
49 const size_t nprintfuncs = sizeof(printfuncs) / sizeof(const char *);
50
51 void
initialize_the_printer(const char * name,const char * driver)52 initialize_the_printer(const char *name, const char *driver)
53 {
54 strncpy(thePrinter.printvars.output_to, name, 63);
55 strncpy(thePrinter.printvars.driver, driver, 63);
56 thePrinter.printvars.top = -1;
57 thePrinter.model = -1;
58 thePrinter.printvars.brightness = 1.0;
59 thePrinter.printvars.gamma = 1.0;
60 thePrinter.printvars.contrast = 1.0;
61 thePrinter.printvars.cyan = 1.0;
62 thePrinter.printvars.magenta = 1.0;
63 thePrinter.printvars.yellow = 1.0;
64 thePrinter.printvars.saturation = 1.0;
65 thePrinter.printvars.density = 1.0;
66 }
67
68 void
output_the_printer(void)69 output_the_printer(void)
70 {
71 printf(" {\n");
72 printf(" %s,\n", thePrinter.printvars.output_to);
73 printf(" %s,\n", thePrinter.printvars.driver);
74 printf(" %d,\n", thePrinter.model);
75 printf(" &stp_%s_printfuncs,\n", printfuncs[thePrinter.printvars.top]);
76 printf(" {\n");
77 printf(" \"\",\n"); /* output_to */
78 printf(" %s,\n", thePrinter.printvars.driver); /* driver */
79 printf(" \"\",\n"); /* ppd_file */
80 printf(" \"\",\n"); /* resolution */
81 printf(" \"\",\n"); /* media_size */
82 printf(" \"\",\n"); /* media_type */
83 printf(" \"\",\n"); /* media_source */
84 printf(" \"\",\n"); /* ink_type */
85 printf(" \"\",\n"); /* dither_algorithm */
86 printf(" %d,\n", thePrinter.printvars.output_type);
87 printf(" %.3f,\n", thePrinter.printvars.brightness);
88 printf(" 1.0,\n"); /* scaling */
89 printf(" -1,\n"); /* orientation */
90 printf(" 0,\n"); /* top */
91 printf(" 0,\n"); /* left */
92 printf(" %.3f,\n", thePrinter.printvars.gamma);
93 printf(" %.3f,\n", thePrinter.printvars.contrast);
94 printf(" %.3f,\n", thePrinter.printvars.cyan);
95 printf(" %.3f,\n", thePrinter.printvars.magenta);
96 printf(" %.3f,\n", thePrinter.printvars.yellow);
97 printf(" %.3f,\n", thePrinter.printvars.saturation);
98 printf(" %.3f,\n", thePrinter.printvars.density);
99 printf(" }\n");
100 printf(" },\n");
101 }
102
103 extern int mylineno;
104 extern char* yytext;
105
yyerror(const char * s)106 static int yyerror( const char *s )
107 {
108 fprintf(stderr,"stdin:%d: %s before '%s'\n",mylineno,s,yytext);
109 return 0;
110 }
111
112 %}
113
114 %token <ival> tINT
115 %token <dval> tDOUBLE
116 %token <sval> tSTRING tCLASS
117 %token tBEGIN tEND ASSIGN PRINTER NAME DRIVER COLOR NOCOLOR MODEL
118 %token LANGUAGE BRIGHTNESS GAMMA CONTRAST
119 %token CYAN MAGENTA YELLOW SATURATION DENSITY ENDPRINTER VALUE
120
121 %start Printers
122
123 %%
124
125 printerstart: tBEGIN PRINTER NAME ASSIGN tSTRING DRIVER ASSIGN tSTRING tEND
126 { initialize_the_printer($5, $8); }
127 ;
128 printerstartalt: tBEGIN PRINTER DRIVER ASSIGN tSTRING NAME ASSIGN tSTRING tEND
129 { initialize_the_printer($8, $5); }
130 ;
131 printerend: tBEGIN ENDPRINTER tEND
132 { output_the_printer(); }
133 ;
134 color: tBEGIN COLOR tEND
135 { thePrinter.printvars.output_type = OUTPUT_COLOR; }
136 ;
137 nocolor: tBEGIN NOCOLOR tEND
138 { thePrinter.printvars.output_type = OUTPUT_GRAY; }
139 ;
140 model: tBEGIN MODEL VALUE ASSIGN tINT tEND
141 { thePrinter.model = $5; }
142 ;
143 language: tBEGIN LANGUAGE VALUE ASSIGN tCLASS tEND
144 {
145 int i;
146 for (i = 0; i < nprintfuncs; i++)
147 {
148 if (!strcmp($5, printfuncs[i]))
149 {
150 thePrinter.printvars.top = i;
151 break;
152 }
153 }
154 }
155 ;
156 brightness: tBEGIN BRIGHTNESS VALUE ASSIGN tDOUBLE tEND
157 { thePrinter.printvars.brightness = $5; }
158 ;
159 gamma: tBEGIN GAMMA VALUE ASSIGN tDOUBLE tEND
160 { thePrinter.printvars.gamma = $5; }
161 ;
162 contrast: tBEGIN CONTRAST VALUE ASSIGN tDOUBLE tEND
163 { thePrinter.printvars.contrast = $5; }
164 ;
165 cyan: tBEGIN CYAN VALUE ASSIGN tDOUBLE tEND
166 { thePrinter.printvars.cyan = $5; }
167 ;
168 magenta: tBEGIN MAGENTA VALUE ASSIGN tDOUBLE tEND
169 { thePrinter.printvars.magenta = $5; }
170 ;
171 yellow: tBEGIN YELLOW VALUE ASSIGN tDOUBLE tEND
172 { thePrinter.printvars.yellow = $5; }
173 ;
174 saturation: tBEGIN SATURATION VALUE ASSIGN tDOUBLE tEND
175 { thePrinter.printvars.saturation = $5; }
176 ;
177 density: tBEGIN DENSITY VALUE ASSIGN tDOUBLE tEND
178 { thePrinter.printvars.density = $5; }
179 ;
180
181 Empty:
182 ;
183
184 pstart: printerstart | printerstartalt
185 ;
186
187 parg: color | nocolor | model | language | brightness | gamma | contrast
188 | cyan | magenta | yellow | saturation | density
189 ;
190
191 pargs: pargs parg | parg
192 ;
193
194 Printer: pstart pargs printerend | pstart printerend
195 ;
196
197 Printers: Printers Printer | Empty
198 ;
199
200 %%
201
202 int
203 main(int argc, char **argv)
204 {
205 int retval;
206 int i;
207 printf("/* This file is automatically generated. See printers.xml.\n");
208 printf(" DO NOT EDIT! */\n\n");
209 for (i = 0; i < nprintfuncs; i++)
210 printf("const extern stp_printfuncs_t stp_%s_printfuncs;\n",
211 printfuncs[i]);
212 printf("\nstatic const stp_internal_printer_t printers[] =\n");
213 printf("{\n");
214 retval = yyparse();
215 printf("};\n");
216 printf("static const int printer_count = sizeof(printers) / sizeof(stp_internal_printer_t);\n");
217 return retval;
218 }
219