~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 --print-defaults         ; Print the modified command line and exit
34
34
****************************************************************************/
35
35
 
36
 
#include "config.h"
37
 
 
38
 
#include "drizzled/internal/my_sys.h"
39
 
#include "drizzled/internal/m_string.h"
40
 
#include "drizzled/charset_info.h"
 
36
#include "mysys/mysys_priv.h"
 
37
#include <mystrings/m_string.h>
 
38
#include <mystrings/m_ctype.h>
41
39
#include <drizzled/configmake.h>
42
40
#include <drizzled/gettext.h>
43
41
 
44
 
#include "drizzled/cached_directory.h"
45
 
 
46
 
#ifdef HAVE_SYS_STAT_H
47
 
# include <sys/stat.h>
48
 
#endif
49
 
 
50
 
#include <cstdio>
 
42
#include <mysys/cached_directory.h>
 
43
 
 
44
#include <stdio.h>
51
45
#include <algorithm>
52
46
 
53
47
using namespace std;
54
48
 
55
 
namespace drizzled
56
 
{
57
 
namespace internal
58
 
{
59
 
 
60
49
const char *my_defaults_file=0;
61
50
const char *my_defaults_group_suffix=0;
62
51
char *my_defaults_extra_file=0;
80
69
 
81
70
struct handle_option_ctx
82
71
{
83
 
   memory::Root *alloc;
 
72
   MEM_ROOT *alloc;
84
73
   DYNAMIC_ARRAY *args;
85
74
   TYPELIB *group;
86
75
};
324
313
  int org_argc= argc, prev_argc= 0;
325
314
  *defaults= *extra_defaults= *group_suffix= 0;
326
315
 
327
 
  const std::string DEFAULTS_FILE("--defaults-file=");
328
 
  const std::string DEFAULTS_EXTRA_FILE("--defaults-extra-file=");
329
 
  const std::string DEFAULTS_GROUP_SUFFIX("--defaults-group-suffix=");
330
 
 
331
316
  while (argc >= 2 && argc != prev_argc)
332
317
  {
333
318
    /* Skip program name or previously handled argument */
334
319
    argv++;
335
320
    prev_argc= argc;                            /* To check if we found */
336
 
    if (!*defaults && (strncmp(*argv,
337
 
                               DEFAULTS_FILE.c_str(),
338
 
                               DEFAULTS_FILE.size()) == 0))
 
321
    if (!*defaults && is_prefix(*argv,"--defaults-file="))
339
322
    {
340
 
      *defaults= *argv + DEFAULTS_FILE.size();
 
323
      *defaults= *argv + sizeof("--defaults-file=")-1;
341
324
       argc--;
342
325
       continue;
343
326
    }
344
 
    if (!*extra_defaults && (strncmp(*argv, 
345
 
                                     DEFAULTS_EXTRA_FILE.c_str(),
346
 
                                     DEFAULTS_EXTRA_FILE.size()) == 0))
 
327
    if (!*extra_defaults && is_prefix(*argv,"--defaults-extra-file="))
347
328
    {
348
 
      *extra_defaults= *argv + DEFAULTS_EXTRA_FILE.size();
 
329
      *extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
349
330
      argc--;
350
331
      continue;
351
332
    }
352
 
    if (!*group_suffix && (strncmp(*argv, 
353
 
                                   DEFAULTS_GROUP_SUFFIX.c_str(),
354
 
                                   DEFAULTS_GROUP_SUFFIX.size()) == 0))
355
 
 
 
333
    if (!*group_suffix && is_prefix(*argv, "--defaults-group-suffix="))
356
334
    {
357
 
      *group_suffix= *argv + DEFAULTS_GROUP_SUFFIX.size();
 
335
      *group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
358
336
      argc--;
359
337
      continue;
360
338
    }
402
380
  bool found_print_defaults= 0;
403
381
  uint32_t args_used= 0;
404
382
  int error= 0;
405
 
  memory::Root alloc;
 
383
  MEM_ROOT alloc;
406
384
  char *ptr,**res;
407
385
  struct handle_option_ctx ctx;
408
386
 
409
387
  init_default_directories();
410
 
  init_alloc_root(&alloc,512);
 
388
  init_alloc_root(&alloc,512,0);
411
389
  /*
412
390
    Check if the user doesn't want any default option processing
413
391
    --no-defaults is always the first option
427
405
    res[i-1]=0;                                 /* End pointer */
428
406
    (*argc)--;
429
407
    *argv=res;
430
 
    *(memory::Root*) ptr= alloc;                        /* Save alloc root for free */
 
408
    *(MEM_ROOT*) ptr= alloc;                    /* Save alloc root for free */
431
409
    return(0);
432
410
  }
433
411
 
479
457
 
480
458
  (*argc)+=int(args.elements);
481
459
  *argv= static_cast<char**>(res);
482
 
  *(memory::Root*) ptr= alloc;                  /* Save alloc root for free */
 
460
  *(MEM_ROOT*) ptr= alloc;                      /* Save alloc root for free */
483
461
  delete_dynamic(&args);
484
462
  if (found_print_defaults)
485
463
  {
501
479
 
502
480
void free_defaults(char **argv)
503
481
{
504
 
  memory::Root ptr;
 
482
  MEM_ROOT ptr;
505
483
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
506
484
  free_root(&ptr,MYF(0));
507
485
}
955
933
    }
956
934
  }
957
935
  puts("\nThe following options may be given as the first argument:\n\
958
 
  --print-defaults      Print the program argument list and exit\n\
959
 
  --no-defaults         Don't read default options from any options file\n\
960
 
  --defaults-file=#     Only read default options from the given file #\n\
961
 
  --defaults-extra-file=# Read this file after the global files are read");
 
936
--print-defaults        Print the program argument list and exit\n\
 
937
--no-defaults           Don't read default options from any options file\n\
 
938
--defaults-file=#       Only read default options from the given file #\n\
 
939
--defaults-extra-file=# Read this file after the global files are read");
962
940
}
963
941
 
964
942
/*
999
977
  ADD_COMMON_DIRECTORIES();
1000
978
  ADD_DIRECTORY("~/");
1001
979
}
1002
 
 
1003
 
} /* namespace internal */
1004
 
} /* namespace drizzled */