summaryrefslogtreecommitdiffstats
path: root/tdeprint/ppdscanner.l
blob: 361f94317add50057a940e46f52c637cb386bc3b (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
%{
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001-2003 Michael Goffioul <[email protected]>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include <qstringlist.h>
#include <qiodevice.h>
#define YYSTYPE TQStringList
#include "ppdparser.cpp.h"

#define yylval tdeprint_ppdlval

TQIODevice *tdeprint_ppdscanner_device = NULL;
#define YY_INPUT(buf,result,max_size) \
	{ \
		if (tdeprint_ppdscanner_device) \
		{ \
			result = tdeprint_ppdscanner_device->readBlock(buf,max_size); \
			if (result < 0) \
				result = 0; \
		} \
		else \
			result = 0; \
	}
int tdeprint_ppdscanner_lno = 0;

#if 0
#define QDEBUG0(s) tqDebug(s)
#define QDEBUG1(s,a) tqDebug(s,a)
#else
#define QDEBUG0(s)
#define QDEBUG1(s,a)
#endif
%}

%x option value translation_1 translation_2 constr
%option noyywrap

WORD     [^:/\x00-\x20\x7F-\xFF]+
WORD2    [^:/\x00-\x20\x7F-\xFF\*]+
WORD3    [^:/\x00-\x20\x7F-\xFF][^:/\x00-\x1F\x7F-\xFF]*
L        [[:alnum:]]

%%

	/**
	 * Initial state
	 */
\*"JCLOpenUI"        |
\*"OpenUI"{L}*       { QDEBUG0("Open UI"); BEGIN(option); return OPENUI; }
\*"JCLCloseUI"       |
\*"CloseUI"{L}*      { QDEBUG0("Close UI"); BEGIN(value); return CLOSEUI; }
\*"OpenGroup"        { QDEBUG0("Open group"); BEGIN(option); return OPENGROUP; }
\*"CloseGroup"       { QDEBUG0("Close group"); BEGIN(option); return CLOSEGROUP; }
\*"Default"\*{WORD}  { yylval = yytext+9; BEGIN(option); return DEFAULT; }
\*"Default"{WORD}    { yylval = yytext+8; BEGIN(option); return DEFAULT; }
\*"UIConstraints"    |
\*"NonUIConstraints" { BEGIN(constr); return CONSTRAINT; }
\*"PaperDimension"   { BEGIN(option); return PAPERDIM; }
\*"ImageableArea"    { BEGIN(option); return IMGAREA; }
\*"End"              { /* eat up */ }

"*% COMDATA #".*$    { yylval = yytext+12; return FOODATA; }
\*%.*                { QDEBUG0("Comment"); return COMMENT; }
\*{WORD}             { yylval = yytext+1; QDEBUG1("Main keyword: %s",yytext+1); BEGIN(option); return KEYWORD; }

	/**
	 * Option state
	 */
<option>{WORD3}      { yylval = yytext; QDEBUG1("Option: %s",yytext); return OPTION; }
<option>":"          { BEGIN(value); return ':'; }
<option>"\n"         { tdeprint_ppdscanner_lno++; BEGIN(INITIAL); }
<option>"/"          { BEGIN(translation_1); return '/'; }

	/**
	 * Translation state (1: without colon)
	 */
<translation_1>[^\n:]*  { yylval = yytext; QDEBUG1("Translation: %s",yytext); return TRANSLATION; }
<translation_1>":"      { BEGIN(value); return ':'; }
<translation_1>"\n"     { tdeprint_ppdscanner_lno++; BEGIN(INITIAL); }

	/**
	 * Value state
	 */
<value>\"[^\"]*\"    { yylval = yytext; tdeprint_ppdscanner_lno += yylval[0].contains('\n'); QDEBUG1("Quoted value: %s",yytext); return QUOTED; }
<value>{WORD}        { yylval = yytext; QDEBUG1("String part: %s",yytext); return STRINGPART; }
<value>"/"           { BEGIN(translation_2); return '/'; }
<value>"\n"          { tdeprint_ppdscanner_lno++; BEGIN(INITIAL); }
<value>":"           { /* stay in the same state */ return ':'; }

	/**
	 * Translation state (2: with colon)
	 */
<translation_2>[^\n]*   { yylval = yytext; QDEBUG1("Translation: %s",yytext); return TRANSLATION; }
<translation_2>"\n"     { tdeprint_ppdscanner_lno++; BEGIN(INITIAL); }

	/**
	 * Constraint state
	 */
<constr>":"         { return ':'; }
<constr>\*{WORD2}   { yylval = yytext+1; QDEBUG1("Constraint keyword: %s",yytext); return KEYWORD; }
<constr>{WORD2}     { yylval = yytext; QDEBUG1("Constraint option: %s",yytext); return OPTION; }
<constr>"\n"        { tdeprint_ppdscanner_lno++; BEGIN(INITIAL); }

"\n"                { tdeprint_ppdscanner_lno++; /* eat up */ }
<*>.                { /* eat up */ }

%%

void tdeprint_ppdscanner_init(TQIODevice *d)
{
	tdeprint_ppdscanner_device = d;
	tdeprint_ppdscanner_lno = 1;
}

void tdeprint_ppdscanner_terminate( bool deleteIt )
{
	if (deleteIt)
		delete tdeprint_ppdscanner_device;
	tdeprint_ppdscanner_device = NULL;
}

int tdeprint_ppdscanner_numberoflines()
{
	return tdeprint_ppdscanner_lno;
}