~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.c

  • Committer: Monty Taylor
  • Date: 2008-07-22 05:48:51 UTC
  • mto: (202.1.3 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: monty@inaugust.com-20080722054851-airxt73370725p7x
Re-enabled optimizations for the normal build, and added back the --with-debug option to turn them off. 

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;
87
87
  @return void
88
88
*/
89
89
 
90
 
static void init_default_directories(void);
 
90
static void (*init_default_directories)(void);
91
91
 
92
92
 
93
93
static char *remove_end_comment(char *ptr);
126
126
*/
127
127
 
128
128
int my_search_option_files(const char *conf_file, int *argc, char ***argv,
129
 
                           uint32_t *args_used, Process_option_func func,
 
129
                           uint *args_used, Process_option_func func,
130
130
                           void *func_ctx)
131
131
{
132
132
  const char **dirs, *forced_default_file, *forced_extra_defaults;
155
155
  if (my_defaults_group_suffix && func == handle_default_option)
156
156
  {
157
157
    /* Handle --defaults-group-suffix= */
158
 
    uint32_t i;
 
158
    uint i;
159
159
    const char **extra_groups;
160
 
    const uint32_t instance_len= strlen(my_defaults_group_suffix); 
 
160
    const uint instance_len= strlen(my_defaults_group_suffix); 
161
161
    struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
162
162
    char *ptr;
163
163
    TYPELIB *group= ctx->group;
169
169
    
170
170
    for (i= 0; i < group->count; i++)
171
171
    {
172
 
      uint32_t len;
 
172
      uint len;
173
173
      extra_groups[i]= group->type_names[i]; /** copy group */
174
174
      
175
175
      len= strlen(extra_groups[i]);
202
202
  }
203
203
  else if (dirname_length(conf_file))
204
204
  {
205
 
    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)
206
206
      goto err;
207
207
  }
208
208
  else
274
274
  {
275
275
    if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
276
276
      return 1;
277
 
    if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
 
277
    if (insert_dynamic(ctx->args, (uchar*) &tmp))
278
278
      return 1;
279
 
    my_stpcpy(tmp, option);
 
279
    strmov(tmp, option);
280
280
  }
281
281
 
282
282
  return 0;
372
372
  DYNAMIC_ARRAY args;
373
373
  TYPELIB group;
374
374
  bool found_print_defaults= 0;
375
 
  uint32_t args_used= 0;
 
375
  uint args_used= 0;
376
376
  int error= 0;
377
377
  MEM_ROOT alloc;
378
378
  char *ptr,**res;
387
387
  if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults"))
388
388
  {
389
389
    /* remove the --no-defaults argument and return only the other arguments */
390
 
    uint32_t i;
 
390
    uint i;
391
391
    if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
392
392
                                 (*argc + 1)*sizeof(char*))))
393
393
      goto err;
429
429
 
430
430
  /* copy name + found arguments + command line arguments to new array */
431
431
  res[0]= argv[0][0];  /* Name MUST be set, even by embedded library */
432
 
  memcpy(res+1, args.buffer, args.elements*sizeof(char*));
 
432
  memcpy((uchar*) (res+1), args.buffer, args.elements*sizeof(char*));
433
433
  /* Skip --defaults-xxx options */
434
434
  (*argc)-= args_used;
435
435
  (*argv)+= args_used;
445
445
  }
446
446
 
447
447
  if (*argc)
448
 
    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*));
449
450
  res[args.elements+ *argc]=0;                  /* last null */
450
451
 
451
452
  (*argc)+=args.elements;
474
475
void free_defaults(char **argv)
475
476
{
476
477
  MEM_ROOT ptr;
477
 
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
 
478
  memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr));
478
479
  free_root(&ptr,MYF(0));
479
480
}
480
481
 
517
518
*/
518
519
 
519
520
static char *get_argument(const char *keyword, size_t kwlen,
520
 
                          char *ptr, char *name, uint32_t line)
 
521
                          char *ptr, char *name, uint line)
521
522
{
522
523
  char *end;
523
524
 
524
525
  /* Skip over "include / includedir keyword" and following whitespace */
525
526
 
526
527
  for (ptr+= kwlen - 1;
527
 
       my_isspace(&my_charset_utf8_general_ci, ptr[0]);
 
528
       my_isspace(&my_charset_latin1, ptr[0]);
528
529
       ptr++)
529
530
  {}
530
531
 
534
535
    Note that my_isspace() is true for \r and \n
535
536
  */
536
537
  for (end= ptr + strlen(ptr) - 1;
537
 
       my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
538
       my_isspace(&my_charset_latin1, *(end - 1));
538
539
       end--)
539
540
  {}
540
541
  end[0]= 0;                                    /* Cut off end space */
586
587
  static const char include_keyword[]= "include";
587
588
  const int max_recursion_level= 10;
588
589
  FILE *fp;
589
 
  uint32_t line=0;
 
590
  uint line=0;
590
591
  bool found_group=0;
591
 
  uint32_t i;
 
592
  uint i;
592
593
  MY_DIR *search_dir;
593
594
  FILEINFO *search_file;
594
595
 
596
597
    return 0;                                   /* Ignore wrong paths */
597
598
  if (dir)
598
599
  {
599
 
    end=convert_dirname(name, dir, NULL);
 
600
    end=convert_dirname(name, dir, NullS);
600
601
    if (dir[0] == FN_HOMELIB)           /* Add . to filenames in home */
601
602
      *end++='.';
602
 
    strxmov(end,config_file,ext,NULL);
 
603
    strxmov(end,config_file,ext,NullS);
603
604
  }
604
605
  else
605
606
  {
606
 
    my_stpcpy(name,config_file);
 
607
    strmov(name,config_file);
607
608
  }
608
609
  fn_format(name,name,"","",4);
609
610
  {
630
631
  {
631
632
    line++;
632
633
    /* Ignore comment and empty lines */
633
 
    for (ptr= buff; my_isspace(&my_charset_utf8_general_ci, *ptr); ptr++)
 
634
    for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++)
634
635
    {}
635
636
 
636
637
    if (*ptr == '#' || *ptr == ';' || !*ptr)
642
643
      if (recursion_level >= max_recursion_level)
643
644
      {
644
645
        for (end= ptr + strlen(ptr) - 1; 
645
 
             my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
646
             my_isspace(&my_charset_latin1, *(end - 1));
646
647
             end--)
647
648
        {}
648
649
        end[0]= 0;
654
655
      }
655
656
 
656
657
      /* skip over `!' and following whitespace */
657
 
      for (++ptr; my_isspace(&my_charset_utf8_general_ci, ptr[0]); ptr++)
 
658
      for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++)
658
659
      {}
659
660
 
660
661
      if ((!strncmp(ptr, includedir_keyword,
661
662
                    sizeof(includedir_keyword) - 1)) &&
662
 
          my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(includedir_keyword) - 1]))
 
