2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-31 14:25:39 +00:00

Mass reindent and coding style cleanups.

git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4708 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare
2007-08-26 10:57:16 +00:00
parent c91457b7de
commit 252c5faf86
4 changed files with 568 additions and 546 deletions

View File

@@ -32,7 +32,7 @@ extern char degstr[5];
static inline float deg_ctof(float cel)
{
return ( cel * ( 9.0F / 5.0F ) + 32.0F );
return cel * (9.0F / 5.0F) + 32.0F;
}
/* minmax = 0 for limit/hysteresis, 1 for max/min, 2 for max only;
@@ -40,90 +40,93 @@ static inline float deg_ctof(float cel)
for the current temp and the limits
note: symbolic constants defined in chips.h */
void print_temp_info(float n_cur, float n_over, float n_hyst,
int minmax, int curprec, int limitprec)
int minmax, int curprec, int limitprec)
{
/* note: deg_ctof() will preserve HUGEVAL */
if (fahrenheit) {
n_cur = deg_ctof(n_cur);
n_over = deg_ctof(n_over);
n_hyst = deg_ctof(n_hyst);
}
/* note: deg_ctof() will preserve HUGEVAL */
if (fahrenheit) {
n_cur = deg_ctof(n_cur);
n_over = deg_ctof(n_over);
n_hyst = deg_ctof(n_hyst);
}
/* use %* to pass precision as an argument */
if (n_cur != HUGE_VAL)
printf("%+6.*f%s ", curprec, n_cur, degstr);
else
printf(" FAULT ");
/* use %* to pass precision as an argument */
if (n_cur != HUGE_VAL)
printf("%+6.*f%s ", curprec, n_cur, degstr);
else
printf(" FAULT ");
if(minmax == MINMAX)
printf("(low = %+5.*f%s, high = %+5.*f%s) ",
limitprec, n_hyst, degstr,
limitprec, n_over, degstr);
else if(minmax == MAXONLY)
printf("(high = %+5.*f%s) ",
limitprec, n_over, degstr);
else if(minmax == CRIT)
printf("(high = %+5.*f%s, crit = %+5.*f%s) ",
limitprec, n_over, degstr,
limitprec, n_hyst, degstr);
else if(minmax == HYST)
printf("(high = %+5.*f%s, hyst = %+5.*f%s) ",
limitprec, n_over, degstr,
limitprec, n_hyst, degstr);
else if(minmax == HYSTONLY)
printf("(hyst = %+5.*f%s) ",
limitprec, n_over, degstr);
else if(minmax != SINGLE)
printf("Unknown temperature mode!");
if (minmax == MINMAX)
printf("(low = %+5.*f%s, high = %+5.*f%s) ",
limitprec, n_hyst, degstr,
limitprec, n_over, degstr);
else if (minmax == MAXONLY)
printf("(high = %+5.*f%s) ",
limitprec, n_over, degstr);
else if (minmax == CRIT)
printf("(high = %+5.*f%s, crit = %+5.*f%s) ",
limitprec, n_over, degstr,
limitprec, n_hyst, degstr);
else if (minmax == HYST)
printf("(high = %+5.*f%s, hyst = %+5.*f%s) ",
limitprec, n_over, degstr,
limitprec, n_hyst, degstr);
else if (minmax == HYSTONLY)
printf("(hyst = %+5.*f%s) ",
limitprec, n_over, degstr);
else if (minmax != SINGLE)
printf("Unknown temperature mode!");
}
void print_label(const char *label, int space)
{
int len=strlen(label)+1;
if (len > space)
printf("%s:\n%*s", label, space, "");
else
printf("%s:%*s", label, space - len, "");
int len = strlen(label)+1;
if (len > space)
printf("%s:\n%*s", label, space, "");
else
printf("%s:%*s", label, space - len, "");
}
void print_vid_info(const sensors_chip_name *name, int f_vid, int label_size)
{
char *label;
double vid;
char *label;
double vid;
if ((label = sensors_get_label(name, f_vid))
&& !sensors_get_value(name, f_vid, &vid)) {
print_label(label, label_size);
printf("%+6.3f V\n", vid);
}
free(label);
if ((label = sensors_get_label(name, f_vid))
&& !sensors_get_value(name, f_vid, &vid)) {
print_label(label, label_size);
printf("%+6.3f V\n", vid);
}
free(label);
}
void print_chip_raw(const sensors_chip_name *name)
{
int a;
const sensors_feature_data *data;
char *label;
double val;
int a;
const sensors_feature_data *data;
char *label;
double val;
a = 0;
while((data=sensors_get_all_features(name, &a))) {
if (!(label = sensors_get_label(name, data->number))) {
printf("ERROR: Can't get feature `%s' data!\n",data->name);
continue;
}
if (data->mode & SENSORS_MODE_R) {
if (sensors_get_value(name, data->number, &val)) {
printf("ERROR: Can't get feature `%s' data!\n",data->name);
continue;
}
if (data->mapping != SENSORS_NO_MAPPING)
printf(" %s: %.2f (%s)\n",label,val,data->name);
else
printf("%s: %.2f (%s)\n",label,val,data->name);
} else
printf("(%s)\n",label);
free(label);
}
a = 0;
while ((data = sensors_get_all_features(name, &a))) {
if (!(label = sensors_get_label(name, data->number))) {
printf("ERROR: Can't get feature `%s' data!\n",
data->name);
continue;
}
if (data->mode & SENSORS_MODE_R) {
if (sensors_get_value(name, data->number, &val)) {
printf("ERROR: Can't get feature `%s' data!\n",
data->name);
continue;
}
if (data->mapping != SENSORS_NO_MAPPING)
printf(" %s: %.2f (%s)\n", label, val,
data->name);
else
printf("%s: %.2f (%s)\n", label, val,
data->name);
} else
printf("(%s)\n", label);
free(label);
}
}

