~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.c

Removed/replaced DBUG symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
****************************************************************************/
35
35
 
36
36
#include "mysys_priv.h"
37
 
#include <mystrings/m_string.h>
38
 
#include <mystrings/m_ctype.h>
 
37
#include "m_string.h"
 
38
#include "m_ctype.h"
39
39
#include <my_dir.h>
40
40
 
41
41
const char *my_defaults_file=0;
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);
86
87
  @return void
87
88
*/
88
89
 
89
 
static void init_default_directories(void);
 
90
static void (*init_default_directories)(void);
90
91
 
91
92
 
92
93
static char *remove_end_comment(char *ptr);
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;
132
133
  int error= 0;
 
134
  DBUG_ENTER("my_search_option_files");
133
135
 
134
136
  /* Check if we want to force the use a specific default file */
135
137
  *args_used+= get_defaults_options(*argc - *args_used, *argv + *args_used,
154
156
  if (my_defaults_group_suffix && func == handle_default_option)
155
157
  {
156
158
    /* Handle --defaults-group-suffix= */
157
 
    uint32_t i;
 
159
    uint i;
158
160
    const char **extra_groups;
159
 
    const uint32_t instance_len= strlen(my_defaults_group_suffix); 
 
161
    const uint instance_len= strlen(my_defaults_group_suffix); 
160
162
    struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
161
163
    char *ptr;
162
164
    TYPELIB *group= ctx->group;
168
170
    
169
171
    for (i= 0; i < group->count; i++)
170
172
    {
171
 
      uint32_t len;
 
173
      uint len;
172
174
      extra_groups[i]= group->type_names[i]; /** copy group */
173
175
      
174
176
      len= strlen(extra_groups[i]);
201
203
  }
202
204
  else if (dirname_length(conf_file))
203
205
  {
204
 
    if ((error= search_default_file(func, func_ctx, NULL, conf_file)) < 0)
 
206
    if ((error= search_default_file(func, func_ctx, NullS, conf_file)) < 0)
205
207
      goto err;
206
208
  }
207
209
  else
228
230
    }
229
231
  }
230
232
 
231
 
  return(error);
 
233
  DBUG_RETURN(error);
232
234
 
233
235
err:
234
236
  fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
273
275
  {
274
276
    if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
275
277
      return 1;
276
 
    if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
 
278
    if (insert_dynamic(ctx->args, (uchar*) &tmp))
277
279
      return 1;
278
 
    my_stpcpy(tmp, option);
 
280
    strmov(tmp, option);
279
281
  }
280
282
 
281
283
  return 0;
370
372
{
371
373
  DYNAMIC_ARRAY args;
372
374
  TYPELIB group;
373
 
  bool found_print_defaults= 0;
374
 
  uint32_t args_used= 0;
 
375
  my_bool found_print_defaults= 0;
 
376
  uint args_used= 0;
375
377
  int error= 0;
376
378
  MEM_ROOT alloc;
377
379
  char *ptr,**res;
378
380
  struct handle_option_ctx ctx;
 
381
  DBUG_ENTER("load_defaults");
379
382
 
380
383
  init_default_directories();
381
384
  init_alloc_root(&alloc,512,0);
386
389
  if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults"))
387
390
  {
388
391
    /* remove the --no-defaults argument and return only the other arguments */
389
 
    uint32_t i;
 
392
    uint i;
390
393
    if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
391
394
                                 (*argc + 1)*sizeof(char*))))
392
395
      goto err;
398
401
    (*argc)--;
399
402
    *argv=res;
400
403
    *(MEM_ROOT*) ptr= alloc;                    /* Save alloc root for free */
401
 
    return(0);
 
404
    DBUG_RETURN(0);
402
405
  }
403
406
 
404
407
  group.count=0;
428
431
 
429
432
  /* copy name + found arguments + command line arguments to new array */
430
433
  res[0]= argv[0][0];  /* Name MUST be set, even by embedded library */
431
 
  memcpy(res+1, args.buffer, args.elements*sizeof(char*));
 
434
  memcpy((uchar*) (res+1), args.buffer, args.elements*sizeof(char*));
432
435
  /* Skip --defaults-xxx options */
433
436
  (*argc)-= args_used;
434
437
  (*argv)+= args_used;
444
447
  }
445
448
 
446
449
  if (*argc)
447
 
    memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
 
450
    memcpy((uchar*) (res+1+args.elements), (char*) ((*argv)+1),
 
451
           (*argc-1)*sizeof(char*));
448
452
  res[args.elements+ *argc]=0;                  /* last null */
449
453
 
450
454
  (*argc)+=args.elements;
461
465
    puts("");
462
466
    exit(0);
463
467
  }
464
 
  return(error);
 
468
  DBUG_RETURN(error);
