29
35
#include "drizzled/charset_info.h"
30
36
#include "drizzled/internal/m_string.h"
31
#include "drizzled/option.h"
33
38
#define SHOW_VERSION "0.1"
35
40
using namespace drizzled;
37
int get_one_option(int optid, const struct option *opt, char *argument);
39
static void get_options(int *argc,char * * *argv);
40
static void print_version(void);
41
static void usage(void);
42
static const char *opt_tmpdir;
43
static const char *new_auto_increment;
44
43
uint64_t new_auto_increment_value;
45
static const char *load_default_groups[]= { "archive_reader", 0 };
46
static char **default_argv;
47
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_table_message;
48
int opt_autoincrement;
47
opt_extract_table_message,
50
53
int main(int argc, char *argv[])
57
po::options_description commandline_options("Options used only in command line");
58
commandline_options.add_options()
59
("force,f",po::value<bool>(&opt_force)->default_value(false)->zero_tokens(),
60
"Restart with -r if there are any errors in the table")
61
("help,?","Display this help and exit")
62
("version,V","Print version and exit")
63
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
64
"Configuration file defaults are not used if no-defaults is set")
67
po::options_description archive_reader_options("Options specific to the archive reader");
68
archive_reader_options.add_options()
69
("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),
70
"Path for temporary files.")
71
("set-auto-increment,A",po::value<uint64_t>(&new_auto_increment_value)->default_value(0),
72
"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.")
73
("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),
74
"Only print errors. One can use two -s to make archive_reader very silent.")
75
("quick,q",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
76
"Faster repair but not modifying the data")
77
("repair,r",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
78
"Repair a damaged Archive version 3 or above file.")
79
("back-up,b",po::value<bool>(&opt_backup)->default_value(false)->zero_tokens(),
80
"Make a backup of an archive table.")
81
("check,c",po::value<bool>(&opt_check)->default_value(false)->zero_tokens(),
82
"Check table for errors")
83
("extract-table-message,e",po::value<bool>(&opt_extract_table_message)->default_value(false)->zero_tokens(),
84
"Extract the table protobuf message.")
53
88
azio_stream reader_handle;
57
get_options(&argc, &argv);
90
std::string system_config_dir_archive_reader(SYSCONFDIR);
91
system_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
93
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
95
po::options_description long_options("Allowed Options");
96
long_options.add(commandline_options).add(archive_reader_options);
99
po::store(po::parse_command_line(argc,argv,long_options),vm);
101
if (! vm["no-defaults"].as<bool>())
103
std::string user_config_dir_archive_reader(user_config_dir);
104
user_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
106
ifstream user_archive_reader_ifs(user_config_dir_archive_reader.c_str());
107
po::store(parse_config_file(user_archive_reader_ifs, archive_reader_options), vm);
109
ifstream system_archive_reader_ifs(system_config_dir_archive_reader.c_str());
110
store(parse_config_file(system_archive_reader_ifs, archive_reader_options), vm);
115
if (vm.count("force") || vm.count("quiet") || vm.count("tmpdir"))
116
cout << "Not implemented yet";
118
if (vm.count("version"))
120
printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
121
HOST_VENDOR, HOST_OS, HOST_CPU);
125
if (vm.count("set-auto-increment"))
127
opt_autoincrement= true;
130
if (vm.count("help") || argc == 0)
132
printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
133
HOST_VENDOR, HOST_OS, HOST_CPU);
134
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free "
136
"and you are welcome to modify and redistribute it under the GPL "
138
puts("Read and modify Archive files directly\n");
139
printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
140
cout << long_options << endl;
61
146
printf("No file specified. \n");
65
150
if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY, AZ_METHOD_BLOCK)))
67
152
printf("Could not open Archive file\n");
71
156
if (opt_autoincrement)
255
340
azclose(&reader_handle);
257
342
internal::my_end();
261
int get_one_option(int optid, const struct option *opt, char *argument)
272
opt_extract_table_message= 1;
276
printf("Not implemented yet\n");
280
printf("Not implemented yet\n");
286
printf("Not implemented yet\n");
289
opt_autoincrement= 1;
291
new_auto_increment_value= strtoull(argument, NULL, 0);
293
new_auto_increment_value= 0;
302
static struct option my_long_options[] =
305
"Make a backup of an archive table.",
306
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
307
{"check", 'c', "Check table for errors.",
308
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
309
{"extract-table-message", 'e',
310
"Extract the table protobuf message.",
311
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
313
"Restart with -r if there are any errors in the table.",
314
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
316
"Display this help and exit.",
317
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
318
{"quick", 'q', "Faster repair by not modifying the data file.",
319
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
320
{"repair", 'r', "Repair a damaged Archive version 3 or above file.",
321
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
322
{"set-auto-increment", 'A',
323
"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.",
324
(char**) &new_auto_increment,
325
(char**) &new_auto_increment,
326
0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
328
"Only print errors. One can use two -s to make archive_reader very silent.",
329
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
331
"Path for temporary files.",
332
(char**) &opt_tmpdir,
333
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
335
"Print version and exit.",
336
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
337
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
340
static void usage(void)
343
puts("Copyright (C) 2007 MySQL AB");
344
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
345
\nand you are welcome to modify and redistribute it under the GPL \
347
puts("Read and modify Archive files directly\n");
348
printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
349
internal::print_defaults("drizzle", load_default_groups);
350
my_print_help(my_long_options);
353
static void print_version(void)
355
printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
356
HOST_VENDOR, HOST_OS, HOST_CPU);
359
static void get_options(int *argc, char ***argv)
361
internal::load_defaults("drizzle", load_default_groups, argc, argv);
364
handle_options(argc, argv, my_long_options, get_one_option);
347
cerr<<"Error"<<e.what()<<endl;