~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <config.h>

#include "binary_log.h"

#include <iostream>
#include <fstream>

#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>

#include <getopt.h>
#include <fcntl.h>

#include <sys/stat.h>

using namespace google::protobuf;
using namespace google::protobuf::io;

void print_usage_and_exit(char *prog) {
  using std::cerr;
  const char *name= strrchr(prog, '/');

  if (name)
    ++name;
  else
    name= "binlog_reader";
  cerr << "Usage: " << name << " <options>\n"
       << "    --input name   Read queries from file <name> (default: 'log.bin')\n"
       << std::flush;
  exit(1);
}


void
print_event(BinaryLog::Event *event)
{
}


int
main(int argc, char *argv[])
{
  using std::ios;

  static struct option options[] = {
    { "input",     1 /* has_arg */, NULL, 0 },
    { 0, 0, 0, 0 }
  };

  const char *file_name= "log.bin";

  int ch, option_index;
  while ((ch= getopt_long(argc, argv, "", options, &option_index)) != -1) {
    if (ch == '?')
      print_usage_and_exit(argv[0]);

    switch (option_index) {
    case 0:                                     // --input
      file_name= optarg;
      break;

    }
  }

  if (optind > argc)
    print_usage_and_exit(argv[0]);

  filebuf fb;

  fb.open(file_name, std::ios::in);
  istream is(&fb);

  ZeroCopyInputStream* raw_input = new IstreamInputStream(&is);
  CodedInputStream *coded_input = new CodedInputStream(raw_input);

  BinaryLog::Event event;
  while (event.read(coded_input))
    event.print(std::cout);

  delete coded_input;
  delete raw_input;
  fb.close();
}