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
|
/* -*-Mode: C-*-
* "$Id: printrcl.l,v 1.2 2012/05/11 13:16:12 rlk Exp $"
*
* printrc parser
*
* Copyright 2003 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.
*/
%{
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gutenprint/gutenprint-intl-internal.h>
#include <gutenprintui2/gutenprintui.h>
#include "gutenprintui-internal.h"
#include "printrc.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define YY_NO_UNPUT
int mylineno = 1;
extern YYSTYPE yylval;
#define DBG(x) \
do \
{ \
if (getenv("STP_DEBUG_PRINTRC")) \
fprintf(stderr, "'%s' => %s\n", yytext, #x); \
} \
while (0)
static char *
q_strdup(const char *s)
{
/* Strip the leading and trailing quote */
if (strlen(s) <= 2)
return NULL;
else
return g_strndup(s + 1, strlen(s) - 2);
}
%}
%option noyywrap
digit [0-9]
boolean (True)|(False)
integer [-+]?{digit}+
float [-+]?{digit}+(\.{digit}+)?([eE][-+]?{digit}+)?
string ([\"][^\"\n]*[\"])|([\'][^\']*[\'])
ws [ \t]+
printrc_hdr #PRINTRCv[234].*\n
word [a-zA-Z][a-zA-Z0-9_]*
%%
Current-Printer: DBG(CURRENT_PRINTER); return CURRENT_PRINTER;
Show-All-Paper-Sizes: DBG(SHOW_ALL_PAPER_SIZES); return SHOW_ALL_PAPER_SIZES;
Printer: DBG(PRINTER); return PRINTER;
Destination: DBG(DESTINATION); return DESTINATION;
Scaling: DBG(SCALING); return SCALING;
Orientation: DBG(ORIENTATION); return ORIENTATION;
Autosize-Roll-Paper: DBG(AUTOSIZE_ROLL_PAPER); return AUTOSIZE_ROLL_PAPER;
Unit: DBG(UNIT); return UNIT;
Driver: DBG(DRIVER); return DRIVER;
Left: DBG(LEFT); return LEFT;
Top: DBG(TOP); return TOP;
Custom_Page_Width: DBG(CUSTOM_PAGE_WIDTH); return CUSTOM_PAGE_WIDTH;
Custom_Page_Height: DBG(CUSTOM_PAGE_HEIGHT); return CUSTOM_PAGE_HEIGHT;
Output_Type: DBG(OUTPUT_TYPE); return OUTPUT_TYPE;
Parameter DBG(PARAMETER); return PARAMETER;
Queue-Name: DBG(QUEUE_NAME); return QUEUE_NAME;
Output-Filename: DBG(OUTPUT_FILENAME); return OUTPUT_FILENAME;
Extra-Printer-Options: DBG(EXTRA_PRINTER_OPTIONS); return EXTRA_PRINTER_OPTIONS;
Custom-Command: DBG(CUSTOM_COMMAND); return CUSTOM_COMMAND;
Command-Type: DBG(COMMAND_TYPE); return COMMAND_TYPE;
Global-Settings: DBG(GLOBAL_SETTINGS); return GLOBAL_SETTINGS;
End-Global-Settings: DBG(END_GLOBAL_SETTINGS); return END_GLOBAL_SETTINGS;
Global: DBG(GLOBAL); return GLOBAL;
Int DBG(pINT); return pINT;
String DBG(pSTRING_LIST); return pSTRING_LIST;
File DBG(pFILE); return pFILE;
Double DBG(pDOUBLE); return pDOUBLE;
Dimension DBG(pDIMENSION); return pDIMENSION;
Boolean DBG(pBOOLEAN); return pBOOLEAN;
Curve DBG(pCURVE); return pCURVE;
{integer} yylval.ival = atoi(yytext); DBG(tINT); return tINT;
{float} yylval.dval = strtod(yytext, NULL); DBG(tDOUBLE); return tDOUBLE;
{string} yylval.sval = q_strdup(yytext); DBG(tSTRING); return tSTRING;
{boolean} yylval.sval = g_strdup(yytext); DBG(tBOOLEAN); return tBOOLEAN;
{word} yylval.sval = g_strdup(yytext); DBG(tWORD); return tWORD;
{printrc_hdr} DBG(PRINTRC_HDR); return PRINTRC_HDR;
{ws} DBG(whitespace1); /* Skip blanks/tabs */
#[^\n]* DBG(comment1); /* Skip comments */
\n DBG(newline); mylineno++;
|