xref: /freebsd/usr.sbin/apmd/apmdlex.l (revision 719b9dc1afc07b94f216383e50f66f55e888c16d)
1d50a71bdSMitsuru IWASAKI %{
2d50a71bdSMitsuru IWASAKI /*-
3d50a71bdSMitsuru IWASAKI  * APM (Advanced Power Management) Event Dispatcher
4d50a71bdSMitsuru IWASAKI  *
5d50a71bdSMitsuru IWASAKI  * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
6d50a71bdSMitsuru IWASAKI  * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
7d50a71bdSMitsuru IWASAKI  * All rights reserved.
8d50a71bdSMitsuru IWASAKI  *
9d50a71bdSMitsuru IWASAKI  * Redistribution and use in source and binary forms, with or without
10d50a71bdSMitsuru IWASAKI  * modification, are permitted provided that the following conditions
11d50a71bdSMitsuru IWASAKI  * are met:
12d50a71bdSMitsuru IWASAKI  * 1. Redistributions of source code must retain the above copyright
13d50a71bdSMitsuru IWASAKI  *    notice, this list of conditions and the following disclaimer.
14d50a71bdSMitsuru IWASAKI  * 2. Redistributions in binary form must reproduce the above copyright
15d50a71bdSMitsuru IWASAKI  *    notice, this list of conditions and the following disclaimer in the
16d50a71bdSMitsuru IWASAKI  *    documentation and/or other materials provided with the distribution.
17d50a71bdSMitsuru IWASAKI  *
18d50a71bdSMitsuru IWASAKI  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19d50a71bdSMitsuru IWASAKI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20d50a71bdSMitsuru IWASAKI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21d50a71bdSMitsuru IWASAKI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22d50a71bdSMitsuru IWASAKI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23d50a71bdSMitsuru IWASAKI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24d50a71bdSMitsuru IWASAKI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25d50a71bdSMitsuru IWASAKI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26d50a71bdSMitsuru IWASAKI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27d50a71bdSMitsuru IWASAKI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28d50a71bdSMitsuru IWASAKI  * SUCH DAMAGE.
29d50a71bdSMitsuru IWASAKI  *
3097d92980SPeter Wemm  * $FreeBSD$
31d50a71bdSMitsuru IWASAKI  */
32d50a71bdSMitsuru IWASAKI 
33d50a71bdSMitsuru IWASAKI #include <string.h>
34d50a71bdSMitsuru IWASAKI #include <syslog.h>
35d50a71bdSMitsuru IWASAKI #include <bitstring.h>
36d50a71bdSMitsuru IWASAKI #include "apmd.h"
37d50a71bdSMitsuru IWASAKI #include "y.tab.h"
38d50a71bdSMitsuru IWASAKI 
39d50a71bdSMitsuru IWASAKI int lineno;
40d50a71bdSMitsuru IWASAKI int first_time;
41d50a71bdSMitsuru IWASAKI %}
42d50a71bdSMitsuru IWASAKI 
43d50a71bdSMitsuru IWASAKI %s TOP
44d50a71bdSMitsuru IWASAKI 
45d50a71bdSMitsuru IWASAKI %%
46d50a71bdSMitsuru IWASAKI 
47d50a71bdSMitsuru IWASAKI %{
48d50a71bdSMitsuru IWASAKI 	if (first_time) {
49d50a71bdSMitsuru IWASAKI 		BEGIN TOP;
50d50a71bdSMitsuru IWASAKI 		lineno = 1;
51d50a71bdSMitsuru IWASAKI 		first_time = 0;
52d50a71bdSMitsuru IWASAKI 	}
53d50a71bdSMitsuru IWASAKI %}
54d50a71bdSMitsuru IWASAKI 
55d50a71bdSMitsuru IWASAKI <TOP>[ \t]+		;
56d50a71bdSMitsuru IWASAKI <TOP>\n			lineno++;
57d50a71bdSMitsuru IWASAKI <TOP>,			{ return COMMA; }
58d50a71bdSMitsuru IWASAKI <TOP>;			{ return SEMICOLON; }
59d50a71bdSMitsuru IWASAKI <TOP>#.*$		;
60d50a71bdSMitsuru IWASAKI 
61d50a71bdSMitsuru IWASAKI <TOP>apm_event		{ return APMEVENT; }
62d50a71bdSMitsuru IWASAKI 
63d50a71bdSMitsuru IWASAKI <TOP>NOEVENT		{ yylval.ev = EVENT_NOEVENT; return EVENT; }
64d50a71bdSMitsuru IWASAKI <TOP>STANDBYREQ		{ yylval.ev = EVENT_STANDBYREQ; return EVENT; }
65d50a71bdSMitsuru IWASAKI <TOP>SUSPENDREQ		{ yylval.ev = EVENT_SUSPENDREQ; return EVENT; }
66d50a71bdSMitsuru IWASAKI <TOP>NORMRESUME		{ yylval.ev = EVENT_NORMRESUME; return EVENT; }
67d50a71bdSMitsuru IWASAKI <TOP>CRITRESUME		{ yylval.ev = EVENT_CRITRESUME; return EVENT; }
68d50a71bdSMitsuru IWASAKI <TOP>BATTERYLOW		{ yylval.ev = EVENT_BATTERYLOW; return EVENT; }
69d50a71bdSMitsuru IWASAKI <TOP>POWERSTATECHANGE	{ yylval.ev = EVENT_POWERSTATECHANGE; return EVENT; }
70d50a71bdSMitsuru IWASAKI <TOP>UPDATETIME		{ yylval.ev = EVENT_UPDATETIME; return EVENT; }
71d50a71bdSMitsuru IWASAKI <TOP>CRITSUSPEND	{ yylval.ev = EVENT_CRITSUSPEND; return EVENT; }
72d50a71bdSMitsuru IWASAKI <TOP>USERSTANDBYREQ	{ yylval.ev = EVENT_USERSTANDBYREQ; return EVENT; }
73d50a71bdSMitsuru IWASAKI <TOP>USERSUSPENDREQ	{ yylval.ev = EVENT_USERSUSPENDREQ; return EVENT; }
74d50a71bdSMitsuru IWASAKI <TOP>STANDBYRESUME	{ yylval.ev = EVENT_STANDBYRESUME; return EVENT; }
75d50a71bdSMitsuru IWASAKI <TOP>CAPABILITIESCHANGE	{ yylval.ev = EVENT_CAPABILITIESCHANGE; return EVENT; }
76d50a71bdSMitsuru IWASAKI 
77719b9dc1SNick Sayer <TOP>apm_battery	{ return APMBATT; }
78719b9dc1SNick Sayer 
79719b9dc1SNick Sayer <TOP>charging		{ return BATTCHARGE; }
80719b9dc1SNick Sayer <TOP>discharging	{ return BATTDISCHARGE; }
81719b9dc1SNick Sayer <TOP>[0-9]+%		{
82719b9dc1SNick Sayer 				yylval.i = atoi(yytext);
83719b9dc1SNick Sayer 				return BATTPERCENT;
84719b9dc1SNick Sayer 			}
85719b9dc1SNick Sayer <TOP>[0-9]+[Mm]		{
86719b9dc1SNick Sayer 				yylval.i = -atoi(yytext);
87719b9dc1SNick Sayer 				return BATTTIME;
88719b9dc1SNick Sayer 			}
89719b9dc1SNick Sayer 
90d50a71bdSMitsuru IWASAKI <TOP>exec		{ return EXECCMD; }
91d50a71bdSMitsuru IWASAKI <TOP>reject		{ return REJECTCMD; }
92d50a71bdSMitsuru IWASAKI 
93d50a71bdSMitsuru IWASAKI <TOP>\{			{ return BEGINBLOCK; }
94d50a71bdSMitsuru IWASAKI <TOP>\}			{ return ENDBLOCK; }
95d50a71bdSMitsuru IWASAKI <TOP>\"[^"]+\"	{
96d50a71bdSMitsuru IWASAKI 				int len = strlen(yytext) - 2;
97d50a71bdSMitsuru IWASAKI 				if ((yylval.str = (char *) malloc(len + 1)) == NULL)
98d50a71bdSMitsuru IWASAKI 					goto out;
99d50a71bdSMitsuru IWASAKI 				memcpy(yylval.str, yytext + 1, len);
100d50a71bdSMitsuru IWASAKI 				yylval.str[len] = '\0';
101d50a71bdSMitsuru IWASAKI 			out:
102d50a71bdSMitsuru IWASAKI 				return STRING;
103d50a71bdSMitsuru IWASAKI 			}
104d50a71bdSMitsuru IWASAKI 
105d50a71bdSMitsuru IWASAKI <TOP>[^"{},;#\n\t ]+	{ yylval.str = strdup(yytext); return UNKNOWN; }
106d50a71bdSMitsuru IWASAKI %%
107d50a71bdSMitsuru IWASAKI 
108d50a71bdSMitsuru IWASAKI void
109d50a71bdSMitsuru IWASAKI yyerror(const char *s)
110d50a71bdSMitsuru IWASAKI {
111d50a71bdSMitsuru IWASAKI 	syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s);
112d50a71bdSMitsuru IWASAKI }
113