3 * $Id: lexer.l,v 1.1 1997/07/21 13:47:48 mdw Exp $
5 * Lexical analyser for `become.conf' files
10 /*----- Licencing 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
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1997/07/21 13:47:48 mdw
37 /*----- Declarations section ----------------------------------------------*/
39 /* --- Header files --- */
52 /* --- Start conditions --- */
58 /* --- A handy static buffer --- */
60 static char lex__buff[4096];
61 static char *lex__ptr;
63 /* --- Line number --- */
69 /*---- Main scanner definition -------------------------------------------*/
71 /* --- Comments --- */
73 <INITIAL,s_KEYWORD,s_NORMAL>{
76 /* --- Whitespace --- */
82 /* --- Keywords --- */
85 user BEGIN(s_NORMAL); return (USER);
86 command BEGIN(s_NORMAL); return (COMMAND);
87 host BEGIN(s_NORMAL); return (HOST);
88 allow BEGIN(s_NORMAL); return (ALLOW);
89 port BEGIN(s_NORMAL); return (PORT);
90 keyfile BEGIN(s_NORMAL); return (KEYFILE);
91 . BEGIN(s_NORMAL); return (BADTOKEN);
93 /* --- Other sorts of tokens --- */
96 [0-9]* yylval.i = atoi(yytext); return (INT);
97 [a-zA-Z_][a-zA-Z_0-9]* yylval.s = yytext; return (WORD);
98 \" BEGIN(s_STRING); lex__ptr = lex__buff;
99 ";" BEGIN(s_KEYWORD); return (';');
101 . return (yytext[0]);
104 /* --- Strings and things --- *
106 * Be a little careful about buffer overflows here.
112 lex__buff + sizeof(lex__buff) - 8) {
113 moan("string too long at line %i",
116 yylval.s = lex__buff;
120 *lex__ptr++ = yytext[1];
124 yylval.s = lex__buff;
130 moan("missing `\"', inserted at line %i",
134 yylval.s = lex__buff;
140 lex__buff + sizeof(lex__buff) - 8) {
141 moan("string too long at line %i",
144 yylval.s = lex__buff;
148 *lex__ptr++ = yytext[0];
154 /*----- Support routines --------------------------------------------------*/
156 /* --- @lexer_scan@ --- *
158 * Arguments: @FILE *fp@ = pointer to a stream object to scan
162 * Use: Initialises the scanner ready to parse from the given
166 void lexer_scan(FILE *fp)
173 /*----- That's all, folks -------------------------------------------------*/