465
469
 
466
470
 err:
467
471
  fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
473
477
void free_defaults(char **argv)
474
478
{
475
479
  MEM_ROOT ptr;
476
 
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
 
480
  memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr));
477
481
  free_root(&ptr,MYF(0));
478
482
}
479
483
 
485
489
{
486
490
  char **ext;
487
491
  const char *empty_list[]= { "", 0 };
488
 
  bool have_ext= fn_ext(config_file)[0] != 0;
 
492
  my_bool have_ext= fn_ext(config_file)[0] != 0;
489
493
  const char **exts_to_use= have_ext ? empty_list : f_extensions;
490
494
 
491
495
  for (ext= (char**) exts_to_use; *ext; ext++)
516
520
*/
517
521
 
518
522
static char *get_argument(const char *keyword, size_t kwlen,
519
 
                          char *ptr, char *name, uint32_t line)
 
523
                          char *ptr, char *name, uint line)
520
524
{
521
525
  char *end;
522
526
 
523
527
  /* Skip over "include / includedir keyword" and following whitespace */
524
528
 
525
529
  for (ptr+= kwlen - 1;
526
 
       my_isspace(&my_charset_utf8_general_ci, ptr[0]);
 
530
       my_isspace(&my_charset_latin1, ptr[0]);
527
531
       ptr++)
528
532
  {}
529
533
 
533
537
    Note that my_isspace() is true for \r and \n
534
538
  */
535
539
  for (end= ptr + strlen(ptr) - 1;
536
 
       my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
540
       my_isspace(&my_charset_latin1, *(end - 1));
537
541
       end--)
538
542
  {}
539
543
  end[0]= 0;                                    /* Cut off end space */
585
589
  static const char include_keyword[]= "include";
586
590
  const int max_recursion_level= 10;
587
591
  FILE *fp;
588
 
  uint32_t line=0;
589
 
  bool found_group=0;
590
 
  uint32_t i;
 
592
  uint line=0;
 
593
  my_bool found_group=0;
 
594
  uint i;
591
595
  MY_DIR *search_dir;
592
596
  FILEINFO *search_file;
593
597
 
595
599
    return 0;                                   /* Ignore wrong paths */
596
600
  if (dir)
597
601
  {
598
 
    end=convert_dirname(name, dir, NULL);
 
602
    end=convert_dirname(name, dir, NullS);
599
603
    if (dir[0] == FN_HOMELIB)           /* Add . to filenames in home */
600
604
      *end++='.';
601
 
    strxmov(end,config_file,ext,NULL);
 
605
    strxmov(end,config_file,ext,NullS);
602
606
  }
603
607
  else
604
608
  {
605
 
    my_stpcpy(name,config_file);
 
609
    strmov(name,config_file);
606
610
  }
607
611
  fn_format(name,name,"","",4);
608
612
  {
629
633
  {
630
634
    line++;
631
635
    /* Ignore comment and empty lines */
632
 
    for (ptr= buff; my_isspace(&my_charset_utf8_general_ci, *ptr); ptr++)
 
636
    for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++)
633
637
    {}
634
638
 
635
639
    if (*ptr == '#' || *ptr == ';' || !*ptr)
641
645
      if (recursion_level >= max_recursion_level)
642
646
      {
643
647
        for (end= ptr + strlen(ptr) - 1; 
644
 
             my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
648
             my_isspace(&my_charset_latin1, *(end - 1));
645
649
             end--)
646
650
        {}
647
651
        end[0]= 0;
653
657
      }
654
658
 
655
659
      /* skip over `!' and following whitespace */
656
 
      for (++ptr; my_isspace(&my_charset_utf8_general_ci, ptr[0]); ptr++)
 
660
      for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++)
657
661
      {}
658
662
 
659
663
      if ((!strncmp(ptr, includedir_keyword,
660
664
                    sizeof(includedir_keyword) - 1)) &&
661
 
          my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(includedir_keyword) - 1]))
 
665
          my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1]))
662
666
      {
663
667
        if (!(ptr= get_argument(includedir_keyword,
664
668
                                sizeof(includedir_keyword),
693
697
        my_dirend(search_dir);
694
698
      }
695
699
      else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
696
 
               my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(include_keyword)-1]))
 
700
               my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1]))
