From 4dbf349a3c8c623f08b9d20991461814888ab492 Mon Sep 17 00:00:00 2001 From: nima Date: Wed, 29 Oct 2008 06:27:31 +0000 Subject: Synced to the latest from upstream, with a light modification required for the module. git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@73 abc39116-655e-4be6-ad55-d661dc543056 --- dmiopt.c | 179 ++++++++++++++++++++++++++++++++------------------------------- dmiopt.h | 28 +++++----- 2 files changed, 105 insertions(+), 102 deletions(-) diff --git a/dmiopt.c b/dmiopt.c index 05dae2c..4456d9f 100644 --- a/dmiopt.c +++ b/dmiopt.c @@ -2,7 +2,7 @@ * Command line handling of dmidecode * This file is part of the dmidecode project. * - * (C) 2005 Jean Delvare + * Copyright (C) 2005-2008 Jean Delvare * * 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 @@ -45,17 +45,17 @@ struct type_keyword const u8 *type; }; -static const u8 opt_type_bios[]={ 0, 13, 255 }; -static const u8 opt_type_system[]={ 1, 12, 15, 23, 32, 255 }; -static const u8 opt_type_baseboard[]={ 2, 10, 255 }; -static const u8 opt_type_chassis[]={ 3, 255 }; -static const u8 opt_type_processor[]={ 4, 255 }; -static const u8 opt_type_memory[]={ 5, 6, 16, 17, 255 }; -static const u8 opt_type_cache[]={ 7, 255 }; -static const u8 opt_type_connector[]={ 8, 255 }; -static const u8 opt_type_slot[]={ 9, 255 }; - -static const struct type_keyword opt_type_keyword[]={ +static const u8 opt_type_bios[] = { 0, 13, 255 }; +static const u8 opt_type_system[] = { 1, 12, 15, 23, 32, 255 }; +static const u8 opt_type_baseboard[] = { 2, 10, 255 }; +static const u8 opt_type_chassis[] = { 3, 255 }; +static const u8 opt_type_processor[] = { 4, 255 }; +static const u8 opt_type_memory[] = { 5, 6, 16, 17, 255 }; +static const u8 opt_type_cache[] = { 7, 255 }; +static const u8 opt_type_connector[] = { 8, 255 }; +static const u8 opt_type_slot[] = { 9, 255 }; + +static const struct type_keyword opt_type_keyword[] = { { "bios", opt_type_bios }, { "system", opt_type_system }, { "baseboard", opt_type_baseboard }, @@ -72,7 +72,7 @@ static void print_opt_type_list(void) unsigned int i; fprintf(stderr, "Valid type keywords are:\n"); - for(i=0; i0xff) + if (val > 0xff) { fprintf(stderr, "Invalid type number: %lu\n", val); goto exit_free; } - p[val]=1; - arg=next; - while(*arg==',' || *arg==' ') + p[val] = 1; + arg = next; + while (*arg == ',' || *arg == ' ') arg++; } @@ -146,31 +146,29 @@ exit_free: /* 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-vendor", 0, 0x04, NULL, NULL }, - { "bios-version", 0, 0x05, NULL, NULL }, - { "bios-release-date", 0, 0x08, NULL, NULL }, - { "system-manufacturer", 1, 0x04, NULL, NULL }, - { "system-product-name", 1, 0x05, NULL, NULL }, - { "system-version", 1, 0x06, NULL, NULL }, - { "system-serial-number", 1, 0x07, NULL, NULL }, - { "system-uuid", 1, 0x08, NULL, dmi_system_uuid }, - { "baseboard-manufacturer", 2, 0x04, NULL, NULL }, - { "baseboard-product-name", 2, 0x05, NULL, NULL }, - { "baseboard-version", 2, 0x06, NULL, NULL }, - { "baseboard-serial-number", 2, 0x07, NULL, NULL }, - { "baseboard-asset-tag", 2, 0x08, NULL, NULL }, - { "chassis-manufacturer", 3, 0x04, NULL, NULL }, - { "chassis-type", 3, 0x05, dmi_chassis_type, NULL }, - { "chassis-version", 3, 0x06, NULL, NULL }, - { "chassis-serial-number", 3, 0x07, NULL, NULL }, - { "chassis-asset-tag", 3, 0x08, NULL, NULL }, - { "processor-family", 4, 0x06, dmi_processor_family, NULL }, - { "processor-manufacturer", 4, 0x07, NULL, NULL }, - { "processor-version", 4, 0x10, NULL, NULL }, - { "processor-frequency", 4, 0x16, NULL, dmi_processor_frequency }, - - { "processor-max-frequency", 4, 0x14, NULL, dmi_processor_frequency }, +static const struct string_keyword opt_string_keyword[] = { + { "bios-vendor", 0, 0x04 }, + { "bios-version", 0, 0x05 }, + { "bios-release-date", 0, 0x08 }, + { "system-manufacturer", 1, 0x04 }, + { "system-product-name", 1, 0x05 }, + { "system-version", 1, 0x06 }, + { "system-serial-number", 1, 0x07 }, + { "system-uuid", 1, 0x08 }, /* dmi_system_uuid() */ + { "baseboard-manufacturer", 2, 0x04 }, + { "baseboard-product-name", 2, 0x05 }, + { "baseboard-version", 2, 0x06 }, + { "baseboard-serial-number", 2, 0x07 }, + { "baseboard-asset-tag", 2, 0x08 }, + { "chassis-manufacturer", 3, 0x04 }, + { "chassis-type", 3, 0x05 }, /* dmi_chassis_type() */ + { "chassis-version", 3, 0x06 }, + { "chassis-serial-number", 3, 0x07 }, + { "chassis-asset-tag", 3, 0x08 }, + { "processor-family", 4, 0x06 }, /* dmi_processor_family() */ + { "processor-manufacturer", 4, 0x07 }, + { "processor-version", 4, 0x10 }, + { "processor-frequency", 4, 0x16 }, /* dmi_processor_frequency() */ }; static void print_opt_string_list(void) @@ -178,7 +176,7 @@ static void print_opt_string_list(void) unsigned int i; fprintf(stderr, "Valid string keywords are:\n"); - for(i=0; i %d loops\n", argc, argv[0], argv[1], argv[2], i); - - if(opt.type!=NULL && opt.string!=NULL) - { - fprintf(stderr, "Options --string and --type are mutually exclusive\n"); - return -1; - } - - if((opt.flags & FLAG_DUMP) && opt.string!=NULL) + /* Check for mutually exclusive output format options */ + if ((opt.string != NULL) + (opt.type != NULL) + + !!(opt.flags & FLAG_DUMP) + !!(opt.flags & FLAG_DUMP_BIN) > 1) { - fprintf(stderr, "Options --string and --dump are mutually exclusive\n"); + fprintf(stderr, "Options --string, --type, --dump and --dump-bin are mutually exclusive\n"); return -1; } + if (opt.flags & (FLAG_DUMP | FLAG_DUMP_BIN)) + opt.flags &= ~FLAG_QUIET; - if((opt.flags & FLAG_DUMP) && (opt.flags & FLAG_QUIET)) + if ((opt.flags & FLAG_FROM_DUMP) && (opt.flags & FLAG_DUMP_BIN)) { - fprintf(stderr, "Options --quiet and --dump are mutually exclusive\n"); + fprintf(stderr, "Options --from-dump and --dump-bin are mutually exclusive\n"); return -1; } @@ -300,7 +301,7 @@ int parse_command_line(int argc, char * const argv[]) void print_help(void) { - static const char *help= + static const char *help = "Usage: dmidecode [OPTIONS]\n" "Options are:\n" " -d, --dev-mem FILE Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n" @@ -309,7 +310,9 @@ void print_help(void) " -s, --string KEYWORD Only display the value of the given DMI string\n" " -t, --type TYPE Only display the entries of given type\n" " -u, --dump Do not decode the entries\n" + " --dump-bin FILE Dump the DMI data to a binary file\n" + " --from-dump FILE Read the DMI data from a binary file\n" " -V, --version Display the version and exit\n"; - + printf("%s", help); } diff --git a/dmiopt.h b/dmiopt.h index 667ff9a..63af792 100644 --- a/dmiopt.h +++ b/dmiopt.h @@ -2,7 +2,7 @@ * Command line handling of dmidecode * This file is part of the dmidecode project. * - * (C) 2005 Jean Delvare + * Copyright (C) 2005-2008 Jean Delvare * * 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 @@ -19,29 +19,29 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - -struct string_keyword { - const char *keyword; - u8 type; - u8 offset; - const char *(*lookup)(u8); - const char *(*print)(u8 *, char *); +struct string_keyword +{ + const char *keyword; + u8 type; + u8 offset; }; struct opt { - const char* devmem; + const char *devmem; unsigned int flags; u8 *type; const struct string_keyword *string; + char *dumpfile; }; extern struct opt opt; -#define FLAG_VERSION (1<<0) -#define FLAG_HELP (1<<1) -#define FLAG_DUMP (1<<2) -#define FLAG_QUIET (1<<3) +#define FLAG_VERSION (1 << 0) +#define FLAG_HELP (1 << 1) +#define FLAG_DUMP (1 << 2) +#define FLAG_QUIET (1 << 3) +#define FLAG_DUMP_BIN (1 << 4) +#define FLAG_FROM_DUMP (1 << 5) int parse_command_line(int argc, char * const argv[]); void print_help(void); -- cgit