File: rcfile.ll

package info (click to toggle)
mailfilter 0.8.6-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 3,280 kB
  • ctags: 2,501
  • sloc: cpp: 2,452; sh: 1,393; ansic: 1,259; lex: 570; yacc: 468; makefile: 167; perl: 72
file content (470 lines) | stat: -rw-r--r-- 11,094 bytes parent folder | download | duplicates (2)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/* *********************************************************************** */
/* A scanner definition for Mailfilter's config files                      */
/* Copyright (c) 2000 - 2009  Andreas Bauer <baueran@gmail.com>            */
/*                                                                         */
/* 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.                                                                    */
/* *********************************************************************** */

/* The states are numbered from 1...n and are stored in YY_START.  */
%s CTRL
%x INCL
%x PARAM
%s PARAM_NUM
%s PARAM_BOOL

%option noyywrap

%{
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>
#include <cstdio>

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "rcparser.hh"

extern "C"
{
#include <wordexp.h>
}

using namespace std;

/* Only allow 'recursion depth' of 1 when including files.  */
#define MAX_INCLUDE_DEPTH   1

/* Define L_DEBUG_MODE to get extra output from the scanner.  */
#ifdef L_DEBUG_MODE
#undef L_DEBUG_MSG
#define L_DEBUG_MSG(msg)    \
   cout << "Lexer: "        \
        << msg              \
        << endl
#else
#define L_DEBUG_MSG(msg)    \
   ;
#endif

YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
int             include_stack_ptr;

extern string expand_path (const string&);
extern string int_to_string (int val);
%}

