2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-09-02 07:15:39 +00:00

Some library cleanup; no interface changes

git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@120 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Frodo Looijaard
1998-12-25 22:15:48 +00:00
parent faa996f454
commit 1654f21fc5
4 changed files with 41 additions and 32 deletions

View File

@@ -58,7 +58,7 @@ int sensors_match_chip(sensors_chip_name chip1, sensors_chip_name chip2)
Note that this visits the list of chips from last to first. Usually, Note that this visits the list of chips from last to first. Usually,
you want the match that was latest in the config file. */ you want the match that was latest in the config file. */
sensors_chip *sensors_for_all_config_chips(sensors_chip_name chip_name, sensors_chip *sensors_for_all_config_chips(sensors_chip_name chip_name,
sensors_chip *last) const sensors_chip *last)
{ {
int nr,i; int nr,i;
sensors_chip_name_list chips; sensors_chip_name_list chips;
@@ -77,10 +77,11 @@ sensors_chip *sensors_for_all_config_chips(sensors_chip_name chip_name,
/* Look up a resource in the intern chip list, and return a pointer to it. /* Look up a resource in the intern chip list, and return a pointer to it.
Do not modify the struct the return value points to! Returns NULL if Do not modify the struct the return value points to! Returns NULL if
not found.*/ not found.*/
sensors_chip_feature *sensors_lookup_feature_nr(const char *prefix, int feature) const sensors_chip_feature *sensors_lookup_feature_nr(const char *prefix,
int feature)
{ {
int i,j; int i,j;
sensors_chip_feature *features; const sensors_chip_feature *features;
for (i = 0; sensors_chip_features_list[i].prefix; i++) for (i = 0; sensors_chip_features_list[i].prefix; i++)
if (!strcmp(sensors_chip_features_list[i].prefix,prefix)) { if (!strcmp(sensors_chip_features_list[i].prefix,prefix)) {
features = sensors_chip_features_list[i].feature; features = sensors_chip_features_list[i].feature;
@@ -94,11 +95,11 @@ sensors_chip_feature *sensors_lookup_feature_nr(const char *prefix, int feature)
/* Look up a resource in the intern chip list, and return a pointer to it. /* Look up a resource in the intern chip list, and return a pointer to it.
Do not modify the struct the return value points to! Returns NULL if Do not modify the struct the return value points to! Returns NULL if
not found.*/ not found.*/
sensors_chip_feature *sensors_lookup_feature_name(const char *prefix, const sensors_chip_feature *sensors_lookup_feature_name(const char *prefix,
const char *feature) const char *feature)
{ {
int i,j; int i,j;
sensors_chip_feature *features; const sensors_chip_feature *features;
for (i = 0; sensors_chip_features_list[i].prefix; i++) for (i = 0; sensors_chip_features_list[i].prefix; i++)
if (!strcmp(sensors_chip_features_list[i].prefix,prefix)) { if (!strcmp(sensors_chip_features_list[i].prefix,prefix)) {
features = sensors_chip_features_list[i].feature; features = sensors_chip_features_list[i].feature;
@@ -129,8 +130,8 @@ int sensors_chip_name_has_wildcards(sensors_chip_name chip)
This function will return 0 on success, and <0 on failure. */ This function will return 0 on success, and <0 on failure. */
int sensors_get_label(sensors_chip_name name, int feature, char **result) int sensors_get_label(sensors_chip_name name, int feature, char **result)
{ {
sensors_chip *chip; const sensors_chip *chip;
sensors_chip_feature *featureptr; const sensors_chip_feature *featureptr;
int i; int i;
if (sensors_chip_name_has_wildcards(name)) if (sensors_chip_name_has_wildcards(name))
@@ -151,13 +152,13 @@ int sensors_get_label(sensors_chip_name name, int feature, char **result)
/* Read the value of a feature of a certain chip. Note that chip should not /* Read the value of a feature of a certain chip. Note that chip should not
contain wildcard values! This function will return 0 on success, and <0 contain wildcard values! This function will return 0 on success, and <0
on failure. */ on failure. */
int sensors_get_feature(sensors_chip_name name, int feature, double *result) int sensors_get_feature(sensors_chip_name name, int feature, double *result)
{ {
sensors_chip_feature *main_feature; const sensors_chip_feature *main_feature;
sensors_chip_feature *alt_feature; const sensors_chip_feature *alt_feature;
sensors_chip *chip; const sensors_chip *chip;
sensors_expr *expr = NULL; const sensors_expr *expr = NULL;
double val; double val;
int res,i; int res,i;
int final_expr=0; int final_expr=0;
@@ -194,12 +195,12 @@ int sensors_get_feature(sensors_chip_name name, int feature, double *result)
/* Set the value of a feature of a certain chip. Note that chip should not /* Set the value of a feature of a certain chip. Note that chip should not
contain wildcard values! This function will return 0 on success, and <0 contain wildcard values! This function will return 0 on success, and <0
on failure. */ on failure. BUGGY! */
int sensors_set_feature(sensors_chip_name name, int feature, double value) int sensors_set_feature(sensors_chip_name name, int feature, double value)
{ {
sensors_chip_feature *featureptr; const sensors_chip_feature *featureptr;
sensors_chip *chip; const sensors_chip *chip;
sensors_expr *expr = NULL; const sensors_expr *expr = NULL;
int i,res; int i,res;
if (sensors_chip_name_has_wildcards(name)) if (sensors_chip_name_has_wildcards(name))
@@ -280,12 +281,12 @@ const sensors_feature_data *sensors_get_all_features (sensors_chip_name name,
return NULL; return NULL;
} }
int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr, int sensors_eval_expr(sensors_chip_name chipname, const sensors_expr *expr,
double val, double *result) double val, double *result)
{ {
double res1,res2; double res1,res2;
int res; int res;
sensors_chip_feature *feature; const sensors_chip_feature *feature;
if (expr->kind == sensors_kind_val) { if (expr->kind == sensors_kind_val) {
*result = expr->data.val; *result = expr->data.val;
@@ -329,5 +330,3 @@ int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,
} }
return 0; return 0;
} }

View File

@@ -31,19 +31,19 @@
Note that this visits the list of chips from last to first. Usually, Note that this visits the list of chips from last to first. Usually,
you want the match that was latest in the config file. */ you want the match that was latest in the config file. */
extern sensors_chip *sensors_for_all_config_chips(sensors_chip_name chip_name, extern sensors_chip *sensors_for_all_config_chips(sensors_chip_name chip_name,
sensors_chip *last); const sensors_chip *last);
/* Look up a resource in the intern chip list, and return a pointer to it. /* Look up a resource in the intern chip list, and return a pointer to it.
Do not modify the struct the return value points to! Returns NULL if Do not modify the struct the return value points to! Returns NULL if
not found. */ not found. */
extern sensors_chip_feature *sensors_lookup_feature_nr(const char *prefix, extern const sensors_chip_feature *sensors_lookup_feature_nr(const char *prefix,
int feature); int feature);
/* Look up a resource in the intern chip list, and return a pointer to it. /* Look up a resource in the intern chip list, and return a pointer to it.
Do not modify the struct the return value points to! Returns NULL if Do not modify the struct the return value points to! Returns NULL if
not found.*/ not found.*/
extern sensors_chip_feature *sensors_lookup_feature_name(const char *prefix, extern const sensors_chip_feature *sensors_lookup_feature_name
const char *feature); (const char *prefix, const char *feature);
/* Substitute configuration bus numbers with real-world /proc bus numbers /* Substitute configuration bus numbers with real-world /proc bus numbers
in the chips lists */ in the chips lists */
@@ -55,7 +55,8 @@ extern int sensors_substitute_busses(void);
extern int sensors_parse_i2cbus_name(const char *name, int *res); extern int sensors_parse_i2cbus_name(const char *name, int *res);
/* Evaluate an expression */ /* Evaluate an expression */
extern int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr, extern int sensors_eval_expr(sensors_chip_name chipname,
const sensors_expr *expr,
double val, double *result); double val, double *result);

View File

@@ -52,7 +52,7 @@ const char *sensors_strerror(int errnum)
void sensors_default_parse_error(const char *err, int lineno) void sensors_default_parse_error(const char *err, int lineno)
{ {
fprintf(stderr,"Line %d: %s\n",lineno,err); fprintf(stderr,"Error: Line %d: %s\n",lineno,err);
} }
void sensors_default_fatal_error(const char *proc, const char *err) void sensors_default_fatal_error(const char *proc, const char *err)

View File

@@ -67,20 +67,24 @@ int sensors_read_proc_chips(void)
int buflen = BUF_LEN; int buflen = BUF_LEN;
char *bufptr = buf; char *bufptr = buf;
sensors_proc_chips_entry entry; sensors_proc_chips_entry entry;
int res; int res,lineno;
if (sysctl(name, 3, bufptr, &buflen, NULL, 0)) if (sysctl(name, 3, bufptr, &buflen, NULL, 0))
return -SENSORS_ERR_PROC; return -SENSORS_ERR_PROC;
lineno = 1;
while (buflen >= sizeof(struct sensors_chips_data)) { while (buflen >= sizeof(struct sensors_chips_data)) {
if ((res = if ((res =
sensors_parse_chip_name(((struct sensors_chips_data *) bufptr)->name, sensors_parse_chip_name(((struct sensors_chips_data *) bufptr)->name,
&entry.name))) &entry.name))) {
sensors_parse_error("Parsing /proc/sys/dev/sensors/chips",lineno);
return res; return res;
}
entry.sysctl = ((struct sensors_chips_data *) bufptr)->sysctl_id; entry.sysctl = ((struct sensors_chips_data *) bufptr)->sysctl_id;
add_proc_chips(&entry); add_proc_chips(&entry);
bufptr += sizeof(struct sensors_chips_data); bufptr += sizeof(struct sensors_chips_data);
buflen -= sizeof(struct sensors_chips_data); buflen -= sizeof(struct sensors_chips_data);
lineno++;
} }
return 0; return 0;
} }
@@ -91,9 +95,12 @@ int sensors_read_proc_bus(void)
char line[255]; char line[255];
char *border; char *border;
sensors_bus entry; sensors_bus entry;
int lineno;
f = fopen("/proc/bus/i2c","r"); f = fopen("/proc/bus/i2c","r");
if (!f) if (!f)
return -SENSORS_ERR_PROC; return -SENSORS_ERR_PROC;
lineno=1;
while (fgets(line,255,f)) { while (fgets(line,255,f)) {
if (strlen(line) > 0) if (strlen(line) > 0)
line[strlen(line)-1] = '\0'; line[strlen(line)-1] = '\0';
@@ -117,12 +124,14 @@ int sensors_read_proc_bus(void)
sensors_strip_of_spaces(entry.algorithm); sensors_strip_of_spaces(entry.algorithm);
sensors_strip_of_spaces(entry.adapter); sensors_strip_of_spaces(entry.adapter);
add_bus(&entry); add_bus(&entry);
lineno++;
} }
fclose(f); fclose(f);
return 0; return 0;
FAT_ERROR: FAT_ERROR:
sensors_fatal_error("sensors_read_proc_bus","Allocating entry"); sensors_fatal_error("sensors_read_proc_bus","Allocating entry");
ERROR: ERROR:
sensors_parse_error("Parsing /proc/bus/i2c",lineno);
fclose(f); fclose(f);
return -SENSORS_ERR_PROC; return -SENSORS_ERR_PROC;
} }
@@ -142,7 +151,7 @@ int sensors_get_chip_id(sensors_chip_name name)
int sensors_read_proc(sensors_chip_name name, int feature, double *value) int sensors_read_proc(sensors_chip_name name, int feature, double *value)
{ {
int sysctl_name[4] = { CTL_DEV, DEV_SENSORS }; int sysctl_name[4] = { CTL_DEV, DEV_SENSORS };
sensors_chip_feature *the_feature; const sensors_chip_feature *the_feature;
int buflen = BUF_LEN; int buflen = BUF_LEN;
int mag; int mag;
@@ -164,7 +173,7 @@ int sensors_read_proc(sensors_chip_name name, int feature, double *value)
int sensors_write_proc(sensors_chip_name name, int feature, double value) int sensors_write_proc(sensors_chip_name name, int feature, double value)
{ {
int sysctl_name[4] = { CTL_DEV, DEV_SENSORS }; int sysctl_name[4] = { CTL_DEV, DEV_SENSORS };
sensors_chip_feature *the_feature; const sensors_chip_feature *the_feature;
int buflen = BUF_LEN; int buflen = BUF_LEN;
int mag; int mag;