2002-03-20 23:21:22 +00:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002
|
|
|
|
* Antti Tapaninen <aet@cc.hut.fi>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; 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 <stdio.h>
|
|
|
|
#include "scconf.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
static scconf_parser *parser;
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%option noyywrap
|
|
|
|
%option nounput
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2003-08-25 09:29:42 +00:00
|
|
|
"#"[^\r\n]* scconf_parse_token(parser, TOKEN_TYPE_COMMENT, yytext);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
|
|
|
\n scconf_parse_token(parser, TOKEN_TYPE_NEWLINE, NULL);
|
|
|
|
|
2003-08-25 09:29:42 +00:00
|
|
|
[ \t\r]+ /* eat up whitespace */
|
2002-03-20 23:21:22 +00:00
|
|
|
|
|
|
|
[,{}=;] scconf_parse_token(parser, TOKEN_TYPE_PUNCT, yytext);
|
|
|
|
|
2003-08-25 09:29:42 +00:00
|
|
|
\"[^\"\n\r]*\r*[\"\n] scconf_parse_token(parser, TOKEN_TYPE_STRING, yytext);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
2003-08-25 09:29:42 +00:00
|
|
|
[^;, \t\r\n]+ scconf_parse_token(parser, TOKEN_TYPE_STRING, yytext);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
2003-04-11 11:19:04 +00:00
|
|
|
#ifndef YY_CURRENT_BUFFER_LVALUE
|
|
|
|
# define YY_CURRENT_BUFFER_LVALUE yy_current_buffer
|
|
|
|
#endif
|
|
|
|
|
2003-01-03 11:54:02 +00:00
|
|
|
static void do_lex(scconf_parser *p)
|
2002-03-20 23:21:22 +00:00
|
|
|
{
|
|
|
|
parser = p;
|
|
|
|
|
|
|
|
yylex();
|
2003-01-03 11:54:02 +00:00
|
|
|
|
2002-11-12 11:35:59 +00:00
|
|
|
#if 1
|
|
|
|
/* For non-reentrant C scanner only. */
|
2003-04-11 11:19:04 +00:00
|
|
|
if (YY_CURRENT_BUFFER) {
|
|
|
|
yy_delete_buffer(YY_CURRENT_BUFFER);
|
|
|
|
YY_CURRENT_BUFFER_LVALUE = NULL;
|
2002-11-12 11:35:59 +00:00
|
|
|
yy_init = 1;
|
|
|
|
yy_start = 0;
|
|
|
|
}
|
2002-04-09 11:24:33 +00:00
|
|
|
#endif
|
2003-01-03 11:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int scconf_lex_parse(scconf_parser *p, const char *filename)
|
|
|
|
{
|
|
|
|
yyin = fopen(filename, "r");
|
|
|
|
if (yyin == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do_lex(p);
|
|
|
|
|
2002-03-20 23:21:22 +00:00
|
|
|
fclose(yyin);
|
2003-01-03 11:54:02 +00:00
|
|
|
yyin = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int scconf_lex_parse_string(scconf_parser *p, const char *conf_string)
|
|
|
|
{
|
|
|
|
yy_scan_string(conf_string);
|
|
|
|
do_lex(p);
|
2002-03-20 23:21:22 +00:00
|
|
|
return 1;
|
|
|
|
}
|