root/lm-sensors/trunk/lib/conf-parse.y

Revision 5301, 9.7 kB (checked in by khali, 5 months ago)

The free_expr() function is no longer static in lib/init.c (it is also
used in lib/conf-parse.y), and therefore must be renamed according to
the libsensors naming conventions.
Patch from Sergey Vlasov.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 %{
2 /*
3     conf-parse.y - Part of libsensors, a Linux library for reading sensor data.
4     Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #define YYERROR_VERBOSE
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 #include "data.h"
28 #include "general.h"
29 #include "error.h"
30 #include "conf.h"
31 #include "access.h"
32 #include "init.h"
33
34 static void sensors_yyerror(const char *err);
35 static sensors_expr *malloc_expr(void);
36
37 static sensors_chip *current_chip = NULL;
38
39 #define bus_add_el(el) sensors_add_array_el(el,\
40                                       &sensors_config_busses,\
41                                       &sensors_config_busses_count,\
42                                       &sensors_config_busses_max,\
43                                       sizeof(sensors_bus))
44 #define label_add_el(el) sensors_add_array_el(el,\
45                                         &current_chip->labels,\
46                                         &current_chip->labels_count,\
47                                         &current_chip->labels_max,\
48                                         sizeof(sensors_label));
49 #define set_add_el(el) sensors_add_array_el(el,\
50                                       &current_chip->sets,\
51                                       &current_chip->sets_count,\
52                                       &current_chip->sets_max,\
53                                       sizeof(sensors_set));
54 #define compute_add_el(el) sensors_add_array_el(el,\
55                                           &current_chip->computes,\
56                                           &current_chip->computes_count,\
57                                           &current_chip->computes_max,\
58                                           sizeof(sensors_compute));
59 #define ignore_add_el(el) sensors_add_array_el(el,\
60                                           &current_chip->ignores,\
61                                           &current_chip->ignores_count,\
62                                           &current_chip->ignores_max,\
63                                           sizeof(sensors_ignore));
64 #define chip_add_el(el) sensors_add_array_el(el,\
65                                        &sensors_config_chips,\
66                                        &sensors_config_chips_count,\
67                                        &sensors_config_chips_max,\
68                                        sizeof(sensors_chip));
69
70 #define fits_add_el(el,list) sensors_add_array_el(el,\
71                                                   &(list).fits,\
72                                                   &(list).fits_count,\
73                                                   &(list).fits_max, \
74                                                   sizeof(sensors_chip_name));
75
76 %}
77
78 %union {
79   double value;
80   char *name;
81   void *nothing;
82   sensors_chip_name_list chips;
83   sensors_expr *expr;
84   int bus;
85   sensors_chip_name chip;
86   int line;
87
88
89 %left <nothing> '-' '+'
90 %left <nothing> '*' '/'
91 %left <nothing> NEG
92 %right <nothing> '^' '`'
93
94 %token <nothing> ','
95 %token <nothing> EOL
96 %token <line> BUS
97 %token <line> LABEL
98 %token <line> SET
99 %token <line> CHIP
100 %token <line> COMPUTE
101 %token <line> IGNORE
102 %token <value> FLOAT
103 %token <name> NAME
104 %token <nothing> ERROR
105
106 %type <chips> chip_name_list
107 %type <expr> expression
108 %type <bus> i2cbus_name
109 %type <name> adapter_name
110 %type <name> algorithm_name
111 %type <name> function_name
112 %type <name> string
113 %type <chip> chip_name
114
115 %start input
116
117 %%
118
119 input:    /* empty */
120         | input line
121 ;
122
123 line:     bus_statement EOL
124         | busalgo_statement EOL
125         | label_statement EOL
126         | set_statement EOL
127         | chip_statement EOL
128         | compute_statement EOL
129         | ignore_statement EOL
130         | error EOL
131 ;
132
133 bus_statement:    BUS i2cbus_name adapter_name
134                   { sensors_bus new_el;
135                     new_el.lineno = $1;
136                     new_el.number = $2;
137                     new_el.adapter = $3;
138                     bus_add_el(&new_el);
139                   }
140 ;
141
142 /* for compatibility, deprecated */
143 busalgo_statement:        BUS i2cbus_name adapter_name algorithm_name
144                           { sensors_bus new_el;
145                             new_el.lineno = $1;
146                             new_el.number = $2;
147                             new_el.adapter = $3;
148                             free($4);
149                             bus_add_el(&new_el);
150                           }
151 ;
152
153 label_statement:          LABEL function_name string
154                           { sensors_label new_el;
155                             if (!current_chip) {
156                               sensors_yyerror("Label statement before first chip statement");
157                               free($2);
158                               free($3);
159                               YYERROR;
160                             }
161                             new_el.lineno = $1;
162                             new_el.name = $2;
163                             new_el.value = $3;
164                             label_add_el(&new_el);
165                           }
166 ;
167
168 set_statement:    SET function_name expression
169                   { sensors_set new_el;
170                     if (!current_chip) {
171                       sensors_yyerror("Set statement before first chip statement");
172                       free($2);
173                       sensors_free_expr($3);
174                       YYERROR;
175                     }
176                     new_el.lineno = $1;
177                     new_el.name = $2;
178                     new_el.value = $3;
179                     set_add_el(&new_el);
180                   }
181 ;
182
183 compute_statement:        COMPUTE function_name expression ',' expression
184                           { sensors_compute new_el;
185                             if (!current_chip) {
186                               sensors_yyerror("Compute statement before first chip statement");
187                               free($2);
188                               sensors_free_expr($3);
189                               sensors_free_expr($5);
190                               YYERROR;
191                             }
192                             new_el.lineno = $1;
193                             new_el.name = $2;
194                             new_el.from_proc = $3;
195                             new_el.to_proc = $5;
196                             compute_add_el(&new_el);
197                           }
198 ;
199
200 ignore_statement:       IGNORE function_name
201                         { sensors_ignore new_el;
202                           if (!current_chip) {
203                             sensors_yyerror("Ignore statement before first chip statement");
204                             free($2);
205                             YYERROR;
206                           }
207                           new_el.lineno = $1;
208                           new_el.name = $2;
209                           ignore_add_el(&new_el);
210                         }
211 ;
212
213 chip_statement:   CHIP chip_name_list
214                   { sensors_chip new_el;
215                     new_el.lineno = $1;
216                     new_el.labels = NULL;
217                     new_el.sets = NULL;
218                     new_el.computes = NULL;
219                     new_el.ignores = NULL;
220                     new_el.labels_count = new_el.labels_max = 0;
221                     new_el.sets_count = new_el.sets_max = 0;
222                     new_el.computes_count = new_el.computes_max = 0;
223                     new_el.ignores_count = new_el.ignores_max = 0;
224                     new_el.chips = $2;
225                     chip_add_el(&new_el);
226                     current_chip = sensors_config_chips +
227                                    sensors_config_chips_count - 1;
228                   }
229 ;
230
231 chip_name_list:   chip_name
232                   {
233                     $$.fits = NULL;
234                     $$.fits_count = $$.fits_max = 0;
235                     fits_add_el(&$1,$$);
236                   }
237                 | chip_name_list chip_name
238                   { $$ = $1;
239                     fits_add_el(&$2,$$);
240                   }
241 ;
242        
243 expression:       FLOAT
244                   { $$ = malloc_expr();
245                     $$->data.val = $1;
246                     $$->kind = sensors_kind_val;
247                   }
248                 | NAME
249                   { $$ = malloc_expr();
250                     $$->data.var = $1;
251                     $$->kind = sensors_kind_var;
252                   }
253                 | '@'
254                   { $$ = malloc_expr();
255                     $$->kind = sensors_kind_source;
256                   }
257                 | expression '+' expression
258                   { $$ = malloc_expr();
259                     $$->kind = sensors_kind_sub;
260                     $$->data.subexpr.op = sensors_add;
261                     $$->data.subexpr.sub1 = $1;
262                     $$->data.subexpr.sub2 = $3;
263                   }
264                 | expression '-' expression
265                   { $$ = malloc_expr();
266                     $$->kind = sensors_kind_sub;
267                     $$->data.subexpr.op = sensors_sub;
268                     $$->data.subexpr.sub1 = $1;
269                     $$->data.subexpr.sub2 = $3;
270                   }
271                 | expression '*' expression
272                   { $$ = malloc_expr();
273                     $$->kind = sensors_kind_sub;
274                     $$->data.subexpr.op = sensors_multiply;
275                     $$->data.subexpr.sub1 = $1;
276                     $$->data.subexpr.sub2 = $3;
277                   }
278                 | expression '/' expression
279                   { $$ = malloc_expr();
280                     $$->kind = sensors_kind_sub;
281                     $$->data.subexpr.op = sensors_divide;
282                     $$->data.subexpr.sub1 = $1;
283                     $$->data.subexpr.sub2 = $3;
284                   }
285                 | '-' expression  %prec NEG
286                   { $$ = malloc_expr();
287                     $$->kind = sensors_kind_sub;
288                     $$->data.subexpr.op = sensors_negate;
289                     $$->data.subexpr.sub1 = $2;
290                     $$->data.subexpr.sub2 = NULL;
291                   }
292                 | '(' expression ')'
293                   { $$ = $2; }
294                 | '^' expression
295                   { $$ = malloc_expr();
296                     $$->kind = sensors_kind_sub;
297                     $$->data.subexpr.op = sensors_exp;
298                     $$->data.subexpr.sub1 = $2;
299                     $$->data.subexpr.sub2 = NULL;
300                   }
301                 | '`' expression
302                   { $$ = malloc_expr();
303                     $$->kind = sensors_kind_sub;
304                     $$->data.subexpr.op = sensors_log;
305                     $$->data.subexpr.sub1 = $2;
306                     $$->data.subexpr.sub2 = NULL;
307                   }
308 ;
309
310 i2cbus_name:      NAME
311                   { int res = sensors_parse_i2cbus_name($1,&$$);
312                     free($1);
313                     if (res) {
314                       sensors_yyerror("Parse error in i2c bus name");
315                       YYERROR;
316                     }
317                   }
318 ;
319
320 adapter_name:     NAME
321                   { sensors_strip_of_spaces($1);
322                     $$ = $1; }
323 ;
324
325 algorithm_name:   NAME
326                   { sensors_strip_of_spaces($1);
327                     $$ = $1; }
328 ;
329
330 function_name:    NAME
331                   { $$ = $1; }
332 ;
333
334 string:   NAME
335           { $$ = $1; }
336 ;
337
338 chip_name:        NAME
339                   { int res = sensors_parse_chip_name($1,&$$);
340                     free($1);
341                     if (res) {
342                       sensors_yyerror("Parse error in chip name");
343                       YYERROR;
344                     }
345                   }
346 ;
347
348 %%
349
350 void sensors_yyerror(const char *err)
351 {
352   if (sensors_lex_error[0]) {
353     sensors_parse_error(sensors_lex_error,sensors_yylineno);
354     sensors_lex_error[0] = '\0';
355   } else
356     sensors_parse_error(err,sensors_yylineno);
357 }
358
359 sensors_expr *malloc_expr(void)
360 {
361   sensors_expr *res = malloc(sizeof(sensors_expr));
362   if (! res)
363     sensors_fatal_error("malloc_expr","Allocating a new expression");
364   return res;
365 }
366  
Note: See TracBrowser for help on using the browser.