Changeset 101

Show
Ignore:
Timestamp:
12/22/98 02:25:25 (10 years ago)
Author:
frodo
Message:

More libary stuff

The bus translation functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/lib/access.h

    r95 r101  
    7171                                                         const char *feature); 
    7272 
     73/* Substitute configuration bus numbers with real-world /proc bus numbers 
     74   in the chips lists */ 
     75extern int sensors_substitute_busses(void); 
     76 
    7377#endif /* def LIB_SENSORS_ACCESS_H */ 
  • lm-sensors/trunk/lib/conf-parse.y

    r98 r101  
    262262 
    263263adapter_name:     NAME 
    264                   { $$ = $1; } 
     264                  { sensors_strip_of_spaces($1); 
     265                    $$ = $1; } 
    265266; 
    266267 
    267268algorithm_name:   NAME 
    268                   { $$ = $1; } 
     269                  { sensors_strip_of_spaces($1); 
     270                    $$ = $1; } 
    269271; 
    270272 
  • lm-sensors/trunk/lib/data.c

    r98 r101  
    3333int sensors_config_busses_max = 0; 
    3434 
     35static int sensors_substitute_chip(sensors_chip_name *name,int lineno); 
    3536 
    3637/* Wow, this must be one of the ugliest functions I have ever written. 
     
    240241  return 0; 
    241242} 
     243 
     244int sensors_substitute_chip(sensors_chip_name *name,int lineno) 
     245{ 
     246  int i,j; 
     247  for (i = 0; i < sensors_config_busses_count; i++) 
     248    if (sensors_config_busses[i].number == name->bus) 
     249      break; 
     250 
     251  if (i == sensors_config_busses_count) { 
     252    sensors_parse_error("Undeclared i2c bus referenced",lineno); 
     253    name->bus = sensors_proc_bus_count; 
     254    return -SENSORS_ERR_BUS_NAME; 
     255  } 
     256 
     257  for (j = 0; j < sensors_proc_bus_count; j++) { 
     258    if (!strcmp(sensors_config_busses[i].adapter, 
     259                sensors_proc_bus[j].adapter) && 
     260        !strcmp(sensors_config_busses[i].algorithm, 
     261                sensors_proc_bus[j].algorithm))  
     262      break; 
     263  } 
     264 
     265  /* Well, if we did not find anything, j - sensors_proc_bus_count; so if 
     266     we set this chip's bus number to j, it will never be matched. Good. */ 
     267  name->bus = j; 
     268  return 0; 
     269} 
     270 
    242271       
     272int sensors_substitute_busses(void) 
     273{ 
     274  int err,i,j,lineno; 
     275  sensors_chip_name_list *chips; 
     276  int res=0; 
    243277   
     278  for(i = 0; i < sensors_config_chips_count; i++) { 
     279    lineno = sensors_config_chips[i].lineno; 
     280    chips = &sensors_config_chips[i].chips; 
     281    for(j = 0; j < chips->fits_count; j++) 
     282      if ((chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ISA) && 
     283          (chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ANY) && 
     284          (chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ANY_I2C)) 
     285        if ((err = sensors_substitute_chip(chips->fits+j, lineno))) 
     286          res = err; 
     287  } 
     288  return res; 
     289} 
  • lm-sensors/trunk/lib/error.h

    r97 r101  
    3737/* This function is called when a parse error is detected. Give it a new 
    3838   value, and your own function is called instead of the default (which 
    39    prints to stderr). */ 
     39   prints to stderr). This function may terminate the program, but it 
     40   usually outputs an error and returns. */ 
    4041extern void (*sensors_parse_error) (const char *err, int lineno); 
    4142 
  • lm-sensors/trunk/lib/general.c

    r95 r101  
    7575  *num_el += nr_els; 
    7676} 
     77 
     78/* Strip a string of all terminating spaces */ 
     79void sensors_strip_of_spaces(char *name) 
     80{ 
     81  int i; 
     82  for (i = strlen(name)-1; (i>=0) && (name[i] == ' '); i--); 
     83  name[i+1] = '\0'; 
     84} 
  • lm-sensors/trunk/lib/general.h

    r91 r101  
    3434                                  int *num_el, int *max_el, int el_size); 
    3535 
     36/* Strip a string of all terminating spaces */ 
     37extern void sensors_strip_of_spaces(char *name); 
     38 
    3639#endif /* LIB_SENSORS_GENERAL */ 
  • lm-sensors/trunk/lib/init.c

    r98 r101  
    4747  sensors_yyin = input; 
    4848  if ((res = sensors_yyparse())) 
    49     return SENSORS_ERR_PARSE; 
     49    return -SENSORS_ERR_PARSE; 
     50  if ((res = sensors_substitute_busses())); 
     51    return res; 
    5052  return 0; 
    5153} 
  • lm-sensors/trunk/lib/proc.c

    r98 r101  
    9696    return -SENSORS_ERR_PROC; 
    9797  while (fgets(line,255,f)) { 
     98    if (strlen(line) > 0) 
     99      line[strlen(line)-1] = '\0'; 
    98100    if (! (border = rindex(line,'\t'))) 
    99101      goto ERROR; 
     
    113115    if (sensors_parse_i2cbus_name(line,&entry.number)) 
    114116      goto ERROR; 
     117    sensors_strip_of_spaces(entry.algorithm); 
     118    sensors_strip_of_spaces(entry.adapter); 
    115119    add_bus(&entry); 
    116120  } 
  • lm-sensors/trunk/lib/proc.h

    r95 r101  
    2424extern int sensors_read_proc_chips(void); 
    2525 
     26/* Read /proc/bus/i2c */ 
     27extern int sensors_read_proc_bus(void); 
     28 
    2629/* Read a value out of a /proc file */ 
    2730extern int sensors_read_proc(sensors_chip_name name, int feature,  
  • lm-sensors/trunk/lib/sensors.h

    r98 r101  
    3737} sensors_chip_name; 
    3838 
    39 /* (Re)load the configuration file and the detected chips list. */ 
     39/* (Re)load the configuration file and the detected chips list. If this  
     40    returns a value unequal to zero, you are in trouble; you can not 
     41    assume anything will be initialized properly. */ 
    4042extern int sensors_init(FILE *input); 
    4143