From 1b56fe8db591a2157651f5f6c61824c6f14f1ba0 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Sat, 12 Apr 2008 08:10:57 +0000 Subject: [PATCH] Helper application that converts the contents of a file into an uint8 array. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24932 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bootman/MakeArray.cpp | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/apps/bootman/MakeArray.cpp diff --git a/src/apps/bootman/MakeArray.cpp b/src/apps/bootman/MakeArray.cpp new file mode 100644 index 0000000000..139e30a7e3 --- /dev/null +++ b/src/apps/bootman/MakeArray.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +int main(int argc, char* argv[]) +{ + const char* application = argv[0]; + if (argc != 3) { + fprintf(stderr, "Usage:\n%s ", application); + return 1; + } + const char* variableName = argv[1]; + const char* fileName = argv[2]; + + int fd = open(fileName, 0); + if (fd < 0) { + fprintf(stderr, "%s: Error opening file '%s'!\n", application, fileName); + return 1; + } + + const int kSize = 1024; + unsigned char buffer[kSize]; + int size = read(fd, buffer, kSize); + const int COLUMNS = 16; + int column = COLUMNS - 1; + bool first = true; + printf("// THIS FILE WAS GENERATED WITH\n"); + printf("// %s %s %s\n\n", application, variableName, fileName); + printf("static const uint8 %s[] = {", variableName); + while (size > 0) { + for (int i = 0; i < size; i ++) { + if (first) + first = false; + else + printf(", "); + column ++; + if (column == COLUMNS) { + printf("\n\t"); + column = 0; + } + printf("0x%2.2x", (int)buffer[i]); + } + size = read(fd, buffer, kSize); + } + printf("\n};\n"); + + close(fd); +} \ No newline at end of file