697
701
      {
698
702
        if (!(ptr= get_argument(include_keyword,
699
703
                                sizeof(include_keyword), ptr,
718
722
        goto err;
719
723
      }
720
724
      /* Remove end space */
721
 
      for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
 
725
      for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
722
726
      end[0]=0;
723
727
 
724
 
      strmake(curr_gr, ptr, cmin((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
 
728
      strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
725
729
 
726
730
      /* signal that a new group is found */
727
731
      opt_handler(handler_ctx, curr_gr, NULL);
740
744
    end= remove_end_comment(ptr);
741
745
    if ((value= strchr(ptr, '=')))
742
746
      end= value;                               /* Option without argument */
743
 
    for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
 
747
    for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
744
748
    if (!value)
745
749
    {
746
 
      strmake(my_stpcpy(option,"--"),ptr, (size_t) (end-ptr));
 
750
      strmake(strmov(option,"--"),ptr, (size_t) (end-ptr));
747
751
      if (opt_handler(handler_ctx, curr_gr, option))
748
752
        goto err;
749
753
    }
751
755
    {
752
756
      /* Remove pre- and end space */
753
757
      char *value_end;
754
 
      for (value++ ; my_isspace(&my_charset_utf8_general_ci,*value); value++) ;
755
 
      value_end= strchr(value, '\0');
 
758
      for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ;
 
759
      value_end=strend(value);
756
760
      /*
757
761
        We don't have to test for value_end >= value as we know there is
758
762
        an '=' before
759
763
      */
760
 
      for ( ; my_isspace(&my_charset_utf8_general_ci,value_end[-1]) ; value_end--) ;
 
764
      for ( ; my_isspace(&my_charset_latin1,value_end[-1]) ; value_end--) ;
761
765
      if (value_end < value)                    /* Empty string */
762
766
        value_end=value;
763
767
 
769
773
        value++;
770
774
        value_end--;
771
775
      }
772
 
      ptr=my_stpncpy(my_stpcpy(option,"--"),ptr,(size_t) (end-ptr));
 
776
      ptr=strnmov(strmov(option,"--"),ptr,(size_t) (end-ptr));
773
777
      *ptr++= '=';
774
778
 
775
779
      for ( ; value != value_end; value++)
849
853
  return ptr;
850
854
}
851
855
 
 
856
#include <help_start.h>
 
857
 
852
858
void my_print_default_files(const char *conf_file)
853
859
{
854
860
  const char *empty_list[]= { "", 0 };
855
 
  bool have_ext= fn_ext(conf_file)[0] != 0;
 
861
  my_bool have_ext= fn_ext(conf_file)[0] != 0;
856
862
  const char **exts_to_use= have_ext ? empty_list : f_extensions;
857
863
  char name[FN_REFLEN], **ext;
858
864
  const char **dirs;
876
882
          pos= my_defaults_extra_file;
877
883
        else
878
884
          continue;
879
 
        end= convert_dirname(name, pos, NULL);
 
885
        end= convert_dirname(name, pos, NullS);
880
886
        if (name[0] == FN_HOMELIB)      /* Add . to filenames in home */
881
887
          *end++='.';
882
 
        strxmov(end, conf_file, *ext, " ", NULL);
 
888
        strxmov(end, conf_file, *ext, " ", NullS);
883
889
        fputs(name,stdout);
884
890
      }
885
891
    }
916
922
--defaults-extra-file=# Read this file after the global files are read");
917
923
}
918
924
 
 
925
#include <help_end.h>
 
926
 
 
927
 
919
928
/*
920
929
  This extra complexity is to avoid declaring 'rc' if it won't be
921
930
  used.
922
931
*/
923
 
#define ADD_DIRECTORY(DIR)  (void) array_append_string_unique((DIR), default_directories, \
 
932
#define ADD_DIRECTORY_INTERNAL(DIR) \
 
933
  array_append_string_unique((DIR), default_directories, \
924
934
                             array_elements(default_directories))
 
935
#ifdef DBUG_OFF
 
936
#  define ADD_DIRECTORY(DIR)  (void) ADD_DIRECTORY_INTERNAL(DIR)
 
937
#else
 
938
#define ADD_DIRECTORY(DIR) \
 
939
  do { \
 
940
    my_bool rc= ADD_DIRECTORY_INTERNAL(DIR); \
 
941
    DBUG_ASSERT(rc == FALSE);                   /* Success */ \
 
942
  } while (0)
 
943
#endif
 
944
 
925
945
 
926
946
#define ADD_COMMON_DIRECTORIES() \
927
947
  do { \
945
965
    6. "~/"
946
966
*/
947
967
 
948
 
static void init_default_directories(void)
 
968
static void init_default_directories_unix(void)
949
969
{
950
 
  memset(default_directories, 0, sizeof(default_directories));
 
970
  bzero((char *) default_directories, sizeof(default_directories));
951
971
  ADD_DIRECTORY("/etc/");
952
972
  ADD_DIRECTORY("/etc/mysql/");
953
973
#if defined(DEFAULT_SYSCONFDIR)
956
976
  ADD_COMMON_DIRECTORIES();
957
977
  ADD_DIRECTORY("~/");
958
978
}
 
979
 
 
980
static void (*init_default_directories)(void)= init_default_directories_unix;