summaryrefslogtreecommitdiff
path: root/vpdopt.c
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2005-10-03 20:06:26 +0000
committerJean Delvare <jdelvare@suse.de>2005-10-03 20:06:26 +0000
commit88c27c2852d642e6476adb00a6ef949e111cbe2f (patch)
tree6e76fb8a262f28f117e7dc9c6fa7f448dfea3760 /vpdopt.c
parent901f5e3bfe854649764103600db4dff7135484ca (diff)
downloaddmidecode-git-88c27c2852d642e6476adb00a6ef949e111cbe2f.tar.gz
Add option -s, --string. It prints one selected VPD string instead of the
regular output.
Diffstat (limited to 'vpdopt.c')
-rw-r--r--vpdopt.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/vpdopt.c b/vpdopt.c
index 932cd59..4ebb892 100644
--- a/vpdopt.c
+++ b/vpdopt.c
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <strings.h>
#include <stdlib.h>
#include <getopt.h>
@@ -32,6 +33,57 @@ struct opt opt;
/*
+ * Handling of option --string
+ */
+
+/* This lookup table could admittedly be reworked for improved performance.
+ Due to the low count of items in there at the moment, it did not seem
+ worth the additional code complexity though. */
+static const struct string_keyword opt_string_keyword[]={
+ { "bios-build-id", 0x0D, 9 },
+ { "box-serial-number", 0x16, 7 },
+ { "motherboard-serial-number", 0x1D, 11 },
+ { "machine-type-model", 0x28, 7 },
+ { "bios-release-date", 0x30, 8 },
+};
+
+static void print_opt_string_list(void)
+{
+ unsigned int i;
+
+ fprintf(stderr, "Valid string keywords are:\n");
+ for(i=0; i<sizeof(opt_string_keyword)/sizeof(struct string_keyword); i++)
+ {
+ fprintf(stderr, " %s\n", opt_string_keyword[i].keyword);
+ }
+}
+
+static int parse_opt_string(const char *arg)
+{
+ unsigned int i;
+
+ if(opt.string)
+ {
+ fprintf(stderr, "Only one string can be specified\n");
+ return -1;
+ }
+
+ for(i=0; i<sizeof(opt_string_keyword)/sizeof(struct string_keyword); i++)
+ {
+ if(!strcasecmp(arg, opt_string_keyword[i].keyword))
+ {
+ opt.string=&opt_string_keyword[i];
+ return 0;
+ }
+ }
+
+ fprintf(stderr, "Invalid string keyword: %s\n", arg);
+ print_opt_string_list();
+ return -1;
+}
+
+
+/*
* Command line options handling
*/
@@ -39,10 +91,11 @@ struct opt opt;
int parse_command_line(int argc, char * const argv[])
{
int option;
- const char *optstring = "d:huV";
+ const char *optstring = "d:hs:uV";
struct option longopts[]={
{ "dev-mem", required_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
+ { "string", required_argument, NULL, 's' },
{ "dump", no_argument, NULL, 'u' },
{ "version", no_argument, NULL, 'V' },
{ 0, 0, 0, 0 }
@@ -57,6 +110,11 @@ int parse_command_line(int argc, char * const argv[])
case 'h':
opt.flags|=FLAG_HELP;
break;
+ case 's':
+ if(parse_opt_string(optarg)<0)
+ return -1;
+ opt.flags|=FLAG_QUIET;
+ break;
case 'u':
opt.flags|=FLAG_DUMP;
break;
@@ -67,6 +125,12 @@ int parse_command_line(int argc, char * const argv[])
return -1;
}
+ if((opt.flags & FLAG_DUMP) && opt.string!=NULL)
+ {
+ fprintf(stderr, "Options --string and --dump are mutually exclusive\n");
+ return -1;
+ }
+
return 0;
}
@@ -77,6 +141,7 @@ void print_help(void)
"Options are:\n"
" -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n"
" -h, --help Display this help text and exit\n"
+ " -s, --string KEYWORD Only display the value of the given VPD string\n"
" -u, --dump Do not decode the VPD records\n"
" -V, --version Display the version and exit\n";