Debian Codegraph @

src/gutenprintui2/printrcl.l

raw
1 /* -*-Mode: C-*-
2 *
3 * printrc parser
4 *
5 * Copyright 2003 Robert Krawitz <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 %{
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <gutenprint/gutenprint-intl-internal.h>
28 #include <gutenprintui2/gutenprintui.h>
29 #include "gutenprintui-internal.h"
30 #include "printrc.h"
31
32 #include <string.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 #define YY_NO_UNPUT
37
38 /* Bison does some stuff that triggers unimportant warnings. */
39 #pragma GCC diagnostic ignored "-Wredundant-decls"
40 #pragma GCC diagnostic ignored "-Wunused-function"
41
42 int mylineno = 1;
43
44 extern YYSTYPE yylval;
45
46 #define DBG(x) \
47 do \
48 { \
49 if (getenv("STP_DEBUG_PRINTRC")) \
50 fprintf(stderr, "'%s' => %s\n", yytext, #x); \
51 } \
52 while (0)
53
54 static char *
55 q_strdup(const char *s)
56 {
57 /* Strip the leading and trailing quote */
58 if (strlen(s) <= 2)
59 return NULL;
60 else
61 return g_strndup(s + 1, strlen(s) - 2);
62 }
63
64 %}
65
66 %option noyywrap
67
68 digit [0-9]
69 boolean (True)|(False)
70 number [-+]?{digit}+(\.{digit}+)?([eE][-+]?{digit}+)?
71 string ([\"][^\"\n]*[\"])|([\'][^\']*[\'])
72 ws [ \t]+
73 printrc_hdr #PRINTRCv[2345].*\n
74 word [a-zA-Z][a-zA-Z0-9_]*
75
76 %%
77
78 Current-Printer: DBG(CURRENT_PRINTER); return CURRENT_PRINTER;
79 Show-All-Paper-Sizes: DBG(SHOW_ALL_PAPER_SIZES); return SHOW_ALL_PAPER_SIZES;
80 Printer: DBG(PRINTER); return PRINTER;
81 Destination: DBG(DESTINATION); return DESTINATION;
82 Scaling: DBG(SCALING); return SCALING;
83 Orientation: DBG(ORIENTATION); return ORIENTATION;
84 Autosize-Roll-Paper: DBG(AUTOSIZE_ROLL_PAPER); return AUTOSIZE_ROLL_PAPER;
85 Unit: DBG(UNIT); return UNIT;
86 Driver: DBG(DRIVER); return DRIVER;
87 Left: DBG(LEFT); return LEFT;
88 Top: DBG(TOP); return TOP;
89 Custom_Page_Width: DBG(CUSTOM_PAGE_WIDTH); return CUSTOM_PAGE_WIDTH;
90 Custom_Page_Height: DBG(CUSTOM_PAGE_HEIGHT); return CUSTOM_PAGE_HEIGHT;
91 Output_Type: DBG(OUTPUT_TYPE); return OUTPUT_TYPE;
92 Parameter DBG(PARAMETER); return PARAMETER;
93 Queue-Name: DBG(QUEUE_NAME); return QUEUE_NAME;
94 Output-Filename: DBG(OUTPUT_FILENAME); return OUTPUT_FILENAME;
95 Extra-Printer-Options: DBG(EXTRA_PRINTER_OPTIONS); return EXTRA_PRINTER_OPTIONS;
96 Custom-Command: DBG(CUSTOM_COMMAND); return CUSTOM_COMMAND;
97 Command-Type: DBG(COMMAND_TYPE); return COMMAND_TYPE;
98 Global-Settings: DBG(GLOBAL_SETTINGS); return GLOBAL_SETTINGS;
99 End-Global-Settings: DBG(END_GLOBAL_SETTINGS); return END_GLOBAL_SETTINGS;
100 Global: DBG(GLOBAL); return GLOBAL;
101
102 Int DBG(pINT); return pINT;
103 String DBG(pSTRING_LIST); return pSTRING_LIST;
104 File DBG(pFILE); return pFILE;
105 Double DBG(pDOUBLE); return pDOUBLE;
106 Dimension DBG(pDIMENSION); return pDIMENSION;
107 Boolean DBG(pBOOLEAN); return pBOOLEAN;
108 Curve DBG(pCURVE); return pCURVE;
109
110 {number} yylval.dval = strtod(yytext, NULL); DBG(tNUMBER); return tNUMBER;
111 {string} yylval.sval = q_strdup(yytext); DBG(tSTRING); return tSTRING;
112 {boolean} yylval.sval = g_strdup(yytext); DBG(tBOOLEAN); return tBOOLEAN;
113 {word} yylval.sval = g_strdup(yytext); DBG(tWORD); return tWORD;
114 {printrc_hdr} DBG(PRINTRC_HDR); return PRINTRC_HDR;
115 {ws} DBG(whitespace1); /* Skip blanks/tabs */
116 #[^\n]* DBG(comment1); /* Skip comments */
117 \n DBG(newline); mylineno++;