token.l revision 147874
119304Speter%{
219304Speter/*-
319304Speter * DEVD (Device action daemon)
419304Speter *
519304Speter * Copyright (c) 2002 M. Warner Losh <imp@freebsd.org>.
619304Speter * All rights reserved.
719304Speter *
819304Speter * Redistribution and use in source and binary forms, with or without
919304Speter * modification, are permitted provided that the following conditions
1019304Speter * are met:
1119304Speter * 1. Redistributions of source code must retain the above copyright
1219304Speter *    notice, this list of conditions and the following disclaimer.
13254225Speter * 2. Redistributions in binary form must reproduce the above copyright
1419304Speter *    notice, this list of conditions and the following disclaimer in the
1519304Speter *    documentation and/or other materials provided with the distribution.
1619304Speter *
1719304Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18254225Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919304Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2019304Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2119304Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2219304Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2319304Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2419304Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2519304Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2619304Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2719304Speter * SUCH DAMAGE.
28254225Speter *
2919304Speter * $FreeBSD: head/sbin/devd/token.l 147874 2005-07-10 03:37:15Z imp $
3019304Speter */
3119304Speter
3219304Speter#include <ctype.h>
3319304Speter#include <stdlib.h>
3419304Speter#include <string.h>
3519304Speter#include <syslog.h>
3619304Speter#include "devd.h"
3719304Speter#include "y.tab.h"
3819304Speter
3919304Speterint lineno = 1;
4019304Speter#define YY_NO_UNPUT
4119304Speter
4219304Speterstatic void
4319304Speterupdate_lineno(const char *cp)
4419304Speter{
4519304Speter	while (*cp)
4619304Speter		if (*cp++ == '\n')
4719304Speter			lineno++;
4819304Speter}
4919304Speter
5019304Speter%}
5119304Speter
5219304Speter%%
5319304Speter
5419304Speter[ \t]+			;
5519304Speter\n			lineno++;
5619304Speter;			{ return SEMICOLON; }
57254225Speter#.*$			;
5819304Speter\/\/.*$			;
5919304Speter\/\*([^*]|(\*+([^*\/])))*\*+\/ { update_lineno(yytext); }
6019304Speter\{			{ return BEGINBLOCK; }
6119304Speter\}			{ return ENDBLOCK; }
6219304Speter[0-9]+			{ yylval.i = atoi(yytext); return NUMBER; }
6319304Speter\"[^"]+\"		{
6419304Speter				update_lineno(yytext);
65254225Speter				int len = strlen(yytext) - 2;
6619304Speter				char *walker;
6719304Speter				int i;
6819304Speter				if ((yylval.str = (char *) malloc(len + 1)) == NULL)
6919304Speter					goto out;
7019304Speter				walker = yylval.str;
7119304Speter				for (i = 1; i <= len; i++) {
7219304Speter					if (yytext[i] == '\\' &&
7319304Speter					    yytext[i + 1] == '\n') {
74254225Speter						i += 2;
75254225Speter						while(isspace(yytext[i]))
76254225Speter							i++;
7719304Speter					}
7819304Speter					*walker++ = yytext[i];
7919304Speter				}
8019304Speter				*walker++ = '\0';
8119304Speter			out:;
8219304Speter				return STRING;
8319304Speter			}
84254225Speter
8519304Speter
8619304Speteroptions			{ return OPTIONS; }
8719304Speterset			{ return SET; }
8819304Speterdirectory		{ return DIRECTORY; }
8919304Speterpid-file		{ return PID_FILE; }
9019304Speterattach			{ return ATTACH; }
9119304Speterdetach			{ return DETACH; }
9219304Speterdevice-name		{ return DEVICE_NAME; }
9319304Spetermedia-type		{ return MEDIA_TYPE; }
9419304Speterclass			{ return CLASS; }
9519304Spetersubdevice		{ return SUBDEVICE; }
9619304Speteraction			{ return ACTION; }
9719304Spetermatch			{ return MATCH; }
9819304Speternomatch			{ return NOMATCH; }
9919304Speternotify			{ return NOTIFY; }
10019304Speter[A-Za-z][A-Za-z0-9_-]*	{
10119304Speter				yylval.str = strdup(yytext);
10219304Speter				return ID;
10319304Speter			}
10419304Speter%%
10519304Speter
10619304Spetervoid
10719304Speteryyerror(const char *s)
10819304Speter{
10919304Speter	syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s);
11019304Speter}
11119304Speter