summaryrefslogtreecommitdiff
path: root/minix/commands/devmand/usb.y
blob: dcb38193915f10e02eeeb99055ee3024c04438ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "usb_driver.h"
#define YY_NO_INPUT
static struct devmand_usb_driver   *current_drv;
static struct devmand_usb_match_id *current_id;

int yylex(void);

void yyerror(char *s)
{
    fprintf(stderr,"parsing error: %s\n",s);
}

int yywrap()
{
    return 1;
}
%}

%union {
       char *string;
}

%start drivers
%token <string>  USB_DRIVER DEV_PREFIX BINARY INTERFACE_CLASS INTERFACE_SUB_CLASS EQUALS DEV_TYPE BLOCK_DEV CHAR_DEV UPSCRIPT DOWNSCRIPT
SEMICOLON BRACKET_OPEN BRACKET_CLOSE STRING ID INTERFACE_PROTOCOL

%%
drivers :
	driver
	{
	}
    | drivers driver
	{
	};

driver :
	USB_DRIVER STRING {current_drv = add_usb_driver($2);}
	BRACKET_OPEN
	usb_driver_statements BRACKET_CLOSE
	{
	};

usb_driver_statements:
	usb_driver_statement
	{
	}
    | usb_driver_statements usb_driver_statement
	{
	};

usb_driver_statement:
	{current_id = add_usb_match_id(current_drv);}
	ID BRACKET_OPEN usb_device_id_statements BRACKET_CLOSE
	{
	}
	| BINARY EQUALS STRING SEMICOLON
	{
		current_drv->binary = $3;
	}
	| DEV_PREFIX EQUALS STRING SEMICOLON
	{
		current_drv->devprefix = $3;
	}
	| DEV_TYPE EQUALS BLOCK_DEV SEMICOLON
	{
		current_drv->dev_type = block_dev;
	}
	| DEV_TYPE EQUALS CHAR_DEV SEMICOLON
	{
		current_drv->dev_type = char_dev;
	}
	| UPSCRIPT EQUALS STRING SEMICOLON
	{
		current_drv->upscript = $3;
	}
	| DOWNSCRIPT EQUALS STRING SEMICOLON
	{
		current_drv->downscript = $3;
	};


usb_device_id_statements:
	usb_device_id_statement
	{
	}
	|usb_device_id_statements usb_device_id_statement
	{
	};


usb_device_id_statement:
	INTERFACE_CLASS EQUALS STRING SEMICOLON
	{
		int res;
		unsigned int num;
		current_id->match_flags |= USB_MATCH_INTERFACE_CLASS;
		res =  sscanf($3, "0x%x", &num);
		if (res != 1) {
			fprintf(stderr, "ERROR");
			exit(1);
		}
		current_id->match_id.bInterfaceClass = num;
	}
	| INTERFACE_SUB_CLASS EQUALS STRING SEMICOLON
	{
		int res;
		unsigned int num;
		current_id->match_flags |= USB_MATCH_INTERFACE_SUBCLASS;
		res =  sscanf($3, "0x%x", &num);
		if (res != 1) {
			fprintf(stderr, "ERROR");
			exit(1);
		}
		current_id->match_id.bInterfaceSubClass = num;

	}
	| INTERFACE_PROTOCOL EQUALS STRING SEMICOLON
	{
		int res;
		unsigned int num;
		current_id->match_flags |= USB_MATCH_INTERFACE_PROTOCOL;
		res =  sscanf($3, "0x%x", &num);
		if (res != 1) {
			fprintf(stderr, "ERROR");
			exit(1);
		}
		current_id->match_id.bInterfaceProtocol = num;

	};
%%