~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/serialize/binlog_reader.cc

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <drizzled/global.h>
 
2
 
 
3
#include <drizzled/serialize/binary_log.h>
 
4
 
 
5
#include <iostream>
 
6
#include <fstream>
 
7
 
 
8
#include <google/protobuf/io/coded_stream.h>
 
9
#include <google/protobuf/io/zero_copy_stream_impl.h>
 
10
 
 
11
#include <getopt.h>
 
12
#include <fcntl.h>
 
13
 
 
14
#include <sys/stat.h>
 
15
 
 
16
using namespace google::protobuf;
 
17
using namespace google::protobuf::io;
 
18
 
 
19
void print_usage_and_exit(char *prog) {
 
20
  using std::cerr;
 
21
  const char *name= strrchr(prog, '/');
 
22
 
 
23
  if (name)
 
24
    ++name;
 
25
  else
 
26
    name= "binlog_reader";
 
27
  cerr << "Usage: " << name << " <options>\n"
 
28
       << "    --input name   Read queries from file <name> (default: 'log.bin')\n"
 
29
       << std::flush;
 
30
  exit(1);
 
31
}
 
32
 
 
33
 
 
34
void
 
35
print_event(BinaryLog::Event *)
 
36
{
 
37
}
 
38
 
 
39
 
 
40
int
 
41
main(int argc, char *argv[])
 
42
{
 
43
  using std::ios;
 
44
 
 
45
  static struct option options[] = {
 
46
    { "input",     1 /* has_arg */, NULL, 0 },
 
47
    { 0, 0, 0, 0 }
 
48
  };
 
49
 
 
50
  const char *file_name= "log.bin";
 
51
 
 
52
  int ch, option_index;
 
53
  while ((ch= getopt_long(argc, argv, "", options, &option_index)) != -1) {
 
54
    if (ch == '?')
 
55
      print_usage_and_exit(argv[0]);
 
56
 
 
57
    switch (option_index) {
 
58
    case 0:                                     // --input
 
59
      file_name= optarg;
 
60
      break;
 
61
 
 
62
    }
 
63
  }
 
64
 
 
65
  if (optind > argc)
 
66
    print_usage_and_exit(argv[0]);
 
67
 
 
68
  filebuf fb;
 
69
 
 
70
  fb.open(file_name, std::ios::in);
 
71
  istream is(&fb);
 
72
 
 
73
  ZeroCopyInputStream* raw_input = new IstreamInputStream(&is);
 
74
  CodedInputStream *coded_input = new CodedInputStream(raw_input);
 
75
 
 
76
  BinaryLog::Event event;
 
77
  while (event.read(coded_input))
 
78
    event.print(std::cout);
 
79
 
 
80
  delete coded_input;
 
81
  delete raw_input;
 
82
  fb.close();
 
83
}