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