663
          my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1]))
663
664
      {
664
665
        if (!(ptr= get_argument(includedir_keyword,
665
666
                                sizeof(includedir_keyword),
694
695
        my_dirend(search_dir);
695
696
      }
696
697
      else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
697
 
               my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(include_keyword)-1]))
 
698
               my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1]))
698
699
      {
699
700
        if (!(ptr= get_argument(include_keyword,
700
701
                                sizeof(include_keyword), ptr,
719
720
        goto err;
720
721
      }
721
722
      /* Remove end space */
722
 
      for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
 
723
      for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
723
724
      end[0]=0;
724
725
 
725
 
      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));
726
727
 
727
728
      /* signal that a new group is found */
728
729
      opt_handler(handler_ctx, curr_gr, NULL);
741
742
    end= remove_end_comment(ptr);
742
743
    if ((value= strchr(ptr, '=')))
743
744
      end= value;                               /* Option without argument */
744
 
    for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
 
745
    for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
745
746
    if (!value)
746
747
    {
747
 
      strmake(my_stpcpy(option,"--"),ptr, (size_t) (end-ptr));
 
748
      strmake(strmov(option,"--"),ptr, (size_t) (end-ptr));
748
749
      if (opt_handler(handler_ctx, curr_gr, option))
749
750
        goto err;
750
751
    }
752
753
    {
753
754
      /* Remove pre- and end space */
754
755
      char *value_end;
755
 
      for (value++ ; my_isspace(&my_charset_utf8_general_ci,*value); value++) ;
756
 
      value_end= strchr(value, '\0');
 
756
      for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ;
 
757
      value_end=strend(value);
757
758
      /*
758
759
        We don't have to test for value_end >= value as we know there is
759
760
        an '=' before
760
761
      */
761
 
      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--) ;
762
763
      if (value_end < value)                    /* Empty string */
763
764
        value_end=value;
764
765
 
770
771
        value++;
771
772
        value_end--;
772
773
      }
773
 
      ptr=my_stpncpy(my_stpcpy(option,"--"),ptr,(size_t) (end-ptr));
 
774
      ptr=strnmov(strmov(option,"--"),ptr,(size_t) (end-ptr));
774
775
      *ptr++= '=';
775
776
 
776
777
      for ( ; value != value_end; value++)
850
851
  return ptr;
851
852
}
852
853
 
 
854
#include <help_start.h>
 
855
 
853
856
void my_print_default_files(const char *conf_file)
854
857
{
855
858
  const char *empty_list[]= { "", 0 };
877
880
          pos= my_defaults_extra_file;
878
881
        else
879
882
          continue;
880
 
        end= convert_dirname(name, pos, NULL);
 
883
        end= convert_dirname(name, pos, NullS);
881
884
        if (name[0] == FN_HOMELIB)      /* Add . to filenames in home */
882
885
          *end++='.';
883
 
        strxmov(end, conf_file, *ext, " ", NULL);
 
886
        strxmov(end, conf_file, *ext, " ", NullS);
884
887
        fputs(name,stdout);
885
888
      }
886
889
    }
917
920
--defaults-extra-file=# Read this file after the global files are read");
918
921
}
919
922
 
 
923
#include <help_end.h>
 
924
 
 
925
 
920
926
/*
921
927
  This extra complexity is to avoid declaring 'rc' if it won't be
922
928
  used.
946
952
    6. "~/"
947
953
*/
948
954
 
949
 
static void init_default_directories(void)
 
955
static void init_default_directories_unix(void)
950
956
{
951
 
  memset(default_directories, 0, sizeof(default_directories));
 
957
  bzero((char *) default_directories, sizeof(default_directories));
952
958
  ADD_DIRECTORY("/etc/");
953
959
  ADD_DIRECTORY("/etc/mysql/");
954
960
#if defined(DEFAULT_SYSCONFDIR)
957
963
  ADD_COMMON_DIRECTORIES();
958
964
  ADD_DIRECTORY("~/");
959
965
}
 
966
 
 
967
static void (*init_default_directories)(void)= init_default_directories_unix;