3 * $Id: lexer.l,v 1.7 2004/04/08 01:36:20 mdw Exp $
5 * Lexical analyser for `become.conf' files
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of `become'
14 * `Become' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * `Become' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with `become'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Declarations section ----------------------------------------------*/
31 /* --- Header files --- */
38 #include <mLib/report.h>
45 /* --- Start conditions --- */
51 /* --- A handy static buffer --- */
53 static char lex__buff[4096];
54 static char *lex__ptr;
56 /* --- Line number --- */
62 /*---- Main scanner definition -------------------------------------------*/
64 /* --- Comments --- */
66 <INITIAL,s_KEYWORD,s_NORMAL>{
69 /* --- Whitespace --- */
75 /* --- Keywords --- */
78 user BEGIN(s_NORMAL); return (USER);
79 command BEGIN(s_NORMAL); return (COMMAND);
80 host BEGIN(s_NORMAL); return (HOST);
81 allow BEGIN(s_NORMAL); return (ALLOW);
82 port BEGIN(s_NORMAL); return (PORT);
83 keyfile BEGIN(s_NORMAL); return (KEYFILE);
84 . BEGIN(s_NORMAL); return (BADTOKEN);
86 /* --- Other sorts of tokens --- */
89 [0-9]* yylval.i = atoi(yytext); return (INT);
90 [a-zA-Z_][a-zA-Z_0-9]* yylval.s = yytext; return (WORD);
91 \" BEGIN(s_STRING); lex__ptr = lex__buff;
92 ";" BEGIN(s_KEYWORD); return (';');
97 /* --- Strings and things --- *
99 * Be a little careful about buffer overflows here.
105 lex__buff + sizeof(lex__buff) - 8) {
106 moan("string too long at line %i",
109 yylval.s = lex__buff;
113 *lex__ptr++ = yytext[1];
117 yylval.s = lex__buff;
123 moan("missing `\"', inserted at line %i",
127 yylval.s = lex__buff;
133 lex__buff + sizeof(lex__buff) - 8) {
134 moan("string too long at line %i",
137 yylval.s = lex__buff;
141 *lex__ptr++ = yytext[0];
147 /*----- Support routines --------------------------------------------------*/
149 /* --- @lexer_scan@ --- *
151 * Arguments: @FILE *fp@ = pointer to a stream object to scan
155 * Use: Initialises the scanner ready to parse from the given
159 void lexer_scan(FILE *fp)
166 /*----- That's all, folks -------------------------------------------------*/