mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-09 00:05:46 +00:00
Added bin2h support
This commit is contained in:
@@ -30,6 +30,7 @@ src/Streams/ByteReader.cpp
|
|||||||
src/Streams/ByteWriter.cpp
|
src/Streams/ByteWriter.cpp
|
||||||
src/Streams/PtyStream.cpp
|
src/Streams/PtyStream.cpp
|
||||||
src/Text/StringConverter.cpp
|
src/Text/StringConverter.cpp
|
||||||
|
src/Text/HeaderGenerator.cpp
|
||||||
src/TextStreams/StreamReader.cpp
|
src/TextStreams/StreamReader.cpp
|
||||||
src/TextStreams/StreamWriter.cpp
|
src/TextStreams/StreamWriter.cpp
|
||||||
src/TextStreams/TextReader.cpp
|
src/TextStreams/TextReader.cpp
|
||||||
@@ -340,6 +341,9 @@ if(TESSESFRAMEWORK_ENABLE_EXAMPLES)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TESSESFRAMEWORK_ENABLE_APPS)
|
if(TESSESFRAMEWORK_ENABLE_APPS)
|
||||||
|
add_executable(tbin2h apps/tbin2h.cpp)
|
||||||
|
target_link_libraries(tbin2h PUBLIC tessesframework)
|
||||||
|
install(TARGETS tbin2h DESTINATION bin)
|
||||||
add_executable(tanonydrop apps/tanonydrop.cpp)
|
add_executable(tanonydrop apps/tanonydrop.cpp)
|
||||||
target_link_libraries(tanonydrop PUBLIC tessesframework)
|
target_link_libraries(tanonydrop PUBLIC tessesframework)
|
||||||
install(TARGETS tanonydrop DESTINATION bin)
|
install(TARGETS tanonydrop DESTINATION bin)
|
||||||
|
|||||||
15
apps/tbin2h.cpp
Normal file
15
apps/tbin2h.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include "TessesFramework/TessesFramework.hpp"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if(argc < 4)
|
||||||
|
{
|
||||||
|
std::cout << "USAGE: " << argv[0] << " BINARYFILE VARNAME HEADERFILE" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Tesses::Framework::Streams::FileStream fs(argv[1],"rb");
|
||||||
|
if(!fs.CanRead()) return 1;
|
||||||
|
Tesses::Framework::TextStreams::StreamWriter writer(argv[3]);
|
||||||
|
Tesses::Framework::Text::GenerateCHeaderFile(&fs, argv[2], &writer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "TextStreams/StringReader.hpp"
|
#include "TextStreams/StringReader.hpp"
|
||||||
#include "TextStreams/StringWriter.hpp"
|
#include "TextStreams/StringWriter.hpp"
|
||||||
#include "Text/StringConverter.hpp"
|
#include "Text/StringConverter.hpp"
|
||||||
|
#include "Text/HeaderGenerator.hpp"
|
||||||
#include "Threading/Thread.hpp"
|
#include "Threading/Thread.hpp"
|
||||||
#include "Threading/Mutex.hpp"
|
#include "Threading/Mutex.hpp"
|
||||||
#include "Threading/ThreadPool.hpp"
|
#include "Threading/ThreadPool.hpp"
|
||||||
|
|||||||
11
include/TessesFramework/Text/HeaderGenerator.hpp
Normal file
11
include/TessesFramework/Text/HeaderGenerator.hpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../Streams/MemoryStream.hpp"
|
||||||
|
#include "../TextStreams/StringWriter.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::Framework::Text {
|
||||||
|
void GenerateCHeaderFile(Streams::Stream* strm,std::string name, TextStreams::TextWriter* writer);
|
||||||
|
|
||||||
|
std::string GenerateCHeaderFile(Streams::Stream* strm,std::string name);
|
||||||
|
void GenerateCHeaderFile(const std::vector<uint8_t>& data,std::string name, TextStreams::TextWriter* writer);
|
||||||
|
std::string GenerateCHeaderFile(const std::vector<uint8_t>& data,std::string name);
|
||||||
|
}
|
||||||
69
src/Text/HeaderGenerator.cpp
Normal file
69
src/Text/HeaderGenerator.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include "TessesFramework/Text/HeaderGenerator.hpp"
|
||||||
|
namespace Tesses::Framework::Text {
|
||||||
|
|
||||||
|
void GenerateCHeaderFile(Streams::Stream* strm,std::string name, TextStreams::TextWriter* writer)
|
||||||
|
{
|
||||||
|
const size_t BLK_SZ=1024;
|
||||||
|
writer->WriteLine("#pragma once");
|
||||||
|
writer->WriteLine("#if defined(__cplusplus)");
|
||||||
|
writer->WriteLine("extern \"C\" {");
|
||||||
|
writer->WriteLine("#endif");
|
||||||
|
writer->WriteLine("#include <stdint.h>");
|
||||||
|
writer->WriteLine("#include <stddef.h>");
|
||||||
|
writer->Write("const uint8_t ");
|
||||||
|
writer->Write(name);
|
||||||
|
writer->WriteLine("_data[] = {");
|
||||||
|
uint64_t total = 0;
|
||||||
|
size_t read;
|
||||||
|
|
||||||
|
uint8_t* data = new uint8_t[BLK_SZ];
|
||||||
|
bool first=true;
|
||||||
|
|
||||||
|
|
||||||
|
do {
|
||||||
|
read = strm->ReadBlock(data, BLK_SZ);
|
||||||
|
|
||||||
|
for(size_t i = 0; i < read; i++)
|
||||||
|
{
|
||||||
|
if(!first) writer->Write(", ");
|
||||||
|
writer->Write((uint64_t)data[i]);
|
||||||
|
first=false;
|
||||||
|
}
|
||||||
|
total += read;
|
||||||
|
} while(read != 0);
|
||||||
|
|
||||||
|
|
||||||
|
delete data;
|
||||||
|
|
||||||
|
writer->WriteLine("};");
|
||||||
|
writer->Write("const size_t ");
|
||||||
|
writer->Write(name);
|
||||||
|
writer->Write("_length = ");
|
||||||
|
writer->Write(total);
|
||||||
|
writer->WriteLine(";");
|
||||||
|
|
||||||
|
writer->WriteLine("#if defined(__cplusplus)");
|
||||||
|
writer->WriteLine("}");
|
||||||
|
writer->WriteLine("#endif");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GenerateCHeaderFile(Streams::Stream* strm,std::string name)
|
||||||
|
{
|
||||||
|
TextStreams::StringWriter writer;
|
||||||
|
GenerateCHeaderFile(strm,name,&writer);
|
||||||
|
return writer.GetString();
|
||||||
|
}
|
||||||
|
void GenerateCHeaderFile(const std::vector<uint8_t>& data,std::string name, TextStreams::TextWriter* writer)
|
||||||
|
{
|
||||||
|
Tesses::Framework::Streams::MemoryStream ms(false);
|
||||||
|
ms.GetBuffer() = data;
|
||||||
|
GenerateCHeaderFile(&ms,name,writer);
|
||||||
|
}
|
||||||
|
std::string GenerateCHeaderFile(std::vector<uint8_t>& data,std::string name)
|
||||||
|
{
|
||||||
|
TextStreams::StringWriter writer;
|
||||||
|
GenerateCHeaderFile(data,name,&writer);
|
||||||
|
return writer.GetString();
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user