ALLOW           allow
ALLOW_CASE      allow_case
ALLOW_NOCASE    allow_nocase
DEL_DUPLICATES  del_duplicates
DENY_NOCASE     deny_nocase
DENY_CASE       deny_case
DENY            deny
HIGHSCORE       highscore
INCLUDE         include[ \t]*=
LOGFILE         logfile
MAXLENGTH       maxlength
MAXSIZE_ALLOW   maxsize_allow
MAXSIZE_DENY    maxsize_deny
MAXSIZE_SCORE   maxsize_score
NORMAL          normal
REG_CASE        reg_case
REG_TYPE        reg_type
SERVER          server
USER            user
PASS            pass
PROTOCOL        protocol
PORT            port
SHOW_HEADERS    show_headers
SCORE           score
SCORE_CASE      score_case
SCORE_NOCASE    score_nocase
TEST            test
TIMEOUT         timeout
VERBOSE         verbose
REM		^[[:blank:]]*#.*
NOT_EQUAL	<>
EXP		\"([[:graph:]]+)|([[:graph:]]+.*[[:graph:]]+)\"
TEXT_ID		[[:alnum:]]+
YES_NO_ID       (yes|no)
SHELL_CMD	\`([[:graph:]]|[[:blank:]])+\'
ENV_VAR		[\$]([[:alnum:]]|_)+
NUM_ID		(\+|\-|[0-9])[0-9]*
CTRL_CHAR	.

		int    num_lines      = 0;
		int    temp_num_lines = 0;
		string sub_file;

%%
{INCLUDE} {
     BEGIN(INCL);
     temp_num_lines = num_lines;
     num_lines = 0;
}

<INCL>[ \t]* {; /* Eat the whitespace.  */ }

<INCL>[^ \t\n]+ {
     /* Include further rcfiles:  */
     wordexp_t result;

     if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
     {
        cerr << PACKAGE_NAME << ": Error: Files nested too deep." << endl;
	exit (-1);
     }
     include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
     
     try
     {
        if (wordexp (yytext, &result, 0) == 0)
        {
	   sub_file = result.we_wordv[0];
           wordfree (&result);
        }
        else
        {
           cerr << PACKAGE_NAME << ": Error: Nested rcfile '";
	   cerr << yytext << "' could not be found." << endl;
	   exit (-1);
        }
	
	// yyin is now a std::istream& it seems. So the following no longer works:
	// yyin = new ifstream (sub_file.c_str ());
	std::ifstream* infile = new ifstream (sub_file.c_str ());

	// if (!((std::ifstream*) yyin)->is_open ())
        if (!infile->is_open ())
        {
           cerr << PACKAGE_NAME << ": Error: Nested rcfile '";
	   cerr << sub_file << "' could not be opened." << endl;
	   exit (-1);
        }

        yy_switch_to_buffer (yy_create_buffer (infile, YY_BUF_SIZE));
	// yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
     }
     catch (...)
     {
	cerr << PACKAGE_NAME << ": Error: Exception was thrown when "
	     << "trying to read '"
             << yytext << "'." << endl;
        exit (-1);
     }

     BEGIN(INITIAL);
}

<<EOF>> {
     if (--include_stack_ptr < 0)
        yyterminate ();
     else
     {
        yy_delete_buffer (YY_CURRENT_BUFFER);
        yy_switch_to_buffer (include_stack[include_stack_ptr]);
     }

     num_lines = temp_num_lines;
     sub_file = "";
}

{REM} {; /* Do nothing with remarks.  */ }

{ALLOW} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Allow.");
     return ALLOW;
}

{ALLOW_CASE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Allow_Case.");
     return ALLOW_CASE;
}

{ALLOW_NOCASE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Allow_Nocase.");
     return ALLOW_NOCASE;
}

{DEL_DUPLICATES} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Del_Duplicates.");
     BEGIN(PARAM_BOOL);
     return DEL_DUPLICATES;
}

{DENY} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Deny.");
     return DENY;
}

{DENY_CASE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Deny_Case.");
     return DENY_CASE;
}

{DENY_NOCASE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Deny_Nocase.");
     return DENY_NOCASE;
}

{HIGHSCORE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Highscore.");
     BEGIN(PARAM_NUM);
     return HIGHSCORE;
}

{LOGFILE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Logfile.");
     return LOGFILE;
}

{MAXLENGTH} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Maxlength.");
     BEGIN(PARAM_NUM);
     return MAXLENGTH;
}

{MAXSIZE_ALLOW} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Maxsize_Allow.");
     BEGIN(PARAM_NUM);
     return MAXSIZE_ALLOW;
}

{MAXSIZE_DENY} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Maxsize_Deny.");
     BEGIN(PARAM_NUM);
     return MAXSIZE_DENY;
}

{MAXSIZE_SCORE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Maxsize_Score.");
     BEGIN(PARAM_NUM);
     return MAXSIZE_SCORE;
}

{NORMAL} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Normal.");
     BEGIN(PARAM_BOOL);
     return NORMAL;
}

{SERVER} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Server.");
     return SERVER;
}

{USER} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("User.");
     return USER;
}

{PASS} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Pass.");
     return PASS;
}

{PROTOCOL} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Protocol.");
     return PROTOCOL;
}

{PORT} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Port.");
     BEGIN(PARAM_NUM);
     return PORT;
}

{REG_CASE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Reg_Case.");
     BEGIN(PARAM_BOOL);
     return REG_CASE;
}

{REG_TYPE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Reg_Type.");
     return REG_TYPE;
}

{SHOW_HEADERS} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Show_Headers.");
     return SHOW_HEADERS;
}

{SCORE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Score.");
     BEGIN(PARAM_NUM);
     return SCORE;
}

{SCORE_CASE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Score_Case.");
     BEGIN(PARAM_NUM);
     return SCORE_CASE;
}

{SCORE_NOCASE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Score_Nocase.");
     BEGIN(PARAM_NUM);
     return SCORE_NOCASE;
}

{TEST} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Test.");
     BEGIN(PARAM_BOOL);
     return TEST;
}

{TIMEOUT} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Timeout.");
     BEGIN(PARAM_NUM);
     return TIMEOUT;
}

{VERBOSE} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Verbose.");
     BEGIN(PARAM_NUM);
     return VERBOSE;
}
     
"=" {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG((string)rclval.sval +
          " (" + int_to_string (YY_START) + ")");
     return '=';
}

"<>" {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG((string)rclval.sval +
	         " (" + int_to_string (YY_START) + ")");
     return NOT_EQUAL;
}

"\"" {
     /* Beginning of an argument:  */
     rclval.sval = strdup (yytext);
     if (YY_START != PARAM_BOOL)
       BEGIN(PARAM);
     L_DEBUG_MSG((string)"Opening \"" +
	         " (" + int_to_string (YY_START) + ")");
     return '"';
}

<PARAM_NUM>{NUM_ID} {
     rclval.ival = atoi (yytext);
     L_DEBUG_MSG("Num_Id: " + (string)yytext +
	         " (" + int_to_string (YY_START) + ")");
     return NUM_ID;
}

<PARAM>{SHELL_CMD} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Shell_Cmd: " + (string)rclval.sval +
	         " (" + int_to_string (YY_START) + ")");
     return SHELL_CMD;
}

<PARAM>{ENV_VAR} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Env_Var: " + (string)rclval.sval +
	         " (" + int_to_string (YY_START) + ")");
     return ENV_VAR;
}

<PARAM_BOOL>{YES_NO_ID} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Yes_No_Id: " + (string)rclval.sval + 
	         " (" + int_to_string (YY_START) + ")");
     return YES_NO_ID;
}

<PARAM>{TEXT_ID} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Text_Id: " + (string)rclval.sval +
                 " (" + int_to_string (YY_START) + ")");
     return TEXT_ID;
}

<PARAM,PARAM_BOOL>\"[[:blank:]]*$ {
     /* Ending of an argument:  */
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG((string)"Closing \"" +
	         " (" + int_to_string (YY_START) + ")");
     return '"';
}

<PARAM>{CTRL_CHAR} {
     rclval.sval = strdup (yytext);
     L_DEBUG_MSG("Ctrl_Char: " + (string)rclval.sval +
	         " (" + int_to_string (YY_START) + ")");
     return CTRL_CHAR;
}

<*>[ \t] {; /* Do nothing with tabs and spaces.  */ }

<*>"\n" { ++num_lines; BEGIN(0); }

<*>. {
     if (sub_file != "")
     {
     	cerr << PACKAGE_NAME << ": Error: Lexicographical error in line ";
        cerr << (num_lines + 1) << " of your rcfile '" << sub_file;
        cerr << "'."  << endl;
     }
     else
     {
        cerr << PACKAGE_NAME << ": Error: Lexicographical error in line ";
        cerr << (num_lines + 1) << " of your main rcfile."  << endl;
     }

     cerr << PACKAGE_NAME << ": The term '" << yytext;
     cerr << "' could not be interpreted." << endl;
     exit (-1);
}

%%