cgdlex.l revision 1.3 1 1.1 elric %{
2 1.3 elric /* $NetBSD: cgdlex.l,v 1.3 2008/05/11 03:15:21 elric 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.3 elric __RCSID("$NetBSD: cgdlex.l,v 1.3 2008/05/11 03:15:21 elric 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.3 elric #define QUOTEDBEGIN() do { \
64 1.3 elric BEGIN(quoted); \
65 1.3 elric quoted_string = string_zero(); \
66 1.3 elric } while (0)
67 1.3 elric #define QUOTEDADD() do { \
68 1.3 elric string_t *tmp; \
69 1.3 elric \
70 1.3 elric tmp = string_new(yytext, yyleng); \
71 1.3 elric quoted_string = string_add_d(quoted_string, tmp); \
72 1.3 elric } while (0)
73 1.3 elric #define RETQUOTED(x) do { \
74 1.3 elric yylval.string = quoted_string; \
75 1.3 elric quoted_string = NULL; \
76 1.3 elric BEGIN(INITIAL); \
77 1.3 elric return(x); \
78 1.3 elric } while (0)
79 1.3 elric
80 1.1 elric int yylineno;
81 1.1 elric
82 1.3 elric string_t *quoted_string;
83 1.3 elric
84 1.1 elric void yyerror(const char *);
85 1.1 elric int yylex(void);
86 1.1 elric %}
87 1.1 elric
88 1.3 elric %x quoted
89 1.3 elric
90 1.1 elric %%
91 1.1 elric
92 1.1 elric [0-9]+ { RETINTEGER(INTEGER); }
93 1.1 elric algorithm { RETTOKEN(ALGORITHM); }
94 1.1 elric keylength { RETTOKEN(KEYLENGTH); }
95 1.1 elric iv-method { RETTOKEN(IVMETHOD); }
96 1.1 elric verify_method { RETTOKEN(VERIFY_METHOD); }
97 1.1 elric keygen { RETTOKEN(KEYGEN); }
98 1.1 elric salt { RETTOKEN(SALT); }
99 1.1 elric iterations { RETTOKEN(ITERATIONS); }
100 1.1 elric key { RETTOKEN(KEY); }
101 1.3 elric cmd { RETTOKEN(CMD); }
102 1.1 elric keygen_method { RETTOKEN(KEYGEN_METHOD); }
103 1.1 elric keygen_salt { RETTOKEN(KEYGEN_SALT); }
104 1.1 elric keygen_iterations { RETTOKEN(KEYGEN_ITERATIONS); }
105 1.1 elric xor_key { RETTOKEN(XOR_KEY); }
106 1.1 elric [;\n] { return EOL; }
107 1.1 elric \\\n /* ignore a quoted nl */
108 1.1 elric [ \t] /* ignore spaces and tabs */
109 1.1 elric #[^;\n]* /* ignore comments */
110 1.3 elric [^ }{\t\n;"]+ { RETSTRING(STRINGLIT); }
111 1.3 elric
112 1.3 elric \" { QUOTEDBEGIN(); }
113 1.3 elric <quoted>[^\"]+ { QUOTEDADD(); }
114 1.3 elric <quoted>\" { RETQUOTED(STRINGLIT); }
115 1.3 elric
116 1.1 elric . { return yytext[0]; }
117 1.1 elric
118 1.1 elric %%
119 1.1 elric
120 1.1 elric void
121 1.1 elric yyerror(const char *msg)
122 1.1 elric {
123 1.1 elric
124 1.1 elric warnx("%s line %d: %s at '%s'", "foo", yylineno, msg, yytext);
125 1.1 elric }
126