3 * $Id: lexer.l,v 1.2 1997/08/04 10:24:23 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 /*----- Revision history --------------------------------------------------*
32 * Revision 1.2 1997/08/04 10:24:23 mdw
33 * Sources placed under CVS control.
35 * Revision 1.1 1997/07/21 13:47:48 mdw
40 /*----- Declarations section ----------------------------------------------*/
42 /* --- Header files --- */
55 /* --- Start conditions --- */
61 /* --- A handy static buffer --- */
63 static char lex__buff[4096];
64 static char *lex__ptr;
66 /* --- Line number --- */
72 /*---- Main scanner definition -------------------------------------------*/
74 /* --- Comments --- */
76 <INITIAL,s_KEYWORD,s_NORMAL>{
79 /* --- Whitespace --- */
85 /* --- Keywords --- */
88 user BEGIN(s_NORMAL); return (USER);
89 command BEGIN(s_NORMAL); return (COMMAND);
90 host BEGIN(s_NORMAL); return (HOST);
91 allow BEGIN(s_NORMAL); return (ALLOW);
92 port BEGIN(s_NORMAL); return (PORT);
93 keyfile BEGIN(s_NORMAL); return (KEYFILE);
94 . BEGIN(s_NORMAL); return (BADTOKEN);
96 /* --- Other sorts of tokens --- */
99 [0-9]* yylval.i = atoi(yytext); return (INT);
100 [a-zA-Z_][a-zA-Z_0-9]* yylval.s = yytext; return (WORD);
101 \" BEGIN(s_STRING); lex__ptr = lex__buff;
102 ";" BEGIN(s_KEYWORD); return (';');
104 . return (yytext[0]);
107 /* --- Strings and things --- *
109 * Be a little careful about buffer overflows here.
115 lex__buff + sizeof(lex__buff) - 8) {
116 moan("string too long at line %i",
119 yylval.s = lex__buff;
123 *lex__ptr++ = yytext[1];
127 yylval.s = lex__buff;
133 moan("missing `\"', inserted at line %i",
137 yylval.s = lex__buff;
143 lex__buff + sizeof(lex__buff) - 8) {
144 moan("string too long at line %i",
147 yylval.s = lex__buff;
151 *lex__ptr++ = yytext[0];
157 /*----- Support routines --------------------------------------------------*/
159 /* --- @lexer_scan@ --- *
161 * Arguments: @FILE *fp@ = pointer to a stream object to scan
165 * Use: Initialises the scanner ready to parse from the given
169 void lexer_scan(FILE *fp)
176 /*----- That's all, folks -------------------------------------------------*/