Changeset 4703
- Timestamp:
- 08/26/07 10:28:10 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/main.c
r4701 r4703 49 49 static void do_a_print(const sensors_chip_name *name); 50 50 static int do_a_set(const sensors_chip_name *name); 51 static int do_the_real_work( int *error);51 static int do_the_real_work(const sensors_chip_name *chip, int *error); 52 52 static const char *sprintf_chip_name(const sensors_chip_name *name); 53 53 54 #define CHIPS_MAX 2055 sensors_chip_name chips[CHIPS_MAX];56 int chips_count=0;57 54 int do_sets, do_raw, fahrenheit, hide_adapter; 58 55 … … 201 198 } 202 199 203 if (optind == argc) {204 chips[0].prefix = SENSORS_CHIP_NAME_PREFIX_ANY;205 chips[0].bus.type = SENSORS_BUS_TYPE_ANY;206 chips[0].bus.nr = SENSORS_BUS_NR_ANY;207 chips[0].addr = SENSORS_CHIP_NAME_ADDR_ANY;208 chips_count = 1;209 } else210 for(i = optind; i < argc; i++)211 if ((res = sensors_parse_chip_name(argv[i],chips+chips_count))) {212 fprintf(stderr,"Parse error in chip name `%s'\n",argv[i]);213 print_short_help();214 exit(1);215 } else if (++chips_count == CHIPS_MAX) {216 fprintf(stderr,"Too many chips on command line!\n");217 exit(1);218 }219 220 200 open_config_file(config_file_name); 221 201 if ((res = sensors_init(config_file))) { … … 228 208 set_degstr(); 229 209 230 if(do_the_real_work(&error)) { 231 sensors_cleanup(); 232 exit(error); 210 if (optind == argc) { /* No chip name on command line */ 211 if (!do_the_real_work(NULL, &error)) { 212 fprintf(stderr, 213 "No sensors found!\n" 214 "Make sure you loaded all the kernel drivers you need.\n" 215 "Try sensors-detect to find out which these are.\n"); 216 error = 1; 217 } 233 218 } else { 234 if (optind == argc) /* No chip name on command line */ 235 fprintf(stderr, 236 "No sensors found!\n" 237 "Make sure you loaded all the kernel drivers you need.\n" 238 "Try sensors-detect to find out which these are.\n"); 239 else 240 fprintf(stderr,"Specified sensor(s) not found!\n"); 241 sensors_cleanup(); 242 exit(1); 243 } 219 int cnt = 0; 220 sensors_chip_name chip; 221 222 for (i = optind; i < argc; i++) { 223 if (sensors_parse_chip_name(argv[i], &chip)) { 224 fprintf(stderr, "Parse error in chip name `%s'\n", argv[i]); 225 print_short_help(); 226 error = 1; 227 goto exit; 228 } 229 cnt += do_the_real_work(&chip, &error); 230 } 231 232 if (!cnt) { 233 fprintf(stderr, "Specified sensor(s) not found!\n"); 234 error = 1; 235 } 236 } 237 238 exit: 239 sensors_cleanup(); 240 exit(res); 244 241 } 245 242 246 243 /* returns number of chips found */ 247 int do_the_real_work( int *error)244 int do_the_real_work(const sensors_chip_name *match, int *error) 248 245 { 249 246 const sensors_chip_name *chip; 250 int chip_nr ,i;247 int chip_nr; 251 248 int cnt = 0; 252 249 253 *error = 0; 254 for (i = 0; i < chips_count; i++) { 255 chip_nr = 0; 256 while ((chip = sensors_get_detected_chips(&chips[i], &chip_nr))) { 257 if (do_sets) { 258 if (do_a_set(chip)) 259 *error = 1; 260 } else 261 do_a_print(chip); 262 cnt++; 263 } 250 chip_nr = 0; 251 while ((chip = sensors_get_detected_chips(match, &chip_nr))) { 252 if (do_sets) { 253 if (do_a_set(chip)) 254 *error = 1; 255 } else 256 do_a_print(chip); 257 cnt++; 264 258 } 265 259 return cnt;
