~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/archive_reader.cc

  • Committer: Jay Pipes
  • Date: 2009-09-21 14:33:44 UTC
  • mfrom: (1126.10.26 dtrace-probes)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: jpipes@serialcoder-20090921143344-jnarp7gcn6zmg19c
Merge fixes from Trond and Padraig on dtrace probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (c) 2006 MySQL AB
5
 
 *  Copyright (c) 2009 Sun Microsystems, Inc.
6
 
 *
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; version 2 of the License.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
 
23
1
#include "azio.h"
24
2
#include <string.h>
25
3
#include <assert.h>
26
4
#include <stdio.h>
27
5
#include <stdarg.h>
28
 
#include <fcntl.h>
29
 
#include "drizzled/charset_info.h"
30
 
#include "drizzled/internal/m_string.h"
31
 
#include "drizzled/option.h"
 
6
#include <mystrings/m_ctype.h>
 
7
#include <mystrings/m_string.h>
 
8
#include <mysys/my_getopt.h>
32
9
 
33
10
#define SHOW_VERSION "0.1"
34
11
 
35
 
using namespace drizzled;
36
 
 
37
 
int get_one_option(int optid, const struct option *opt, char *argument);
 
12
extern "C" bool
 
13
get_one_option(int optid, const struct my_option *opt, char *argument);
38
14
 
39
15
static void get_options(int *argc,char * * *argv);
40
16
static void print_version(void);
44
20
uint64_t new_auto_increment_value;
45
21
static const char *load_default_groups[]= { "archive_reader", 0 };
46
22
static char **default_argv;
47
 
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_table_message;
 
23
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_frm;
48
24
int opt_autoincrement;
49
25
 
50
26
int main(int argc, char *argv[])
52
28
  unsigned int ret;
53
29
  azio_stream reader_handle;
54
30
 
55
 
  internal::my_init();
 
31
  my_init();
56
32
  MY_INIT(argv[0]);
57
33
  get_options(&argc, &argv);
58
34
 
111
87
    printf("\tLongest Row %u\n", reader_handle.longest_row);
112
88
    printf("\tShortest Row %u\n", reader_handle.shortest_row);
113
89
    printf("\tState %s\n", ( reader_handle.dirty ? "dirty" : "clean"));
114
 
    printf("\tTable protobuf message stored at %u\n",
115
 
           reader_handle.frm_start_pos);
 
90
    printf("\tFRM stored at %u\n", reader_handle.frm_start_pos);
116
91
    printf("\tComment stored at %u\n", reader_handle.comment_start_pos);
117
92
    printf("\tData starts at %u\n", (unsigned int)reader_handle.start);
118
93
    if (reader_handle.frm_start_pos)
119
 
      printf("\tTable proto message length %u\n", reader_handle.frm_length);
 
94
      printf("\tFRM length %u\n", reader_handle.frm_length);
120
95
    if (reader_handle.comment_start_pos)
121
96
    {
122
97
      char *comment =
233
208
    azclose(&writer_handle);
234
209
  }
235
210
 
236
 
  if (opt_extract_table_message)
 
211
  if (opt_extract_frm)
237
212
  {
238
 
    int frm_file;
 
213
    File frm_file;
239
214
    char *ptr;
240
 
    frm_file= internal::my_open(argv[1], O_CREAT|O_RDWR, MYF(0));
 
215
    frm_file= my_open(argv[1], O_CREAT|O_RDWR, MYF(0));
241
216
    ptr= (char *)malloc(sizeof(char) * reader_handle.frm_length);
242
217
    if (ptr == NULL)
243
218
    {
245
220
      goto end;
246
221
    }
247
222
    azread_frm(&reader_handle, ptr);
248
 
    internal::my_write(frm_file, (unsigned char*) ptr, reader_handle.frm_length, MYF(0));
249
 
    internal::my_close(frm_file, MYF(0));
 
223
    my_write(frm_file, (unsigned char*) ptr, reader_handle.frm_length, MYF(0));
 
224
    my_close(frm_file, MYF(0));
250
225
    free(ptr);
251
226
  }
252
227
 
254
229
  printf("\n");
255
230
  azclose(&reader_handle);
256
231
 
257
 
  internal::my_end();
 
232
  my_end(0);
258
233
  return 0;
259
234
}
260
235
 
261
 
int get_one_option(int optid, const struct option *opt, char *argument)
 
236
bool get_one_option(int optid, const struct my_option *opt, char *argument)
262
237
{
263
238
  (void)opt;
264
239
  switch (optid) {
269
244
    opt_check= 1;
270
245
    break;
271
246
  case 'e':
272
 
    opt_extract_table_message= 1;
 
247
    opt_extract_frm= 1;
273
248
    break;
274
249
  case 'f':
275
250
    opt_force= 1;
299
274
  return 0;
300
275
}
301
276
 
302
 
static struct option my_long_options[] =
 
277
static struct my_option my_long_options[] =
303
278
{
304
279
  {"backup", 'b',
305
280
   "Make a backup of an archive table.",
306
281
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
307
282
  {"check", 'c', "Check table for errors.",
308
283
   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.",
 
284
  {"extract-frm", 'e',
 
285
   "Extract the frm file.",
311
286
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
312
287
  {"force", 'f',
313
288
   "Restart with -r if there are any errors in the table.",
345
320
       \nand you are welcome to modify and redistribute it under the GPL \
346
321
       license\n");
347
322
  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);
 
323
  printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", my_progname);
 
324
  print_defaults("drizzle", load_default_groups);
350
325
  my_print_help(my_long_options);
351
326
}
352
327
 
353
328
static void print_version(void)
354
329
{
355
 
  printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
 
330
  printf("%s  Ver %s, for %s-%s (%s)\n", my_progname, SHOW_VERSION,
356
331
         HOST_VENDOR, HOST_OS, HOST_CPU);
357
332
}
358
333
 
359
334
static void get_options(int *argc, char ***argv)
360
335
{
361
 
  internal::load_defaults("drizzle", load_default_groups, argc, argv);
 
336
  load_defaults("drizzle", load_default_groups, argc, argv);
362
337
  default_argv= *argv;
363
338
 
364
339
  handle_options(argc, argv, my_long_options, get_one_option);