~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

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_priv.h"
 
37
#include <mystrings/m_string.h>
 
38
#include <mystrings/m_ctype.h>
 
39
#include <mysys/my_dir.h>
41
40
#include <drizzled/configmake.h>
42
 
#include <drizzled/gettext.h>
43
 
 
44
 
#include "drizzled/cached_directory.h"
45
 
 
46
 
#ifdef HAVE_SYS_STAT_H
47
 
# include <sys/stat.h>
48
 
#endif
49
 
 
50
 
#include <cstdio>
51
 
#include <algorithm>
52
 
 
53
 
using namespace std;
54
 
 
55
 
namespace drizzled
56
 
{
57
 
namespace internal
58
 
{
 
41
 
 
42
#include <stdio.h>
59
43
 
60
44
const char *my_defaults_file=0;
61
45
const char *my_defaults_group_suffix=0;
80
64
 
81
65
struct handle_option_ctx
82
66
{
83
 
   memory::Root *alloc;
 
67
   MEM_ROOT *alloc;
84
68
   DYNAMIC_ARRAY *args;
85
69
   TYPELIB *group;
86
70
};
175
159
    /* Handle --defaults-group-suffix= */
176
160
    uint32_t i;
177
161
    const char **extra_groups;
178
 
    const size_t instance_len= strlen(my_defaults_group_suffix);
 
162
    const uint32_t instance_len= strlen(my_defaults_group_suffix);
179
163
    struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
180
164
    char *ptr;
181
165
    TYPELIB *group= ctx->group;
187
171
 
188
172
    for (i= 0; i < group->count; i++)
189
173
    {
190
 
      size_t len;
 
174
      uint32_t len;
191
175
      extra_groups[i]= group->type_names[i]; /** copy group */
192
176
 
193
177
      len= strlen(extra_groups[i]);
324
308
  int org_argc= argc, prev_argc= 0;
325
309
  *defaults= *extra_defaults= *group_suffix= 0;
326
310
 
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
311
  while (argc >= 2 && argc != prev_argc)
332
312
  {
333
313
    /* Skip program name or previously handled argument */
334
314
    argv++;
335
315
    prev_argc= argc;                            /* To check if we found */
336
 
    if (!*defaults && (strncmp(*argv,
337
 
                               DEFAULTS_FILE.c_str(),
338
 
                               DEFAULTS_FILE.size()) == 0))
 
316
    if (!*defaults && is_prefix(*argv,"--defaults-file="))
339
317
    {
340
 
      *defaults= *argv + DEFAULTS_FILE.size();
 
318
      *defaults= *argv + sizeof("--defaults-file=")-1;
341
319
       argc--;
342
320
       continue;
343
321
    }
344
 
    if (!*extra_defaults && (strncmp(*argv, 
345
 
                                     DEFAULTS_EXTRA_FILE.c_str(),
346
 
                                     DEFAULTS_EXTRA_FILE.size()) == 0))
 
322
    if (!*extra_defaults && is_prefix(*argv,"--defaults-extra-file="))
347
323
    {
348
 
      *extra_defaults= *argv + DEFAULTS_EXTRA_FILE.size();
 
324
      *extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
349
325
      argc--;
350
326
      continue;
351
327
    }
352
 
    if (!*group_suffix && (strncmp(*argv, 
353
 
                                   DEFAULTS_GROUP_SUFFIX.c_str(),
354
 
                                   DEFAULTS_GROUP_SUFFIX.size()) == 0))
355
 
 
 
328
    if (!*group_suffix && is_prefix(*argv, "--defaults-group-suffix="))
356
329
    {
357
 
      *group_suffix= *argv + DEFAULTS_GROUP_SUFFIX.size();
 
330
      *group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
358
331
      argc--;
359
332
      continue;
360
333
    }
402
375
  bool found_print_defaults= 0;
403
376
  uint32_t args_used= 0;
404
377
  int error= 0;
405
 
  memory::Root alloc;
 
378
  MEM_ROOT alloc;
406
379
  char *ptr,**res;
407
380
  struct handle_option_ctx ctx;
408
381
 
409
382
  init_default_directories();
410
 
  init_alloc_root(&alloc,512);
 
383
  init_alloc_root(&alloc,512,0);
411
384
  /*
412
385
    Check if the user doesn't want any default option processing
413
386
    --no-defaults is always the first option
427
400
    res[i-1]=0;                                 /* End pointer */
428
401
    (*argc)--;
429
402
    *argv=res;
430
 
    *(memory::Root*) ptr= alloc;                        /* Save alloc root for free */
 
403
    *(MEM_ROOT*) ptr= alloc;                    /* Save alloc root for free */
431
404
    return(0);
432
405
  }
433
406
 
477
450
    memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
478
451
  res[args.elements+ *argc]=0;                  /* last null */
479
452
 
480
 
  (*argc)+=int(args.elements);
481
 
  *argv= static_cast<char**>(res);
482
 
  *(memory::Root*) ptr= alloc;                  /* Save alloc root for free */
 
453
  (*argc)+=args.elements;
 
454
  *argv= (char**) res;
 
455
  *(MEM_ROOT*) ptr= alloc;                      /* Save alloc root for free */
483
456
  delete_dynamic(&args);
484
457
  if (found_print_defaults)
485
458
  {
501
474
 
502
475
void free_defaults(char **argv)
503
476
{
504
 
  memory::Root ptr;
 
477
  MEM_ROOT ptr;
505
478
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
506
479
  free_root(&ptr,MYF(0));
507
480
}
616
589
  FILE *fp;
617
590
  uint32_t line=0;
618
591
  bool found_group=0;
 
592
  uint32_t i;
 
593
  MY_DIR *search_dir;
 
594
  FILEINFO *search_file;
619
595
 
620
596
  if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3)
621
597
    return 0;                                   /* Ignore wrong paths */
692
668
                                ptr, name, line)))
