claws-mail/src/matcher_parser_lex.l
Colin Leroy c25c80704c 2004-08-24 [colin] 0.9.12cvs79.3
* src/matcher_parser_lex.l
		Fix 8bits strings not in utf8
2004-08-24 09:16:16 +00:00

114 lines
2.5 KiB
Plaintext

%{
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (c) 2001-2002 by Hiroyuki Yamamoto & The Sylpheed Claws Team.
*
* 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.
*/
#include <string.h>
#include <glib.h>
#include "codeconv.h"
#include "matcher.h"
#include "matcher_parser_lex.h"
#include "matcher_parser_parse.h"
#define MAX_STR_CONST 512
#define YY_NO_UNPUT 1
static char string_buf[MAX_STR_CONST];
static char *string_buf_ptr;
static void add_char(char ch)
{
if (string_buf_ptr - string_buf < sizeof(string_buf))
*string_buf_ptr++ = ch;
}
/* this function will reinitializes the parser */
void matcher_parser_init(void)
{
BEGIN(0);
}
%}
%option prefix="matcher_parser"
%option outfile="lex.yy.c"
%option yylineno
%x string
%x section
%%
/*
* a keyword consists of alpha and underscore
* characters, possibly preceded by a tilde (~)
*/
(~|[a-z])[a-z_]* {
gint id;
if (-1 == (id = get_matchparser_tab_id(yytext))) {
REJECT;
} else
return id;
}
[ \t]+
"\n" return MATCHER_EOL;
"&" return MATCHER_AND;
"|" return MATCHER_OR;
\" {
BEGIN(string);
string_buf_ptr = string_buf;
}
<string>\" {
/* get out of the state: string ends. */
BEGIN(0);
*string_buf_ptr = '\0';
if (!g_utf8_validate(string_buf, -1, NULL)) {
gchar *tmp = conv_codeset_strdup(string_buf, conv_get_current_charset_str(), CS_UTF_8);
if (tmp) {
strcpy(string_buf, tmp);
g_free(tmp);
}
}
yylval.str = string_buf;
return MATCHER_STRING;
}
<string>\\. {
/* take care of quoted characters */
add_char(yytext[1]);
}
<string>. {
add_char(yytext[0]);
}
\[[^\[\]]*\] {
/* for section name in configuration file */
BEGIN(0);
yylval.str = yytext + 1;
yytext[strlen(yytext) - 1] = '\0';
return MATCHER_SECTION;
}
[-+]?[0-9]+ {
yylval.str = yytext;
return MATCHER_INTEGER;
}
%%