1 /*
2 * "$Id: printdefl.l,v 1.2 2001/06/03 20:53:24 rlk 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 #define YY_NO_UNPUT
31
32 int mylineno = 1;
33
34 #if 0
35 #define DBG(x) fprintf(stderr, "'%s'%s\n", yytext, #x);
36 #else
37 #define DBG(x)
38 #endif
39
40 static char *
c_strdup(const char * s)41 c_strdup(const char *s)
42 {
43 char *ret = malloc(strlen(s) + 1);
44 if (!ret)
45 {
46 fprintf(stderr, "Malloc failed.\n");
47 exit(1);
48 }
49 strcpy(ret, s);
50 return ret;
51 }
52
53 %}
54
55 %option noyywrap
56
57 digit [0-9]
58 integer [-+]?{digit}+
59 float [-+]?{digit}+(\.{digit}+)?([eE][-+]?{digit}+)?
60 class [a-zA-Z][a-zA-Z0-9_]+
61 string [\"][^\"]+[\"]
62 ws [ \t]+
63
64 %%
65
66 \< DBG(tBEGIN) return tBEGIN;
67 \> DBG(tEND) return tEND;
68 = DBG(ASSIGN) return ASSIGN;
69 printer DBG(PRINTER) return PRINTER;
70 \/printer DBG(ENDPRINTER) return ENDPRINTER;
71 name DBG(NAME) return NAME;
72 driver DBG(DRIVER) return DRIVER;
73 color DBG(COLOR) return COLOR;
74 nocolor DBG(NOCOLOR) return NOCOLOR;
75 model DBG(MODEL) return MODEL;
76 language DBG(LANGUAGE) return LANGUAGE;
77 brightness DBG(BRIGHTNESS) return BRIGHTNESS;
78 gamma DBG(GAMMA) return GAMMA;
79 contrast DBG(CONTRAST) return CONTRAST;
80 cyan DBG(CYAN) return CYAN;
81 magenta DBG(MAGENTA) return MAGENTA;
82 yellow DBG(YELLOW) return YELLOW;
83 saturation DBG(SATURATION) return SATURATION;
84 density DBG(DENSITY) return DENSITY;
85 value DBG(VALUE) return VALUE;
86
87 {integer} yylval.ival = atoi(yytext); DBG(tINT) return tINT;
88 {float} yylval.dval = strtod(yytext, NULL); DBG(tDOUBLE) return tDOUBLE;
89 {string} yylval.sval = c_strdup(yytext); DBG(tSTRING) return tSTRING;
90 {class} yylval.sval = c_strdup(yytext); DBG(tCLASS) return tCLASS;
91 {ws} DBG(whitespace1) /* Skip blanks/tabs */
92 #[^\n]* DBG(comment1) /* Skip comments */
93 \n DBG(newline) mylineno++;
94