~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/default.cc

  • Committer: Stewart Smith
  • Date: 2010-03-18 12:01:34 UTC
  • mto: (1666.2.3 build)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: stewart@flamingspork.com-20100318120134-45fdnsw8g3j6c7oy
move RAND() into a plugin

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
181
181
    TYPELIB *group= ctx->group;
182
182
 
183
183
    if (!(extra_groups=
184
 
          (const char**)ctx->alloc->alloc_root(
 
184
          (const char**)alloc_root(ctx->alloc,
185
185
                                   (2*group->count+1)*sizeof(char*))))
186
186
      goto err;
187
187
 
191
191
      extra_groups[i]= group->type_names[i]; /** copy group */
192
192
 
193
193
      len= strlen(extra_groups[i]);
194
 
      if (!(ptr= (char *)ctx->alloc->alloc_root( len+instance_len+1)))
 
194
      if (!(ptr= (char *)alloc_root(ctx->alloc, len+instance_len+1)))
195
195
        goto err;
196
196
 
197
197
      extra_groups[i+group->count]= ptr;
289
289
 
290
290
  if (find_type((char *)group_name, ctx->group, 3))
291
291
  {
292
 
    if (!(tmp= (char *)ctx->alloc->alloc_root(strlen(option) + 1)))
 
292
    if (!(tmp= (char *)alloc_root(ctx->alloc, strlen(option) + 1)))
293
293
      return 1;
294
294
    if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
295
295
      return 1;
324
324
  int org_argc= argc, prev_argc= 0;
325
325
  *defaults= *extra_defaults= *group_suffix= 0;
326
326
 
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
327
  while (argc >= 2 && argc != prev_argc)
332
328
  {
333
329
    /* Skip program name or previously handled argument */
334
330
    argv++;
335
331
    prev_argc= argc;                            /* To check if we found */
336
 
    if (!*defaults && (strncmp(*argv,
337
 
                               DEFAULTS_FILE.c_str(),
338
 
                               DEFAULTS_FILE.size()) == 0))
 
332
    if (!*defaults && (strncmp(*argv,"--defaults-file=", sizeof("--defaults-file=")) == 0))
339
333
    {
340
 
      *defaults= *argv + DEFAULTS_FILE.size();
 
334
      *defaults= *argv + sizeof("--defaults-file=")-1;
341
335
       argc--;
342
336
       continue;
343
337
    }
344
 
    if (!*extra_defaults && (strncmp(*argv, 
345
 
                                     DEFAULTS_EXTRA_FILE.c_str(),
346
 
                                     DEFAULTS_EXTRA_FILE.size()) == 0))
 
338
    if (!*extra_defaults && (strncmp(*argv, "--defaults-extra-file=", sizeof("--defaults-extra-file=")) == 0))
347
339
    {
348
 
      *extra_defaults= *argv + DEFAULTS_EXTRA_FILE.size();
 
340
      *extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
349
341
      argc--;
350
342
      continue;
351
343
    }
352
 
    if (!*group_suffix && (strncmp(*argv, 
353
 
                                   DEFAULTS_GROUP_SUFFIX.c_str(),
354
 
                                   DEFAULTS_GROUP_SUFFIX.size()) == 0))
355
 
 
 
344
    if (!*group_suffix && (strncmp(*argv, "--defaults-group-suffix=", sizeof("--defaults-group-suffix=")) == 0))
356
345
    {
357
 
      *group_suffix= *argv + DEFAULTS_GROUP_SUFFIX.size();
 
346
      *group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
358
347
      argc--;
359
348
      continue;
360
349
    }
399
388
{
400
389
  DYNAMIC_ARRAY args;
401
390
  TYPELIB group;
 
391
  bool found_print_defaults= 0;
402
392
  uint32_t args_used= 0;
403
393
  int error= 0;
404
 
  memory::Root alloc(512);
 
394
  memory::Root alloc;
405
395
  char *ptr,**res;
406
396
  struct handle_option_ctx ctx;
407
397
 
408
398
  init_default_directories();
 
399
  init_alloc_root(&alloc,512);
409
400
  /*
410
401
    Check if the user doesn't want any default option processing
411
402
    --no-defaults is always the first option
414
405
  {
415
406
    /* remove the --no-defaults argument and return only the other arguments */
416
407
    uint32_t i;
417
 
    if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (*argc + 1)*sizeof(char*))))
 
408
    if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
409
                                 (*argc + 1)*sizeof(char*))))
418
410
      goto err;
419
411
    res= (char**) (ptr+sizeof(alloc));
420
412
    memset(res,0,(*argc + 1));
448
440
    Here error contains <> 0 only if we have a fully specified conf_file
449
441
    or a forced default file
450
442
  */
451
 
  if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (args.elements + *argc +1) *sizeof(char*))))
 
443
  if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
444
                               (args.elements + *argc +1) *sizeof(char*))))
452
445
    goto err;
453
446
  res= (char**) (ptr+sizeof(alloc));
454
447
 
463
456
    Check if we wan't to see the new argument list
464
457
    This options must always be the last of the default options
465
458
  */
 
459
  if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults"))
 
460
  {
 
461
    found_print_defaults=1;
 
462
    --*argc; ++*argv;                           /* skip argument */
 
463
  }
 
464
 
466
465
  if (*argc)
467
466
    memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
468
467
  res[args.elements+ *argc]=0;                  /* last null */
471
470
  *argv= static_cast<char**>(res);
472
471
  *(memory::Root*) ptr= alloc;                  /* Save alloc root for free */
473
472
  delete_dynamic(&args);
474
 
 
 
473
  if (found_print_defaults)
 
474
  {
 
475
    int i;
 
476
    printf("%s would have been started with the following arguments:\n",
 
477
           **argv);
 
478
    for (i=1 ; i < *argc ; i++)
 
479
      printf("%s ", (*argv)[i]);
 
480
    puts("");
 
481
    exit(0);
 
482
  }
475
483
  return(error);
476
484
 
477
485
 err:
484
492
{
485
493
  memory::Root ptr;
486
494
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
487
 
  ptr.free_root(MYF(0));
 
495
  free_root(&ptr,MYF(0));
488
496
}
489
497
 
490
498
 
936
944
    }
937
945
  }
938
946
  puts("\nThe following options may be given as the first argument:\n\
 
947
  --print-defaults      Print the program argument list and exit\n\
939
948
  --no-defaults         Don't read default options from any options file\n\
940
949
  --defaults-file=#     Only read default options from the given file #\n\
941
950
  --defaults-extra-file=# Read this file after the global files are read");