xref: /freebsd/sbin/devd/parse.y (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 %{
2 /*-
3  * DEVD (Device action daemon)
4  *
5  * Copyright (c) 2002 M. Warner Losh <imp@freebsd.org>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 #include <sys/cdefs.h>
33 #include "devd.h"
34 #include <stdio.h>
35 #include <string.h>
36 
37 %}
38 
39 %union {
40 	char *str;
41 	int i;
42 	struct eps *eps;	/* EventProcStatement */
43 	struct event_proc *eventproc;
44 }
45 
46 %token SEMICOLON BEGINBLOCK ENDBLOCK COMMA
47 %token <i> NUMBER
48 %token <str> STRING
49 %token <str> ID
50 %token OPTIONS SET DIRECTORY PID_FILE DEVICE_NAME ACTION MATCH
51 %token ATTACH DETACH NOMATCH NOTIFY MEDIA_TYPE CLASS SUBDEVICE
52 
53 %type <eventproc> match_or_action_list
54 %type <eps> match_or_action match action
55 
56 %%
57 
58 config_file
59 	: config_list
60 	|
61 	;
62 
63 config_list
64 	: config
65 	| config_list config
66 	;
67 
68 config
69 	: option_block
70 	| attach_block
71 	| detach_block
72 	| nomatch_block
73 	| notify_block
74 	;
75 
76 option_block
77 	: OPTIONS BEGINBLOCK options ENDBLOCK SEMICOLON
78 	;
79 
80 options
81 	: option
82 	| options option
83 
84 option
85 	: directory_option
86 	| pid_file_option
87 	| set_option
88 	;
89 
90 directory_option
91 	: DIRECTORY STRING SEMICOLON { add_directory($2); }
92 	;
93 
94 pid_file_option
95 	: PID_FILE STRING SEMICOLON { set_pidfile($2); }
96 	;
97 
98 set_option
99 	: SET ID STRING SEMICOLON { set_variable($2, $3); }
100 	;
101 
102 attach_block
103 	: ATTACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
104 		{ add_attach($2, $4); }
105 	| ATTACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
106 	;
107 
108 detach_block
109 	: DETACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
110 		{ add_detach($2, $4); }
111 	| DETACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
112 	;
113 
114 nomatch_block
115 	: NOMATCH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
116 		{ add_nomatch($2, $4); }
117 	| NOMATCH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
118 	;
119 
120 notify_block
121 	: NOTIFY NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
122 		{ add_notify($2, $4); }
123 	| NOTIFY NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
124 	;
125 
126 match_or_action_list
127 	: match_or_action { $$ = add_to_event_proc( NULL, $1); }
128 	| match_or_action_list match_or_action
129 			{ $$ = add_to_event_proc($1, $2); }
130 	;
131 
132 match_or_action
133 	: match
134 	| action
135 	;
136 
137 match
138 	: MATCH STRING STRING SEMICOLON	{ $$ = new_match($2, $3); }
139 	| DEVICE_NAME STRING SEMICOLON
140 		{ $$ = new_match(strdup("device-name"), $2); }
141 	| MEDIA_TYPE STRING SEMICOLON
142 		{ $$ = new_media(strdup("media-type"), $2); }
143 	| CLASS STRING SEMICOLON
144 		{ $$ = new_match(strdup("class"), $2); }
145 	| SUBDEVICE STRING SEMICOLON
146 		{ $$ = new_match(strdup("subdevice"), $2); }
147 	;
148 
149 action
150 	: ACTION STRING SEMICOLON	{ $$ = new_action($2); }
151 	;
152 
153 %%
154