~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/archive_reader.cc

  • Committer: Mark Atwood
  • Date: 2010-06-24 03:15:21 UTC
  • mto: (1637.2.4 build)
  • mto: This revision was merged to the branch mainline in revision 1639.
  • Revision ID: me@mark.atwood.name-20100624031521-gafmppfbf5afm68w
new syslog module, with plugins for query log, error message, and SYSLOG() function

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2006 MySQL AB
5
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (c) 2006 MySQL AB
 
5
 *  Copyright (c) 2009 Sun Microsystems, Inc.
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
8
8
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
 
22
#include CSTDINT_H
22
23
#include <iostream>
23
24
#include <string>
24
 
#include <fstream>
25
 
#include <drizzled/configmake.h>
26
25
using namespace std;
27
26
#include <boost/program_options.hpp>
28
 
#include <boost/scoped_ptr.hpp>
29
27
namespace po= boost::program_options;
30
28
#include "azio.h"
31
29
#include <string.h>
33
31
#include <stdio.h>
34
32
#include <stdarg.h>
35
33
#include <fcntl.h>
36
 
#include <memory>
37
 
#include <drizzled/charset_info.h>
38
 
#include <drizzled/internal/m_string.h>
 
34
#include "drizzled/charset_info.h"
 
35
#include "drizzled/internal/m_string.h"
 
36
#include "drizzled/option.h"
39
37
 
40
38
#define SHOW_VERSION "0.1"
41
39
 
43
41
 
44
42
string opt_tmpdir;
45
43
uint64_t new_auto_increment_value;
 
44
static const char *load_default_groups[]= { "archive_reader", 0 };
 
45
static char **default_argv;
46
46
bool opt_check, 
47
47
  opt_force,
48
48
  opt_backup, 
