Changeset 4538
- Timestamp:
- 07/03/07 10:18:21 (6 years ago)
- Files:
-
- 1 modified
-
lm-sensors/branches/lm-sensors-3.0.0/lib/access.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/branches/lm-sensors-3.0.0/lib/access.c
r4520 r4538 21 21 #include <string.h> 22 22 #include <math.h> 23 #include <regex.h>24 23 #include "access.h" 25 24 #include "sensors.h" … … 28 27 #include "proc.h" 29 28 #include "general.h" 30 31 #define GET_TYPE_REGEX "\\([[:alpha:]]\\{1,\\}\\)[[:digit:]]\\{0,\\}\\(_\\([[:alpha:]]\\{1,\\}\\)\\)\\{0,1\\}"32 29 33 30 static int sensors_do_this_chip_sets(sensors_chip_name name); … … 542 539 543 540 static struct feature_type_match matches[] = { 544 { "temp", SENSORS_FEATURE_TEMP, temp_matches }, 545 { "in", SENSORS_FEATURE_IN, in_matches }, 546 { "fan", SENSORS_FEATURE_FAN, fan_matches }, 547 { "cpu", SENSORS_FEATURE_UNKNOWN, cpu_matches }, 548 { "vrm", SENSORS_FEATURE_VRM, 0 }, 541 { "temp%d%c", SENSORS_FEATURE_TEMP, temp_matches }, 542 { "in%d%c", SENSORS_FEATURE_IN, in_matches }, 543 { "fan%d%c", SENSORS_FEATURE_FAN, fan_matches }, 544 { "cpu%d%c", SENSORS_FEATURE_UNKNOWN, cpu_matches }, 549 545 { 0 } 550 546 }; … … 554 550 const sensors_feature_data *feature) 555 551 { 556 regmatch_t pmatch[4];557 int size_first, size_second, retval, i;552 char c; 553 int i, nr, count; 558 554 struct feature_type_match *submatches; 559 static regex_t reg;560 static regex_t *preg = NULL;561 555 562 if (!preg) { 563 regcomp(®, GET_TYPE_REGEX, 0); 564 preg = ® 565 } 566 567 retval = regexec(preg, feature->name, 4, pmatch, 0); 568 569 if (retval == -1) 570 return SENSORS_FEATURE_UNKNOWN; 571 572 size_first = pmatch[1].rm_eo - pmatch[1].rm_so; 573 size_second = pmatch[3].rm_eo - pmatch[3].rm_so; 556 /* vrm is special */ 557 if (!strcmp(feature->name, "vrm")) 558 return SENSORS_FEATURE_VRM; 574 559 575 560 for(i = 0; matches[i].name != 0; i++) 576 if ( !strncmp(feature->name, matches[i].name, size_first))561 if ((count = sscanf(feature->name, matches[i].name, &nr, &c))) 577 562 break; 578 563 579 564 if (matches[i].name == NULL) /* no match */ 580 565 return SENSORS_FEATURE_UNKNOWN; 581 else if ( size_second == 0) /* single type */566 else if (count == 1) /* single type */ 582 567 return matches[i].type; 583 else if (matches[i].submatches == NULL) /* not single type, but no submatches */ 568 569 /* assert: count == 2 */ 570 if (c != '_') 584 571 return SENSORS_FEATURE_UNKNOWN; 585 572 586 573 submatches = matches[i].submatches; 587 574 for(i = 0; submatches[i].name != 0; i++) 588 if (!strcmp( feature->name + pmatch[3].rm_so, submatches[i].name))575 if (!strcmp(strchr(feature->name, '_') + 1, submatches[i].name)) 589 576 return submatches[i].type; 590 577
