[syslinux] [Syslinux] [PATCH] [RFC] lib: add a hex dump lib function
Liu Aleaxander
aleaxander at gmail.com
Mon Dec 14 01:12:17 PST 2009
Hi Sebastian,
On Sat, Dec 12, 2009 at 10:08 PM, Sebastian Herbszt <herbszt at gmx.de> wrote:
>
[snip]
>
>> diff --git a/com32/lib/hexdump.c b/com32/lib/hexdump.c
>> new file mode 100644
>> index 0000000..04edbcf
>> --- /dev/null
>> +++ b/com32/lib/hexdump.c
>> @@ -0,0 +1,42 @@
>> +/*
>> + * The hex dump lib.
>> + *
>> + * Copyright (C) 2009 Liu Aleaxander -- All rights reserved. This file
>> + * may be redistributed under the terms of the GNU Public License.
>> + */
>> +
>
> com32/LICENCE says libcom32 is under the MIT license.
>
Thanks! and sorry for not noticing that.
And here is the version 2, with a hexdump.h file included in include/ directory.
---
com32/include/hexdump.h | 6 ++++
com32/lib/Makefile | 2 +
com32/lib/hexdump.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 0 deletions(-)
create mode 100644 com32/include/hexdump.h
create mode 100644 com32/lib/hexdump.c
diff --git a/com32/include/hexdump.h b/com32/include/hexdump.h
new file mode 100644
index 0000000..0ff9bb3
--- /dev/null
+++ b/com32/include/hexdump.h
@@ -0,0 +1,6 @@
+#ifndef HEXDUMP_H
+#define HEXDUMP_H
+
+__extern void hexdump(const void *, int);
+
+#endif /* hexdump.h */
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index c5b1981..0c7cf07 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -29,6 +29,8 @@ LIBOBJS = \
\
opendir.o readdir.o closedir.o getcwd.o chdir.o fdopendir.o \
\
+ hexdump.o \
+ \
libgcc/__ashldi3.o libgcc/__udivdi3.o \
libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o \
libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o \
diff --git a/com32/lib/hexdump.c b/com32/lib/hexdump.c
new file mode 100644
index 0000000..5fbabfd
--- /dev/null
+++ b/com32/lib/hexdump.c
@@ -0,0 +1,61 @@
+/*
+ * The hex dump lib.
+ *
+ * Copyright (C) 2009 Liu Aleaxander -- All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+void hexdump(const void *data, int len)
+{
+ int i, index, offset = 0;
+ uint8_t *p = data;
+ uint8_t hex[16 * 3 + 1] = {0, };
+ uint8_t text[16 + 1] = {0, };
+ uint8_t c;
+
+ for (i = 0; i < len; i++) {
+ index = i & 0xf;
+ if (i && index == 0) {
+ /* print the buffer before reset it */
+ printf("%08x %-48s |%-16s|\n", offset, hex, text);
+ offset += 0x10;
+ memset(hex, 0, sizeof hex);
+ memset(text, 0, sizeof text);
+ }
+
+ c = *p++;
+ sprintf((char *)&hex[index * 3], "%02x ", c);
+ if (c < 0x20 || c > 0x7f)
+ text[index] = '.';
+ else
+ text[index] = c;
+ }
+
+ /* print the last part */
+ printf("%08x %-48s |%-16s|\n", offset, hex, text);
+}
--
1.6.4.1
--
regards
Liu Aleaxander
More information about the Syslinux
mailing list