1 %{ 2 /* 3 * $Id$ 4 * 5 * Copyright (C) 2002 6 * Antti Tapaninen <aet@cc.hut.fi> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 #include <stdio.h> 27 #include "scconf.h" 28 #include "internal.h" 29 30 static scconf_parser *parser; 31 32 %} 33 34 %option noyywrap 35 %option nounput 36 37 %% 38 39 "#"[^\r\n]* scconf_parse_token(parser, TOKEN_TYPE_COMMENT, yytext); 40 41 \n scconf_parse_token(parser, TOKEN_TYPE_NEWLINE, NULL); 42 43 [ \t\r]+ /* eat up whitespace */ 44 45 [,{}=;] scconf_parse_token(parser, TOKEN_TYPE_PUNCT, yytext); 46 47 \"[^\"\n\r]*\r*[\"\n] scconf_parse_token(parser, TOKEN_TYPE_STRING, yytext); 48 49 [^;, \t\r\n]+ scconf_parse_token(parser, TOKEN_TYPE_STRING, yytext); 50 51 %% 52 53 #ifndef YY_CURRENT_BUFFER_LVALUE 54 # define YY_CURRENT_BUFFER_LVALUE yy_current_buffer 55 #endif 56 57 static void do_lex(scconf_parser *p) 58 { 59 parser = p; 60 61 yylex(); 62 63 #if 1 64 /* For non-reentrant C scanner only. */ 65 if (YY_CURRENT_BUFFER) { 66 yy_delete_buffer(YY_CURRENT_BUFFER); 67 YY_CURRENT_BUFFER_LVALUE = NULL; 68 yy_init = 1; 69 yy_start = 0; 70 } 71 #endif 72 } 73 74 int scconf_lex_parse(scconf_parser *p, const char *filename) 75 { 76 yyin = fopen(filename, "r"); 77 if (yyin == NULL) 78 return 0; 79 80 do_lex(p); 81 82 fclose(yyin); 83 yyin = NULL; 84 return 1; 85 } 86 87 int scconf_lex_parse_string(scconf_parser *p, const char *conf_string) 88 { 89 yy_scan_string(conf_string); 90 do_lex(p); 91 return 1; 92 } 93