~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.c

Merged from jay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
const char *default_directories[MAX_DEFAULT_DIRS + 1];
49
49
 
50
50
static const char *f_extensions[]= { ".cnf", 0 };
 
51
#define NEWLINE "\n"
51
52
 
52
53
static int handle_default_option(void *in_ctx, const char *group_name,
53
54
                                 const char *option);
125
126
*/
126
127
 
127
128
int my_search_option_files(const char *conf_file, int *argc, char ***argv,
128
 
                           uint32_t *args_used, Process_option_func func,
 
129
                           uint *args_used, Process_option_func func,
129
130
                           void *func_ctx)
130
131
{
131
132
  const char **dirs, *forced_default_file, *forced_extra_defaults;
154
155
  if (my_defaults_group_suffix && func == handle_default_option)
155
156
  {
156
157
    /* Handle --defaults-group-suffix= */
157
 
    uint32_t i;
 
158
    uint i;
158
159
    const char **extra_groups;
159
 
    const uint32_t instance_len= strlen(my_defaults_group_suffix); 
 
160
    const uint instance_len= strlen(my_defaults_group_suffix); 
160
161
    struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
161
162
    char *ptr;
162
163
    TYPELIB *group= ctx->group;
168
169
    
169
170
    for (i= 0; i < group->count; i++)
170
171
    {
171
 
      uint32_t len;
 
172
      uint len;
172
173
      extra_groups[i]= group->type_names[i]; /** copy group */
173
174
      
174
175
      len= strlen(extra_groups[i]);
201
202
  }
202
203
  else if (dirname_length(conf_file))
203
204
  {
204
 
    if ((error= search_default_file(func, func_ctx, NULL, conf_file)) < 0)
 
205
    if ((error= search_default_file(func, func_ctx, NullS, conf_file)) < 0)
205
206
      goto err;
206
207
  }
207
208
  else
273
274
  {
274
275
    if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
275
276
      return 1;
276
 
    if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
 
277
    if (insert_dynamic(ctx->args, (uchar*) &tmp))
277
278
      return 1;
278
 
    my_stpcpy(tmp, option);
 
279
    strmov(tmp, option);
279
280
  }
280
281
 
281
282
  return 0;
371
372
  DYNAMIC_ARRAY args;
372
373
  TYPELIB group;
373
374
  bool found_print_defaults= 0;
374
 
  uint32_t args_used= 0;
 
375
  uint args_used= 0;
375
376
  int error= 0;
376
377
  MEM_ROOT alloc;
377
378
  char *ptr,**res;
386
387
  if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults"))
387
388
  {
388
389
    /* remove the --no-defaults argument and return only the other arguments */
389
 
    uint32_t i;
 
390
    uint i;
390
391
    if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
391
392
                                 (*argc + 1)*sizeof(char*))))
392
393
      goto err;
428
429
 
429
430
  /* copy name + found arguments + command line arguments to new array */
430
431
  res[0]= argv[0][0];  /* Name MUST be set, even by embedded library */
431
 
  memcpy(res+1, args.buffer, args.elements*sizeof(char*));
 
432
  memcpy((uchar*) (res+1), args.buffer, args.elements*sizeof(char*));
432
433
  /* Skip --defaults-xxx options */
433
434
  (*argc)-= args_used;
434
435
  (*argv)+= args_used;
444
445
  }
445
446
 
446
447
  if (*argc)
447
 
    memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
 
448
    memcpy((uchar*) (res+1+args.elements), (char*) ((*argv)+1),
 
449
           (*argc-1)*sizeof(char*));
448
450
  res[args.elements+ *argc]=0;                  /* last null */
449
451
 
450
452
  (*argc)+=args.elements;
473
475
void free_defaults(char **argv)
474
476
{
475
477
  MEM_ROOT ptr;
476
 
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
 
478
  memcpy((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr));
477
479
  free_root(&ptr,MYF(0));
478
480
}
479
481
 
516
518
*/
517
519
 
518
520
static char *get_argument(const char *keyword, size_t kwlen,
519
 
                          char *ptr, char *name, uint32_t line)
 
521
                          char *ptr, char *name, uint line)
