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