Show
Ignore:
Timestamp:
09/05/07 18:14:53 (7 years ago)
Author:
khali
Message:

Move sensors_feature_get_type() from access.c to sysfs.c, it's only called
from this file. This lets the compiler do additional optimizations.

Files:
1 modified

Legend:

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

    r4769 r4776  
    495495        return res; 
    496496} 
    497  
    498 /* Static mappings for use by sensors_feature_get_type() */ 
    499 struct feature_subtype_match 
    500 { 
    501         const char *name; 
    502         sensors_feature_type type; 
    503 }; 
    504  
    505 struct feature_type_match 
    506 { 
    507         const char *name; 
    508         const struct feature_subtype_match *submatches; 
    509 }; 
    510  
    511 static const struct feature_subtype_match temp_matches[] = { 
    512         { "input", SENSORS_FEATURE_TEMP }, 
    513         { "max", SENSORS_FEATURE_TEMP_MAX }, 
    514         { "max_hyst", SENSORS_FEATURE_TEMP_MAX_HYST }, 
    515         { "min", SENSORS_FEATURE_TEMP_MIN }, 
    516         { "crit", SENSORS_FEATURE_TEMP_CRIT }, 
    517         { "crit_hyst", SENSORS_FEATURE_TEMP_CRIT_HYST }, 
    518         { "alarm", SENSORS_FEATURE_TEMP_ALARM }, 
    519         { "min_alarm", SENSORS_FEATURE_TEMP_MIN_ALARM }, 
    520         { "max_alarm", SENSORS_FEATURE_TEMP_MAX_ALARM }, 
    521         { "crit_alarm", SENSORS_FEATURE_TEMP_CRIT_ALARM }, 
    522         { "fault", SENSORS_FEATURE_TEMP_FAULT }, 
    523         { "type", SENSORS_FEATURE_TEMP_TYPE }, 
    524         { "offset", SENSORS_FEATURE_TEMP_OFFSET }, 
    525         { NULL, 0 } 
    526 }; 
    527  
    528 static const struct feature_subtype_match in_matches[] = { 
    529         { "input", SENSORS_FEATURE_IN }, 
    530         { "min", SENSORS_FEATURE_IN_MIN }, 
    531         { "max", SENSORS_FEATURE_IN_MAX }, 
    532         { "alarm", SENSORS_FEATURE_IN_ALARM }, 
    533         { "min_alarm", SENSORS_FEATURE_IN_MIN_ALARM }, 
    534         { "max_alarm", SENSORS_FEATURE_IN_MAX_ALARM }, 
    535         { NULL, 0 } 
    536 }; 
    537  
    538 static const struct feature_subtype_match fan_matches[] = { 
    539         { "input", SENSORS_FEATURE_FAN }, 
    540         { "min", SENSORS_FEATURE_FAN_MIN }, 
    541         { "div", SENSORS_FEATURE_FAN_DIV }, 
    542         { "alarm", SENSORS_FEATURE_FAN_ALARM }, 
    543         { "fault", SENSORS_FEATURE_FAN_FAULT }, 
    544         { NULL, 0 } 
    545 }; 
    546  
    547 static const struct feature_subtype_match cpu_matches[] = { 
    548         { "vid", SENSORS_FEATURE_VID }, 
    549         { NULL, 0 } 
    550 }; 
    551  
    552 static struct feature_type_match matches[] = {  
    553         { "temp%d%c", temp_matches }, 
    554         { "in%d%c", in_matches }, 
    555         { "fan%d%c", fan_matches }, 
    556         { "cpu%d%c", cpu_matches }, 
    557 }; 
    558  
    559 /* Return the feature type and channel number based on the feature name */ 
    560 sensors_feature_type sensors_feature_get_type(const char *name, int *nr) 
    561 { 
    562         char c; 
    563         int i, count; 
    564         const struct feature_subtype_match *submatches; 
    565          
    566         /* Special case */ 
    567         if (!strcmp(name, "beep_enable")) { 
    568                 *nr = 0; 
    569                 return SENSORS_FEATURE_BEEP_ENABLE; 
    570         } 
    571  
    572         for (i = 0; i < ARRAY_SIZE(matches); i++) 
    573                 if ((count = sscanf(name, matches[i].name, nr, &c))) 
    574                         break; 
    575          
    576         if (i == ARRAY_SIZE(matches) || count != 2 || c != '_') 
    577                 return SENSORS_FEATURE_UNKNOWN;  /* no match */ 
    578  
    579         submatches = matches[i].submatches; 
    580         name = strchr(name + 3, '_') + 1; 
    581         for (i = 0; submatches[i].name != NULL; i++) 
    582                 if (!strcmp(name, submatches[i].name)) 
    583                         return submatches[i].type; 
    584          
    585         return SENSORS_FEATURE_UNKNOWN; 
    586 }