main.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <library/cpp/resource/registry.h>
  2. #include <util/digest/city.h>
  3. #include <util/stream/output.h>
  4. #include <util/stream/file.h>
  5. #include <util/string/escape.h>
  6. #include <util/string/vector.h>
  7. #include <util/string/split.h>
  8. using namespace NResource;
  9. void GenOne(const TString& raw, const TString& key, IOutputStream& out) {
  10. TString size = raw + "Size";
  11. TString name = ToString(CityHash64(key.data(), key.size()));
  12. out << "extern \"C\" const char " << raw << "[];\n"
  13. << "extern \"C\" const unsigned int " << size << ";\n"
  14. << "static const NResource::TRegHelper REG_name" << name
  15. << "(\"" << EscapeC(key) << "\", TStringBuf(" << raw << ", " << size << "));\n"
  16. << "\n";
  17. };
  18. int main(int argc, char** argv) {
  19. if (argc < 3) {
  20. Cerr << "usage: " << argv[0] << " outfile [key=value]+" << Endl;
  21. return 1;
  22. }
  23. TFixedBufferFileOutput out(argv[1]);
  24. argv = argv + 2;
  25. out << "#include <library/cpp/resource/registry.h>\n\n";
  26. while (*argv) {
  27. TVector<TString> items = StringSplitter(TString(*(argv))).Split('=').Limit(2).ToList<TString>();
  28. GenOne(items[0], items[1], out);
  29. argv++;
  30. }
  31. }