Changeset 98

Show
Ignore:
Timestamp:
12/21/98 15:14:25 (14 years ago)
Author:
frodo
Message:

More library extensions

Most notably, config file line numbers are now stored, so we can now generate
better error messages.

Location:
lm-sensors/trunk/lib
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/lib/access.c

    r97 r98  
    117117{ 
    118118  if ((chip.prefix == SENSORS_CHIP_NAME_PREFIX_ANY) || 
    119       (chip.bus == SENSORS_CHIP_NAME_BUS_ISA) || 
    120119      (chip.bus == SENSORS_CHIP_NAME_BUS_ANY) || 
    121120      (chip.bus == SENSORS_CHIP_NAME_BUS_ANY_I2C) || 
  • lm-sensors/trunk/lib/conf-lex.l

    r91 r98  
    9797 /* Some keywords at the beginning of lines */ 
    9898<INITIAL>"label" { 
     99                  sensors_yylval.line = sensors_yylineno; 
    99100                  BEGIN(MIDDLE); 
    100101                  return LABEL; 
     
    102103 
    103104<INITIAL>"set"  { 
     105                  sensors_yylval.line = sensors_yylineno; 
    104106                  BEGIN(MIDDLE); 
    105107                  return SET; 
     
    107109 
    108110<INITIAL>"compute" { 
     111                  sensors_yylval.line = sensors_yylineno; 
    109112                  BEGIN(MIDDLE); 
    110113                  return COMPUTE; 
     
    112115 
    113116<INITIAL>"bus"  { 
     117                  sensors_yylval.line = sensors_yylineno; 
    114118                  BEGIN(MIDDLE); 
    115119                  return BUS; 
     
    117121 
    118122<INITIAL>"chip" { 
     123                  sensors_yylval.line = sensors_yylineno; 
    119124                  BEGIN(MIDDLE); 
    120125                  return CHIP; 
  • lm-sensors/trunk/lib/conf-parse.y

    r91 r98  
    9090  int bus; 
    9191  sensors_chip_name chip; 
     92  int line; 
    9293 
    9394 
     
    9899%token <nothing> ',' 
    99100%token <nothing> EOL 
    100 %token <nothing> BUS 
    101 %token <nothing> LABEL 
    102 %token <nothing> SET 
    103 %token <nothing> CHIP 
    104 %token <nothing> COMPUTE 
     101%token <line> BUS 
     102%token <line> LABEL 
     103%token <line> SET 
     104%token <line> CHIP 
     105%token <line> COMPUTE 
    105106%token <value> FLOAT 
    106107%token <name> NAME 
     
    134135bus_statement:    BUS i2cbus_name adapter_name algorithm_name 
    135136                  { sensors_bus new_el; 
     137                    new_el.lineno = $1; 
    136138                    new_el.number = $2; 
    137139                    new_el.adapter = $3; 
     
    144146                          { sensors_label new_el; 
    145147                            check_current_chip(); 
     148                            new_el.lineno = $1; 
    146149                            new_el.name = $2; 
    147150                            new_el.value = $3; 
     
    153156                  { sensors_set new_el; 
    154157                    check_current_chip(); 
     158                    new_el.lineno = $1; 
    155159                    new_el.name = $2; 
    156160                    new_el.value = $3; 
     
    162166                          { sensors_compute new_el; 
    163167                            check_current_chip(); 
     168                            new_el.lineno = $1; 
    164169                            new_el.name = $2; 
    165170                            new_el.from_proc = $3; 
     
    171176chip_statement:   CHIP chip_name_list 
    172177                  { sensors_chip new_el; 
     178                    new_el.lineno = $1; 
    173179                    new_el.labels = NULL; 
    174180                    new_el.sets = NULL; 
  • lm-sensors/trunk/lib/data.c

    r97 r98  
    199199} 
    200200 
     201 
    201202int sensors_eval_expr(sensors_expr *expr, double val, double *result) 
    202203{ 
  • lm-sensors/trunk/lib/data.h

    r97 r98  
    5555  char *name; 
    5656  char *value; 
     57  int lineno; 
    5758} sensors_label; 
    5859 
     
    6061  char *name; 
    6162  sensors_expr *value; 
     63  int lineno; 
    6264} sensors_set; 
    6365 
     
    6668  sensors_expr *from_proc; 
    6769  sensors_expr *to_proc; 
     70  int lineno; 
    6871} sensors_compute; 
    6972 
     
    8588  int computes_count; 
    8689  int computes_max; 
     90  int lineno; 
    8791} sensors_chip; 
    8892 
     
    9498  char *adapter; 
    9599  char *algorithm; 
     100  int lineno; 
    96101} sensors_bus; 
    97102 
     
    100105  sensors_chip_name name; 
    101106} sensors_proc_chips_entry; 
     107 
    102108 
    103109extern sensors_chip *sensors_config_chips; 
     
    113119extern int sensors_proc_chips_max; 
    114120 
     121extern sensors_bus *sensors_proc_bus; 
     122extern int sensors_proc_bus_count; 
     123extern int sensors_proc_bus_max; 
     124 
    115125/* Parse an i2c bus name into its components. Returns 0 on succes, a value from 
    116126   error.h on failure. */ 
  • lm-sensors/trunk/lib/init.c

    r97 r98  
    1919 
    2020#include <stdlib.h> 
     21#include <stdio.h> 
    2122#include "sensors.h" 
    2223#include "data.h" 
     
    2526 
    2627extern int sensors_yyparse(void); 
     28extern FILE *sensors_yyin; 
    2729 
    2830static void free_proc_chips_entry(sensors_proc_chips_entry entry); 
     
    3537static void free_expr(sensors_expr *expr); 
    3638 
    37 int sensors_init(void) 
     39int sensors_init(FILE *input) 
    3840{ 
    3941  int res; 
     
    4143  if ((res = sensors_read_proc_chips())) 
    4244    return res; 
     45  if ((res = sensors_read_proc_bus())) 
     46    return res; 
     47  sensors_yyin = input; 
    4348  if ((res = sensors_yyparse())) 
    4449    return SENSORS_ERR_PARSE; 
     
    6772  sensors_config_chips = NULL; 
    6873  sensors_config_chips_count = sensors_config_chips_max = 0; 
     74 
     75  for (i = 0; i < sensors_proc_bus_count; i++) 
     76    free_bus(sensors_proc_bus[i]); 
     77  free(sensors_proc_bus); 
     78  sensors_proc_bus = NULL; 
     79  sensors_proc_bus_count = sensors_proc_bus_max = 0; 
    6980} 
    7081 
  • lm-sensors/trunk/lib/proc.c

    r95 r98  
    1919 
    2020#include <stddef.h> 
     21#include <stdio.h> 
     22#include <string.h> 
    2123#include <sys/sysctl.h> 
    2224#include <linux/sysctl.h> 
     
    3739static char buf[BUF_LEN]; 
    3840 
     41sensors_proc_chips_entry *sensors_proc_chips; 
     42int sensors_proc_chips_count; 
     43int sensors_proc_chips_max; 
     44 
     45sensors_bus *sensors_proc_bus; 
     46int sensors_proc_bus_count; 
     47int sensors_proc_bus_max; 
     48 
    3949static int sensors_get_chip_id(sensors_chip_name name); 
    4050 
     
    4454                                       &sensors_proc_chips_max,\ 
    4555                                       sizeof(struct sensors_proc_chips_entry)) 
     56 
     57#define add_bus(el) sensors_add_array_el(el,\ 
     58                                       (void **) &sensors_proc_bus,\ 
     59                                       &sensors_proc_bus_count,\ 
     60                                       &sensors_proc_bus_max,\ 
     61                                       sizeof(struct sensors_bus)) 
    4662 
    4763/* This reads /proc/sys/dev/sensors/chips into memory */ 
     
    6985  return 0; 
    7086} 
     87 
     88int sensors_read_proc_bus(void) 
     89{ 
     90  FILE *f; 
     91  char line[255]; 
     92  char *border; 
     93  sensors_bus entry; 
     94  f = fopen("/proc/bus/i2c","r"); 
     95  if (!f) 
     96    return -SENSORS_ERR_PROC; 
     97  while (fgets(line,255,f)) { 
     98    if (! (border = rindex(line,'\t'))) 
     99      goto ERROR; 
     100    if (! (entry.algorithm = strdup(border+1))) 
     101      goto FAT_ERROR; 
     102    *border='\0'; 
     103    if (! (border = rindex(line,'\t'))) 
     104      goto ERROR; 
     105    if (! (entry.adapter = strdup(border + 1))) 
     106      goto FAT_ERROR; 
     107    *border='\0'; 
     108    if (! (border = rindex(line,'\t'))) 
     109      goto ERROR; 
     110    *border='\0'; 
     111    if (strncmp(line,"i2c-",4)) 
     112      goto ERROR; 
     113    if (sensors_parse_i2cbus_name(line,&entry.number)) 
     114      goto ERROR; 
     115    add_bus(&entry); 
     116  } 
     117  fclose(f); 
     118  return 0; 
     119FAT_ERROR: 
     120  sensors_fatal_error("sensors_read_proc_bus","Allocating entry"); 
     121ERROR: 
     122  fclose(f); 
     123  return -SENSORS_ERR_PROC; 
     124} 
     125     
    71126 
    72127/* This returns the first detected chip which matches the name */ 
  • lm-sensors/trunk/lib/sensors.h

    r97 r98  
    2121#define LIB_SENSORS_SENSORS_H 
    2222 
     23#include <stdio.h> 
     24 
    2325/* Publicly accessible library functions */ 
    2426 
     
    3638 
    3739/* (Re)load the configuration file and the detected chips list. */ 
    38 extern int sensors_init(void); 
     40extern int sensors_init(FILE *input); 
    3941 
    4042/* Strictly optional clean-up function: You can't access anything after 
    4143   this, until the next sensors_init() call! */ 
    4244extern void sensors_cleanup(void); 
    43  
    4445 
    4546/* Parse a chip name to the internal representation. Return 0 on succes, <0