Author: oxygene Date: Tue Jan 18 13:14:08 2011 New Revision: 6267 URL: https://tracker.coreboot.org/trac/coreboot/changeset/6267
Log: Remove overengineering, part 1/many
Signed-off-by: Patrick Georgi patrick.georgi@secunet.com Acked-by: Patrick Georgi patrick.georgi@secunet.com
Modified: trunk/util/nvramtool/hexdump.c trunk/util/nvramtool/hexdump.h trunk/util/nvramtool/lbtable.c trunk/util/nvramtool/nvramtool.c
Modified: trunk/util/nvramtool/hexdump.c ============================================================================== --- trunk/util/nvramtool/hexdump.c Tue Jan 18 13:12:47 2011 (r6266) +++ trunk/util/nvramtool/hexdump.c Tue Jan 18 13:14:08 2011 (r6267) @@ -46,8 +46,7 @@ static void addrprint(FILE * outfile, uint64_t address, int width); static void hexprint(FILE * outfile, unsigned char byte); static void charprint(FILE * outfile, unsigned char byte, - unsigned char nonprintable, - is_printable_fn_t is_printable_fn); + unsigned char nonprintable);
/*-------------------------------------------------------------------------- * hexdump @@ -70,17 +69,11 @@ { int bytes_left, index, i; const unsigned char *p; - is_printable_fn_t is_printable_fn;
/* Quietly return if the caller asks us to do something unreasonable. */ if ((format->bytes_per_line <= 0) || (bytes < 0)) return;
- is_printable_fn = format->is_printable_fn; - - if (is_printable_fn == NULL) - is_printable_fn = default_is_printable_fn; - p = (const unsigned char *)mem; index = 0;
@@ -112,8 +105,7 @@
/* display the bytes as characters */ for (i = 0; i < format->bytes_per_line; i++) - charprint(outfile, p[index++], format->nonprintable, - is_printable_fn); + charprint(outfile, p[index++], format->nonprintable);
fprintf(outfile, "\n"); } @@ -148,8 +140,7 @@
/* display bytes for last line as characters */ for (i = 0; i < bytes_left; i++) - charprint(outfile, p[index++], format->nonprintable, - is_printable_fn); + charprint(outfile, p[index++], format->nonprintable);
/* pad the rest of the character area with spaces */ for (; i < format->bytes_per_line; i++) @@ -159,25 +150,6 @@ }
/*-------------------------------------------------------------------------- - * default_is_printable_fn - * - * Determine whether the input character is printable. The proper behavior - * for this type of function may be system-dependent. This function takes a - * conservative approach. If it is not adequate for your purposes, you can - * write your own. - * - * parameters: - * c: the input character - * - * return value: - * Return 1 if the input character is printable. Otherwise return 0. - *--------------------------------------------------------------------------*/ -int default_is_printable_fn(unsigned char c) -{ - return (c >= 0x20) && (c <= 0x7e); -} - -/*-------------------------------------------------------------------------- * addrprint * * Display an address as a hexadecimal number. @@ -245,12 +217,9 @@ * byte: the byte to display * nonprintable: a substitute character to display if the byte * represents a nonprintable character - * is_printable_fn: a function that returns a boolean value indicating - * whether a given character is printable *--------------------------------------------------------------------------*/ static void charprint(FILE * outfile, unsigned char byte, - unsigned char nonprintable, - is_printable_fn_t is_printable_fn) + unsigned char nonprintable) { - fprintf(outfile, "%c", is_printable_fn(byte) ? byte : nonprintable); + fprintf(outfile, "%c", ((byte >= 0x20) && (byte <= 0x7e)) ? byte : nonprintable); }
Modified: trunk/util/nvramtool/hexdump.h ============================================================================== --- trunk/util/nvramtool/hexdump.h Tue Jan 18 13:12:47 2011 (r6266) +++ trunk/util/nvramtool/hexdump.h Tue Jan 18 13:14:08 2011 (r6267) @@ -48,8 +48,6 @@ #include <sys/types.h> #include <stdio.h>
-typedef int (*is_printable_fn_t) (unsigned char c); - /*-------------------------------------------------------------------------- * hexdump_format_t * @@ -75,11 +73,6 @@ * characters. It serves as a separator. * nonprintable: This is a substitute character to display in place * of nonprintable characters. - * is_printable_fn: This is a user-supplied function that takes a byte - * value as input and returns a boolean value - * indicating whether the corresponding character is - * printable. A value of NULL will cause - * default_is_printable_fn to be used. *--------------------------------------------------------------------------*/ typedef struct { int bytes_per_line; @@ -89,7 +82,6 @@ const char *sep2; const char *sep3; unsigned char nonprintable; - is_printable_fn_t is_printable_fn; } hexdump_format_t;
/*-------------------------------------------------------------------------- @@ -111,20 +103,4 @@ void hexdump(const void *mem, int bytes, uint64_t addrprint_start, FILE * outfile, const hexdump_format_t * format);
-/*-------------------------------------------------------------------------- - * default_is_printable_fn - * - * Determine whether the input character is printable. The proper behavior - * for this type of function may be system-dependent. This function appears - * to work well on a Linux system. However, if it is not adequate for your - * purposes, you can write your own. - * - * parameters: - * c: the input character - * - * return value: - * Return 1 if the input character is printable. Otherwise return 0. - *--------------------------------------------------------------------------*/ -int default_is_printable_fn(unsigned char c); - #endif /* _HEXDUMP_H */
Modified: trunk/util/nvramtool/lbtable.c ============================================================================== --- trunk/util/nvramtool/lbtable.c Tue Jan 18 13:12:47 2011 (r6266) +++ trunk/util/nvramtool/lbtable.c Tue Jan 18 13:14:08 2011 (r6267) @@ -234,7 +234,7 @@ static const struct cmos_option_table *cmos_table = NULL;
static const hexdump_format_t format = - { 12, 4, " ", " | ", " ", " | ", '.', NULL }; + { 12, 4, " ", " | ", " ", " | ", '.' };
/**************************************************************************** * vtophys
Modified: trunk/util/nvramtool/nvramtool.c ============================================================================== --- trunk/util/nvramtool/nvramtool.c Tue Jan 18 13:12:47 2011 (r6266) +++ trunk/util/nvramtool/nvramtool.c Tue Jan 18 13:14:08 2011 (r6267) @@ -85,7 +85,7 @@ };
static const hexdump_format_t cmos_dump_format = - { 16, 2, "", " | ", " ", " | ", '.', NULL }; + { 16, 2, "", " | ", " ", " | ", '.' };
/**************************************************************************** * main