Skip to content

Commit

Permalink
Modify the opt structure to handle the string option more efficiently.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelvare committed Sep 14, 2005
1 parent 02b421e commit f0fed13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
18 changes: 9 additions & 9 deletions dmidecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3819,7 +3819,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
struct dmi_header *h=(struct dmi_header *)data;
int display=((opt.type==NULL || opt.type[h->type])
&& !((opt.flags & FLAG_QUIET) && h->type>39)
&& !opt.string_offset);
&& !opt.string);

/* In quiet mode, stop decoding at end of table marker */
if((opt.flags & FLAG_QUIET) && h->type==127)
Expand Down Expand Up @@ -3847,18 +3847,18 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
printf("\t<TRUNCATED>\n");
printf("\n");
}
else if(opt.string_type==h->type
&& opt.string_offset
&& opt.string_offset<h->length)
else if(opt.string!=NULL
&& opt.string->type==h->type
&& opt.string->offset<h->length)
{
if (opt.string_lookup != NULL)
printf("%s\n", opt.string_lookup(data[opt.string_offset]));
else if (opt.string_print != NULL) {
opt.string_print(data+opt.string_offset);
if (opt.string->lookup!=NULL)
printf("%s\n", opt.string->lookup(data[opt.string->offset]));
else if (opt.string->print!=NULL) {
opt.string->print(data+opt.string->offset);
printf("\n");
}
else
printf("%s\n", dmi_string(h, data[opt.string_offset]));
printf("%s\n", dmi_string(h, data[opt.string->offset]));
}

data=next;
Expand Down
20 changes: 4 additions & 16 deletions dmiopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@ static u8 *parse_opt_type(u8 *p, const char *arg)
* Handling of option --string
*/

struct string_keyword
{
const char *keyword;
u8 type;
u8 offset;
const char *(*lookup)(u8);
void (*print)(u8 *);
};

/* 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. */
Expand Down Expand Up @@ -194,7 +185,7 @@ static int parse_opt_string(const char *arg)
{
unsigned int i;

if(opt.string_offset)
if(opt.string)
{
fprintf(stderr, "Only one string can be specified\n");
return -1;
Expand All @@ -204,10 +195,7 @@ static int parse_opt_string(const char *arg)
{
if(!strcasecmp(arg, opt_string_keyword[i].keyword))
{
opt.string_type=opt_string_keyword[i].type;
opt.string_offset=opt_string_keyword[i].offset;
opt.string_lookup=opt_string_keyword[i].lookup;
opt.string_print=opt_string_keyword[i].print;
opt.string=&opt_string_keyword[i];
return 0;
}
}
Expand Down Expand Up @@ -281,13 +269,13 @@ int parse_command_line(int argc, char * const argv[])
return -1;
}

if(opt.type!=NULL && opt.string_offset)
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_offset)
if((opt.flags & FLAG_DUMP) && opt.string!=NULL)
{
fprintf(stderr, "Options --string and --dump are mutually exclusive\n");
return -1;
Expand Down
14 changes: 10 additions & 4 deletions dmiopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

struct string_keyword
{
const char *keyword;
u8 type;
u8 offset;
const char *(*lookup)(u8);
void (*print)(u8 *);
};

struct opt
{
const char* devmem;
unsigned int flags;
u8 *type;
u8 string_type;
u8 string_offset;
const char *(*string_lookup)(u8);
void (*string_print)(u8 *);
const struct string_keyword *string;
};
extern struct opt opt;

Expand Down

0 comments on commit f0fed13

Please sign in to comment.