~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.cc

  • Committer: Monty Taylor
  • Date: 2009-12-14 22:00:27 UTC
  • mto: (1241.9.10 out-of-tree)
  • mto: This revision was merged to the branch mainline in revision 1250.
  • Revision ID: mordred@inaugust.com-20091214220027-kpmfbl452nctzc0g
pandora-build v0.85 - Fixed C++ standard setting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/****************************************************************************
17
17
 Add all options from files named "group".cnf from the default_directories
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
};
181
170
    TYPELIB *group= ctx->group;
182
171
 
183
172
    if (!(extra_groups=
184
 
          (const char**)ctx->alloc->alloc_root(
 
173
          (const char**)alloc_root(ctx->alloc,
185
174
                                   (2*group->count+1)*sizeof(char*))))
186
175
      goto err;
187
176
 
191
180
      extra_groups[i]= group->type_names[i]; /** copy group */
192
181
 
193
182
      len= strlen(extra_groups[i]);
194
 
      if (!(ptr= (char *)ctx->alloc->alloc_root( len+instance_len+1)))
 
183
      if (!(ptr= (char *)alloc_root(ctx->alloc, len+instance_len+1)))
195
184
        goto err;
196
185
 
197
186
      extra_groups[i+group->count]= ptr;
289
278
 
290
279
  if (find_type((char *)group_name, ctx->group, 3))
291
280
  {
292
 
    if (!(tmp= (char *)ctx->alloc->alloc_root(strlen(option) + 1)))
 
281
    if (!(tmp= (char *)alloc_root(ctx->alloc, strlen(option) + 1)))
293
282
      return 1;
294
283
    if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
295
284
      return 1;
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
    }
399
377
{
400
378
  DYNAMIC_ARRAY args;
401
379
  TYPELIB group;
 
380
  bool found_print_defaults= 0;
402
381
  uint32_t args_used= 0;
403
382
  int error= 0;
404
 
  memory::Root alloc(512);
 
383
  MEM_ROOT alloc;
405
384
  char *ptr,**res;
406
385
  struct handle_option_ctx ctx;
407
386
 
408
387
  init_default_directories();
 
388
  init_alloc_root(&alloc,512,0);
409
389
  /*
410
390
    Check if the user doesn't want any default option processing
411
391
    --no-defaults is always the first option
414
394
  {
415
395
    /* remove the --no-defaults argument and return only the other arguments */
416
396
    uint32_t i;
417
 
    if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (*argc + 1)*sizeof(char*))))
 
397
    if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
398
                                 (*argc + 1)*sizeof(char*))))
418
399
      goto err;
419
400
    res= (char**) (ptr+sizeof(alloc));
420
401
    memset(res,0,(*argc + 1));
424
405
    res[i-1]=0;                                 /* End pointer */
425
406
    (*argc)--;
426
407
    *argv=res;
427
 
    *(memory::Root*) ptr= alloc;                        /* Save alloc root for free */
 
408
    *(MEM_ROOT*) ptr= alloc;                    /* Save alloc root for free */
428
409
    return(0);
429
410
  }
430
411
 
448
429
    Here error contains <> 0 only if we have a fully specified conf_file
449
430
    or a forced default file
450
431
  */
451
 
  if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (args.elements + *argc +1) *sizeof(char*))))
 
432
  if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
433
                               (args.elements + *argc +1) *sizeof(char*))))
452
434
    goto err;
453
435
  res= (char**) (ptr+sizeof(alloc));
454
436
 
463
445
    Check if we wan't to see the new argument list
464
446
    This options must always be the last of the default options
465
447
  */
 
448
  if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults"))
 
449
  {
 
450
    found_print_defaults=1;
 
451
    --*argc; ++*argv;                           /* skip argument */
 
452
  }
 
453
 
466
454
  if (*argc)
467
455
    memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
468
456
  res[args.elements+ *argc]=0;                  /* last null */
469
457
 
470
458
  (*argc)+=int(args.elements);
471
459
  *argv= static_cast<char**>(res);
472
 
  *(memory::Root*) ptr= alloc;                  /* Save alloc root for free */
 
460
  *(MEM_ROOT*) ptr= alloc;                      /* Save alloc root for free */
473
461
  delete_dynamic(&args);
474
 
 
 
462
  if (found_print_defaults)
 
463
  {
 
464
    int i;
 
465
    printf("%s would have been started with the following arguments:\n",
 
466
           **argv);
 
467
    for (i=1 ; i < *argc ; i++)
 
468
      printf("%s ", (*argv)[i]);
 
469
    puts("");
 
470
    exit(0);
 
471
  }
475
472
  return(error);
476
473
 
477
474
 err:
482
479
 
483
480
void free_defaults(char **argv)
484
481
{
485
 
  memory::Root ptr;
 
482
  MEM_ROOT ptr;
486
483
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
487
 
  ptr.free_root(MYF(0));
 
484
  free_root(&ptr,MYF(0));
488
485
}
489
486
 
490
487
 
936
933
    }
937
934
  }
938
935
  puts("\nThe following options may be given as the first argument:\n\
939
 
  --no-defaults         Don't read default options from any options file\n\
940
 
  --defaults-file=#     Only read default options from the given file #\n\
941
 
  --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");
942
940
}
943
941
 
944
942
/*
979
977
  ADD_COMMON_DIRECTORIES();
980
978
  ADD_DIRECTORY("~/");
981
979
}
982
 
 
983
 
} /* namespace internal */
984
 
} /* namespace drizzled */