56
56
{
57
57
try
58
58
{
59
 
  po::options_description commandline_options("Options used only in command line");
60
 
  commandline_options.add_options()
 
59
  po::options_description long_options("Allowed Options");
 
60
  long_options.add_options()
 
61
  ("back_up,b",po::value<bool>(&opt_backup)->default_value(false)->zero_tokens(),
 
62
  "Make a backup of an archive table.")
 
63
  ("check,c",po::value<bool>(&opt_check)->default_value(false)->zero_tokens(),
 
64
  "Check table for errors")
 
65
  ("extract-table-message,e",po::value<bool>(&opt_extract_table_message)->default_value(false)->zero_tokens(),
 
66
  "Extract the table protobuf message.")
61
67
  ("force,f",po::value<bool>(&opt_force)->default_value(false)->zero_tokens(),
62
68
  "Restart with -r if there are any errors in the table")
63
69
  ("help,?","Display this help and exit")
64
 
  ("version,V","Print version and exit")
65
 
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
66
 
  "Configuration file defaults are not used if no-defaults is set")
67
 
  ;
68
 
 
69
 
  po::options_description archive_reader_options("Options specific to the archive reader");
70
 
  archive_reader_options.add_options()
71
 
  ("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),
72
 
  "Path for temporary files.") 
 
70
  ("quick,q",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
 
71
  "Faster repair but not modifying the data")
 
72
  ("repair,r",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
 
73
  "Repair a damaged Archive version 3 or above file.")
73
74
  ("set-auto-increment,A",po::value<uint64_t>(&new_auto_increment_value)->default_value(0),
74
75
  "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.")
75
76
  ("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),
76
77
  "Only print errors. One can use two -s to make archive_reader very silent.")
77
 
  ("quick,q",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
78
 
  "Faster repair but not modifying the data")
79
 
  ("repair,r",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
80
 
  "Repair a damaged Archive version 3 or above file.")
81
 
  ("back-up,b",po::value<bool>(&opt_backup)->default_value(false)->zero_tokens(),
82
 
  "Make a backup of an archive table.")
83
 
  ("check,c",po::value<bool>(&opt_check)->default_value(false)->zero_tokens(),
84
 
  "Check table for errors")
85
 
  ("extract-table-message,e",po::value<bool>(&opt_extract_table_message)->default_value(false)->zero_tokens(),
86
 
  "Extract the table protobuf message.")
 
78
  ("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),
 
79
  "Path for temporary files.") 
 
80
  ("version,V","Print version and exit")
87
81
  ;
88
82
 
89
83
  unsigned int ret;
90
 
  boost::scoped_ptr<azio_stream> reader_handle_ap(new azio_stream);
91
 
  azio_stream &reader_handle= *reader_handle_ap.get();
92
 
 
93
 
  std::string system_config_dir_archive_reader(SYSCONFDIR); 
94
 
  system_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
95
 
 
96
 
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
97
 
 
98
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
99
 
  {
100
 
    char *homedir;
101
 
    homedir= getenv("HOME");
102
 
    if (homedir != NULL)
103
 
      user_config_dir.replace(0, 1, homedir);
104
 
  }
 
84
  azio_stream reader_handle;
 
85
 
 
86
  internal::my_init();
 
87
  MY_INIT(argv[0]);
 
88
  internal::load_defaults("drizzle", load_default_groups, &argc, &argv);
 
89
  default_argv= argv;
105
90
  
106
 
  po::options_description long_options("Allowed Options");
107
 
  long_options.add(commandline_options).add(archive_reader_options);
108
 
 
109
91
  po::variables_map vm;
110
92
  po::store(po::parse_command_line(argc,argv,long_options),vm);
111
 
 
112
 
  if (! vm["no-defaults"].as<bool>())
113
 
  {
114
 
    std::string user_config_dir_archive_reader(user_config_dir);
115
 
    user_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
116
 
  
117
 
    ifstream user_archive_reader_ifs(user_config_dir_archive_reader.c_str());
118
 
    po::store(parse_config_file(user_archive_reader_ifs, archive_reader_options), vm);
119
 
 
120
 
    ifstream system_archive_reader_ifs(system_config_dir_archive_reader.c_str());
121
 
    store(parse_config_file(system_archive_reader_ifs, archive_reader_options), vm);
122
 
 
123
 
  }
124
93
  po::notify(vm);
125
94
 
126
 
  if (vm.count("force") || vm.count("quiet") || vm.count("tmpdir"))
127
 
    cout << "Not implemented yet";
 
95
  if(vm.count("force")||vm.count("quiet")||vm.count("tmpdir"))
 
96
    cout<<"Not implemented yet";
128
97
 
129
 
  if (vm.count("version"))
 
98
  if(vm.count("version"))
130
99
  {
131
100
    printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
132
101
        HOST_VENDOR, HOST_OS, HOST_CPU);
133
102
    exit(0);
134
103
  }
135
104
  
136
 
  if (vm.count("set-auto-increment"))
 
105
  if(vm.count("set-auto-increment"))
137
106
  {
138
107
    opt_autoincrement= true;
139
108
  }
140
109
 
141
 
  if (vm.count("help") || argc == 0)
 
110
  if(vm.count("help")||argc == 0)
142
111
  {
143
112
    printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
144
113
        HOST_VENDOR, HOST_OS, HOST_CPU);
145
 
    puts("This software comes with ABSOLUTELY NO WARRANTY. This is free "
146
 
         "software,\n"
147
 
         "and you are welcome to modify and redistribute it under the GPL "
148
 
         "license\n");
 
114
    puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
 
115
       \nand you are welcome to modify and redistribute it under the GPL \
 
116
       license\n");
149
117
    puts("Read and modify Archive files directly\n");
150
118
    printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
151
 
    cout << long_options << endl;    
 
119
    internal::print_defaults("drizzle", load_default_groups);
 
120
    cout<<long_options<<endl;    
152
121
    exit(0); 
153
122
  }
154
123
  
166
135
 
167
136
  if (opt_autoincrement)
168
137
  {
169
 
    boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
170
 
    azio_stream &writer_handle= *writer_handle_ap.get();
 
138
    azio_stream writer_handle;
171
139
 
172
140
    if (new_auto_increment_value)
173
141
    {
264
232
    uint64_t row_count= 0;
265
233
    char *buffer;
266
234
 
267
 
    boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
268
 
    azio_stream &writer_handle= *writer_handle_ap.get();
 
235
    azio_stream writer_handle;
269
236
 
270
237
    buffer= (char *)malloc(reader_handle.longest_row);
271
238
    if (buffer == NULL)