sra@chromium.org | 04ca1bc | 2009-05-08 23:00:29 | [diff] [blame] | 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 | |
| 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 | |
sra@chromium.org | 04ca1bc | 2009-05-08 23:00:29 | [diff] [blame] | 11 | #include "courgette/courgette.h" |
| 12 | #include "courgette/streams.h" |
altimin | 979ea2e | 2016-05-18 16:16:24 | [diff] [blame] | 13 | #include "courgette/third_party/bsdiff/bsdiff.h" |
sra@chromium.org | 04ca1bc | 2009-05-08 23:00:29 | [diff] [blame] | 14 | |
| 15 | void PrintHelp() { |
| 16 | fprintf(stderr, |
| 17 | "Usage:\n" |
| 18 | " courgette_minimal_tool <old-file-input> <patch-file-input>" |
| 19 | " <new-file-output>\n" |
| 20 | "\n"); |
| 21 | } |
| 22 | |
| 23 | void UsageProblem(const char* message) { |
| 24 | fprintf(stderr, "%s\n", message); |
| 25 | PrintHelp(); |
| 26 | exit(1); |
| 27 | } |
| 28 | |
| 29 | void Problem(const char* message) { |
| 30 | fprintf(stderr, "%s\n", message); |
| 31 | exit(1); |
| 32 | } |
| 33 | |
sra@google.com | 54f1b82 | 2009-07-18 03:28:40 | [diff] [blame] | 34 | #if defined(OS_WIN) |
sra@chromium.org | 04ca1bc | 2009-05-08 23:00:29 | [diff] [blame] | 35 | int wmain(int argc, const wchar_t* argv[]) { |
sra@google.com | 54f1b82 | 2009-07-18 03:28:40 | [diff] [blame] | 36 | #else |
| 37 | int main(int argc, const char* argv[]) { |
| 38 | #endif |
sra@chromium.org | 04ca1bc | 2009-05-08 23:00:29 | [diff] [blame] | 39 | if (argc != 4) |
| 40 | UsageProblem("bad args"); |
| 41 | |
| 42 | courgette::Status status = |
| 43 | courgette::ApplyEnsemblePatch(argv[1], argv[2], argv[3]); |
| 44 | |
| 45 | if (status != courgette::C_OK) { |
| 46 | if (status == courgette::C_READ_OPEN_ERROR) Problem("Can't open file."); |
| 47 | if (status == courgette::C_WRITE_OPEN_ERROR) Problem("Can't open file."); |
| 48 | if (status == courgette::C_READ_ERROR) Problem("Can't read from file."); |
| 49 | if (status == courgette::C_WRITE_ERROR) Problem("Can't write to file."); |
| 50 | Problem("patch failed."); |
| 51 | } |
sra@chromium.org | d38c3a2 | 2009-07-22 01:30:06 | [diff] [blame] | 52 | |
| 53 | return 0; |
sra@chromium.org | 04ca1bc | 2009-05-08 23:00:29 | [diff] [blame] | 54 | } |