1 %{
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "usb_driver.h"
6 #define YY_NO_INPUT
7 static struct devmand_usb_driver *current_drv;
8 static struct devmand_usb_match_id *current_id;
9
10 int yylex(void);
11
yyerror(char * s)12 void yyerror(char *s)
13 {
14 fprintf(stderr,"parsing error: %s\n",s);
15 }
16
yywrap()17 int yywrap()
18 {
19 return 1;
20 }
21 %}
22
23 %union {
24 char *string;
25 }
26
27 %start drivers
28 %token <string> USB_DRIVER DEV_PREFIX BINARY INTERFACE_CLASS INTERFACE_SUB_CLASS EQUALS DEV_TYPE BLOCK_DEV CHAR_DEV UPSCRIPT DOWNSCRIPT
29 SEMICOLON BRACKET_OPEN BRACKET_CLOSE STRING ID INTERFACE_PROTOCOL
30
31 %%
32 drivers :
33 driver
34 {
35 }
36 | drivers driver
37 {
38 };
39
40 driver :
41 USB_DRIVER STRING {current_drv = add_usb_driver($2);}
42 BRACKET_OPEN
43 usb_driver_statements BRACKET_CLOSE
44 {
45 };
46
47 usb_driver_statements:
48 usb_driver_statement
49 {
50 }
51 | usb_driver_statements usb_driver_statement
52 {
53 };
54
55 usb_driver_statement:
56 {current_id = add_usb_match_id(current_drv);}
57 ID BRACKET_OPEN usb_device_id_statements BRACKET_CLOSE
58 {
59 }
60 | BINARY EQUALS STRING SEMICOLON
61 {
62 current_drv->binary = $3;
63 }
64 | DEV_PREFIX EQUALS STRING SEMICOLON
65 {
66 current_drv->devprefix = $3;
67 }
68 | DEV_TYPE EQUALS BLOCK_DEV SEMICOLON
69 {
70 current_drv->dev_type = block_dev;
71 }
72 | DEV_TYPE EQUALS CHAR_DEV SEMICOLON
73 {
74 current_drv->dev_type = char_dev;
75 }
76 | UPSCRIPT EQUALS STRING SEMICOLON
77 {
78 current_drv->upscript = $3;
79 }
80 | DOWNSCRIPT EQUALS STRING SEMICOLON
81 {
82 current_drv->downscript = $3;
83 };
84
85
86 usb_device_id_statements:
87 usb_device_id_statement
88 {
89 }
90 |usb_device_id_statements usb_device_id_statement
91 {
92 };
93
94
95 usb_device_id_statement:
96 INTERFACE_CLASS EQUALS STRING SEMICOLON
97 {
98 int res;
99 unsigned int num;
100 current_id->match_flags |= USB_MATCH_INTERFACE_CLASS;
101 res = sscanf($3, "0x%x", &num);
102 if (res != 1) {
103 fprintf(stderr, "ERROR");
104 exit(1);
105 }
106 current_id->match_id.bInterfaceClass = num;
107 }
108 | INTERFACE_SUB_CLASS EQUALS STRING SEMICOLON
109 {
110 int res;
111 unsigned int num;
112 current_id->match_flags |= USB_MATCH_INTERFACE_SUBCLASS;
113 res = sscanf($3, "0x%x", &num);
114 if (res != 1) {
115 fprintf(stderr, "ERROR");
116 exit(1);
117 }
118 current_id->match_id.bInterfaceSubClass = num;
119
120 }
121 | INTERFACE_PROTOCOL EQUALS STRING SEMICOLON
122 {
123 int res;
124 unsigned int num;
125 current_id->match_flags |= USB_MATCH_INTERFACE_PROTOCOL;
126 res = sscanf($3, "0x%x", &num);
127 if (res != 1) {
128 fprintf(stderr, "ERROR");
129 exit(1);
130 }
131 current_id->match_id.bInterfaceProtocol = num;
132
133 };
134 %%
135