179727Sschweikh%{
281588Sru/*-
379727Sschweikh * APM (Advanced Power Management) Event Dispatcher
471088Sjasone *
571088Sjasone * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
671088Sjasone * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
771088Sjasone * All rights reserved.
871088Sjasone *
979727Sschweikh * Redistribution and use in source and binary forms, with or without
1071088Sjasone * modification, are permitted provided that the following conditions
1171088Sjasone * are met:
1271088Sjasone * 1. Redistributions of source code must retain the above copyright
1371088Sjasone *    notice, this list of conditions and the following disclaimer.
1471088Sjasone * 2. Redistributions in binary form must reproduce the above copyright
1571088Sjasone *    notice, this list of conditions and the following disclaimer in the
1671088Sjasone *    documentation and/or other materials provided with the distribution.
1771088Sjasone *
1871088Sjasone * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1971088Sjasone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2071088Sjasone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2171088Sjasone * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2271088Sjasone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2371088Sjasone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2471088Sjasone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2571088Sjasone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2671088Sjasone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2771088Sjasone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2871088Sjasone * SUCH DAMAGE.
29247812Sdavide *
3071088Sjasone * $FreeBSD$
3171088Sjasone */
3271088Sjasone
3371088Sjasone#include <string.h>
3471088Sjasone#include <syslog.h>
3571088Sjasone#include <bitstring.h>
3671088Sjasone#include "apmd.h"
3771088Sjasone#include "y.tab.h"
38167373Sjhb
3971088Sjasoneint lineno;
40247812Sdavideint first_time;
4171088Sjasone%}
42247812Sdavide
4371088Sjasone/* We don't need it, avoid the warning. */
4471088Sjasone%option nounput
45126814Sjhb%option noinput
4671088Sjasone
4771088Sjasone%s TOP
4871088Sjasone
4988509Sdavidc%%
5088509Sdavidc
5184306Sru%{
5271088Sjasone	if (first_time) {
5371088Sjasone		BEGIN TOP;
5471088Sjasone		lineno = 1;
5571088Sjasone		first_time = 0;
5671088Sjasone	}
57167789Sjhb%}
5871088Sjasone
59167789Sjhb<TOP>[ \t]+		;
60167373Sjhb<TOP>\n			lineno++;
61167789Sjhb<TOP>,			{ return COMMA; }
6271088Sjasone<TOP>;			{ return SEMICOLON; }
63167789Sjhb<TOP>#.*$		;
6471088Sjasone
65247812Sdavide<TOP>apm_event		{ return APMEVENT; }
66247812Sdavide
67247812Sdavide<TOP>NOEVENT		{ yylval.ev = EVENT_NOEVENT; return EVENT; }
68167789Sjhb<TOP>STANDBYREQ		{ yylval.ev = EVENT_STANDBYREQ; return EVENT; }
69247812Sdavide<TOP>SUSPENDREQ		{ yylval.ev = EVENT_SUSPENDREQ; return EVENT; }
70247812Sdavide<TOP>NORMRESUME		{ yylval.ev = EVENT_NORMRESUME; return EVENT; }
71247812Sdavide<TOP>CRITRESUME		{ yylval.ev = EVENT_CRITRESUME; return EVENT; }
7271088Sjasone<TOP>BATTERYLOW		{ yylval.ev = EVENT_BATTERYLOW; return EVENT; }
7371088Sjasone<TOP>POWERSTATECHANGE	{ yylval.ev = EVENT_POWERSTATECHANGE; return EVENT; }
7471088Sjasone<TOP>UPDATETIME		{ yylval.ev = EVENT_UPDATETIME; return EVENT; }
7571088Sjasone<TOP>CRITSUSPEND	{ yylval.ev = EVENT_CRITSUSPEND; return EVENT; }
7671088Sjasone<TOP>USERSTANDBYREQ	{ yylval.ev = EVENT_USERSTANDBYREQ; return EVENT; }
77126814Sjhb<TOP>USERSUSPENDREQ	{ yylval.ev = EVENT_USERSUSPENDREQ; return EVENT; }
7871088Sjasone<TOP>STANDBYRESUME	{ yylval.ev = EVENT_STANDBYRESUME; return EVENT; }
7971088Sjasone<TOP>CAPABILITIESCHANGE	{ yylval.ev = EVENT_CAPABILITIESCHANGE; return EVENT; }
8071088Sjasone
8171088Sjasone<TOP>apm_battery	{ return APMBATT; }
8271088Sjasone
8371088Sjasone<TOP>charging		{ return BATTCHARGE; }
8471088Sjasone<TOP>discharging	{ return BATTDISCHARGE; }
8571088Sjasone<TOP>[0-9]+%		{
8671096Sru				yylval.i = atoi(yytext);
8771088Sjasone				return BATTPERCENT;
8871096Sru			}
8971088Sjasone<TOP>[0-9]+[Mm]		{
9071096Sru				yylval.i = -atoi(yytext);
9171088Sjasone				return BATTTIME;
9271088Sjasone			}
9371088Sjasone
9471088Sjasone<TOP>exec		{ return EXECCMD; }
9571088Sjasone<TOP>reject		{ return REJECTCMD; }
9671088Sjasone
9771088Sjasone<TOP>\{			{ return BEGINBLOCK; }
98167373Sjhb<TOP>\}			{ return ENDBLOCK; }
9971088Sjasone<TOP>\"[^"]+\"	{
10071088Sjasone				int len = strlen(yytext) - 2;
10171088Sjasone				if ((yylval.str = (char *) malloc(len + 1)) == NULL)
10271088Sjasone					goto out;
10371088Sjasone				memcpy(yylval.str, yytext + 1, len);
10471088Sjasone				yylval.str[len] = '\0';
10571088Sjasone			out:
106126814Sjhb				return STRING;
107126814Sjhb			}
10871088Sjasone
109126814Sjhb<TOP>[^"{},;#\n\t ]+	{ yylval.str = strdup(yytext); return UNKNOWN; }
110126814Sjhb%%
111130843Smpp
112126814Sjhbvoid
113126814Sjhbyyerror(const char *s)
11471088Sjasone{
11571088Sjasone	syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s);
11671096Sru}
11771088Sjasone