693
669
          goto err;
694
670
 
695
 
        CachedDirectory dir_cache(ptr);
696
 
 
697
 
        if (dir_cache.fail())
698
 
        {
699
 
          /**
700
 
           * @todo
701
 
           * Since clients still use this code, we use fprintf here.
702
 
           * This fprintf needs to be turned into errmsg_printf
703
 
           * as soon as the client programs no longer use mysys
704
 
           * and can use the pluggable error message system.
705
 
           */
706
 
          fprintf(stderr, _("error: could not open directory: %s\n"), ptr);
 
671
        if (!(search_dir= my_dir(ptr, MYF(MY_WME))))
707
672
          goto err;
708
 
        }
709
 
 
710
 
        CachedDirectory::Entries files= dir_cache.getEntries();
711
 
        CachedDirectory::Entries::iterator file_iter= files.begin();
712
 
 
713
 
        while (file_iter != files.end())
 
673
 
 
674
        for (i= 0; i < (uint32_t) search_dir->number_off_files; i++)
714
675
        {
715
 
          CachedDirectory::Entry *entry= *file_iter;
716
 
          ext= fn_ext(entry->filename.c_str());
 
676
          search_file= search_dir->dir_entry + i;
 
677
          ext= fn_ext(search_file->name);
717
678
 
718
679
          /* check extension */
719
680
          for (tmp_ext= (char**) f_extensions; *tmp_ext; tmp_ext++)
720
681
          {
721
682
            if (!strcmp(ext, *tmp_ext))
722
 
            {
723
 
              fn_format(tmp, entry->filename.c_str(), ptr, "",
724
 
                        MY_UNPACK_FILENAME | MY_SAFE_PATH);
725
 
 
726
 
              search_default_file_with_ext(opt_handler, handler_ctx, "", "",
727
 
                                           tmp, recursion_level + 1);
728
 
            }
729
 
          }
730
 
 
731
 
          ++file_iter;
 
683
              break;
 
684
          }
 
685
 
 
686
          if (*tmp_ext)
 
687
          {
 
688
            fn_format(tmp, search_file->name, ptr, "",
 
689
                      MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
690
 
 
691
            search_default_file_with_ext(opt_handler, handler_ctx, "", "", tmp,
 
692
                                         recursion_level + 1);
 
693
          }
732
694
        }
 
695
 
 
696
        my_dirend(search_dir);
733
697
      }
734
698
      else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
735
699
               my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(include_keyword)-1]))
760
724
      for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
761
725
      end[0]=0;
762
726
 
763
 
      strncpy(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
764
 
      curr_gr[min((size_t)(end-ptr)+1, sizeof(curr_gr)-1)] = '\0';
 
727
      strncpy(curr_gr, ptr, cmin((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
 
728
      curr_gr[cmin((size_t)(end-ptr)+1, sizeof(curr_gr)-1)] = '\0';
765
729
 
766
730
      /* signal that a new group is found */
767
731
      opt_handler(handler_ctx, curr_gr, NULL);
955
919
    }
956
920
  }
957
921
  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");
 
922
--print-defaults        Print the program argument list and exit\n\
 
923
--no-defaults           Don't read default options from any options file\n\
 
924
--defaults-file=#       Only read default options from the given file #\n\
 
925
--defaults-extra-file=# Read this file after the global files are read");
962
926
}
963
927
 
964
928
/*
999
963
  ADD_COMMON_DIRECTORIES();
1000
964
  ADD_DIRECTORY("~/");
1001
965
}
1002
 
 
1003
 
} /* namespace internal */
1004
 
} /* namespace drizzled */