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