Add a parameter to sensors_get_detected_chips(), to optionally let the

caller select which subset of chips it wants. This is slightly better
size-wise than letting all applications do the filtering by themselves.

This will change the way the command line parameters of "sensors" are
interpreted. Beforehand, the chips were always returned in the order
in which they were listed by the library. Also, each chip could be listed
only once. From now on, the chips will be listed in the order in which
they are passed on the command line, which I think makes more sense. A
side effect is that chips can be listed more than once, if that's what
the user asks for. Not very useful though.

This change makes it possible to make sensors_match_chip() internal
to the library. Filtering the list of chips returned by
sensors_get_detected_chips() was the last known external use for this
function.

This patch looks much bigger than it really is, but the largest part is
really only code reindentation.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4701 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-08-26 08:26:20 +00:00
1 parent ff4cfd53d5
commit 4d6bec8bb2
6 files changed
+76 -70

No files matched your search

+14 -11
View File
@@ -303,13 +303,17 @@ int sensors_set_value(const sensors_chip_name *name, int feature,
return 0;
}
const sensors_chip_name *sensors_get_detected_chips(int *nr)
const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
*match, int *nr)
{
const sensors_chip_name *res;
res = (*nr >= sensors_proc_chips_count ?
NULL : &sensors_proc_chips[*nr].chip);
(*nr)++;
return res;
while (*nr < sensors_proc_chips_count) {
res = &sensors_proc_chips[(*nr)++].chip;
if (!match || sensors_match_chip(res, match))
return res;
}
return NULL;
}
const char *sensors_get_adapter_name(const sensors_bus_id *bus)
@@ -480,12 +484,11 @@ int sensors_do_chip_sets(const sensors_chip_name *name)
const sensors_chip_name *found_name;
int res = 0;
for (nr = 0; (found_name = sensors_get_detected_chips(&nr));)
if (sensors_match_chip(name, found_name)) {
this_res = sensors_do_this_chip_sets(found_name);
if (!res)
res = this_res;
}
for (nr = 0; (found_name = sensors_get_detected_chips(name, &nr));) {
this_res = sensors_do_this_chip_sets(found_name);
if (this_res)
res = this_res;
}
return res;
}