courgette_minimal_tool.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2009 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // 'courgette_minimal_tool' is not meant to be a serious command-line tool. It
  5. // has the minimum logic to apply a Courgette patch to a file. The main purpose
  6. // is to monitor the code size of the patcher.
  7. #include <string>
  8. #include "build/build_config.h"
  9. #include "courgette/courgette.h"
  10. #include "courgette/streams.h"
  11. #include "courgette/third_party/bsdiff/bsdiff.h"
  12. void PrintHelp() {
  13. fprintf(stderr,
  14. "Usage:\n"
  15. " courgette_minimal_tool <old-file-input> <patch-file-input>"
  16. " <new-file-output>\n"
  17. "\n");
  18. }
  19. void UsageProblem(const char* message) {
  20. fprintf(stderr, "%s\n", message);
  21. PrintHelp();
  22. exit(1);
  23. }
  24. void Problem(const char* message) {
  25. fprintf(stderr, "%s\n", message);
  26. exit(1);
  27. }
  28. #if BUILDFLAG(IS_WIN)
  29. int wmain(int argc, const wchar_t* argv[]) {
  30. #else
  31. int main(int argc, const char* argv[]) {
  32. #endif
  33. if (argc != 4)
  34. UsageProblem("bad args");
  35. courgette::Status status =
  36. courgette::ApplyEnsemblePatch(argv[1], argv[2], argv[3]);
  37. if (status != courgette::C_OK) {
  38. if (status == courgette::C_READ_OPEN_ERROR) Problem("Can't open file.");
  39. if (status == courgette::C_WRITE_OPEN_ERROR) Problem("Can't open file.");
  40. if (status == courgette::C_READ_ERROR) Problem("Can't read from file.");
  41. if (status == courgette::C_WRITE_ERROR) Problem("Can't write to file.");
  42. Problem("patch failed.");
  43. }
  44. return 0;
  45. }