summaryrefslogtreecommitdiff
path: root/src/printdef/printdefy.y
blob: 13d4f3704f5b194ce6039fb8913e27c6df83a0fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * "$Id: printdefy.y,v 1.7.4.1 2003/10/01 20:35:27 rleigh Exp $"
 *
 *   Parse printer definition pseudo-XML
 *
 *   Copyright 2000 Robert Krawitz (rlk@alum.mit.edu)
 *
 *   This program is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License as published by the Free
 *   Software Foundation; either version 2 of the License, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *   for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

%{

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "printdef.h"

extern int mylineno;
stp_printer_t thePrinter;
char *quotestrip(const char *i);
char *endstrip(const char *i);

extern int yylex(void);
void initialize_the_printer(const char *name, const char *driver);
void output_the_printer(void);
static int yyerror(const char *s);

const char *printfuncs[] =
{
  "canon",
  "escp2",
  "pcl",
  "ps",
  "lexmark"
};

const size_t nprintfuncs = sizeof(printfuncs) / sizeof(const char *);

void
initialize_the_printer(const char *name, const char *driver)
{
  strncpy(thePrinter.printvars.output_to, name, 63);
  strncpy(thePrinter.printvars.driver, driver, 63);
  thePrinter.printvars.top = -1;
  thePrinter.model = -1;
  thePrinter.printvars.brightness = 1.0;
  thePrinter.printvars.gamma = 1.0;
  thePrinter.printvars.contrast = 1.0;
  thePrinter.printvars.cyan = 1.0;
  thePrinter.printvars.magenta = 1.0;
  thePrinter.printvars.yellow = 1.0;
  thePrinter.printvars.saturation = 1.0;
  thePrinter.printvars.density = 1.0;
}

void
output_the_printer(void)
{
  printf("  {\n");
  printf("    %s,\n", thePrinter.printvars.output_to);
  printf("    %s,\n", thePrinter.printvars.driver);
  printf("    %d,\n", thePrinter.model);
  printf("    &stp_%s_printfuncs,\n", printfuncs[thePrinter.printvars.top]);
  printf("    {\n");
  printf("      \"\",\n");	/* output_to */
  printf("      %s,\n", thePrinter.printvars.driver);	/* driver */
  printf("      \"\",\n");	/* ppd_file */
  printf("      \"\",\n");	/* resolution */
  printf("      \"\",\n");	/* media_size */
  printf("      \"\",\n");	/* media_type */
  printf("      \"\",\n");	/* media_source */
  printf("      \"\",\n");	/* ink_type */
  printf("      \"\",\n");	/* dither_algorithm */
  printf("      %d,\n", thePrinter.printvars.output_type);
  printf("      %.3f,\n", thePrinter.printvars.brightness);
  printf("      1.0,\n");	/* scaling */
  printf("      -1,\n");	/* orientation */
  printf("      0,\n");		/* top */
  printf("      0,\n");		/* left */
  printf("      %.3f,\n", thePrinter.printvars.gamma);
  printf("      %.3f,\n", thePrinter.printvars.contrast);
  printf("      %.3f,\n", thePrinter.printvars.cyan);
  printf("      %.3f,\n", thePrinter.printvars.magenta);
  printf("      %.3f,\n", thePrinter.printvars.yellow);
  printf("      %.3f,\n", thePrinter.printvars.saturation);
  printf("      %.3f,\n", thePrinter.printvars.density);
  printf("    }\n");
  printf("  },\n");
}

extern int mylineno;
extern char* yytext;

static int yyerror( const char *s )
{
	fprintf(stderr,"stdin:%d: %s before '%s'\n",mylineno,s,yytext);
	return 0;
}

%}

%token <ival> tINT
%token <dval> tDOUBLE
%token <sval> tSTRING tCLASS
%token tBEGIN tEND ASSIGN PRINTER NAME DRIVER COLOR NOCOLOR MODEL
%token LANGUAGE BRIGHTNESS GAMMA CONTRAST
%token CYAN MAGENTA YELLOW SATURATION DENSITY ENDPRINTER VALUE

%start Printers

%%

printerstart:	tBEGIN PRINTER NAME ASSIGN tSTRING DRIVER ASSIGN tSTRING tEND
	{ initialize_the_printer($5, $8); }
;
printerstartalt: tBEGIN PRINTER DRIVER ASSIGN tSTRING NAME ASSIGN tSTRING tEND
	{ initialize_the_printer($8, $5); }
;
printerend: 		tBEGIN ENDPRINTER tEND
	{ output_the_printer(); }
;
color:			tBEGIN COLOR tEND
	{ thePrinter.printvars.output_type = OUTPUT_COLOR; }
;
nocolor:		tBEGIN NOCOLOR tEND
	{ thePrinter.printvars.output_type = OUTPUT_GRAY; }
;
model:			tBEGIN MODEL VALUE ASSIGN tINT tEND
	{ thePrinter.model = $5; }
;
language:		tBEGIN LANGUAGE VALUE ASSIGN tCLASS tEND
	{
	  int i;
	  for (i = 0; i < nprintfuncs; i++)
	    {
	      if (!strcmp($5, printfuncs[i]))
		{
		  thePrinter.printvars.top = i;
		  break;
		}
	    }
	}
;
brightness:		tBEGIN BRIGHTNESS VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.brightness = $5; }
;
gamma:			tBEGIN GAMMA VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.gamma = $5; }
;
contrast:		tBEGIN CONTRAST VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.contrast = $5; }
;
cyan:			tBEGIN CYAN VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.cyan = $5; }
;
magenta:			tBEGIN MAGENTA VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.magenta = $5; }
;
yellow:			tBEGIN YELLOW VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.yellow = $5; }
;
saturation:		tBEGIN SATURATION VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.saturation = $5; }
;
density:		tBEGIN DENSITY VALUE ASSIGN tDOUBLE tEND
	{ thePrinter.printvars.density = $5; }
;

Empty:
;

pstart: printerstart | printerstartalt
;

parg: color | nocolor | model | language | brightness | gamma | contrast
	| cyan | magenta | yellow | saturation | density
;

pargs: pargs parg | parg
;

Printer: pstart pargs printerend | pstart printerend
;

Printers: Printers Printer | Empty
;

%%

int
main(int argc, char **argv)
{
  int retval;
  int i;
  printf("/* This file is automatically generated.  See printers.xml.\n");
  printf("   DO NOT EDIT! */\n\n");
  for (i = 0; i < nprintfuncs; i++)
    printf("const extern stp_printfuncs_t stp_%s_printfuncs;\n",
	   printfuncs[i]);
  printf("\nstatic const stp_internal_printer_t printers[] =\n");
  printf("{\n");
  retval = yyparse();
  printf("};\n");
  printf("static const int printer_count = sizeof(printers) / sizeof(stp_internal_printer_t);\n");
  return retval;
}