root/lm-sensors/trunk/lib/init.c

Revision 5301, 5.0 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     init.c - Part of libsensors, a Linux library for reading sensor data.
3     Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <locale.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "sensors.h"
25 #include "data.h"
26 #include "proc.h"
27 #include "error.h"
28 #include "access.h"
29 #include "conf.h"
30 #include "sysfs.h"
31 #include "scanner.h"
32 #include "init.h"
33
34 static void free_proc_chips_entry(sensors_proc_chips_entry entry);
35 static void free_chip_name(sensors_chip_name name);
36 static void free_bus(sensors_bus bus);
37 static void free_chip(sensors_chip chip);
38 static void free_label(sensors_label label);
39 static void free_set(sensors_set set);
40 static void free_compute(sensors_compute compute);
41 static void free_ignore(sensors_ignore ignore);
42
43 /* Wrapper around sensors_yyparse(), which clears the locale so that
44    the decimal numbers are always parsed properly. */
45 static int sensors_parse(void)
46 {
47   int res;
48   char *locale;
49
50   /* Remember the current locale and clear it */
51   locale = setlocale(LC_ALL, NULL);
52   if (locale) {
53     locale = strdup(locale);
54     setlocale(LC_ALL, "C");
55   }
56
57   res = sensors_yyparse();
58
59   /* Restore the old locale */
60   if (locale) {
61     setlocale(LC_ALL, locale);
62     free(locale);
63   }
64
65   return res;
66 }
67
68 int sensors_init(FILE *input)
69 {
70   int res;
71   sensors_cleanup();
72   if (sensors_init_sysfs()) {
73     if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips()))
74       return res;
75   } else {
76     if ((res = sensors_read_proc_bus()) || (res = sensors_read_proc_chips()))
77       return res;
78   }
79   if ((res = sensors_scanner_init(input)))
80     return -SENSORS_ERR_PARSE;
81   if ((res = sensors_parse()))
82     return -SENSORS_ERR_PARSE;
83   if ((res = sensors_substitute_busses()))
84     return res;
85   return 0;
86 }
87
88 void sensors_cleanup(void)
89 {
90   int i;
91
92   sensors_scanner_exit();
93
94   for (i = 0; i < sensors_proc_chips_count; i++)
95     free_proc_chips_entry(sensors_proc_chips[i]);
96   free(sensors_proc_chips);
97   sensors_proc_chips = NULL;
98   sensors_proc_chips_count = sensors_proc_chips_max = 0;
99  
100   for (i = 0; i < sensors_config_busses_count; i++)
101     free_bus(sensors_config_busses[i]);
102   free(sensors_config_busses);
103   sensors_config_busses = NULL;
104   sensors_config_busses_count = sensors_config_busses_max = 0;
105
106   for (i = 0; i < sensors_config_chips_count; i++)
107     free_chip(sensors_config_chips[i]);
108   free(sensors_config_chips);
109   sensors_config_chips = NULL;
110   sensors_config_chips_count = sensors_config_chips_max = 0;
111
112   for (i = 0; i < sensors_proc_bus_count; i++)
113     free_bus(sensors_proc_bus[i]);
114   free(sensors_proc_bus);
115   sensors_proc_bus = NULL;
116   sensors_proc_bus_count = sensors_proc_bus_max = 0;
117 }
118
119 void free_proc_chips_entry(sensors_proc_chips_entry entry)
120 {
121     free_chip_name(entry.name);
122 }
123
124 void free_chip_name(sensors_chip_name name)
125 {
126   free(name.prefix);
127   free(name.busname);
128 }
129
130 void free_bus(sensors_bus bus)
131 {
132   free(bus.adapter);
133 }
134
135 void free_chip(sensors_chip chip)
136 {
137   int i;
138
139   for (i = 0; i < chip.chips.fits_count; i++)
140     free_chip_name(chip.chips.fits[i]);
141   free(chip.chips.fits);
142   chip.chips.fits_count = chip.chips.fits_max = 0;
143
144   for (i = 0; i < chip.labels_count; i++)
145     free_label(chip.labels[i]);
146   free(chip.labels);
147   chip.labels_count = chip.labels_max = 0;
148
149   for (i = 0; i < chip.sets_count; i++)
150     free_set(chip.sets[i]);
151   free(chip.sets);
152   chip.sets_count = chip.sets_max = 0;
153
154   for (i = 0; i < chip.computes_count; i++)
155     free_compute(chip.computes[i]);
156   free(chip.computes);
157   chip.computes_count = chip.computes_max = 0;
158
159   for (i = 0; i < chip.ignores_count; i++)
160     free_ignore(chip.ignores[i]);
161   free(chip.ignores);
162   chip.ignores_count = chip.ignores_max = 0;
163 }
164
165 void free_label(sensors_label label)
166 {
167   free(label.name);
168   free(label.value);
169 }
170
171 void free_set(sensors_set set)
172 {
173   free(set.name);
174   sensors_free_expr(set.value);
175 }
176
177 void free_compute(sensors_compute compute)
178 {
179   free(compute.name);
180   sensors_free_expr(compute.from_proc);
181   sensors_free_expr(compute.to_proc);
182 }
183
184 void free_ignore(sensors_ignore ignore)
185 {
186   free(ignore.name);
187 }
188
189 void sensors_free_expr(sensors_expr *expr)
190 {
191   if ((expr->kind) == sensors_kind_var)
192     free(expr->data.var);
193   else if ((expr->kind) == sensors_kind_sub) {
194     if (expr->data.subexpr.sub1)
195       sensors_free_expr(expr->data.subexpr.sub1);
196     if (expr->data.subexpr.sub2)
197       sensors_free_expr(expr->data.subexpr.sub2);
198   }
199   free(expr);
200 }
Note: See TracBrowser for help on using the browser.