Changeset 140

Show
Ignore:
Timestamp:
12/29/98 21:33:34 (14 years ago)
Author:
frodo
Message:

Command-line chip specifications introduced in prog/sensors; minor

lib problem resolved.

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

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

    r138 r140  
    199199/* Set the value of a feature of a certain chip. Note that chip should not 
    200200   contain wildcard values! This function will return 0 on success, and <0 
    201    on failure. BUGGY! */ 
     201   on failure. */ 
    202202int sensors_set_feature(sensors_chip_name name, int feature, double value) 
    203203{ 
  • lm-sensors/trunk/prog/sensors/main.c

    r138 r140  
    4444static void open_config_file(void); 
    4545static int open_this_config_file(char *filename); 
     46static void do_a_print(sensors_chip_name name); 
     47static void do_a_set(sensors_chip_name name); 
     48static void do_the_real_work(void); 
     49static const char *sprintf_chip_name(sensors_chip_name name); 
     50 
     51#define CHIPS_MAX 20 
     52sensors_chip_name chips[CHIPS_MAX]; 
     53int chips_count=0; 
     54int do_sets; 
    4655 
    4756void print_short_help(void) 
     
    5261void print_long_help(void) 
    5362{ 
    54   printf("Usage: %s [OPTION]...\n",PROGRAM); 
     63  printf("Usage: %s [OPTION]... [CHIP]...\n",PROGRAM); 
    5564  printf("  -c, --config-file     Specify a config file\n"); 
    5665  printf("  -h, --help            Display this help text\n"); 
     
    6069  printf("By default, a list of directories is examined for the config file `sensors.conf'\n"); 
    6170  printf("Use `-' after `-c' to read the config file from stdin\n"); 
     71  printf("If no chips are specified, all chip info will be printed\n"); 
    6272} 
    6373 
     
    120130int main (int argc, char *argv[]) 
    121131{ 
    122   int c,res; 
    123   int do_sets; 
    124  
    125   int chip_nr; 
    126   const sensors_chip_name *chip; 
    127   const char *algo,*adap; 
     132  int c,res,i; 
    128133 
    129134  struct option long_opts[] =  { 
     
    158163    default: 
    159164      fprintf(stderr,"Internal error while parsing options!\n"); 
     165      exit(1); 
    160166    } 
    161167  } 
     168 
     169  if (optind == argc) { 
     170    chips[0].prefix = SENSORS_CHIP_NAME_PREFIX_ANY; 
     171    chips[0].bus = SENSORS_CHIP_NAME_BUS_ANY; 
     172    chips[0].addr = SENSORS_CHIP_NAME_ADDR_ANY; 
     173    chips_count = 1; 
     174  } else  
     175    for(i = optind; i < argc; i++)  
     176      if ((res = sensors_parse_chip_name(argv[i],chips+chips_count))) { 
     177        fprintf(stderr,"Parse error in chip name `%s'\n",argv[i]); 
     178        exit(1); 
     179      } else if (++chips_count == CHIPS_MAX) { 
     180        fprintf(stderr,"Too many chips on command line!\n"); 
     181        exit(1); 
     182      } 
     183 
     184 
    162185  open_config_file(); 
    163186 
     
    172195  } 
    173196 
    174   /* Here comes the real code... */ 
    175  
    176   if (do_sets)  
    177     if ((res = sensors_do_all_sets())) { 
    178       fprintf(stderr,"%s\n",sensors_strerror(res)); 
    179       exit(1); 
    180     } 
    181    
    182   for (chip_nr = 0; (chip = sensors_get_detected_chips(&chip_nr));) { 
    183     if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA) 
    184       printf("%s-isa-%04x\n",chip->prefix,chip->addr); 
    185     else 
    186       printf("%s-i2c-%d-%02x\n",chip->prefix,chip->bus,chip->addr); 
    187     adap = sensors_get_adapter_name(chip->bus); 
    188     if (adap) 
    189       printf("Adapter: %s\n",adap); 
    190     algo = sensors_get_algorithm_name(chip->bus); 
    191     if (algo) 
    192       printf("Algorithm: %s\n",algo); 
    193     if (!algo || !adap) 
    194       printf(" ERROR: Can't get adapter or algorithm?!?\n"); 
    195     if (!strcmp(chip->prefix,"lm75")) 
    196       print_lm75(chip); 
    197     else if (!strcmp(chip->prefix,"lm78") || !strcmp(chip->prefix,"lm78-j") || 
    198              !strcmp(chip->prefix,"lm79")) 
    199       print_lm78(chip); 
    200     else if (!strcmp(chip->prefix,"gl518sm-r00") ||  
    201              !strcmp(chip->prefix,"gl518sm-r80")) 
    202       print_gl518(chip); 
    203     else if (!strcmp(chip->prefix,"w83781d")) 
    204       print_w83781d(chip); 
    205     else 
    206       print_unknown_chip(chip); 
    207     printf("\n"); 
    208   } 
     197  do_the_real_work(); 
    209198  exit(0); 
    210199} 
    211200 
    212  
     201void do_the_real_work(void) 
     202{ 
     203  const sensors_chip_name *chip; 
     204  int chip_nr,i; 
     205 
     206  for (chip_nr = 0; (chip = sensors_get_detected_chips(&chip_nr));) 
     207    for(i = 0; i < chips_count; i++) 
     208      if (sensors_match_chip(*chip,chips[i])) { 
     209        if(do_sets) 
     210          do_a_set(*chip); 
     211        else 
     212          do_a_print(*chip); 
     213        i = chips_count; 
     214      } 
     215} 
     216 
     217void do_a_set(sensors_chip_name name) 
     218{ 
     219  int res; 
     220  if ((res = sensors_do_chip_sets(name)))  
     221    fprintf(stderr,"%s: %s\n",sprintf_chip_name(name),sensors_strerror(res)); 
     222} 
     223 
     224const char *sprintf_chip_name(sensors_chip_name name) 
     225{ 
     226  #define BUF_SIZE 200 
     227  static char buf[BUF_SIZE]; 
     228 
     229  if (name.bus == SENSORS_CHIP_NAME_BUS_ISA) 
     230    snprintf(buf,BUF_SIZE,"%s-isa-%04x",name.prefix,name.addr); 
     231  else 
     232    snprintf(buf,BUF_SIZE,"%s-i2c-%d-%02x",name.prefix,name.bus,name.addr); 
     233  return buf; 
     234} 
     235 
     236void do_a_print(sensors_chip_name name) 
     237{ 
     238  const char *algo,*adap; 
     239 
     240  printf("%s\n",sprintf_chip_name(name)); 
     241  adap = sensors_get_adapter_name(name.bus); 
     242  if (adap) 
     243    printf("Adapter: %s\n",adap); 
     244  algo = sensors_get_algorithm_name(name.bus); 
     245  if (algo) 
     246    printf("Algorithm: %s\n",algo); 
     247  if (!algo || !adap) 
     248    printf(" ERROR: Can't get adapter or algorithm?!?\n"); 
     249  if (!strcmp(name.prefix,"lm75")) 
     250    print_lm75(&name); 
     251  else if (!strcmp(name.prefix,"lm78") || !strcmp(name.prefix,"lm78-j") || 
     252           !strcmp(name.prefix,"lm79")) 
     253    print_lm78(&name); 
     254  else if (!strcmp(name.prefix,"gl518sm-r00") ||  
     255           !strcmp(name.prefix,"gl518sm-r80")) 
     256    print_gl518(&name); 
     257  else if (!strcmp(name.prefix,"w83781d")) 
     258    print_w83781d(&name); 
     259  else 
     260    print_unknown_chip(&name); 
     261  printf("\n"); 
     262}