~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

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