Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1076)

Side by Side Diff: courgette/courgette_tool.cc

Issue 149597: Code changes to get the code to compile under GCC.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « courgette/courgette_minimal_tool.cc ('k') | courgette/difference_estimator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 #include <string> 6 #include <string>
7 7
8 #include "base/at_exit.h" 8 #include "base/at_exit.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 27 matching lines...) Expand all
38 void Problem(const char* format, ...) { 38 void Problem(const char* format, ...) {
39 va_list args; 39 va_list args;
40 va_start(args, format); 40 va_start(args, format);
41 vfprintf(stderr, format, args); 41 vfprintf(stderr, format, args);
42 fprintf(stderr, "\n"); 42 fprintf(stderr, "\n");
43 va_end(args); 43 va_end(args);
44 exit(1); 44 exit(1);
45 } 45 }
46 46
47 std::string ReadOrFail(const std::wstring& file_name, const char* kind) { 47 std::string ReadOrFail(const std::wstring& file_name, const char* kind) {
48 #if defined(OS_WIN)
48 FilePath file_path(file_name); 49 FilePath file_path(file_name);
50 #else
51 FilePath file_path(WideToASCII(file_name));
52 #endif
49 std::string buffer; 53 std::string buffer;
50 if (!file_util::ReadFileToString(file_path, &buffer)) 54 if (!file_util::ReadFileToString(file_path, &buffer))
51 Problem("Can't read %s file.", kind); 55 Problem("Can't read %s file.", kind);
52 return buffer; 56 return buffer;
53 } 57 }
54 58
55 void WriteSinkToFile(const courgette::SinkStream *sink, 59 void WriteSinkToFile(const courgette::SinkStream *sink,
56 const std::wstring& output_file) { 60 const std::wstring& output_file) {
61 #if defined(OS_WIN)
57 FilePath output_path(output_file); 62 FilePath output_path(output_file);
63 #else
64 FilePath output_path(WideToASCII(output_file));
65 #endif
58 int count = 66 int count =
59 file_util::WriteFile(output_path, 67 file_util::WriteFile(output_path,
60 reinterpret_cast<const char*>(sink->Buffer()), 68 reinterpret_cast<const char*>(sink->Buffer()),
61 sink->Length()); 69 sink->Length());
62 if (count == -1) 70 if (count == -1)
63 Problem("Cant write output."); 71 Problem("Can't write output.");
64 if (count != sink->Length()) 72 if (static_cast<size_t>(count) != sink->Length())
65 Problem("Incomplete write."); 73 Problem("Incomplete write.");
66 } 74 }
67 75
68 void Disassemble(const std::wstring& input_file, 76 void Disassemble(const std::wstring& input_file,
69 const std::wstring& output_file) { 77 const std::wstring& output_file) {
70 std::string buffer = ReadOrFail(input_file, "input"); 78 std::string buffer = ReadOrFail(input_file, "input");
71 79
72 courgette::AssemblyProgram* program = NULL; 80 courgette::AssemblyProgram* program = NULL;
73 const courgette::Status parse_status = 81 const courgette::Status parse_status =
74 courgette::ParseWin32X86PE(buffer.c_str(), buffer.length(), &program); 82 courgette::ParseWin32X86PE(buffer.c_str(), buffer.length(), &program);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 331
324 courgette::SinkStream new_stream; 332 courgette::SinkStream new_stream;
325 courgette::BSDiffStatus status = 333 courgette::BSDiffStatus status =
326 courgette::ApplyBinaryPatch(&old_stream, &patch_stream, &new_stream); 334 courgette::ApplyBinaryPatch(&old_stream, &patch_stream, &new_stream);
327 335
328 if (status != courgette::OK) Problem("-applybsdiff failed."); 336 if (status != courgette::OK) Problem("-applybsdiff failed.");
329 337
330 WriteSinkToFile(&new_stream, new_file); 338 WriteSinkToFile(&new_stream, new_file);
331 } 339 }
332 340
341 bool WideStringToInt(const std::wstring& str, int *output) {
342 string16 copy(str.begin(), str.end());
343 return StringToInt(copy, output);
344 }
345
333 int main(int argc, const char* argv[]) { 346 int main(int argc, const char* argv[]) {
334 base::AtExitManager at_exit_manager; 347 base::AtExitManager at_exit_manager;
335 CommandLine::Init(argc, argv); 348 CommandLine::Init(argc, argv);
336 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 349 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
337 350
338 bool cmd_dis = command_line.HasSwitch(L"dis"); 351 bool cmd_dis = command_line.HasSwitch(L"dis");
339 bool cmd_asm = command_line.HasSwitch(L"asm"); 352 bool cmd_asm = command_line.HasSwitch(L"asm");
340 bool cmd_disadj = command_line.HasSwitch(L"disadj"); 353 bool cmd_disadj = command_line.HasSwitch(L"disadj");
341 bool cmd_make_patch = command_line.HasSwitch(L"gen"); 354 bool cmd_make_patch = command_line.HasSwitch(L"gen");
342 bool cmd_apply_patch = command_line.HasSwitch(L"apply"); 355 bool cmd_apply_patch = command_line.HasSwitch(L"apply");
343 bool cmd_make_bsdiff_patch = command_line.HasSwitch(L"genbsdiff"); 356 bool cmd_make_bsdiff_patch = command_line.HasSwitch(L"genbsdiff");
344 bool cmd_apply_bsdiff_patch = command_line.HasSwitch(L"applybsdiff"); 357 bool cmd_apply_bsdiff_patch = command_line.HasSwitch(L"applybsdiff");
345 bool cmd_spread_1_adjusted = command_line.HasSwitch(L"gen1a"); 358 bool cmd_spread_1_adjusted = command_line.HasSwitch(L"gen1a");
346 bool cmd_spread_1_unadjusted = command_line.HasSwitch(L"gen1u"); 359 bool cmd_spread_1_unadjusted = command_line.HasSwitch(L"gen1u");
347 360
348 std::vector<std::wstring> values = command_line.GetLooseValues(); 361 std::vector<std::wstring> values = command_line.GetLooseValues();
349 362
350 // '-repeat=N' is for debugging. Running many iterations can reveal leaks and 363 // '-repeat=N' is for debugging. Running many iterations can reveal leaks and
351 // bugs in cleanup. 364 // bugs in cleanup.
352 int repeat_count = 1; 365 int repeat_count = 1;
353 std::wstring repeat_switch = command_line.GetSwitchValue(L"repeat"); 366 std::wstring repeat_switch = command_line.GetSwitchValue(L"repeat");
354 if (!repeat_switch.empty()) 367 if (!repeat_switch.empty())
355 if (!StringToInt(repeat_switch, &repeat_count)) 368 if (!WideStringToInt(repeat_switch, &repeat_count))
356 repeat_count = 1; 369 repeat_count = 1;
357 370
358 if (cmd_dis + cmd_asm + cmd_disadj + cmd_make_patch + cmd_apply_patch + 371 if (cmd_dis + cmd_asm + cmd_disadj + cmd_make_patch + cmd_apply_patch +
359 cmd_make_bsdiff_patch + cmd_apply_bsdiff_patch + 372 cmd_make_bsdiff_patch + cmd_apply_bsdiff_patch +
360 cmd_spread_1_adjusted + cmd_spread_1_unadjusted 373 cmd_spread_1_adjusted + cmd_spread_1_unadjusted
361 != 1) 374 != 1)
362 UsageProblem( 375 UsageProblem(
363 "Must have exactly one of:\n" 376 "Must have exactly one of:\n"
364 " -asm, -dis, -disadj, -gen or -apply, -genbsdiff or -applybsdiff."); 377 " -asm, -dis, -disadj, -gen or -apply, -genbsdiff or -applybsdiff.");
365 378
(...skipping 29 matching lines...) Expand all
395 } else if (cmd_spread_1_adjusted || cmd_spread_1_unadjusted) { 408 } else if (cmd_spread_1_adjusted || cmd_spread_1_unadjusted) {
396 if (values.size() != 3) 409 if (values.size() != 3)
397 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); 410 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>");
398 DisassembleAdjustDiff(values[0], values[1], values[2], 411 DisassembleAdjustDiff(values[0], values[1], values[2],
399 cmd_spread_1_adjusted); 412 cmd_spread_1_adjusted);
400 } else { 413 } else {
401 UsageProblem("No operation specified"); 414 UsageProblem("No operation specified");
402 } 415 }
403 } 416 }
404 } 417 }
OLDNEW
« no previous file with comments | « courgette/courgette_minimal_tool.cc ('k') | courgette/difference_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698