diff options
| author | lbavoil <[email protected]> | 2018-03-15 11:08:34 +0100 |
|---|---|---|
| committer | lbavoil <[email protected]> | 2018-03-15 11:08:34 +0100 |
| commit | 636807e68a85a978473764d171ed0c7cc36f9be6 (patch) | |
| tree | 784a3d4fa8f48b4c085dd959678505b2af12f425 /build/tools/Stringify/Stringify.cpp | |
| parent | Remove test folder (diff) | |
| download | hbaoplus-636807e68a85a978473764d171ed0c7cc36f9be6.tar.xz hbaoplus-636807e68a85a978473764d171ed0c7cc36f9be6.zip | |
HBAO+ 4.0.0.23740451
Diffstat (limited to 'build/tools/Stringify/Stringify.cpp')
| -rw-r--r-- | build/tools/Stringify/Stringify.cpp | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/build/tools/Stringify/Stringify.cpp b/build/tools/Stringify/Stringify.cpp index ea3fe68..38bd512 100644 --- a/build/tools/Stringify/Stringify.cpp +++ b/build/tools/Stringify/Stringify.cpp @@ -1,8 +1,8 @@ -// Stringify.cpp : Defines the entry point for the console application. -// - -#include "stdafx.h" - +#define _CRT_SECURE_NO_WARNINGS +#include <stdio.h> +#include <tchar.h> +#include <stdlib.h> +#include <vector> int main(int argc, char* argv[]) { @@ -16,7 +16,15 @@ int main(int argc, char* argv[]) const char* pVariableName = argv[2]; const char *pFilenameOut = argv[3]; - FILE *fpIn = fopen(pFilenameIn, "r"); + FILE *fpIn = fopen(pFilenameIn, "rb"); + fseek(fpIn, 0, SEEK_END); + long fileSize = ftell(fpIn); + fseek(fpIn, 0, SEEK_SET); + std::vector<uint8_t> entireFile(fileSize); + fread(entireFile.data(), 1, (size_t)fileSize, fpIn); + entireFile.push_back(0); + fseek(fpIn, 0, SEEK_SET); + if (!fpIn) { fprintf(stderr, "Error: Failed to open %s\n", pFilenameIn); @@ -30,17 +38,29 @@ int main(int argc, char* argv[]) exit(1); } - fprintf(fpOut, "static const char* %s =\n", pVariableName); + // fprintf(fpOut, "// static const char* %s =\n", pVariableName); + // + // char row[1024]; + // while (fgets(row, sizeof(row), fpIn)) + // { + // row[strlen(row) - 1] = row[strlen(row) - 2] = 0; // remove \r\n + // + // fprintf(fpOut, "// \"%s\\n\"", row); + // } + // + // fprintf(fpOut, "// ;\n"); - char row[1024]; - while (fgets(row, sizeof(row), fpIn)) - { - row[strlen(row) - 1] = 0; // remove \n + fprintf(fpOut, "static const char %s[] =\n{", pVariableName); - fprintf(fpOut, "\"%s\\n\"\n", row); + for (size_t i = 0; i < entireFile.size(); ++i) + { + fprintf(fpOut, "0x%X, ", (uint32_t)entireFile[i]); + if (i % 16 == 15) + { + fprintf(fpOut, "\n"); + } } - - fprintf(fpOut, ";\n"); + fprintf(fpOut, "};\n"); fclose(fpIn); fclose(fpOut); |