| | 508 | /* Static mappings for use by sensors_feature_get_type() */ |
| | 509 | struct feature_type_match |
| | 510 | { |
| | 511 | const char *name; |
| | 512 | sensors_feature_type type; |
| | 513 | |
| | 514 | struct feature_type_match *submatches; |
| | 515 | }; |
| | 516 | |
| | 517 | static struct feature_type_match temp_matches[] = { |
| | 518 | { "max", SENSORS_FEATURE_TEMP_MAX }, |
| | 519 | { "min", SENSORS_FEATURE_TEMP_MIN }, |
| | 520 | { "type", SENSORS_FEATURE_TEMP_SENS }, |
| | 521 | { "hyst", SENSORS_FEATURE_TEMP_HYST }, |
| | 522 | { "over", SENSORS_FEATURE_TEMP_OVER }, |
| | 523 | { "max", SENSORS_FEATURE_TEMP_MAX }, |
| | 524 | { "min", SENSORS_FEATURE_TEMP_MIN }, |
| | 525 | { "low", SENSORS_FEATURE_TEMP_LOW }, |
| | 526 | { "crit", SENSORS_FEATURE_TEMP_CRIT }, |
| | 527 | { "fault", SENSORS_FEATURE_TEMP_FAULT }, |
| | 528 | { "alarm", SENSORS_FEATURE_TEMP_ALARM }, |
| | 529 | { "type", SENSORS_FEATURE_TEMP_SENS }, |
| | 530 | { 0 } |
| | 531 | }; |
| | 532 | |
| | 533 | static struct feature_type_match in_matches[] = { |
| | 534 | { "max", SENSORS_FEATURE_IN_MAX }, |
| | 535 | { "max_alarm", SENSORS_FEATURE_IN_MAX_ALARM }, |
| | 536 | { "min", SENSORS_FEATURE_IN_MIN }, |
| | 537 | { "min_alarm", SENSORS_FEATURE_IN_MIN_ALARM }, |
| | 538 | { "alarm", SENSORS_FEATURE_IN_ALARM }, |
| | 539 | { 0 } |
| | 540 | }; |
| | 541 | |
| | 542 | static struct feature_type_match fan_matches[] = { |
| | 543 | { "min", SENSORS_FEATURE_FAN_MIN }, |
| | 544 | { "div", SENSORS_FEATURE_FAN_DIV }, |
| | 545 | { "alarm", SENSORS_FEATURE_FAN_ALARM }, |
| | 546 | { "fault", SENSORS_FEATURE_FAN_FAULT }, |
| | 547 | { 0 } |
| | 548 | }; |
| | 549 | |
| | 550 | static struct feature_type_match matches[] = { |
| | 551 | { "temp", SENSORS_FEATURE_TEMP, temp_matches }, |
| | 552 | { "in", SENSORS_FEATURE_IN, in_matches }, |
| | 553 | { "fan", SENSORS_FEATURE_FAN, fan_matches }, |
| | 554 | { "vrm", SENSORS_FEATURE_VRM, 0 }, |
| | 555 | { "vid", SENSORS_FEATURE_VID, 0 }, |
| | 556 | { "sensor", SENSORS_FEATURE_TEMP_SENS, 0 }, |
| | 557 | { 0 } |
| | 558 | }; |
| | 559 | |
| 504 | | const char *name; |
| 505 | | |
| 506 | | /* this will only work when the sensors_chip_feature is obtained through |
| 507 | | sensors_get_all_features */ |
| 508 | | if (((const struct sensors_chip_feature *)feature)->sysname) |
| 509 | | name = ((const struct sensors_chip_feature *)feature)->sysname; |
| | 564 | const char *name; |
| | 565 | regex_t preg; |
| | 566 | regmatch_t pmatch[4]; |
| | 567 | int size_first, size_second, retval, i; |
| | 568 | struct feature_type_match *submatches; |
| | 569 | |
| | 570 | /* use sysname if exists */ |
| | 571 | if (container_of(feature, const struct sensors_chip_feature, data)->sysname) |
| | 572 | name = container_of(feature, const struct sensors_chip_feature, data)->sysname; |
| 513 | | if (strstr(name, "temp")) { |
| 514 | | if (strlen(name) == 5) |
| 515 | | return SENSORS_FEATURE_TEMP; |
| 516 | | |
| 517 | | if (strstr(name, "hyst")) |
| 518 | | return SENSORS_FEATURE_TEMP_HYST; |
| 519 | | |
| 520 | | if (strstr(name, "over")) |
| 521 | | return SENSORS_FEATURE_TEMP_OVER; |
| 522 | | |
| 523 | | if (strstr(name, "max")) |
| 524 | | return SENSORS_FEATURE_TEMP_MAX; |
| 525 | | |
| 526 | | if (strstr(name, "min")) |
| 527 | | return SENSORS_FEATURE_TEMP_MIN; |
| 528 | | |
| 529 | | if (strstr(name, "low")) |
| 530 | | return SENSORS_FEATURE_TEMP_LOW; |
| 531 | | |
| 532 | | if (strstr(name, "crit")) |
| 533 | | return SENSORS_FEATURE_TEMP_CRIT; |
| 534 | | } else if (strstr(name, "in") && name[0] != 'f') { |
| 535 | | if (strlen(name) == 3 || strstr(name, "input")) |
| 536 | | return SENSORS_FEATURE_IN; |
| 537 | | |
| 538 | | if (strstr(name, "max_alarm")) |
| 539 | | return SENSORS_FEATURE_IN_MAX_ALARM; |
| 540 | | |
| 541 | | if (strstr(name, "max")) |
| 542 | | return SENSORS_FEATURE_IN_MAX; |
| 543 | | |
| 544 | | if (strstr(name, "min_alarm")) |
| 545 | | return SENSORS_FEATURE_IN_MIN_ALARM; |
| 546 | | |
| 547 | | if (strstr(name, "min")) |
| 548 | | return SENSORS_FEATURE_IN_MIN; |
| 549 | | |
| 550 | | if (strstr(name, "alarm")) |
| 551 | | return SENSORS_FEATURE_IN_ALARM; |
| 552 | | } else if (strstr(name, "fan")) { |
| 553 | | if (strlen(name) == 4) |
| 554 | | return SENSORS_FEATURE_FAN; |
| 555 | | |
| 556 | | if (strstr(name, "min")) |
| 557 | | return SENSORS_FEATURE_FAN_MIN; |
| 558 | | |
| 559 | | if (strstr(name, "div")) |
| 560 | | return SENSORS_FEATURE_FAN_DIV; |
| 561 | | } else if (!strcmp(name, "vrm")) { |
| 562 | | return SENSORS_FEATURE_VRM; |
| 563 | | } else if (strstr(name, "vid")) { |
| 564 | | return SENSORS_FEATURE_VID; |
| 565 | | } |
| | 576 | regcomp(&preg, GET_TYPE_REGEX, 0); |
| | 577 | |
| | 578 | retval = regexec(&preg, name, 4, pmatch, 0); |
| | 579 | |
| | 580 | regfree(&preg); |
| | 581 | |
| | 582 | if (retval == -1) |
| | 583 | return SENSORS_FEATURE_UNKNOWN; |
| | 584 | |
| | 585 | size_first = pmatch[1].rm_eo - pmatch[1].rm_so; |
| | 586 | size_second = pmatch[3].rm_eo - pmatch[3].rm_so; |
| | 587 | |
| | 588 | for(i = 0; matches[i].name != 0; i++) |
| | 589 | if (!strncmp(name, matches[i].name, size_first)) |
| | 590 | break; |
| | 591 | |
| | 592 | if (matches[i].name == NULL) /* no match */ |
| | 593 | return SENSORS_FEATURE_UNKNOWN; |
| | 594 | else if (size_second == 0) /* single type */ |
| | 595 | return matches[i].type; |
| | 596 | else if (matches[i].submatches == NULL) /* not single type, but no submatches */ |
| | 597 | return SENSORS_FEATURE_UNKNOWN; |
| | 598 | |
| | 599 | submatches = matches[i].submatches; |
| | 600 | for(i = 0; submatches[i].name != 0; i++) |
| | 601 | if (!strncmp(name + pmatch[3].rm_so, submatches[i].name, size_second)) |
| | 602 | return submatches[i].type; |