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$
30105573Simp */
31105573Simp
32107665Simp#include <ctype.h>
33105573Simp#include <stdlib.h>
34105573Simp#include <string.h>
35105573Simp#include <syslog.h>
36105573Simp#include "devd.h"
37105573Simp#include "y.tab.h"
38105573Simp
39105573Simpint lineno = 1;
40105573Simp
41107665Simpstatic void
42107665Simpupdate_lineno(const char *cp)
43107665Simp{
44107665Simp	while (*cp)
45107665Simp		if (*cp++ == '\n')
46107665Simp			lineno++;
47107665Simp}
48107665Simp
49105573Simp%}
50105573Simp
51252181Smarius%option nounput
52252181Smarius%option noinput
53252181Smarius
54105573Simp%%
55105573Simp
56105573Simp[ \t]+			;
57105573Simp\n			lineno++;
58105573Simp;			{ return SEMICOLON; }
59107665Simp#.*$			;
60105573Simp\/\/.*$			;
61117945Simp\/\*([^*]|(\*+([^*\/])))*\*+\/ { update_lineno(yytext); }
62105573Simp\{			{ return BEGINBLOCK; }
63105573Simp\}			{ return ENDBLOCK; }
64105573Simp[0-9]+			{ yylval.i = atoi(yytext); return NUMBER; }
65105573Simp\"[^"]+\"		{
66105573Simp				int len = strlen(yytext) - 2;
67107665Simp				char *walker;
68107665Simp				int i;
69177483Simp				update_lineno(yytext);
70105573Simp				if ((yylval.str = (char *) malloc(len + 1)) == NULL)
71105573Simp					goto out;
72107665Simp				walker = yylval.str;
73107665Simp				for (i = 1; i <= len; i++) {
74107665Simp					if (yytext[i] == '\\' &&
75107665Simp					    yytext[i + 1] == '\n') {
76107665Simp						i += 2;
77107665Simp						while(isspace(yytext[i]))
78107665Simp							i++;
79107665Simp					}
80107665Simp					*walker++ = yytext[i];
81107665Simp				}
82107665Simp				*walker++ = '\0';
83105573Simp			out:;
84105573Simp				return STRING;
85105573Simp			}
86105573Simp
87105573Simp
88105573Simpoptions			{ return OPTIONS; }
89105573Simpset			{ return SET; }
90105573Simpdirectory		{ return DIRECTORY; }
91105573Simppid-file		{ return PID_FILE; }
92105573Simpattach			{ return ATTACH; }
93105573Simpdetach			{ return DETACH; }
94105573Simpdevice-name		{ return DEVICE_NAME; }
95147874Simpmedia-type		{ return MEDIA_TYPE; }
96147874Simpclass			{ return CLASS; }
97147874Simpsubdevice		{ return SUBDEVICE; }
98105573Simpaction			{ return ACTION; }
99105573Simpmatch			{ return MATCH; }
100105573Simpnomatch			{ return NOMATCH; }
101121487Simpnotify			{ return NOTIFY; }
102108014Simp[A-Za-z][A-Za-z0-9_-]*	{
103107665Simp				yylval.str = strdup(yytext);
104105573Simp				return ID;
105105573Simp			}
106105573Simp%%
107105573Simp
108105573Simpvoid
109105573Simpyyerror(const char *s)
110105573Simp{
111105573Simp	syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s);
112105573Simp}
113