%{ /* VTun - Virtual Tunnel over TCP/IP network. Copyright (C) 1998-2000 Maxim Krasnyansky VTun has been derived from VPPP package by Maxim Krasnyansky. 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. */ /* * $Id: cfg_file.l,v 1.4.2.1 2007/06/29 05:25:49 mtbishop Exp $ */ #include "config.h" #include #include "vtun.h" #include "cfg_file.tab.h" #include "cfg_kwords.h" /* static buffer for strings */ char str_buf[255]; int find_keyword(struct kword *kw, char *str); #define ECHO {;} #define YY_DECL int yylex(void) /* Push and pop parser state */ static int stack[16]; static int ptr = 0; #define PUSH_STATE() \ do { \ if( ptr == 16 ){ \ yyerror("To many pushes to parser's state stack"); \ return K_ERROR; \ } \ stack[ptr++] = YY_START; \ } while(0) #define POP_STATE() \ do { \ if( !ptr ){ \ yyerror("To many pops from parser's state stack"); \ return K_ERROR; \ } \ BEGIN(stack[--ptr]); \ } while(0) int cfg_error(const char *ftm, ...); int yyerror(char *str); %} num [0-9]+ dnum {num}:{num} word [A-Za-z0-9\-\_+=\!\$\#\%\&\*\^\@@\\\~\.]+ wordnm {word}:{num} kword [A-Za-z0-9\_\-]+ comment \#.*\n fname [A-Za-z0-9\_\.\-]+ path (\/{fname})+ string \".*\" %x OPTION PARAM %% <*>[ \t] ; /* Skip spaces and tabs (All stages) */ <*>\n { lineno++; } /* (All stages) */ {comment} { lineno++; } /* Skip comments */ {kword} { int kw = find_keyword(cfg_keyword,yytext); if( kw != -1 ) return kw; /* Keyword not found, means host definition. */ yylval.str = yytext; return K_HOST; } {word} { yylval.str = yytext; return K_ERROR; } <*>\{ { PUSH_STATE(); BEGIN(OPTION); return *yytext; } <*>\} { POP_STATE(); return *yytext; }