cgdlex.l revision 1.1 1 %{
2 /* $NetBSD: cgdlex.l,v 1.1 2003/03/24 02:02:50 elric Exp $ */
3
4 /*-
5 * Copyright (c) 2003 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Roland C. Dowdeswell.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/cdefs.h>
41 #ifndef lint
42 __RCSID("$NetBSD: cgdlex.l,v 1.1 2003/03/24 02:02:50 elric Exp $");
43 #endif
44
45 #include <err.h>
46 #include <stdio.h>
47
48 #include "utils.h"
49 #include "cgdparse.h"
50
51 /*
52 * We use macros here to separate the C from the tokeniser, to
53 * ease reading each.
54 */
55
56 #define RETSTRING(x) do { \
57 yylval.string = string_new(yytext, yyleng); \
58 return (x); \
59 } while (0)
60 #define RETTOKEN(x) do { \
61 yylval.token.text = yytext; \
62 yylval.token.length = yyleng; \
63 return (x); \
64 } while (0)
65 #define RETINTEGER(x) do { \
66 yylval.integer = atoi(yytext); \
67 return (x); \
68 } while (0)
69
70 int yylineno;
71
72 void yyerror(const char *);
73 int yylex(void);
74 %}
75
76 %%
77
78 [0-9]+ { RETINTEGER(INTEGER); }
79 algorithm { RETTOKEN(ALGORITHM); }
80 keylength { RETTOKEN(KEYLENGTH); }
81 iv-method { RETTOKEN(IVMETHOD); }
82 verify_method { RETTOKEN(VERIFY_METHOD); }
83 keygen { RETTOKEN(KEYGEN); }
84 salt { RETTOKEN(SALT); }
85 iterations { RETTOKEN(ITERATIONS); }
86 key { RETTOKEN(KEY); }
87 keygen_method { RETTOKEN(KEYGEN_METHOD); }
88 keygen_salt { RETTOKEN(KEYGEN_SALT); }
89 keygen_iterations { RETTOKEN(KEYGEN_ITERATIONS); }
90 xor_key { RETTOKEN(XOR_KEY); }
91 [;\n] { return EOL; }
92 \\\n /* ignore a quoted nl */
93 [ \t] /* ignore spaces and tabs */
94 #[^;\n]* /* ignore comments */
95 [^ }{\t\n;]+ { RETSTRING(STRINGLIT); }
96 . { return yytext[0]; }
97
98 %%
99
100 void
101 yyerror(const char *msg)
102 {
103
104 warnx("%s line %d: %s at '%s'", "foo", yylineno, msg, yytext);
105 }
106