View File

@@ -32,7 +32,7 @@ extern void print_chip_raw(const sensors_chip_name *name);
#define SINGLE 4
#define HYSTONLY 5
void print_temp_info(float n_cur, float n_over, float n_hyst,
int minmax, int curprec, int limitprec);
int minmax, int curprec, int limitprec);
void print_vid_info(const sensors_chip_name *name, int f_vid, int label_size);

View File

@@ -27,54 +27,52 @@
#include "chips.h"
static int get_feature_value(const sensors_chip_name *name,
const sensors_feature_data *feature,
double *val)
const sensors_feature_data *feature,
double *val)
{
return sensors_get_value(name, feature->number, val);
return sensors_get_value(name, feature->number, val);
}
static void sensors_get_available_features(const sensors_chip_name *name,
const sensors_feature_data *feature,
int i,
short *has_features,
double *feature_vals,
int size,
int first_val)
const sensors_feature_data *feature,
int i, short *has_features,
double *feature_vals, int size,
int first_val)
{
const sensors_feature_data *iter;
const sensors_feature_data *iter;
while((iter = sensors_get_all_features(name, &i)) &&
iter->mapping == feature->number) {
int indx;
while ((iter = sensors_get_all_features(name, &i)) &&
iter->mapping == feature->number) {
int indx;
indx = iter->type - first_val - 1;
if (indx < 0 || indx >= size) {
printf("ERROR: Bug in sensors: index out of bound");
return;
}
indx = iter->type - first_val - 1;
if (indx < 0 || indx >= size) {
printf("ERROR: Bug in sensors: index out of bound");
return;
}
if (get_feature_value(name, iter, &feature_vals[indx]))
printf("ERROR: Can't get %s data!\n", iter->name);
if (get_feature_value(name, iter, &feature_vals[indx]))
printf("ERROR: Can't get %s data!\n", iter->name);
has_features[indx] = 1;
}
has_features[indx] = 1;
}
}
static int sensors_get_label_size(const sensors_chip_name *name)
{
int i;
const sensors_feature_data *iter;
char *label;
unsigned int max_size = 11; /* Initialised to 11 as minumum label-width */
int i;
const sensors_feature_data *iter;
char *label;
unsigned int max_size = 11; /* 11 as minumum label width */
i = 0;
while((iter = sensors_get_all_features(name, &i))) {
if ((label = sensors_get_label(name, iter->number)) &&
strlen(label) > max_size)
max_size = strlen(label);
free(label);
}
return max_size + 1;
i = 0;
while ((iter = sensors_get_all_features(name, &i))) {
if ((label = sensors_get_label(name, iter->number)) &&
strlen(label) > max_size)
max_size = strlen(label);
free(label);
}
return max_size + 1;
}
extern int fahrenheit;
@@ -82,261 +80,276 @@ extern char degstr[5];
static inline float deg_ctof(float cel)
{
return ( cel * ( 9.0F / 5.0F ) + 32.0F );
return cel * (9.0F / 5.0F) + 32.0F;
}
#define TEMP_FEATURE(x) has_features[x - SENSORS_FEATURE_TEMP - 1]
#define TEMP_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_TEMP - 1]
#define TEMP_FEATURE(x) has_features[x - SENSORS_FEATURE_TEMP - 1]
#define TEMP_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_TEMP - 1]
static void print_generic_chip_temp(const sensors_chip_name *name,
const sensors_feature_data *feature,
int i, int label_size)
const sensors_feature_data *feature,
int i, int label_size)
{
double val, max, min;
char *label;
int type;
const int size = SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP;
short has_features[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = {0, };
double feature_vals[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = {0.0, };
double val, max, min;
char *label;
int type;
const int size = SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP;
short has_features[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = { 0, };
double feature_vals[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = { 0.0, };
if (!(label = sensors_get_label(name, feature->number))) {
printf("ERROR: Can't get temperature label!\n");
return;
}
if (!(label = sensors_get_label(name, feature->number))) {
printf("ERROR: Can't get temperature label!\n");
return;
}
if (get_feature_value(name, feature, &val)) {
printf("ERROR: Can't get %s data!\n", label);
free(label);
return;
}
if (get_feature_value(name, feature, &val)) {
printf("ERROR: Can't get %s data!\n", label);
free(label);
return;
}
sensors_get_available_features(name, feature, i, has_features,
feature_vals, size, SENSORS_FEATURE_TEMP);
sensors_get_available_features(name, feature, i, has_features,
feature_vals, size,
SENSORS_FEATURE_TEMP);
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX)) {
max = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MAX);
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX)) {
max = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MAX);
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MIN)) {
min = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MIN);
type = MINMAX;
} else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX_HYST)) {
min = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MAX_HYST);
type = HYST;
} else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT)) {
min = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT);
type = CRIT;
} else {
min = 0;
type = MAXONLY;
}
} else {
min = max = 0;
type = SINGLE;
}
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MIN)) {
min = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MIN);
type = MINMAX;
} else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX_HYST)) {
min = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MAX_HYST);
type = HYST;
} else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT)) {
min = TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT);
type = CRIT;
} else {
min = 0;
type = MAXONLY;
}
} else {
min = max = 0;
type = SINGLE;
}
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_FAULT) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_FAULT))
val = HUGE_VAL;
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_FAULT) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_FAULT))
val = HUGE_VAL;
print_label(label, label_size);
free(label);
print_label(label, label_size);
free(label);
print_temp_info(val, max, min, type, 1, 1);
print_temp_info(val, max, min, type, 1, 1);
/* ALARM features */
if ((TEMP_FEATURE(SENSORS_FEATURE_TEMP_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_ALARM) > 0.5)
|| (type == MINMAX &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_MIN_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MIN_ALARM) > 0.5)
|| (type == MINMAX &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MAX_ALARM) > 0.5)
|| (type == CRIT &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_ALARM) > 0.5)) {
printf("ALARM ");
}
/* ALARM features */
if ((TEMP_FEATURE(SENSORS_FEATURE_TEMP_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_ALARM) > 0.5)
|| (type == MINMAX &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_MIN_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MIN_ALARM) > 0.5)
|| (type == MINMAX &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_MAX_ALARM) > 0.5)
|| (type == CRIT &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_ALARM) > 0.5)) {
printf("ALARM ");
}
if (type != CRIT && TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT)) {
if (fahrenheit) {
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT) = deg_ctof(
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT));
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_HYST) = deg_ctof(
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_HYST));
}
if (type != CRIT && TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT)) {
if (fahrenheit) {
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT) = deg_ctof(
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT));
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_HYST) = deg_ctof(
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_HYST));
}
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT_HYST))
printf("\n%*s(crit = %+5.1f%s, hyst = %+5.1f%s) ", label_size + 10, "",
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT), degstr,
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_HYST), degstr);
else
printf("\n%*s(crit = %+5.1f%s) ", label_size + 10, "",
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT), degstr);
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT_HYST))
printf("\n%*s(crit = %+5.1f%s, hyst = %+5.1f%s) ",
label_size + 10, "",
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT),
degstr,
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_HYST),
degstr);
else
printf("\n%*s(crit = %+5.1f%s) ",
label_size + 10, "",
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT),
degstr);
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_ALARM)) {
printf("ALARM ");
}
}
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_CRIT_ALARM) &&
TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_CRIT_ALARM)) {
printf("ALARM ");
}
}
/* print out temperature sensor info */
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_SENS)) {
int sens = (int)TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_SENS);
/* print out temperature sensor info */
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_SENS)) {
int sens = (int)TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_SENS);
/* older kernels / drivers sometimes report a beta value for thermistors */
if (sens > 1000)
sens = 4;
/* older kernels / drivers sometimes report a beta value for
thermistors */
if (sens > 1000)
sens = 4;
printf("sensor = %s", sens == 0 ? "disabled" :
sens == 1 ? "diode" :
sens == 2 ? "transistor" :
sens == 3 ? "thermal diode" :
sens == 4 ? "thermistor" :
sens == 5 ? "AMD AMDSI" :
sens == 6 ? "Intel PECI" :
"unknown");
}
printf("\n");
printf("sensor = %s", sens == 0 ? "disabled" :
sens == 1 ? "diode" :
sens == 2 ? "transistor" :
sens == 3 ? "thermal diode" :
sens == 4 ? "thermistor" :
sens == 5 ? "AMD AMDSI" :
sens == 6 ? "Intel PECI" : "unknown");
}
printf("\n");
}
#define IN_FEATURE(x) has_features[x - SENSORS_FEATURE_IN - 1]
#define IN_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_IN - 1]
#define IN_FEATURE(x) has_features[x - SENSORS_FEATURE_IN - 1]
#define IN_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_IN - 1]
static void print_generic_chip_in(const sensors_chip_name *name,
const sensors_feature_data *feature,
int i, int label_size)
const sensors_feature_data *feature,
int i, int label_size)
{
const int size = SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN;
short has_features[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = {0, };
double feature_vals[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = {0.0, };
double val, alarm_max, alarm_min;
char *label;
const int size = SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN;
short has_features[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = { 0, };
double feature_vals[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = { 0.0, };
double val, alarm_max, alarm_min;
char *label;
if (!(label = sensors_get_label(name, feature->number))) {
printf("ERROR: Can't get in label!\n");
return;
}
if (!(label = sensors_get_label(name, feature->number))) {
printf("ERROR: Can't get in label!\n");
return;
}
if (get_feature_value(name, feature, &val)) {
printf("ERROR: Can't get %s data!\n", label);
free(label);
return;
}
if (get_feature_value(name, feature, &val)) {
printf("ERROR: Can't get %s data!\n", label);
free(label);
return;
}
sensors_get_available_features(name, feature, i, has_features, feature_vals,
size, SENSORS_FEATURE_IN);
sensors_get_available_features(name, feature, i, has_features,
feature_vals, size, SENSORS_FEATURE_IN);
print_label(label, label_size);
free(label);
printf("%+6.2f V", val);
print_label(label, label_size);
free(label);
printf("%+6.2f V", val);
if (IN_FEATURE(SENSORS_FEATURE_IN_MIN) && IN_FEATURE(SENSORS_FEATURE_IN_MAX))
printf(" (min = %+6.2f V, max = %+6.2f V)",
IN_FEATURE_VAL(SENSORS_FEATURE_IN_MIN),
IN_FEATURE_VAL(SENSORS_FEATURE_IN_MAX));
else if (IN_FEATURE(SENSORS_FEATURE_IN_MIN))
printf(" (min = %+6.2f V)", IN_FEATURE_VAL(SENSORS_FEATURE_IN_MIN));
else if (IN_FEATURE(SENSORS_FEATURE_IN_MAX))
printf(" (max = %+6.2f V)", IN_FEATURE_VAL(SENSORS_FEATURE_IN_MAX));
if (IN_FEATURE(SENSORS_FEATURE_IN_MIN) &&
IN_FEATURE(SENSORS_FEATURE_IN_MAX))
printf(" (min = %+6.2f V, max = %+6.2f V)",
IN_FEATURE_VAL(SENSORS_FEATURE_IN_MIN),
IN_FEATURE_VAL(SENSORS_FEATURE_IN_MAX));
else if (IN_FEATURE(SENSORS_FEATURE_IN_MIN))
printf(" (min = %+6.2f V)",
IN_FEATURE_VAL(SENSORS_FEATURE_IN_MIN));
else if (IN_FEATURE(SENSORS_FEATURE_IN_MAX))
printf(" (max = %+6.2f V)",
IN_FEATURE_VAL(SENSORS_FEATURE_IN_MAX));
if (IN_FEATURE(SENSORS_FEATURE_IN_MAX_ALARM) ||
IN_FEATURE(SENSORS_FEATURE_IN_MIN_ALARM)) {
alarm_max = IN_FEATURE_VAL(SENSORS_FEATURE_IN_MAX_ALARM);
alarm_min = IN_FEATURE_VAL(SENSORS_FEATURE_IN_MIN_ALARM);
if (IN_FEATURE(SENSORS_FEATURE_IN_MAX_ALARM) ||
IN_FEATURE(SENSORS_FEATURE_IN_MIN_ALARM)) {
alarm_max = IN_FEATURE_VAL(SENSORS_FEATURE_IN_MAX_ALARM);
alarm_min = IN_FEATURE_VAL(SENSORS_FEATURE_IN_MIN_ALARM);
if (alarm_min || alarm_max) {
printf(" ALARM (");
if (alarm_min || alarm_max) {
printf(" ALARM (");
if (alarm_min)
printf("MIN");
if (alarm_max)
printf("%sMAX", (alarm_min) ? ", " : "");
if (alarm_min)
printf("MIN");
if (alarm_max)
printf("%sMAX", (alarm_min) ? ", " : "");
printf(")");
}
} else if (IN_FEATURE(SENSORS_FEATURE_IN_ALARM)) {
printf(" %s",
IN_FEATURE_VAL(SENSORS_FEATURE_IN_ALARM) ? "ALARM" : "");
}
printf(")");
}
} else if (IN_FEATURE(SENSORS_FEATURE_IN_ALARM)) {
printf(" %s",
IN_FEATURE_VAL(SENSORS_FEATURE_IN_ALARM) ? "ALARM" : "");
}
printf("\n");
printf("\n");
}
#define FAN_FEATURE(x) has_features[x - SENSORS_FEATURE_FAN - 1]
#define FAN_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_FAN - 1]
#define FAN_FEATURE(x) has_features[x - SENSORS_FEATURE_FAN - 1]
#define FAN_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_FAN - 1]
static void print_generic_chip_fan(const sensors_chip_name *name,
const sensors_feature_data *feature,
int i, int label_size)
const sensors_feature_data *feature,
int i, int label_size)
{
char *label;
const int size = SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN;
short has_features[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN] = {0, };
double feature_vals[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN] = {0.0, };
double val;
char *label;
const int size = SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN;
short has_features[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN] = { 0, };
double feature_vals[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN] = { 0.0, };
double val;
if (!(label = sensors_get_label(name, feature->number))) {
printf("ERROR: Can't get fan label!\n");
return;
}
if (!(label = sensors_get_label(name, feature->number))) {
printf("ERROR: Can't get fan label!\n");
return;
}
if (get_feature_value(name, feature, &val))
{
printf("ERROR: Can't get %s data!\n", label);
free(label);
return;
}
if (get_feature_value(name, feature, &val)) {
printf("ERROR: Can't get %s data!\n", label);
free(label);
return;
}
print_label(label, label_size);
free(label);
print_label(label, label_size);
free(label);
if (FAN_FEATURE(SENSORS_FEATURE_FAN_FAULT) &&
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_FAULT))
printf(" FAULT");
else
printf("%4.0f RPM", val);
if (FAN_FEATURE(SENSORS_FEATURE_FAN_FAULT) &&
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_FAULT))
printf(" FAULT");
else
printf("%4.0f RPM", val);
sensors_get_available_features(name, feature, i, has_features, feature_vals,
size, SENSORS_FEATURE_FAN);
sensors_get_available_features(name, feature, i, has_features,
feature_vals, size, SENSORS_FEATURE_FAN);
if (FAN_FEATURE(SENSORS_FEATURE_FAN_MIN) &&
FAN_FEATURE(SENSORS_FEATURE_FAN_DIV))
printf(" (min = %4.0f RPM, div = %1.0f)",
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_MIN),
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_DIV));
else if (FAN_FEATURE(SENSORS_FEATURE_FAN_MIN))
printf(" (min = %4.0f RPM)", FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_MIN));
else if (FAN_FEATURE(SENSORS_FEATURE_FAN_DIV))
printf(" (div = %1.0f)", FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_DIV));
if (FAN_FEATURE(SENSORS_FEATURE_FAN_MIN) &&
FAN_FEATURE(SENSORS_FEATURE_FAN_DIV))
printf(" (min = %4.0f RPM, div = %1.0f)",
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_MIN),
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_DIV));
else if (FAN_FEATURE(SENSORS_FEATURE_FAN_MIN))
printf(" (min = %4.0f RPM)",
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_MIN));
else if (FAN_FEATURE(SENSORS_FEATURE_FAN_DIV))
printf(" (div = %1.0f)",
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_DIV));
if (FAN_FEATURE(SENSORS_FEATURE_FAN_ALARM) &&
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_ALARM)) {
printf(" ALARM");
}
if (FAN_FEATURE(SENSORS_FEATURE_FAN_ALARM) &&
FAN_FEATURE_VAL(SENSORS_FEATURE_FAN_ALARM)) {
printf(" ALARM");
}
printf("\n");
printf("\n");
}
void print_generic_chip(const sensors_chip_name *name)
{
const sensors_feature_data *feature;
int i, label_size;
const sensors_feature_data *feature;
int i, label_size;
label_size = sensors_get_label_size(name);
label_size = sensors_get_label_size(name);
i = 0;
while((feature = sensors_get_all_features(name, &i))) {
if (feature->mapping != SENSORS_NO_MAPPING)
continue;
i = 0;
while ((feature = sensors_get_all_features(name, &i))) {
if (feature->mapping != SENSORS_NO_MAPPING)
continue;
switch (feature->type) {
case SENSORS_FEATURE_TEMP:
print_generic_chip_temp(name, feature, i, label_size); break;
case SENSORS_FEATURE_IN:
print_generic_chip_in(name, feature, i, label_size); break;
case SENSORS_FEATURE_FAN:
print_generic_chip_fan(name, feature, i, label_size); break;
case SENSORS_FEATURE_VID:
print_vid_info(name, feature->number, label_size); break;
default: continue;
}
}
switch (feature->type) {
case SENSORS_FEATURE_TEMP:
print_generic_chip_temp(name, feature, i, label_size);
break;
case SENSORS_FEATURE_IN:
print_generic_chip_in(name, feature, i, label_size);
break;
case SENSORS_FEATURE_FAN:
print_generic_chip_fan(name, feature, i, label_size);
break;
case SENSORS_FEATURE_VID:
print_vid_info(name, feature->number, label_size);
break;
default:
continue;
}
}
}

