parse.y revision 147874
190075Sobrien%{
290075Sobrien/*-
390075Sobrien * DEVD (Device action daemon)
490075Sobrien *
590075Sobrien * Copyright (c) 2002 M. Warner Losh <imp@freebsd.org>.
690075Sobrien * All rights reserved.
790075Sobrien *
890075Sobrien * Redistribution and use in source and binary forms, with or without
990075Sobrien * modification, are permitted provided that the following conditions
1090075Sobrien * are met:
1190075Sobrien * 1. Redistributions of source code must retain the above copyright
1290075Sobrien *    notice, this list of conditions and the following disclaimer.
1390075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1490075Sobrien *    notice, this list of conditions and the following disclaimer in the
1590075Sobrien *    documentation and/or other materials provided with the distribution.
1690075Sobrien *
1790075Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1890075Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1990075Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2090075Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2190075Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2290075Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23117395Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24117395Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25117395Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2690075Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2790075Sobrien * SUCH DAMAGE.
2890075Sobrien *
2990075Sobrien * $FreeBSD: head/sbin/devd/parse.y 147874 2005-07-10 03:37:15Z imp $
3090075Sobrien */
3190075Sobrien
3290075Sobrien#include "devd.h"
3390075Sobrien#include <stdio.h>
3490075Sobrien#include <string.h>
3590075Sobrien
3690075Sobrien%}
3790075Sobrien
3890075Sobrien%union {
3990075Sobrien	char *str;
4090075Sobrien	int i;
4190075Sobrien	struct eps *eps;	/* EventProcStatement */
4290075Sobrien	struct event_proc *eventproc;
4390075Sobrien}
4490075Sobrien
4590075Sobrien%token SEMICOLON BEGINBLOCK ENDBLOCK COMMA
4690075Sobrien%token <i> NUMBER
4790075Sobrien%token <str> STRING
4890075Sobrien%token <str> ID
4990075Sobrien%token OPTIONS SET DIRECTORY PID_FILE DEVICE_NAME ACTION MATCH
5090075Sobrien%token ATTACH DETACH NOMATCH NOTIFY MEDIA_TYPE CLASS SUBDEVICE
5190075Sobrien
5290075Sobrien%type <eventproc> match_or_action_list
5390075Sobrien%type <eps> match_or_action match action
5490075Sobrien
5590075Sobrien%%
5690075Sobrien
5790075Sobrienconfig_file
5890075Sobrien	: config_list
5990075Sobrien	|
6090075Sobrien	;
6190075Sobrien
6290075Sobrienconfig_list
6390075Sobrien	: config
6490075Sobrien	| config_list config
6590075Sobrien	;
6690075Sobrien
6790075Sobrienconfig
6890075Sobrien	: option_block
6990075Sobrien	| attach_block
7090075Sobrien	| detach_block
7190075Sobrien	| nomatch_block
7290075Sobrien	| notify_block
7390075Sobrien	;
7490075Sobrien
7590075Sobrienoption_block
7690075Sobrien	: OPTIONS BEGINBLOCK options ENDBLOCK SEMICOLON
7790075Sobrien	;
7890075Sobrien
7990075Sobrienoptions
8090075Sobrien	: option
8190075Sobrien	| options option
8290075Sobrien
8390075Sobrienoption
8490075Sobrien	: directory_option
8590075Sobrien	| pid_file_option
8690075Sobrien	| set_option
8790075Sobrien	;
8890075Sobrien
89102780Skandirectory_option
90102780Skan	: DIRECTORY STRING SEMICOLON { add_directory($2); }
91102780Skan	;
92102780Skan
93102780Skanpid_file_option
94102780Skan	: PID_FILE STRING SEMICOLON { set_pidfile($2); }
9590075Sobrien	;
9690075Sobrien
9790075Sobrienset_option
9890075Sobrien	: SET ID STRING SEMICOLON { set_variable($2, $3); }
9990075Sobrien	;
10090075Sobrien
10190075Sobrienattach_block
10290075Sobrien	: ATTACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
10390075Sobrien		{ add_attach($2, $4); }
10490075Sobrien	| ATTACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
10590075Sobrien	;
10690075Sobrien
10790075Sobriendetach_block
10890075Sobrien	: DETACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
10990075Sobrien		{ add_detach($2, $4); }
11090075Sobrien	| DETACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
11190075Sobrien	;
112117395Skan
11390075Sobriennomatch_block
11490075Sobrien	: NOMATCH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
11590075Sobrien		{ add_nomatch($2, $4); }
11690075Sobrien	| NOMATCH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
11790075Sobrien	;
11890075Sobrien
11990075Sobriennotify_block
12090075Sobrien	: NOTIFY NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
12190075Sobrien		{ add_notify($2, $4); }
12290075Sobrien	| NOTIFY NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
12390075Sobrien	;
12490075Sobrien
12590075Sobrienmatch_or_action_list
12690075Sobrien	: match_or_action { $$ = add_to_event_proc( NULL, $1); }
12790075Sobrien	| match_or_action_list match_or_action
12890075Sobrien			{ $$ = add_to_event_proc($1, $2); }
12990075Sobrien	;
13090075Sobrien
13190075Sobrienmatch_or_action
13290075Sobrien	: match
13390075Sobrien	| action
13490075Sobrien	;
13590075Sobrien
13690075Sobrienmatch
13790075Sobrien	: MATCH STRING STRING SEMICOLON	{ $$ = new_match($2, $3); }
13890075Sobrien	| DEVICE_NAME STRING SEMICOLON
13990075Sobrien		{ $$ = new_match(strdup("device-name"), $2); }
14090075Sobrien	| MEDIA_TYPE STRING SEMICOLON
14190075Sobrien		{ $$ = new_media(strdup("media-type"), $2); }
14290075Sobrien	| CLASS STRING SEMICOLON
14390075Sobrien		{ $$ = new_match(strdup("class"), $2); }
14490075Sobrien	| SUBDEVICE STRING SEMICOLON
14590075Sobrien		{ $$ = new_match(strdup("subdevice"), $2); }
14690075Sobrien	;
14790075Sobrien
14890075Sobrienaction
14990075Sobrien	: ACTION STRING SEMICOLON	{ $$ = new_action($2); }
15090075Sobrien	;
15190075Sobrien
15290075Sobrien%%
15390075Sobrien