Home | History | Annotate | Line # | Download | only in cgdconfig
cgdlex.l revision 1.1.34.1
      1       1.1  elric %{
      2  1.1.34.1   yamt /* $NetBSD: cgdlex.l,v 1.1.34.1 2008/05/18 12:30:50 yamt 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.1.34.1   yamt __RCSID("$NetBSD: cgdlex.l,v 1.1.34.1 2008/05/18 12:30:50 yamt 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.34.1   yamt #define QUOTEDBEGIN() do {						\
     64  1.1.34.1   yamt 		BEGIN(quoted);						\
     65  1.1.34.1   yamt 		quoted_string = string_zero();				\
     66  1.1.34.1   yamt 	} while (0)
     67  1.1.34.1   yamt #define QUOTEDADD() do {						\
     68  1.1.34.1   yamt 		string_t	*tmp;					\
     69  1.1.34.1   yamt 									\
     70  1.1.34.1   yamt 		tmp = string_new(yytext, yyleng);			\
     71  1.1.34.1   yamt 		quoted_string = string_add_d(quoted_string, tmp);	\
     72  1.1.34.1   yamt 	} while (0)
     73  1.1.34.1   yamt #define RETQUOTED(x) do {						\
     74  1.1.34.1   yamt 		yylval.string = quoted_string;				\
     75  1.1.34.1   yamt 		quoted_string = NULL;					\
     76  1.1.34.1   yamt 		BEGIN(INITIAL);						\
     77  1.1.34.1   yamt 		return(x);						\
     78  1.1.34.1   yamt 	} while (0)
     79  1.1.34.1   yamt 
     80       1.1  elric int yylineno;
     81       1.1  elric 
     82  1.1.34.1   yamt string_t	*quoted_string;
     83  1.1.34.1   yamt 
     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.1.34.1   yamt %x quoted
     89  1.1.34.1   yamt 
     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.1.34.1   yamt 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.1.34.1   yamt [^ }{\t\n;"]+				{ RETSTRING(STRINGLIT); }
    111  1.1.34.1   yamt 
    112  1.1.34.1   yamt \"					{ QUOTEDBEGIN(); }
    113  1.1.34.1   yamt <quoted>[^\"]+				{ QUOTEDADD(); }
    114  1.1.34.1   yamt <quoted>\"				{ RETQUOTED(STRINGLIT); }
    115  1.1.34.1   yamt 
    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