root/lm-sensors/branches/lm-sensors-3.0.0/lib/init.c @ 4736

Revision 4736, 4.4 KB (checked in by khali, 7 years ago)

Mass reindent, coding style and whitespace cleanups.

  • 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 <stdlib.h>
21#include <stdio.h>
22#include "sensors.h"
23#include "data.h"
24#include "error.h"
25#include "access.h"
26#include "conf.h"
27#include "sysfs.h"
28#include "scanner.h"
29
30static void free_chip_name(sensors_chip_name *name);
31static void free_chip_features(sensors_chip_feature *features);
32static void free_bus(sensors_bus *bus);
33static void free_chip(sensors_chip *chip);
34static void free_label(sensors_label *label);
35static void free_set(sensors_set *set);
36static void free_compute(sensors_compute *compute);
37static void free_ignore(sensors_ignore *ignore);
38static void free_expr(sensors_expr *expr);
39
40int sensors_init(FILE *input)
41{
42        int res;
43
44        if (!sensors_init_sysfs())
45                return -SENSORS_ERR_PROC;
46        if ((res = sensors_read_sysfs_bus()) ||
47            (res = sensors_read_sysfs_chips()))
48                return res;
49        if ((res = sensors_scanner_init(input)))
50                return -SENSORS_ERR_PARSE;
51        if ((res = sensors_yyparse()))
52                return -SENSORS_ERR_PARSE;
53        if ((res = sensors_substitute_busses()))
54                return res;
55        return 0;
56}
57
58void sensors_cleanup(void)
59{
60        int i;
61
62        sensors_scanner_exit();
63
64        for (i = 0; i < sensors_proc_chips_count; i++) {
65                free_chip_name(&sensors_proc_chips[i].chip);
66                free_chip_features(sensors_proc_chips[i].feature);
67        }
68        free(sensors_proc_chips);
69        sensors_proc_chips = NULL;
70        sensors_proc_chips_count = sensors_proc_chips_max = 0;
71
72        for (i = 0; i < sensors_config_busses_count; i++)
73                free_bus(&sensors_config_busses[i]);
74        free(sensors_config_busses);
75        sensors_config_busses = NULL;
76        sensors_config_busses_count = sensors_config_busses_max = 0;
77
78        for (i = 0; i < sensors_config_chips_count; i++)
79                free_chip(&sensors_config_chips[i]);
80        free(sensors_config_chips);
81        sensors_config_chips = NULL;
82        sensors_config_chips_count = sensors_config_chips_max = 0;
83
84        for (i = 0; i < sensors_proc_bus_count; i++)
85                free_bus(&sensors_proc_bus[i]);
86        free(sensors_proc_bus);
87        sensors_proc_bus = NULL;
88        sensors_proc_bus_count = sensors_proc_bus_max = 0;
89}
90
91void free_chip_name(sensors_chip_name *name)
92{
93        free(name->prefix);
94        free(name->path);
95}
96
97void free_chip_features(sensors_chip_feature *features)
98{
99        int i;
100
101        for (i = 0; features[i].data.name; i++)
102                free(features[i].data.name);
103        free(features);
104}
105
106void free_bus(sensors_bus *bus)
107{
108        free(bus->adapter);
109}
110
111void free_chip(sensors_chip *chip)
112{
113        int i;
114
115        for (i = 0; i < chip->chips.fits_count; i++)
116                free_chip_name(&chip->chips.fits[i]);
117        free(chip->chips.fits);
118        chip->chips.fits_count = chip->chips.fits_max = 0;
119
120        for (i = 0; i < chip->labels_count; i++)
121                free_label(&chip->labels[i]);
122        free(chip->labels);
123        chip->labels_count = chip->labels_max = 0;
124
125        for (i = 0; i < chip->sets_count; i++)
126                free_set(&chip->sets[i]);
127        free(chip->sets);
128        chip->sets_count = chip->sets_max = 0;
129
130        for (i = 0; i < chip->computes_count; i++)
131                free_compute(&chip->computes[i]);
132        free(chip->computes);
133        chip->computes_count = chip->computes_max = 0;
134
135        for (i = 0; i < chip->ignores_count; i++)
136                free_ignore(&chip->ignores[i]);
137        free(chip->ignores);
138        chip->ignores_count = chip->ignores_max = 0;
139}
140
141void free_label(sensors_label *label)
142{
143        free(label->name);
144        free(label->value);
145}
146
147void free_set(sensors_set *set)
148{
149        free(set->name);
150        free_expr(set->value);
151}
152
153void free_compute(sensors_compute *compute)
154{
155        free(compute->name);
156        free_expr(compute->from_proc);
157        free_expr(compute->to_proc);
158}
159
160void free_ignore(sensors_ignore *ignore)
161{
162        free(ignore->name);
163}
164
165void free_expr(sensors_expr *expr)
166{
167        if ((expr->kind) == sensors_kind_var)
168                free(expr->data.var);
169        else if ((expr->kind) == sensors_kind_sub) {
170                if (expr->data.subexpr.sub1)
171                        free_expr(expr->data.subexpr.sub1);
172                if (expr->data.subexpr.sub2)
173                        free_expr(expr->data.subexpr.sub2);
174        }
175        free(expr);
176}
Note: See TracBrowser for help on using the browser.