~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/archive_reader.cc

  • Committer: Monty Taylor
  • Date: 2010-06-01 20:35:25 UTC
  • mfrom: (1578.1.5 build)
  • Revision ID: mordred@inaugust.com-20100601203525-klt550a0q0e81qq2
Merged in pthread atomics unittests and archive_reader
boost::program_options, with build fixes for solaris.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
 
 
22
#include CSTDINT_H
 
23
#include <iostream>
 
24
#include <string>
 
25
using namespace std;
 
26
#include <boost/program_options.hpp>
 
27
namespace po= boost::program_options;
23
28
#include "azio.h"
24
29
#include <string.h>
25
30
#include <assert.h>
34
39
 
35
40
using namespace drizzled;
36
41
 
37
 
int get_one_option(int optid, const struct option *opt, char *argument);
38
 
 
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;
 
42
string opt_tmpdir;
44
43
uint64_t new_auto_increment_value;
45
44
static const char *load_default_groups[]= { "archive_reader", 0 };
46
45
static char **default_argv;
47
 
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_table_message;
48
 
int opt_autoincrement;
 
46
bool opt_check, 
 
47
  opt_force,
 
48
  opt_backup, 
 
49
  opt_extract_table_message, 
 
50
  opt_silent,
 
51
  opt_quiet,
 
52
  opt_quick,
 
53
  opt_autoincrement;
49
54
 
50
55
int main(int argc, char *argv[])
51
56
{
 
57
try
 
58
{
 
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.")
 
67
  ("force,f",po::value<bool>(&opt_force)->default_value(false)->zero_tokens(),
 
68
  "Restart with -r if there are any errors in the table")
 
69
  ("help,?","Display this help and exit")
 
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.")
 
74
  ("set-auto-increment,A",po::value<uint64_t>(&new_auto_increment_value)->default_value(0),
 
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.")
 
76
  ("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),
 
77
  "Only print errors. One can use two -s to make archive_reader very silent.")
 
78
  ("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),
 
79
  "Path for temporary files.") 
 
80
  ("version,V","Print version and exit")
 
81
  ;
 
82
 
52
83
  unsigned int ret;
53
84
  azio_stream reader_handle;
54
85
 
55
86
  internal::my_init();
56
87
  MY_INIT(argv[0]);
57
 
  get_options(&argc, &argv);
58
 
 
 
88
  internal::load_defaults("drizzle", load_default_groups, &argc, &argv);
 
89
  default_argv= argv;
 
90
  
 
91
  po::variables_map vm;
 
92
  po::store(po::parse_command_line(argc,argv,long_options),vm);
 
93
  po::notify(vm);
 
94
 
 
95
  if(vm.count("force")||vm.count("quiet")||vm.count("tmpdir"))
 
96
    cout<<"Not implemented yet";
 
97
 
 
98
  if(vm.count("version"))
 
99
  {
 
100
    printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
 
101
        HOST_VENDOR, HOST_OS, HOST_CPU);
 
102
    exit(0);
 
103
  }
 
104
  
 
105
  if(vm.count("set-auto-increment"))
 
106
  {
 
107
    opt_autoincrement= true;
 
108
  }
 
109
 
 
110
  if(vm.count("help")||argc == 0)
 
111
  {
 
112
    printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
 
113
        HOST_VENDOR, HOST_OS, HOST_CPU);
 
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");
 
117
    puts("Read and modify Archive files directly\n");
 
118
    printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
 
119
    internal::print_defaults("drizzle", load_default_groups);
 
120
    cout<<long_options<<endl;    
 
121
    exit(0); 
 
122
  }
 
123
  
59
124
  if (argc < 1)
60
125
  {
61
126
    printf("No file specified. \n");
62
 
    return 0;
 
127
    return -1;
63
128
  }
64
129
 
65
130
  if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY, AZ_METHOD_BLOCK)))
66
131
  {
67
132
    printf("Could not open Archive file\n");
68
 
    return 0;
 
133
    return -1;
69
134
  }
70
135
 
71
136
  if (opt_autoincrement)
255
320
  azclose(&reader_handle);
256
321
 
257
322
  internal::my_end();
258
 
  return 0;
259
 
}
260
 
 
261
 
int get_one_option(int optid, const struct option *opt, char *argument)
262
 
{
263
 
  (void)opt;
264
 
  switch (optid) {
265
 
  case 'b':
266
 
    opt_backup= 1;
267
 
    break;
268
 
  case 'c':
269
 
    opt_check= 1;
270
 
    break;
271
 
  case 'e':
272
 
    opt_extract_table_message= 1;
273
 
    break;
274
 
  case 'f':
275
 
    opt_force= 1;
276
 
    printf("Not implemented yet\n");
277
 
    break;
278
 
  case 'q':
279
 
    opt_quiet= 1;
280
 
    printf("Not implemented yet\n");
281
 
    break;
282
 
  case 'V':
283
 
    print_version();
284
 
    exit(0);
285
 
  case 't':
286
 
    printf("Not implemented yet\n");
287
 
    break;
288
 
  case 'A':
289
 
    opt_autoincrement= 1;
290
 
    if (argument)
291
 
      new_auto_increment_value= strtoull(argument, NULL, 0);
292
 
    else
293
 
      new_auto_increment_value= 0;
294
 
    break;
295
 
  case '?':
296
 
    usage();
297
 
    exit(0);
298
 
  }
299
 
  return 0;
300
 
}
301
 
 
302
 
static struct option my_long_options[] =
303
 
{
304
 
  {"backup", 'b',
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},
312
 
  {"force", 'f',
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},
315
 
  {"help", '?',
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},
327
 
  {"silent", 's',
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},
330
 
  {"tmpdir", 't',
331
 
   "Path for temporary files.",
332
 
   (char**) &opt_tmpdir,
333
 
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
334
 
  {"version", 'V',
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}
338
 
};
339
 
 
340
 
static void usage(void)
341
 
{
342
 
  print_version();
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 \
346
 
       license\n");
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);
351
 
}
352
 
 
353
 
static void print_version(void)
354
 
{
355
 
  printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
356
 
         HOST_VENDOR, HOST_OS, HOST_CPU);
357
 
}
358
 
 
359
 
static void get_options(int *argc, char ***argv)
360
 
{
361
 
  internal::load_defaults("drizzle", load_default_groups, argc, argv);
362
 
  default_argv= *argv;
363
 
 
364
 
  handle_options(argc, argv, my_long_options, get_one_option);
365
 
 
366
 
  if (*argc == 0)
 
323
 
 
324
}
 
325
  catch(exception &e)
367
326
  {
368
 
    usage();
369
 
    exit(-1);
 
327
    cerr<<"Error"<<e.what()<<endl;
370
328
  }
 
329
  return 0;
 
330
}
371
331
 
372
 
  return;
373
 
} /* get options */