~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.c

  • Committer: Monty Taylor
  • Date: 2008-07-05 22:08:52 UTC
  • mto: This revision was merged to the branch mainline in revision 77.
  • Revision ID: monty@inaugust.com-20080705220852-cqd9t6tfkhvlcf73
Removed HAVE_LONG_LONG, as this is now assumed.

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