View File

@@ -36,8 +36,8 @@
#include "version.h"
#include "chips_generic.h"
#define PROGRAM "sensors"
#define VERSION LM_VERSION
#define PROGRAM "sensors"
#define VERSION LM_VERSION
#define DEFAULT_CONFIG_FILE ETCDIR "/sensors.conf"
FILE *config_file;
@@ -57,254 +57,260 @@ char degstr[5]; /* store the correct string to print degrees */
void print_short_help(void)
{
printf("Try `%s -h' for more information\n",PROGRAM);
printf("Try `%s -h' for more information\n", PROGRAM);
}
void print_long_help(void)
{
printf("Usage: %s [OPTION]... [CHIP]...\n",PROGRAM);
printf(" -c, --config-file Specify a config file (default: %s)\n",
DEFAULT_CONFIG_FILE);
puts(" -h, --help Display this help text\n"
" -s, --set Execute `set' statements (root only)\n"
" -f, --fahrenheit Show temperatures in degrees fahrenheit\n"
" -A, --no-adapter Do not show adapter for each chip\n"
" -u Raw output (debugging only)\n"
" -v, --version Display the program version\n"
"\n"
"Use `-' after `-c' to read the config file from stdin.\n"
"If no chips are specified, all chip info will be printed.\n"
"Example chip names:\n"
"\tlm78-i2c-0-2d\t*-i2c-0-2d\n"
"\tlm78-i2c-0-*\t*-i2c-0-*\n"
"\tlm78-i2c-*-2d\t*-i2c-*-2d\n"
"\tlm78-i2c-*-*\t*-i2c-*-*\n"
"\tlm78-isa-0290\t*-isa-0290\n"
"\tlm78-isa-*\t*-isa-*\n"
"\tlm78-*");
printf("Usage: %s [OPTION]... [CHIP]...\n", PROGRAM);
printf(" -c, --config-file Specify a config file (default: %s)\n",
DEFAULT_CONFIG_FILE);
puts(" -h, --help Display this help text\n"
" -s, --set Execute `set' statements (root only)\n"
" -f, --fahrenheit Show temperatures in degrees fahrenheit\n"
" -A, --no-adapter Do not show adapter for each chip\n"
" -u Raw output (debugging only)\n"
" -v, --version Display the program version\n"
"\n"
"Use `-' after `-c' to read the config file from stdin.\n"
"If no chips are specified, all chip info will be printed.\n"
"Example chip names:\n"
"\tlm78-i2c-0-2d\t*-i2c-0-2d\n"
"\tlm78-i2c-0-*\t*-i2c-0-*\n"
"\tlm78-i2c-*-2d\t*-i2c-*-2d\n"
"\tlm78-i2c-*-*\t*-i2c-*-*\n"
"\tlm78-isa-0290\t*-isa-0290\n"
"\tlm78-isa-*\t*-isa-*\n"
"\tlm78-*");
}
void print_version(void)
{
printf("%s version %s with libsensors version %s\n", PROGRAM, VERSION, libsensors_version);
printf("%s version %s with libsensors version %s\n", PROGRAM, VERSION,
libsensors_version);
}
/* This examines global var config_file, and leaves the name there too.
It also opens config_file. */
static void open_config_file(const char* config_file_name)
{
if (!strcmp(config_file_name,"-")) {
config_file = stdin;
return;
}
if (!strcmp(config_file_name, "-")) {
config_file = stdin;
return;
}
config_file = fopen(config_file_name, "r");
if (!config_file) {
fprintf(stderr, "Could not open config file\n");
perror(config_file_name);
exit(1);
}
config_file = fopen(config_file_name, "r");
if (!config_file) {
fprintf(stderr, "Could not open config file\n");
perror(config_file_name);
exit(1);
}
}
static void close_config_file(const char* config_file_name)
{
if (fclose(config_file) == EOF) {
fprintf(stderr,"Could not close config file\n");
perror(config_file_name);
}
if (fclose(config_file) == EOF) {
fprintf(stderr, "Could not close config file\n");
perror(config_file_name);
}
}
static void set_degstr(void)
{
const char *deg_default_text[2] = {" C", " F"};
const char *deg_default_text[2] = { " C", " F" };
#ifdef HAVE_ICONV
/* Size hardcoded for better performance.
Don't forget to count the trailing \0! */
size_t deg_latin1_size = 3;
char *deg_latin1_text[2] = {"\260C", "\260F"};
size_t nconv;
size_t degstr_size = sizeof(degstr);
char *degstr_ptr = degstr;
/* Size hardcoded for better performance.
Don't forget to count the trailing \0! */
size_t deg_latin1_size = 3;
char *deg_latin1_text[2] = { "\260C", "\260F" };
size_t nconv;
size_t degstr_size = sizeof(degstr);
char *degstr_ptr = degstr;
iconv_t cd = iconv_open(nl_langinfo(CODESET), "ISO-8859-1");
if (cd != (iconv_t) -1) {
nconv = iconv(cd, &(deg_latin1_text[fahrenheit]), &deg_latin1_size,
&degstr_ptr, &degstr_size);
iconv_close(cd);
iconv_t cd = iconv_open(nl_langinfo(CODESET), "ISO-8859-1");
if (cd != (iconv_t) -1) {
nconv = iconv(cd, &(deg_latin1_text[fahrenheit]),
&deg_latin1_size, &degstr_ptr, &degstr_size);
iconv_close(cd);
if (nconv != (size_t) -1)
return;
}
if (nconv != (size_t) -1)
return;
}
#endif /* HAVE_ICONV */
/* There was an error during the conversion, use the default text */
strcpy(degstr, deg_default_text[fahrenheit]);
/* There was an error during the conversion, use the default text */
strcpy(degstr, deg_default_text[fahrenheit]);
}
int main (int argc, char *argv[])
{
int c,res,i,error;
const char *config_file_name = DEFAULT_CONFIG_FILE;
int c, res, i, error;
const char *config_file_name = DEFAULT_CONFIG_FILE;
struct option long_opts[] = {
{ "help", no_argument, NULL, 'h' },
{ "set", no_argument, NULL, 's' },
{ "version", no_argument, NULL, 'v'},
{ "fahrenheit", no_argument, NULL, 'f' },
{ "no-adapter", no_argument, NULL, 'A' },
{ "config-file", required_argument, NULL, 'c' },
{ 0,0,0,0 }
};
struct option long_opts[] = {
{ "help", no_argument, NULL, 'h' },
{ "set", no_argument, NULL, 's' },
{ "version", no_argument, NULL, 'v'},
{ "fahrenheit", no_argument, NULL, 'f' },
{ "no-adapter", no_argument, NULL, 'A' },
{ "config-file", required_argument, NULL, 'c' },
{ 0, 0, 0, 0 }
};
setlocale(LC_CTYPE, "");
setlocale(LC_CTYPE, "");
do_raw = 0;
do_sets = 0;
hide_adapter = 0;
while (1) {
c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL);
if (c == EOF)
break;
switch(c) {
case ':':
case '?':
print_short_help();
exit(1);
case 'h':
print_long_help();
exit(0);
case 'v':
print_version();
exit(0);
case 'c':
config_file_name = optarg;
break;
case 's':
do_sets = 1;
break;
case 'f':
fahrenheit = 1;
break;
case 'A':
hide_adapter = 1;
break;
case 'u':
do_raw = 1;
break;
default:
fprintf(stderr,"Internal error while parsing options!\n");
exit(1);
}
}
do_raw = 0;
do_sets = 0;
hide_adapter = 0;
while (1) {
c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL);
if (c == EOF)
break;
switch(c) {
case ':':
case '?':
print_short_help();
exit(1);
case 'h':
print_long_help();
exit(0);
case 'v':
print_version();
exit(0);
case 'c':
config_file_name = optarg;
break;
case 's':
do_sets = 1;
break;
case 'f':
fahrenheit = 1;
break;
case 'A':
hide_adapter = 1;
break;
case 'u':
do_raw = 1;
break;
default:
fprintf(stderr,
"Internal error while parsing options!\n");
exit(1);
}
}
open_config_file(config_file_name);
if ((res = sensors_init(config_file))) {
fprintf(stderr, "sensors_init: %s\n", sensors_strerror(res));
exit(1);
}
close_config_file(config_file_name);
open_config_file(config_file_name);
if ((res = sensors_init(config_file))) {
fprintf(stderr, "sensors_init: %s\n", sensors_strerror(res));
exit(1);
}
close_config_file(config_file_name);
/* build the degrees string */
set_degstr();
/* build the degrees string */
set_degstr();
if (optind == argc) { /* No chip name on command line */
if (!do_the_real_work(NULL, &error)) {
fprintf(stderr,
"No sensors found!\n"
"Make sure you loaded all the kernel drivers you need.\n"
"Try sensors-detect to find out which these are.\n");
error = 1;
}
} else {
int cnt = 0;
sensors_chip_name chip;
if (optind == argc) { /* No chip name on command line */
if (!do_the_real_work(NULL, &error)) {
fprintf(stderr,
"No sensors found!\n"
"Make sure you loaded all the kernel drivers you need.\n"
"Try sensors-detect to find out which these are.\n");
error = 1;
}
} else {
int cnt = 0;
sensors_chip_name chip;
for (i = optind; i < argc; i++) {
if (sensors_parse_chip_name(argv[i], &chip)) {
fprintf(stderr, "Parse error in chip name `%s'\n", argv[i]);
print_short_help();
error = 1;
goto exit;
}
cnt += do_the_real_work(&chip, &error);
}
for (i = optind; i < argc; i++) {
if (sensors_parse_chip_name(argv[i], &chip)) {
fprintf(stderr,
"Parse error in chip name `%s'\n",
argv[i]);
print_short_help();
error = 1;
goto exit;
}
cnt += do_the_real_work(&chip, &error);
}
if (!cnt) {
fprintf(stderr, "Specified sensor(s) not found!\n");
error = 1;
}
}
if (!cnt) {
fprintf(stderr, "Specified sensor(s) not found!\n");
error = 1;
}
}
exit:
sensors_cleanup();
exit(res);
sensors_cleanup();
exit(res);
}
/* returns number of chips found */
int do_the_real_work(const sensors_chip_name *match, int *error)
{
const sensors_chip_name *chip;
int chip_nr;
int cnt = 0;
const sensors_chip_name *chip;
int chip_nr;
int cnt = 0;
chip_nr = 0;
while ((chip = sensors_get_detected_chips(match, &chip_nr))) {
if (do_sets) {
if (do_a_set(chip))
*error = 1;
} else
do_a_print(chip);
cnt++;
}
return cnt;
chip_nr = 0;
while ((chip = sensors_get_detected_chips(match, &chip_nr))) {
if (do_sets) {
if (do_a_set(chip))
*error = 1;
} else
do_a_print(chip);
cnt++;
}
return cnt;
}
/* returns 1 on error */
int do_a_set(const sensors_chip_name *name)
{
int res;
int res;
if ((res = sensors_do_chip_sets(name))) {
if (res == -SENSORS_ERR_PROC) {
fprintf(stderr,"%s: %s for writing;\n",sprintf_chip_name(name),
sensors_strerror(res));
fprintf(stderr,"Run as root?\n");
return 1;
} else if (res == -SENSORS_ERR_ACCESS_W) {
fprintf(stderr, "%s: At least one \"set\" statement failed\n",
sprintf_chip_name(name));
} else {
fprintf(stderr,"%s: %s\n",sprintf_chip_name(name),
sensors_strerror(res));
}
}
return 0;
if ((res = sensors_do_chip_sets(name))) {
if (res == -SENSORS_ERR_PROC) {
fprintf(stderr, "%s: %s for writing;\n",
sprintf_chip_name(name),
sensors_strerror(res));
fprintf(stderr, "Run as root?\n");
return 1;
} else if (res == -SENSORS_ERR_ACCESS_W) {
fprintf(stderr,
"%s: At least one \"set\" statement failed\n",
sprintf_chip_name(name));
} else {
fprintf(stderr, "%s: %s\n", sprintf_chip_name(name),
sensors_strerror(res));
}
}
return 0;
}
const char *sprintf_chip_name(const sensors_chip_name *name)
{
#define BUF_SIZE 200
static char buf[BUF_SIZE];
#define BUF_SIZE 200
static char buf[BUF_SIZE];
if (sensors_snprintf_chip_name(buf, BUF_SIZE, name) < 0)
return NULL;
return buf;
if (sensors_snprintf_chip_name(buf, BUF_SIZE, name) < 0)
return NULL;
return buf;
}
void do_a_print(const sensors_chip_name *name)
{
printf("%s\n",sprintf_chip_name(name));
if (!hide_adapter) {
const char *adap = sensors_get_adapter_name(&name->bus);
if (adap)
printf("Adapter: %s\n", adap);
else
fprintf(stderr, "Can't get adapter name\n");
}
if (do_raw)
print_chip_raw(name);
else
print_generic_chip(name);
printf("\n");
printf("%s\n", sprintf_chip_name(name));
if (!hide_adapter) {
const char *adap = sensors_get_adapter_name(&name->bus);
if (adap)
printf("Adapter: %s\n", adap);
else
fprintf(stderr, "Can't get adapter name\n");
}
if (do_raw)
print_chip_raw(name);
else
print_generic_chip(name);
printf("\n");
}