520
522
{
521
523
  char *end;
522
524
 
523
525
  /* Skip over "include / includedir keyword" and following whitespace */
524
526
 
525
527
  for (ptr+= kwlen - 1;
526
 
       my_isspace(&my_charset_utf8_general_ci, ptr[0]);
 
528
       my_isspace(&my_charset_latin1, ptr[0]);
527
529
       ptr++)
528
530
  {}
529
531
 
533
535
    Note that my_isspace() is true for \r and \n
534
536
  */
535
537
  for (end= ptr + strlen(ptr) - 1;
536
 
       my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
538
       my_isspace(&my_charset_latin1, *(end - 1));
537
539
       end--)
538
540
  {}
539
541
  end[0]= 0;                                    /* Cut off end space */
585
587
  static const char include_keyword[]= "include";
586
588
  const int max_recursion_level= 10;
587
589
  FILE *fp;
588
 
  uint32_t line=0;
 
590
  uint line=0;
589
591
  bool found_group=0;
590
 
  uint32_t i;
 
592
  uint i;
591
593
  MY_DIR *search_dir;
592
594
  FILEINFO *search_file;
593
595
 
595
597
    return 0;                                   /* Ignore wrong paths */
596
598
  if (dir)
597
599
  {
598
 
    end=convert_dirname(name, dir, NULL);
 
600
    end=convert_dirname(name, dir, NullS);
599
601
    if (dir[0] == FN_HOMELIB)           /* Add . to filenames in home */
600
602
      *end++='.';
601
 
    strxmov(end,config_file,ext,NULL);
 
603
    strxmov(end,config_file,ext,NullS);
602
604
  }
603
605
  else
604
606
  {
605
 
    my_stpcpy(name,config_file);
 
607
    strmov(name,config_file);
606
608
  }
607
609
  fn_format(name,name,"","",4);
608
610
  {
629
631
  {
630
632
    line++;
631
633
    /* Ignore comment and empty lines */
632
 
    for (ptr= buff; my_isspace(&my_charset_utf8_general_ci, *ptr); ptr++)
 
634
    for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++)
633
635
    {}
634
636
 
635
637
    if (*ptr == '#' || *ptr == ';' || !*ptr)
641
643
      if (recursion_level >= max_recursion_level)
642
644
      {
643
645
        for (end= ptr + strlen(ptr) - 1; 
644
 
             my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
646
             my_isspace(&my_charset_latin1, *(end - 1));
645
647
             end--)
646
648
        {}
647
649
        end[0]= 0;
653
655
      }
654
656
 
655
657
      /* skip over `!' and following whitespace */
656
 
      for (++ptr; my_isspace(&my_charset_utf8_general_ci, ptr[0]); ptr++)
 
658
      for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++)
657
659
      {}
658
660
 
659
661
      if ((!strncmp(ptr, includedir_keyword,
660
662
                    sizeof(includedir_keyword) - 1)) &&
661
 
          my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(includedir_keyword) - 1]))
 
663
          my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1]))
662
664
      {
663
665
        if (!(ptr= get_argument(includedir_keyword,
664
666
                                sizeof(includedir_keyword),
693
695
        my_dirend(search_dir);
694
696
      }
695
697
      else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
696
 
               my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(include_keyword)-1]))
 
698
               my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1]))
697
699
      {
698
700
        if (!(ptr= get_argument(include_keyword,
699
701
                                sizeof(include_keyword), ptr,
718
720
        goto err;
719
721
      }
720
722
      /* Remove end space */
721
 
      for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
 
723
      for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
722
724
      end[0]=0;
723
725
 
724
 
      strmake(curr_gr, ptr, cmin((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
 
726
      strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
725
727
 
726
728
      /* signal that a new group is found */
727
729
      opt_handler(handler_ctx, curr_gr, NULL);
740
742
    end= remove_end_comment(ptr);
741
743
    if ((value= strchr(ptr, '=')))
742
744
      end= value;                               /* Option without argument */
743
 
    for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
 
745
    for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
744
746
    if (!value)
745
747
    {
746
 
      strmake(my_stpcpy(option,"--"),ptr, (size_t) (end-ptr));
 
748
      strmake(strmov(option,"--"),ptr, (size_t) (end-ptr));
747
749
      if (opt_handler(handler_ctx, curr_gr, option))
748
750
        goto err;
749
751
    }
751
753
    {
752
754
      /* Remove pre- and end space */
753
755
      char *value_end;
754
 
      for (value++ ; my_isspace(&my_charset_utf8_general_ci,*value); value++) ;
755
 
      value_end= strchr(value, '\0');
 
756
      for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ;
 
757
      value_end=strend(value);
756
758
      /*
757
759
        We don't have to test for value_end >= value as we know there is
758
760
        an '=' before
759
761
      */
760
 
      for ( ; my_isspace(&my_charset_utf8_general_ci,value_end[-1]) ; value_end--) ;
 
762
      for ( ; my_isspace(&my_charset_latin1,value_end[-1]) ; value_end--) ;
761
763
      if (value_end < value)                    /* Empty string */
762
764
        value_end=value;
763
765
 
769
771
        value++;
770
772
        value_end--;
771
773
      }
772
 
      ptr=my_stpncpy(my_stpcpy(option,"--"),ptr,(size_t) (end-ptr));
 
774
      ptr=strnmov(strmov(option,"--"),ptr,(size_t) (end-ptr));
773
775
      *ptr++= '=';
774
776
 
775
777
      for ( ; value != value_end; value++)
876
878
          pos= my_defaults_extra_file;
877
879
        else
878
880
          continue;
879
 
        end= convert_dirname(name, pos, NULL);
 
881
        end= convert_dirname(name, pos, NullS);
880
882
        if (name[0] == FN_HOMELIB)      /* Add . to filenames in home */
881
883
          *end++='.';
882
 
        strxmov(end, conf_file, *ext, " ", NULL);
 
884
        strxmov(end, conf_file, *ext, " ", NullS);
883
885
        fputs(name,stdout);
884
886
      }
885
887
    }
938
940
 
939
941
  @details
940
942
    1. /etc/
941
 
    2. /etc/drizzle/
 
943
    2. /etc/mysql/
942
944
    3. --sysconfdir=<path> (compile-time option)
943
945
    4. getenv(DEFAULT_HOME_ENV)
944
946
    5. --defaults-extra-file=<path> (run-time option)
947
949
 
948
950
static void init_default_directories(void)
949
951
{
950
 
  memset(default_directories, 0, sizeof(default_directories));
 
952
  memset((char *) default_directories, 0, sizeof(default_directories));
951
953
  ADD_DIRECTORY("/etc/");
952
 
  ADD_DIRECTORY("/etc/drizzle/");
 
954
  ADD_DIRECTORY("/etc/mysql/");
953
955
#if defined(DEFAULT_SYSCONFDIR)
954
956
    ADD_DIRECTORY(DEFAULT_SYSCONFDIR);
955
957
#endif