~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/serialize/binlog_reader.cc

Put errmsg.c in sql-common since it can be built only once and used twice.
Put client.c and net_serv.c in libmysql so that we can only have one
link_sources section. 
Got rid of just about all copying and other weirdness, other than some stuff
in client and client.c/net_serv.c, which need to be reworked.

Show diffs side-by-side

added added

removed removed

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