Squashed 'src/leveldb/' changes from 20ca81f..a31c8aa
[bitcoinplatinum.git] / db / leveldbutil.cc
blob9f4b7dd70c245302e9841e6a407e89659992284f
1 // Copyright (c) 2012 The LevelDB 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. See the AUTHORS file for names of contributors.
5 #include <stdio.h>
6 #include "leveldb/dumpfile.h"
7 #include "leveldb/env.h"
8 #include "leveldb/status.h"
10 namespace leveldb {
11 namespace {
13 class StdoutPrinter : public WritableFile {
14 public:
15 virtual Status Append(const Slice& data) {
16 fwrite(data.data(), 1, data.size(), stdout);
17 return Status::OK();
19 virtual Status Close() { return Status::OK(); }
20 virtual Status Flush() { return Status::OK(); }
21 virtual Status Sync() { return Status::OK(); }
24 bool HandleDumpCommand(Env* env, char** files, int num) {
25 StdoutPrinter printer;
26 bool ok = true;
27 for (int i = 0; i < num; i++) {
28 Status s = DumpFile(env, files[i], &printer);
29 if (!s.ok()) {
30 fprintf(stderr, "%s\n", s.ToString().c_str());
31 ok = false;
34 return ok;
37 } // namespace
38 } // namespace leveldb
40 static void Usage() {
41 fprintf(
42 stderr,
43 "Usage: leveldbutil command...\n"
44 " dump files... -- dump contents of specified files\n"
48 int main(int argc, char** argv) {
49 leveldb::Env* env = leveldb::Env::Default();
50 bool ok = true;
51 if (argc < 2) {
52 Usage();
53 ok = false;
54 } else {
55 std::string command = argv[1];
56 if (command == "dump") {
57 ok = leveldb::HandleDumpCommand(env, argv+2, argc-2);
58 } else {
59 Usage();
60 ok = false;
63 return (ok ? 0 : 1);