diff options
author | heretic <heretic@yandex-team.ru> | 2022-02-10 16:45:43 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:43 +0300 |
commit | 397cbe258b9e064f49c4ca575279f02f39fef76e (patch) | |
tree | a0b0eb3cca6a14e4e8ea715393637672fa651284 /tools/rescompressor | |
parent | 43f5a35593ebc9f6bcea619bb170394ea7ae468e (diff) | |
download | ydb-397cbe258b9e064f49c4ca575279f02f39fef76e.tar.gz |
Restoring authorship annotation for <heretic@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'tools/rescompressor')
-rw-r--r-- | tools/rescompressor/main.cpp | 168 | ||||
-rw-r--r-- | tools/rescompressor/ya.make | 6 |
2 files changed, 87 insertions, 87 deletions
diff --git a/tools/rescompressor/main.cpp b/tools/rescompressor/main.cpp index 9aba1002c5..e038cdab7f 100644 --- a/tools/rescompressor/main.cpp +++ b/tools/rescompressor/main.cpp @@ -1,46 +1,46 @@ #include <library/cpp/resource/registry.h> -#include <util/stream/file.h> -#include <util/folder/path.h> - -using namespace NResource; - -class TAsmWriter { -private: - IOutputStream& AsmOut; - TString AsmPrefix; - -public: - TAsmWriter(IOutputStream& out, const TString& prefix) : AsmOut(out), AsmPrefix(prefix) - { - } - - void Write(TStringBuf filename, const TString& data, bool raw) { - TString constname(Basename(filename)); - if (constname.rfind('.') != TStringBuf::npos) { - constname = constname.substr(0, constname.rfind('.')); - } - WriteHeader(constname); - if (raw) { - WriteRaw(constname, data); - } else { - WriteIncBin(constname, filename, data); - } +#include <util/stream/file.h> +#include <util/folder/path.h> + +using namespace NResource; + +class TAsmWriter { +private: + IOutputStream& AsmOut; + TString AsmPrefix; + +public: + TAsmWriter(IOutputStream& out, const TString& prefix) : AsmOut(out), AsmPrefix(prefix) + { + } + + void Write(TStringBuf filename, const TString& data, bool raw) { + TString constname(Basename(filename)); + if (constname.rfind('.') != TStringBuf::npos) { + constname = constname.substr(0, constname.rfind('.')); + } + WriteHeader(constname); + if (raw) { + WriteRaw(constname, data); + } else { + WriteIncBin(constname, filename, data); + } WriteFooter(constname); WriteSymbolSize(constname); - } - -private: - void WriteHeader(const TStringBuf& constname) { - AsmOut << "global " << AsmPrefix << constname << "\n"; - AsmOut << "global " << AsmPrefix << constname << "Size\n"; - AsmOut << "SECTION .rodata\n"; - } - + } + +private: + void WriteHeader(const TStringBuf& constname) { + AsmOut << "global " << AsmPrefix << constname << "\n"; + AsmOut << "global " << AsmPrefix << constname << "Size\n"; + AsmOut << "SECTION .rodata\n"; + } + void WriteFooter(TStringBuf constname) { AsmOut << AsmPrefix << constname << "Size:\n"; AsmOut << "dd " << AsmPrefix << constname << ".end - " << AsmPrefix << constname << "\n"; - } - + } + void WriteSymbolSize(TStringBuf constname) { AsmOut << "%ifidn __OUTPUT_FORMAT__,elf64\n"; AsmOut << "size " << AsmPrefix << constname << " " << AsmPrefix << constname << ".end - " << AsmPrefix << constname << "\n"; @@ -48,34 +48,34 @@ private: AsmOut << "%endif\n"; } - void WriteIncBin(TStringBuf constname, TStringBuf filename, const TString& data) { - AsmOut << AsmPrefix << constname << ":\nincbin \"" << Basename(filename) << "\"\n"; + void WriteIncBin(TStringBuf constname, TStringBuf filename, const TString& data) { + AsmOut << AsmPrefix << constname << ":\nincbin \"" << Basename(filename) << "\"\n"; AsmOut << ".end:\n"; TFixedBufferFileOutput out(filename.data()); - out << data; - } - - void WriteRaw(TStringBuf constname, const TString& data) { - AsmOut << AsmPrefix << constname << ":\ndb "; + out << data; + } + + void WriteRaw(TStringBuf constname, const TString& data) { + AsmOut << AsmPrefix << constname << ":\ndb "; for (size_t i = 0; i < data.size() - 1; i++) { - unsigned char c = static_cast<unsigned char>(data[i]); - AsmOut << IntToString<10, unsigned char>(c) << ","; - } + unsigned char c = static_cast<unsigned char>(data[i]); + AsmOut << IntToString<10, unsigned char>(c) << ","; + } AsmOut << IntToString<10, unsigned char>(static_cast<unsigned char>(data[data.size() - 1])) << "\n"; AsmOut << ".end:\n"; - } - - TString Basename(TStringBuf origin) { - TString result(origin); - if (result.rfind('/') != TString::npos) { - result = result.substr(result.rfind('/') + 1); - } else if (result.rfind('\\') != TString::npos) { - result = result.substr(result.rfind('\\') + 1); - } - return result; - } -}; - + } + + TString Basename(TStringBuf origin) { + TString result(origin); + if (result.rfind('/') != TString::npos) { + result = result.substr(result.rfind('/') + 1); + } else if (result.rfind('\\') != TString::npos) { + result = result.substr(result.rfind('\\') + 1); + } + return result; + } +}; + static TString CompressPath(const TVector<TStringBuf>& replacements, TStringBuf in) { for (auto r : replacements) { TStringBuf from, to; @@ -88,37 +88,37 @@ static TString CompressPath(const TVector<TStringBuf>& replacements, TStringBuf return Compress(in); } -int main(int argc, char** argv) { +int main(int argc, char** argv) { int ind = 0; - if (argc < 4) { + if (argc < 4) { Cerr << "usage: " << argv[ind] << "asm_output --prefix? [-? origin_resource ro_resource]+" << Endl; - return 1; - } - + return 1; + } + TVector<TStringBuf> replacements; ind++; TFixedBufferFileOutput asmout(argv[ind]); ind++; - TString prefix; + TString prefix; if (TStringBuf(argv[ind]) == "--prefix") { - prefix = "_"; + prefix = "_"; ind++; - } - else { - prefix = ""; - } - + } + else { + prefix = ""; + } + while (TStringBuf(argv[ind]).StartsWith("--replace=")) { replacements.push_back(TStringBuf(argv[ind]).SubStr(TStringBuf("--replace=").Size())); ind++; } - TAsmWriter aw(asmout, prefix); - bool raw; + TAsmWriter aw(asmout, prefix); + bool raw; bool error = false; while (ind < argc) { - TString compressed; + TString compressed; if ("-"sv == argv[ind]) { ind++; if (ind >= argc) { @@ -126,14 +126,14 @@ int main(int argc, char** argv) { break; } compressed = CompressPath(replacements, TStringBuf(argv[ind])); - raw = true; - } - else { + raw = true; + } + else { TUnbufferedFileInput inp(argv[ind]); - TString data = inp.ReadAll(); + TString data = inp.ReadAll(); compressed = Compress(TStringBuf(data.data(), data.size())); - raw = false; - } + raw = false; + } ind++; if (ind >= argc) { error = true; @@ -141,10 +141,10 @@ int main(int argc, char** argv) { } aw.Write(argv[ind], compressed, raw); ind++; - } + } if (error) { Cerr << "Incorrect number of parameters at argument " << ind - 1 << argv[ind-1] << Endl; return 1; } - return 0; -} + return 0; +} diff --git a/tools/rescompressor/ya.make b/tools/rescompressor/ya.make index 4c118c0bc6..8f76a7f315 100644 --- a/tools/rescompressor/ya.make +++ b/tools/rescompressor/ya.make @@ -1,13 +1,13 @@ OWNER(heretic g:ymake) - + IF (USE_PREBUILT_TOOLS) INCLUDE(${ARCADIA_ROOT}/build/prebuilt/tools/rescompressor/ya.make.prebuilt) ENDIF() - + IF (NOT PREBUILT) INCLUDE(${ARCADIA_ROOT}/tools/rescompressor/bin/ya.make) ENDIF() - + RECURSE( bin ) |