mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-30 22:05:11 +00:00
New program: doc-features
This program automatically documents the available features for each chip. Basically, it translates the data in lib/chips.c back to a human-readable format. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@208 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
2
Makefile
2
Makefile
@@ -114,7 +114,7 @@ MANGRP := root
|
||||
|
||||
# The subdirectories we need to build things in
|
||||
SRCDIRS := kernel kernel/busses kernel/chips kernel/include lib prog/sensors \
|
||||
prog/dump etc
|
||||
prog/dump prog/doc etc
|
||||
ifeq ($(I2C),1)
|
||||
SRCDIRS += i2c i2c/detect i2c/drivers i2c/eeprom
|
||||
endif
|
||||
|
41
prog/doc/Module.mk
Normal file
41
prog/doc/Module.mk
Normal file
@@ -0,0 +1,41 @@
|
||||
# Module.mk - Makefile for a Linux module for reading sensor data.
|
||||
# Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
# Note that MODULE_DIR (the directory in which this file resides) is a
|
||||
# 'simply expanded variable'. That means that its value is substituted
|
||||
# verbatim in the rules, until it is redefined.
|
||||
MODULE_DIR := prog/doc
|
||||
|
||||
# Regrettably, even 'simply expanded variables' will not put their currently
|
||||
# defined value verbatim into the command-list of rules...
|
||||
PROGDOCTARGETS := $(MODULE_DIR)/doc-features
|
||||
PROGDOCSOURCES := $(MODULE_DIR)/doc-features.c
|
||||
|
||||
# Include all dependency files. We use '.rd' to indicate this will create
|
||||
# executables.
|
||||
INCLUDEFILES += $(PROGDOCSOURCES:.c=.rd)
|
||||
|
||||
$(PROGDOCTARGETS): $(PROGDOCSOURCES:.c=.ro) lib/$(LIBSHBASENAME)
|
||||
$(CC) -o $@ $(PROGDOCSOURCES:.c=.ro) -Llib -lsensors
|
||||
|
||||
all-prog-doc: $(PROGDOCTARGETS)
|
||||
all :: all-prog-doc
|
||||
|
||||
clean-prog-doc:
|
||||
$(RM) $(PROGDOCSOURCES:.c=.rd) $(PROGDOCSOURCES:.c=.ro) \
|
||||
$(PROGDOCTARGETS)
|
||||
clean :: clean-prog-doc
|
149
prog/doc/doc-features.c
Normal file
149
prog/doc/doc-features.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
doc-features.c - A program to dump sensor feature documentation
|
||||
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/* This program uses undocumented sensors library access. It it undocumented
|
||||
for a reason: normal programs really should not work on this level! */
|
||||
|
||||
#include "lib/data.h"
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
const char *lookup_feature_name(int featurenr,
|
||||
const sensors_chip_features *chipdata)
|
||||
{
|
||||
int i;
|
||||
if (featurenr == SENSORS_NO_MAPPING)
|
||||
return "";
|
||||
for (i = 0; chipdata->feature[i].name ; i++)
|
||||
if (chipdata->feature[i].number == featurenr)
|
||||
return chipdata->feature[i].name;
|
||||
return "***ERROR***";
|
||||
}
|
||||
|
||||
const char *mode_string(int mode)
|
||||
{
|
||||
if (mode == SENSORS_MODE_RW)
|
||||
return "RW";
|
||||
else if (mode == SENSORS_MODE_R)
|
||||
return "R ";
|
||||
else if (mode == SENSORS_MODE_W)
|
||||
return " W";
|
||||
else
|
||||
return "--";
|
||||
}
|
||||
|
||||
void dump_feature(const sensors_chip_feature *featuredata,
|
||||
const sensors_chip_features *chipdata)
|
||||
{
|
||||
printf(" %17s: %17s %17s %2s %2d\n",featuredata->name,
|
||||
lookup_feature_name(featuredata->logical_mapping,chipdata),
|
||||
lookup_feature_name(featuredata->compute_mapping,chipdata),
|
||||
mode_string(featuredata->mode),
|
||||
featuredata->scaling);
|
||||
}
|
||||
|
||||
int qsort_compare (const void *f1, const void *f2)
|
||||
{
|
||||
return strcmp((* ((sensors_chip_feature * const *)f1))->name,
|
||||
(* ((sensors_chip_feature * const *)f2))->name);
|
||||
}
|
||||
|
||||
void dump_chip (const sensors_chip_features *chipdata)
|
||||
{
|
||||
int i;
|
||||
sensors_chip_feature **features;
|
||||
for (i = 0; chipdata->feature[i].name; i++);
|
||||
|
||||
features = malloc(sizeof(*features) * i+1);
|
||||
for (i = 0; chipdata->feature[i].name; i++)
|
||||
features[i] = chipdata->feature + i;
|
||||
features[i] = chipdata->feature + i;
|
||||
qsort(features,i,sizeof(*features),qsort_compare);
|
||||
|
||||
printf("Chip `%s'\n",chipdata->prefix);
|
||||
printf(" %17s %17s %17s %2s %s\n","NAME","LABEL CLASS","COMPUTE CLASS",
|
||||
"RW","SCALE");
|
||||
for (i = 0; features[i]->name; i++)
|
||||
dump_feature(features[i],chipdata);
|
||||
|
||||
free(features);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_short_help(void)
|
||||
{
|
||||
fprintf(stderr,"Usage: doc-features [-h] [-v] [chipname]..\n");
|
||||
fprintf(stderr,"Try `doc-features -h' for more information\n");
|
||||
}
|
||||
|
||||
void print_long_help(void)
|
||||
{
|
||||
fprintf(stderr,"Usage: doc-features [-h] [-v] [chipname]..\n");
|
||||
fprintf(stderr," -h, --help Display this help text\n");
|
||||
fprintf(stderr," -v, --version Display version information\n");
|
||||
fprintf(stderr,"If no chipnames are specified, information for all chips is dumped.\n");
|
||||
}
|
||||
|
||||
void print_version(void)
|
||||
{
|
||||
printf("doc-features version 1.0\n");
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int c,i;
|
||||
|
||||
struct option long_opts[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'v'}
|
||||
};
|
||||
|
||||
while(1) {
|
||||
c = getopt_long(argc,argv,"hv",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);
|
||||
default:
|
||||
fprintf(stderr,"Internal error while parsing options!\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
for (i = 0; sensors_chip_features_list[i].prefix ; i++)
|
||||
dump_chip(sensors_chip_features_list+i);
|
||||
else
|
||||
for (; optind != argc ; optind ++)
|
||||
for (i = 0; sensors_chip_features_list[i].prefix; i++)
|
||||
if (!strcmp(sensors_chip_features_list[i].prefix,argv[optind]))
|
||||
dump_chip(sensors_chip_features_list+i);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user