mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-29 12:50:43 +00:00
More library extensions
Most notably, config file line numbers are now stored, so we can now generate better error messages. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@98 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
1779b684c1
commit
f26b52021b
8 files changed
+97
-9
No files matched your search
@@ -116,7 +116,6 @@ sensors_chip_feature *sensors_lookup_feature_name(const char *prefix,
|
||||
int sensors_chip_name_has_wildcards(sensors_chip_name chip)
|
||||
{
|
||||
if ((chip.prefix == SENSORS_CHIP_NAME_PREFIX_ANY) ||
|
||||
(chip.bus == SENSORS_CHIP_NAME_BUS_ISA) ||
|
||||
(chip.bus == SENSORS_CHIP_NAME_BUS_ANY) ||
|
||||
(chip.bus == SENSORS_CHIP_NAME_BUS_ANY_I2C) ||
|
||||
(chip.bus == SENSORS_CHIP_NAME_ADDR_ANY))
|
||||
|
||||
@@ -96,26 +96,31 @@ OCTESC (1[0-7]{0,2})|([2-7][0-7]?)|(0[1-7][0-7]?)|(00[1-7])
|
||||
|
||||
/* Some keywords at the beginning of lines */
|
||||
<INITIAL>"label" {
|
||||
sensors_yylval.line = sensors_yylineno;
|
||||
BEGIN(MIDDLE);
|
||||
return LABEL;
|
||||
}
|
||||
|
||||
<INITIAL>"set" {
|
||||
sensors_yylval.line = sensors_yylineno;
|
||||
BEGIN(MIDDLE);
|
||||
return SET;
|
||||
}
|
||||
|
||||
<INITIAL>"compute" {
|
||||
sensors_yylval.line = sensors_yylineno;
|
||||
BEGIN(MIDDLE);
|
||||
return COMPUTE;
|
||||
}
|
||||
|
||||
<INITIAL>"bus" {
|
||||
sensors_yylval.line = sensors_yylineno;
|
||||
BEGIN(MIDDLE);
|
||||
return BUS;
|
||||
}
|
||||
|
||||
<INITIAL>"chip" {
|
||||
sensors_yylval.line = sensors_yylineno;
|
||||
BEGIN(MIDDLE);
|
||||
return CHIP;
|
||||
}
|
||||
|
||||
+11
-5
@@ -89,6 +89,7 @@ static sensors_chip *current_chip = NULL;
|
||||
sensors_expr *expr;
|
||||
int bus;
|
||||
sensors_chip_name chip;
|
||||
int line;
|
||||
}
|
||||
|
||||
%left <nothing> '-' '+'
|
||||
@@ -97,11 +98,11 @@ static sensors_chip *current_chip = NULL;
|
||||
|
||||
%token <nothing> ','
|
||||
%token <nothing> EOL
|
||||
%token <nothing> BUS
|
||||
%token <nothing> LABEL
|
||||
%token <nothing> SET
|
||||
%token <nothing> CHIP
|
||||
%token <nothing> COMPUTE
|
||||
%token <line> BUS
|
||||
%token <line> LABEL
|
||||
%token <line> SET
|
||||
%token <line> CHIP
|
||||
%token <line> COMPUTE
|
||||
%token <value> FLOAT
|
||||
%token <name> NAME
|
||||
%token <nothing> ERROR
|
||||
@@ -133,6 +134,7 @@ line: bus_statement EOL
|
||||
|
||||
bus_statement: BUS i2cbus_name adapter_name algorithm_name
|
||||
{ sensors_bus new_el;
|
||||
new_el.lineno = $1;
|
||||
new_el.number = $2;
|
||||
new_el.adapter = $3;
|
||||
new_el.algorithm = $4;
|
||||
@@ -143,6 +145,7 @@ bus_statement: BUS i2cbus_name adapter_name algorithm_name
|
||||
label_statement: LABEL function_name string
|
||||
{ sensors_label new_el;
|
||||
check_current_chip();
|
||||
new_el.lineno = $1;
|
||||
new_el.name = $2;
|
||||
new_el.value = $3;
|
||||
label_add_el(&new_el);
|
||||
@@ -152,6 +155,7 @@ label_statement: LABEL function_name string
|
||||
set_statement: SET function_name expression
|
||||
{ sensors_set new_el;
|
||||
check_current_chip();
|
||||
new_el.lineno = $1;
|
||||
new_el.name = $2;
|
||||
new_el.value = $3;
|
||||
set_add_el(&new_el);
|
||||
@@ -161,6 +165,7 @@ set_statement: SET function_name expression
|
||||
compute_statement: COMPUTE function_name expression ',' expression
|
||||
{ sensors_compute new_el;
|
||||
check_current_chip();
|
||||
new_el.lineno = $1;
|
||||
new_el.name = $2;
|
||||
new_el.from_proc = $3;
|
||||
new_el.to_proc = $5;
|
||||
@@ -170,6 +175,7 @@ compute_statement: COMPUTE function_name expression ',' expression
|
||||
|
||||
chip_statement: CHIP chip_name_list
|
||||
{ sensors_chip new_el;
|
||||
new_el.lineno = $1;
|
||||
new_el.labels = NULL;
|
||||
new_el.sets = NULL;
|
||||
new_el.computes = NULL;
|
||||
|
||||
@@ -198,6 +198,7 @@ int sensors_parse_i2cbus_name(const char *name, int *res)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int sensors_eval_expr(sensors_expr *expr, double val, double *result)
|
||||
{
|
||||
double res1,res2;
|
||||
|
||||
+10
@@ -54,17 +54,20 @@ typedef struct sensors_expr {
|
||||
typedef struct sensors_label {
|
||||
char *name;
|
||||
char *value;
|
||||
int lineno;
|
||||
} sensors_label;
|
||||
|
||||
typedef struct sensors_set {
|
||||
char *name;
|
||||
sensors_expr *value;
|
||||
int lineno;
|
||||
} sensors_set;
|
||||
|
||||
typedef struct sensors_compute {
|
||||
char *name;
|
||||
sensors_expr *from_proc;
|
||||
sensors_expr *to_proc;
|
||||
int lineno;
|
||||
} sensors_compute;
|
||||
|
||||
typedef struct sensors_chip_name_list {
|
||||
@@ -84,6 +87,7 @@ typedef struct sensors_chip {
|
||||
sensors_compute *computes;
|
||||
int computes_count;
|
||||
int computes_max;
|
||||
int lineno;
|
||||
} sensors_chip;
|
||||
|
||||
typedef enum sensors_bus_type {sensors_i2c, sensors_isa,
|
||||
@@ -93,6 +97,7 @@ typedef struct sensors_bus {
|
||||
int number;
|
||||
char *adapter;
|
||||
char *algorithm;
|
||||
int lineno;
|
||||
} sensors_bus;
|
||||
|
||||
typedef struct sensors_proc_chips_entry {
|
||||
@@ -100,6 +105,7 @@ typedef struct sensors_proc_chips_entry {
|
||||
sensors_chip_name name;
|
||||
} sensors_proc_chips_entry;
|
||||
|
||||
|
||||
extern sensors_chip *sensors_config_chips;
|
||||
extern int sensors_config_chips_count;
|
||||
extern int sensors_config_chips_max;
|
||||
@@ -112,6 +118,10 @@ extern sensors_proc_chips_entry *sensors_proc_chips;
|
||||
extern int sensors_proc_chips_count;
|
||||
extern int sensors_proc_chips_max;
|
||||
|
||||
extern sensors_bus *sensors_proc_bus;
|
||||
extern int sensors_proc_bus_count;
|
||||
extern int sensors_proc_bus_max;
|
||||
|
||||
/* Parse an i2c bus name into its components. Returns 0 on succes, a value from
|
||||
error.h on failure. */
|
||||
extern int sensors_parse_i2cbus_name(const char *name, int *res);
|
||||
|
||||
+12
-1
@@ -18,12 +18,14 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "sensors.h"
|
||||
#include "data.h"
|
||||
#include "proc.h"
|
||||
#include "error.h"
|
||||
|
||||
extern int sensors_yyparse(void);
|
||||
extern FILE *sensors_yyin;
|
||||
|
||||
static void free_proc_chips_entry(sensors_proc_chips_entry entry);
|
||||
static void free_chip_name(sensors_chip_name name);
|
||||
@@ -34,12 +36,15 @@ static void free_set(sensors_set set);
|
||||
static void free_compute(sensors_compute compute);
|
||||
static void free_expr(sensors_expr *expr);
|
||||
|
||||
int sensors_init(void)
|
||||
int sensors_init(FILE *input)
|
||||
{
|
||||
int res;
|
||||
sensors_cleanup();
|
||||
if ((res = sensors_read_proc_chips()))
|
||||
return res;
|
||||
if ((res = sensors_read_proc_bus()))
|
||||
return res;
|
||||
sensors_yyin = input;
|
||||
if ((res = sensors_yyparse()))
|
||||
return SENSORS_ERR_PARSE;
|
||||
return 0;
|
||||
@@ -66,6 +71,12 @@ void sensors_cleanup(void)
|
||||
free(sensors_config_chips);
|
||||
sensors_config_chips = NULL;
|
||||
sensors_config_chips_count = sensors_config_chips_max = 0;
|
||||
|
||||
for (i = 0; i < sensors_proc_bus_count; i++)
|
||||
free_bus(sensors_proc_bus[i]);
|
||||
free(sensors_proc_bus);
|
||||
sensors_proc_bus = NULL;
|
||||
sensors_proc_bus_count = sensors_proc_bus_max = 0;
|
||||
}
|
||||
|
||||
void free_proc_chips_entry(sensors_proc_chips_entry entry)
|
||||
|
||||
+55
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include "src/sensors.h"
|
||||
@@ -36,6 +38,14 @@
|
||||
|
||||
static char buf[BUF_LEN];
|
||||
|
||||
sensors_proc_chips_entry *sensors_proc_chips;
|
||||
int sensors_proc_chips_count;
|
||||
int sensors_proc_chips_max;
|
||||
|
||||
sensors_bus *sensors_proc_bus;
|
||||
int sensors_proc_bus_count;
|
||||
int sensors_proc_bus_max;
|
||||
|
||||
static int sensors_get_chip_id(sensors_chip_name name);
|
||||
|
||||
#define add_proc_chips(el) sensors_add_array_el(el,\
|
||||
@@ -44,6 +54,12 @@ static int sensors_get_chip_id(sensors_chip_name name);
|
||||
&sensors_proc_chips_max,\
|
||||
sizeof(struct sensors_proc_chips_entry))
|
||||
|
||||
#define add_bus(el) sensors_add_array_el(el,\
|
||||
(void **) &sensors_proc_bus,\
|
||||
&sensors_proc_bus_count,\
|
||||
&sensors_proc_bus_max,\
|
||||
sizeof(struct sensors_bus))
|
||||
|
||||
/* This reads /proc/sys/dev/sensors/chips into memory */
|
||||
int sensors_read_proc_chips(void)
|
||||
{
|
||||
@@ -69,6 +85,45 @@ int sensors_read_proc_chips(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sensors_read_proc_bus(void)
|
||||
{
|
||||
FILE *f;
|
||||
char line[255];
|
||||
char *border;
|
||||
sensors_bus entry;
|
||||
f = fopen("/proc/bus/i2c","r");
|
||||
if (!f)
|
||||
return -SENSORS_ERR_PROC;
|
||||
while (fgets(line,255,f)) {
|
||||
if (! (border = rindex(line,'\t')))
|
||||
goto ERROR;
|
||||
if (! (entry.algorithm = strdup(border+1)))
|
||||
goto FAT_ERROR;
|
||||
*border='\0';
|
||||
if (! (border = rindex(line,'\t')))
|
||||
goto ERROR;
|
||||
if (! (entry.adapter = strdup(border + 1)))
|
||||
goto FAT_ERROR;
|
||||
*border='\0';
|
||||
if (! (border = rindex(line,'\t')))
|
||||
goto ERROR;
|
||||
*border='\0';
|
||||
if (strncmp(line,"i2c-",4))
|
||||
goto ERROR;
|
||||
if (sensors_parse_i2cbus_name(line,&entry.number))
|
||||
goto ERROR;
|
||||
add_bus(&entry);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
FAT_ERROR:
|
||||
sensors_fatal_error("sensors_read_proc_bus","Allocating entry");
|
||||
ERROR:
|
||||
fclose(f);
|
||||
return -SENSORS_ERR_PROC;
|
||||
}
|
||||
|
||||
|
||||
/* This returns the first detected chip which matches the name */
|
||||
int sensors_get_chip_id(sensors_chip_name name)
|
||||
{
|
||||
|
||||
+3
-2
@@ -20,6 +20,8 @@
|
||||
#ifndef LIB_SENSORS_SENSORS_H
|
||||
#define LIB_SENSORS_SENSORS_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Publicly accessible library functions */
|
||||
|
||||
#define SENSORS_CHIP_NAME_PREFIX_ANY NULL
|
||||
@@ -35,13 +37,12 @@ typedef struct sensors_chip_name {
|
||||
} sensors_chip_name;
|
||||
|
||||
/* (Re)load the configuration file and the detected chips list. */
|
||||
extern int sensors_init(void);
|
||||
extern int sensors_init(FILE *input);
|
||||
|
||||
/* Strictly optional clean-up function: You can't access anything after
|
||||
this, until the next sensors_init() call! */
|
||||
extern void sensors_cleanup(void);
|
||||
|
||||
|
||||
/* Parse a chip name to the internal representation. Return 0 on succes, <0
|
||||
on error. */
|
||||
extern int sensors_parse_chip_name(const char *orig_name,
|
||||
|
||||
Reference in new issue
Block a user