token.l revision 105573
1105573Simp%{
2105573Simp/*-
3105573Simp * DEVD (Device action daemon)
4105573Simp *
5105573Simp * Copyright (c) 2002 M. Warner Losh <imp@freebsd.org>.
6105573Simp * All rights reserved.
7105573Simp *
8105573Simp * Redistribution and use in source and binary forms, with or without
9105573Simp * modification, are permitted provided that the following conditions
10105573Simp * are met:
11105573Simp * 1. Redistributions of source code must retain the above copyright
12105573Simp *    notice, this list of conditions and the following disclaimer.
13105573Simp * 2. Redistributions in binary form must reproduce the above copyright
14105573Simp *    notice, this list of conditions and the following disclaimer in the
15105573Simp *    documentation and/or other materials provided with the distribution.
16105573Simp *
17105573Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18105573Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19105573Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20105573Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21105573Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22105573Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23105573Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24105573Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25105573Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26105573Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27105573Simp * SUCH DAMAGE.
28105573Simp *
29105573Simp * $FreeBSD: head/sbin/devd/token.l 105573 2002-10-20 22:15:17Z imp $
30105573Simp */
31105573Simp
32105573Simp#include <stdlib.h>
33105573Simp#include <string.h>
34105573Simp#include <syslog.h>
35105573Simp#include "devd.h"
36105573Simp#include "y.tab.h"
37105573Simp
38105573Simpint lineno = 1;
39105573Simp#define YY_NO_UNPUT
40105573Simp
41105573Simp%}
42105573Simp
43105573Simp%%
44105573Simp
45105573Simp[ \t]+			;
46105573Simp\n			lineno++;
47105573Simp;			{ return SEMICOLON; }
48105573Simp\/\/.*$			;
49105573Simp\/\*(.|\n)*\*\/		;
50105573Simp\{			{ return BEGINBLOCK; }
51105573Simp\}			{ return ENDBLOCK; }
52105573Simp[0-9]+			{ yylval.i = atoi(yytext); return NUMBER; }
53105573Simp\"[^"]+\"		{
54105573Simp				int len = strlen(yytext) - 2;
55105573Simp				if ((yylval.str = (char *) malloc(len + 1)) == NULL)
56105573Simp					goto out;
57105573Simp				memcpy(yylval.str, yytext + 1, len);
58105573Simp				yylval.str[len] = '\0';
59105573Simp			out:;
60105573Simp				return STRING;
61105573Simp			}
62105573Simp
63105573Simp
64105573Simpoptions			{ return OPTIONS; }
65105573Simpset			{ return SET; }
66105573Simpdirectory		{ return DIRECTORY; }
67105573Simppid-file		{ return PID_FILE; }
68105573Simpattach			{ return ATTACH; }
69105573Simpdetach			{ return DETACH; }
70105573Simpdevice-name		{ return DEVICE_NAME; }
71105573Simpaction			{ return ACTION; }
72105573Simpmatch			{ return MATCH; }
73105573Simpnomatch			{ return NOMATCH; }
74105573Simp[A-Za-z][A-Za-z0-9-]*	{
75105573Simp				int len = strlen(yytext);
76105573Simp				if ((yylval.str = (char *) malloc(len + 1)) == NULL)
77105573Simp					goto out2;
78105573Simp				memcpy(yylval.str, yytext + 1, len);
79105573Simp				yylval.str[len] = '\0';
80105573Simp			out2:;
81105573Simp				return ID;
82105573Simp			}
83105573Simp%%
84105573Simp
85105573Simpvoid
86105573Simpyyerror(const char *s)
87105573Simp{
88105573Simp	syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s);
89105573Simp}
90