From 2ca4cee18f778d2d25b85cdd001dbc561752a36b Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 18 Mar 2008 14:06:57 +0000 Subject: [PATCH] * Renamed hbsg to generate_boot_screen and moved it to src/tools. * Build generate_boot_screen as a build platform tool. It requires libpng to be installed. * Added output file name as fourth argument. * Replaced unnecessarily complicated fwrite(, strlen(),...) and sprintf()+fwrite() constructs by fputs() and fprintf() respectively. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24440 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tools/Jamfile | 3 ++ .../generate_boot_screen.cpp} | 54 +++++++++---------- 2 files changed, 29 insertions(+), 28 deletions(-) rename src/{bin/hbsg.cpp => tools/generate_boot_screen.cpp} (77%) diff --git a/src/tools/Jamfile b/src/tools/Jamfile index a50d31877e..c42c97dd86 100644 --- a/src/tools/Jamfile +++ b/src/tools/Jamfile @@ -37,6 +37,9 @@ BuildPlatformMain copyattr : copyattr.cpp BuildPlatformMain data_to_source : data_to_source.cpp : $(HOST_LIBSUPC++) ; +BuildPlatformMain generate_boot_screen : generate_boot_screen.cpp + : $(HOST_LIBSUPC++) $(HOST_LIBSTDC++) png ; + BuildPlatformMain listattr : listattr.cpp : $(HOST_LIBBE) ; if $(HOST_PLATFORM_BEOS_COMPATIBLE) { diff --git a/src/bin/hbsg.cpp b/src/tools/generate_boot_screen.cpp similarity index 77% rename from src/bin/hbsg.cpp rename to src/tools/generate_boot_screen.cpp index 974c218855..417aa00c2e 100644 --- a/src/bin/hbsg.cpp +++ b/src/tools/generate_boot_screen.cpp @@ -120,24 +120,21 @@ writeHeader(char *filename) printf("Exporting image %s\n", varName); // dumping palette - char *line = new char[80]; - sprintf(line, "static const uint8 %sPalette[] = {\n", varName); - fwrite(line, strlen(line), 1, foutput); + fprintf(foutput, "static const uint8 %sPalette[] = {\n", varName); for (int i = 0; i < paletteColors; i++) { - if (i == paletteColors - 1) - sprintf(line, "\t0x%x, 0x%x, 0x%x\n", palette[i].red, palette[i].green, palette[i].blue); - else - sprintf(line, "\t0x%x, 0x%x, 0x%x,\n", palette[i].red, palette[i].green, palette[i].blue); - fwrite(line, strlen(line), 1, foutput); + if (i == paletteColors - 1) { + fprintf(foutput, "\t0x%x, 0x%x, 0x%x\n", palette[i].red, + palette[i].green, palette[i].blue); + } else { + fprintf(foutput, "\t0x%x, 0x%x, 0x%x,\n", palette[i].red, + palette[i].green, palette[i].blue); + } } - fwrite("};\n\n", strlen("};\n\n"), 1, foutput); + fputs("};\n\n", foutput); - sprintf(line, "static const uint %sWidth=%d;\n", varName, width); - fwrite(line, strlen(line), 1, foutput); - sprintf(line, "static const uint %sHeight=%d;\n", varName, height); - fwrite(line, strlen(line), 1, foutput); - sprintf(line, "static const uint8 %sImage[] = {\n\t", varName); - fwrite(line, strlen(line), 1, foutput); + fprintf(foutput, "static const uint %sWidth=%d;\n", varName, width); + fprintf(foutput, "static const uint %sHeight=%d;\n", varName, height); + fprintf(foutput, "static const uint8 %sImage[] = {\n\t", varName); int offset = 0; unsigned char *data = new unsigned char[width * height]; for (y = 0; y < height; y++) { @@ -153,19 +150,18 @@ writeHeader(char *filename) offset = 0; while (!end) { if (offset == (width * height)) { - sprintf(line, "0x%x", data[offset]); + fprintf(foutput, "0x%x", data[offset]); end = true; } else - sprintf(line, "0x%x, ", data[offset]); - fwrite(line, strlen(line), 1, foutput); + fprintf(foutput, "0x%x, ", data[offset]); if ((offset % 8) == 0) { - fwrite("\n\t", strlen("\n\t"), 1, foutput); + fputs("\n\t", foutput); } offset++; } - fwrite("};\n\n", strlen("};\n\n"), 1, foutput); + fputs("};\n\n", foutput); delete varName; } @@ -183,18 +179,20 @@ main(int argc, char *argv[]) printf("Copyright 2008, Artur Wyszynski \n"); printf("Distributed under the terms of the Haiku License. All rights reserved.\n"); - if (argc < 4) { + if (argc < 5) { printf("Usage:\n"); - printf("\thbsg splash.png icons.png copyright.png\n"); + printf("\thbsg \n"); return 0; } - - foutput = fopen("images.h", "wb"); - if (!foutput) - error("Could not open file images.h for writing"); - fwrite("// This file was generated by Haiku Boot Splash Generator\n\n", - strlen("// This file was generated by Haiku Boot Splash Generator\n\n"), 1, foutput); + const char* headerFileName = argv[4]; + + foutput = fopen(headerFileName, "wb"); + if (!foutput) + error("Could not open file \"%s\" for writing", headerFileName); + + fputs("// This file was generated by Haiku Boot Splash Generator\n\n", + foutput); parseImage(argv[1]); parseImage(argv[2]);