~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default.c

Renamed more stuff to drizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 --print-defaults         ; Print the modified command line and exit
34
34
****************************************************************************/
35
35
 
36
 
#include "config.h"
37
 
 
38
 
#include "drizzled/internal/my_sys.h"
39
 
#include "drizzled/internal/m_string.h"
40
 
#include "drizzled/charset_info.h"
41
 
#include <drizzled/configmake.h>
42
 
#include <drizzled/gettext.h>
43
 
 
44
 
#include "drizzled/cached_directory.h"
45
 
 
46
 
#ifdef HAVE_SYS_STAT_H
47
 
# include <sys/stat.h>
48
 
#endif
49
 
 
50
 
#include <cstdio>
51
 
#include <algorithm>
52
 
 
53
 
using namespace std;
54
 
 
55
 
namespace drizzled
56
 
{
57
 
namespace internal
58
 
{
 
36
#include "mysys_priv.h"
 
37
#include "m_string.h"
 
38
#include "m_ctype.h"
 
39
#include <my_dir.h>
59
40
 
60
41
const char *my_defaults_file=0;
61
42
const char *my_defaults_group_suffix=0;
67
48
const char *default_directories[MAX_DEFAULT_DIRS + 1];
68
49
 
69
50
static const char *f_extensions[]= { ".cnf", 0 };
 
51
#define NEWLINE "\n"
70
52
 
71
 
int handle_default_option(void *in_ctx, const char *group_name,
72
 
                          const char *option);
 
53
static int handle_default_option(void *in_ctx, const char *group_name,
 
54
                                 const char *option);
73
55
 
74
56
/*
75
57
   This structure defines the context that we pass to callback
80
62
 
81
63
struct handle_option_ctx
82
64
{
83
 
   memory::Root *alloc;
 
65
   MEM_ROOT *alloc;
84
66
   DYNAMIC_ARRAY *args;
85
67
   TYPELIB *group;
86
68
};
105
87
  @return void
106
88
*/
107
89
 
108
 
static void init_default_directories(void);
 
90
static void (*init_default_directories)(void);
109
91
 
110
92
 
111
93
static char *remove_end_comment(char *ptr);
144
126
*/
145
127
 
146
128
int my_search_option_files(const char *conf_file, int *argc, char ***argv,
147
 
                           uint32_t *args_used, Process_option_func func,
 
129
                           uint *args_used, Process_option_func func,
148
130
                           void *func_ctx)
149
131
{
150
132
  const char **dirs, *forced_default_file, *forced_extra_defaults;
151
133
  int error= 0;
 
134
  DBUG_ENTER("my_search_option_files");
152
135
 
153
136
  /* Check if we want to force the use a specific default file */
154
137
  *args_used+= get_defaults_options(*argc - *args_used, *argv + *args_used,
157
140
                                    (char **) &my_defaults_group_suffix);
158
141
 
159
142
  if (! my_defaults_group_suffix)
160
 
    my_defaults_group_suffix= getenv("DRIZZLE_GROUP_SUFFIX");
 
143
    my_defaults_group_suffix= getenv(STRINGIFY_ARG(DEFAULT_GROUP_SUFFIX_ENV));
161
144
 
162
145
  if (forced_extra_defaults)
163
146
    my_defaults_extra_file= (char *) forced_extra_defaults;
164
 
 
 
147
  
165
148
  if (forced_default_file)
166
149
    my_defaults_file= forced_default_file;
167
150
 
170
153
    load_defaults() as otherwise we can't know the type of 'func_ctx'
171
154
  */
172
155
 
173
 
  if (my_defaults_group_suffix && (func == handle_default_option))
 
156
  if (my_defaults_group_suffix && func == handle_default_option)
174
157
  {
175
158
    /* Handle --defaults-group-suffix= */
176
 
    uint32_t i;
 
159
    uint i;
177
160
    const char **extra_groups;
178
 
    const size_t instance_len= strlen(my_defaults_group_suffix);
 
161
    const uint instance_len= strlen(my_defaults_group_suffix); 
179
162
    struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
180
163
    char *ptr;
181
164
    TYPELIB *group= ctx->group;
182
 
 
183
 
    if (!(extra_groups=
184
 
          (const char**)ctx->alloc->alloc_root(
 
165
    
 
166
    if (!(extra_groups= 
 
167
          (const char**)alloc_root(ctx->alloc,
185
168
                                   (2*group->count+1)*sizeof(char*))))
186
169
      goto err;
187
 
 
 
170
    
188
171
    for (i= 0; i < group->count; i++)
189
172
    {
190
 
      size_t len;
 
173
      uint len;
191
174
      extra_groups[i]= group->type_names[i]; /** copy group */
192
 
 
 
175
      
193
176
      len= strlen(extra_groups[i]);
194
 
      if (!(ptr= (char *)ctx->alloc->alloc_root( len+instance_len+1)))
 
177
      if (!(ptr= alloc_root(ctx->alloc, len+instance_len+1)))
195
178
        goto err;
196
 
 
 
179
      
197
180
      extra_groups[i+group->count]= ptr;
198
 
 
 
181
      
199
182
      /** Construct new group */
200
183
      memcpy(ptr, extra_groups[i], len);
201
184
      memcpy(ptr+len, my_defaults_group_suffix, instance_len+1);
202
185
    }
203
 
 
 
186
    
204
187
    group->count*= 2;
205
188
    group->type_names= extra_groups;
206
189
    group->type_names[group->count]= 0;
207
190
  }
208
 
 
 
191
  
209
192
  if (forced_default_file)
210
193
  {
211
194
    if ((error= search_default_file_with_ext(func, func_ctx, "", "",
220
203
  }
221
204
  else if (dirname_length(conf_file))
222
205
  {
223
 
    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)
224
207
      goto err;
225
208
  }
226
209
  else
247
230
    }
248
231
  }
249
232
 
250
 
  return(error);
 
233
  DBUG_RETURN(error);
251
234
 
252
235
err:
253
236
  fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
254
237
  exit(1);
 
238
  return 0;                                     /* Keep compiler happy */
255
239
}
256
240
 
257
241
 
278
262
    1 - error occured
279
263
*/
280
264
 
281
 
int handle_default_option(void *in_ctx, const char *group_name,
282
 
                          const char *option)
 
265
static int handle_default_option(void *in_ctx, const char *group_name,
 
266
                                 const char *option)
283
267
{
284
268
  char *tmp;
285
269
  struct handle_option_ctx *ctx= (struct handle_option_ctx *) in_ctx;
289
273
 
290
274
  if (find_type((char *)group_name, ctx->group, 3))
291
275
  {
292
 
    if (!(tmp= (char *)ctx->alloc->alloc_root(strlen(option) + 1)))
293
 
      return 1;
294
 
    if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
295
 
      return 1;
296
 
    strcpy(tmp, option);
 
276
    if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
 
277
      return 1;
 
278
    if (insert_dynamic(ctx->args, (uchar*) &tmp))
 
279
      return 1;
 
280
    strmov(tmp, option);
297
281
  }
298
282
 
299
283
  return 0;
324
308
  int org_argc= argc, prev_argc= 0;
325
309
  *defaults= *extra_defaults= *group_suffix= 0;
326
310
 
327
 
  const std::string DEFAULTS_FILE("--defaults-file=");
328
 
  const std::string DEFAULTS_EXTRA_FILE("--defaults-extra-file=");
329
 
  const std::string DEFAULTS_GROUP_SUFFIX("--defaults-group-suffix=");
330
 
 
331
311
  while (argc >= 2 && argc != prev_argc)
332
312
  {
333
313
    /* Skip program name or previously handled argument */
334
314
    argv++;
335
315
    prev_argc= argc;                            /* To check if we found */
336
 
    if (!*defaults && (strncmp(*argv,
337
 
                               DEFAULTS_FILE.c_str(),
338
 
                               DEFAULTS_FILE.size()) == 0))
 
316
    if (!*defaults && is_prefix(*argv,"--defaults-file="))
339
317
    {
340
 
      *defaults= *argv + DEFAULTS_FILE.size();
 
318
      *defaults= *argv + sizeof("--defaults-file=")-1;
341
319
       argc--;
342
320
       continue;
343
321
    }
344
 
    if (!*extra_defaults && (strncmp(*argv, 
345
 
                                     DEFAULTS_EXTRA_FILE.c_str(),
346
 
                                     DEFAULTS_EXTRA_FILE.size()) == 0))
 
322
    if (!*extra_defaults && is_prefix(*argv,"--defaults-extra-file="))
347
323
    {
348
 
      *extra_defaults= *argv + DEFAULTS_EXTRA_FILE.size();
 
324
      *extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
349
325
      argc--;
350
326
      continue;
351
327
    }
352
 
    if (!*group_suffix && (strncmp(*argv, 
353
 
                                   DEFAULTS_GROUP_SUFFIX.c_str(),
354
 
                                   DEFAULTS_GROUP_SUFFIX.size()) == 0))
355
 
 
 
328
    if (!*group_suffix && is_prefix(*argv, "--defaults-group-suffix="))
356
329
    {
357
 
      *group_suffix= *argv + DEFAULTS_GROUP_SUFFIX.size();
 
330
      *group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
358
331
      argc--;
359
332
      continue;
360
333
    }
384
357
   NOTES
385
358
    In case of fatal error, the function will print a warning and do
386
359
    exit(1)
387
 
 
 
360
 
388
361
    To free used memory one should call free_defaults() with the argument
389
362
    that was put in *argv
390
363
 
399
372
{
400
373
  DYNAMIC_ARRAY args;
401
374
  TYPELIB group;
402
 
  uint32_t args_used= 0;
 
375
  my_bool found_print_defaults= 0;
 
376
  uint args_used= 0;
403
377
  int error= 0;
404
 
  memory::Root alloc(512);
 
378
  MEM_ROOT alloc;
405
379
  char *ptr,**res;
406
380
  struct handle_option_ctx ctx;
 
381
  DBUG_ENTER("load_defaults");
407
382
 
408
383
  init_default_directories();
 
384
  init_alloc_root(&alloc,512,0);
409
385
  /*
410
386
    Check if the user doesn't want any default option processing
411
387
    --no-defaults is always the first option
413
389
  if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults"))
414
390
  {
415
391
    /* remove the --no-defaults argument and return only the other arguments */
416
 
    uint32_t i;
417
 
    if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (*argc + 1)*sizeof(char*))))
 
392
    uint i;
 
393
    if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
394
                                 (*argc + 1)*sizeof(char*))))
418
395
      goto err;
419
396
    res= (char**) (ptr+sizeof(alloc));
420
 
    memset(res,0,(*argc + 1));
421
397
    res[0]= **argv;                             /* Copy program name */
422
 
    for (i=2 ; i < (uint32_t) *argc ; i++)
 
398
    for (i=2 ; i < (uint) *argc ; i++)
423
399
      res[i-1]=argv[0][i];
424
400
    res[i-1]=0;                                 /* End pointer */
425
401
    (*argc)--;
426
402
    *argv=res;
427
 
    *(memory::Root*) ptr= alloc;                        /* Save alloc root for free */
428
 
    return(0);
 
403
    *(MEM_ROOT*) ptr= alloc;                    /* Save alloc root for free */
 
404
    DBUG_RETURN(0);
429
405
  }
430
406
 
431
407
  group.count=0;
448
424
    Here error contains <> 0 only if we have a fully specified conf_file
449
425
    or a forced default file
450
426
  */
451
 
  if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (args.elements + *argc +1) *sizeof(char*))))
 
427
  if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
428
                               (args.elements + *argc +1) *sizeof(char*))))
452
429
    goto err;
453
430
  res= (char**) (ptr+sizeof(alloc));
454
431
 
455
432
  /* copy name + found arguments + command line arguments to new array */
456
433
  res[0]= argv[0][0];  /* Name MUST be set, even by embedded library */
457
 
  memcpy(res+1, args.buffer, args.elements*sizeof(char*));
 
434
  memcpy((uchar*) (res+1), args.buffer, args.elements*sizeof(char*));
458
435
  /* Skip --defaults-xxx options */
459
436
  (*argc)-= args_used;
460
437
  (*argv)+= args_used;
463
440
    Check if we wan't to see the new argument list
464
441
    This options must always be the last of the default options
465
442
  */
 
443
  if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults"))
 
444
  {
 
445
    found_print_defaults=1;
 
446
    --*argc; ++*argv;                           /* skip argument */
 
447
  }
 
448
 
466
449
  if (*argc)
467
 
    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*));
468
452
  res[args.elements+ *argc]=0;                  /* last null */
469
453
 
470
 
  (*argc)+=int(args.elements);
471
 
  *argv= static_cast<char**>(res);
472
 
  *(memory::Root*) ptr= alloc;                  /* Save alloc root for free */
 
454
  (*argc)+=args.elements;
 
455
  *argv= (char**) res;
 
456
  *(MEM_ROOT*) ptr= alloc;                      /* Save alloc root for free */
473
457
  delete_dynamic(&args);
474
 
 
475
 
  return(error);
 
458
  if (found_print_defaults)
 
459
  {
 
460
    int i;
 
461
    printf("%s would have been started with the following arguments:\n",
 
462
           **argv);
 
463
    for (i=1 ; i < *argc ; i++)
 
464
      printf("%s ", (*argv)[i]);
 
465
    puts("");
 
466
    exit(0);
 
467
  }
 
468
  DBUG_RETURN(error);
476
469
 
477
470
 err:
478
471
  fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
479
472
  exit(1);
 
473
  return 0;                                     /* Keep compiler happy */
480
474
}
481
475
 
482
476
 
483
477
void free_defaults(char **argv)
484
478
{
485
 
  memory::Root ptr;
486
 
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
487
 
  ptr.free_root(MYF(0));
 
479
  MEM_ROOT ptr;
 
480
  memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr));
 
481
  free_root(&ptr,MYF(0));
488
482
}
489
483
 
490
484
 
495
489
{
496
490
  char **ext;
497
491
  const char *empty_list[]= { "", 0 };
498
 
  bool have_ext= fn_ext(config_file)[0] != 0;
 
492
  my_bool have_ext= fn_ext(config_file)[0] != 0;
499
493
  const char **exts_to_use= have_ext ? empty_list : f_extensions;
500
494
 
501
495
  for (ext= (char**) exts_to_use; *ext; ext++)
526
520
*/
527
521
 
528
522
static char *get_argument(const char *keyword, size_t kwlen,
529
 
                          char *ptr, char *name, uint32_t line)
 
523
                          char *ptr, char *name, uint line)
530
524
{
531
525
  char *end;
532
526
 
533
527
  /* Skip over "include / includedir keyword" and following whitespace */
534
528
 
535
529
  for (ptr+= kwlen - 1;
536
 
       my_isspace(&my_charset_utf8_general_ci, ptr[0]);
 
530
       my_isspace(&my_charset_latin1, ptr[0]);
537
531
       ptr++)
538
532
  {}
539
533
 
543
537
    Note that my_isspace() is true for \r and \n
544
538
  */
545
539
  for (end= ptr + strlen(ptr) - 1;
546
 
       my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
540
       my_isspace(&my_charset_latin1, *(end - 1));
547
541
       end--)
548
542
  {}
549
543
  end[0]= 0;                                    /* Cut off end space */
567
561
    search_default_file_with_ext()
568
562
    opt_handler                 Option handler function. It is used to process
569
563
                                every separate option.
570
 
    handler_ctx                 Pointer to the structure to store actual
 
564
    handler_ctx                 Pointer to the structure to store actual 
571
565
                                parameters of the function.
572
566
    dir                         directory to read
573
567
    ext                         Extension for configuration file
595
589
  static const char include_keyword[]= "include";
596
590
  const int max_recursion_level= 10;
597
591
  FILE *fp;
598
 
  uint32_t line=0;
599
 
  bool found_group=0;
 
592
  uint line=0;
 
593
  my_bool found_group=0;
 
594
  uint i;
 
595
  MY_DIR *search_dir;
 
596
  FILEINFO *search_file;
600
597
 
601
598
  if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3)
602
599
    return 0;                                   /* Ignore wrong paths */
603
600
  if (dir)
604
601
  {
605
 
    end=convert_dirname(name, dir, NULL);
 
602
    end=convert_dirname(name, dir, NullS);
606
603
    if (dir[0] == FN_HOMELIB)           /* Add . to filenames in home */
607
604
      *end++='.';
608
 
    sprintf(end,"%s%s",config_file,ext);
 
605
    strxmov(end,config_file,ext,NullS);
609
606
  }
610
607
  else
611
608
  {
612
 
    strcpy(name,config_file);
 
609
    strmov(name,config_file);
613
610
  }
614
611
  fn_format(name,name,"","",4);
615
612
  {
619
616
    /*
620
617
      Ignore world-writable regular files.
621
618
      This is mainly done to protect us to not read a file created by
622
 
      the mysqld server, but the check is still valid in most context.
 
619
      the mysqld server, but the check is still valid in most context. 
623
620
    */
624
621
    if ((stat_info.st_mode & S_IWOTH) &&
625
622
        (stat_info.st_mode & S_IFMT) == S_IFREG)
629
626
      return 0;
630
627
    }
631
628
  }
632
 
  if (!(fp= fopen(name, "r")))
 
629
  if (!(fp= my_fopen(name, O_RDONLY, MYF(0))))
633
630
    return 1;                                   /* Ignore wrong files */
634
631
 
635
 
  memset(buff,0,sizeof(buff));
636
632
  while (fgets(buff, sizeof(buff) - 1, fp))
637
633
  {
638
634
    line++;
639
635
    /* Ignore comment and empty lines */
640
 
    for (ptr= buff; my_isspace(&my_charset_utf8_general_ci, *ptr); ptr++)
 
636
    for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++)
641
637
    {}
642
638
 
643
639
    if (*ptr == '#' || *ptr == ';' || !*ptr)
648
644
    {
649
645
      if (recursion_level >= max_recursion_level)
650
646
      {
651
 
        for (end= ptr + strlen(ptr) - 1;
652
 
             my_isspace(&my_charset_utf8_general_ci, *(end - 1));
 
647
        for (end= ptr + strlen(ptr) - 1; 
 
648
             my_isspace(&my_charset_latin1, *(end - 1));
653
649
             end--)
654
650
        {}
655
651
        end[0]= 0;
661
657
      }
662
658
 
663
659
      /* skip over `!' and following whitespace */
664
 
      for (++ptr; my_isspace(&my_charset_utf8_general_ci, ptr[0]); ptr++)
 
660
      for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++)
665
661
      {}
666
662
 
667
663
      if ((!strncmp(ptr, includedir_keyword,
668
664
                    sizeof(includedir_keyword) - 1)) &&
669
 
          my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(includedir_keyword) - 1]))
 
665
          my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1]))
670
666
      {
671
667
        if (!(ptr= get_argument(includedir_keyword,
672
668
                                sizeof(includedir_keyword),
673
669
                                ptr, name, line)))
674
670
          goto err;
675
671
 
676
 
        CachedDirectory dir_cache(ptr);
677
 
 
678
 
        if (dir_cache.fail())
679
 
        {
680
 
          /**
681
 
           * @todo
682
 
           * Since clients still use this code, we use fprintf here.
683
 
           * This fprintf needs to be turned into errmsg_printf
684
 
           * as soon as the client programs no longer use mysys
685
 
           * and can use the pluggable error message system.
686
 
           */
687
 
          fprintf(stderr, _("error: could not open directory: %s\n"), ptr);
 
672
        if (!(search_dir= my_dir(ptr, MYF(MY_WME))))
688
673
          goto err;
689
 
        }
690
 
 
691
 
        CachedDirectory::Entries files= dir_cache.getEntries();
692
 
        CachedDirectory::Entries::iterator file_iter= files.begin();
693
 
 
694
 
        while (file_iter != files.end())
 
674
 
 
675
        for (i= 0; i < (uint) search_dir->number_off_files; i++)
695
676
        {
696
 
          CachedDirectory::Entry *entry= *file_iter;
697
 
          ext= fn_ext(entry->filename.c_str());
 
677
          search_file= search_dir->dir_entry + i;
 
678
          ext= fn_ext(search_file->name);
698
679
 
699
680
          /* check extension */
700
681
          for (tmp_ext= (char**) f_extensions; *tmp_ext; tmp_ext++)
701
682
          {
702
683
            if (!strcmp(ext, *tmp_ext))
703
 
            {
704
 
              fn_format(tmp, entry->filename.c_str(), ptr, "",
705
 
                        MY_UNPACK_FILENAME | MY_SAFE_PATH);
706
 
 
707
 
              search_default_file_with_ext(opt_handler, handler_ctx, "", "",
708
 
                                           tmp, recursion_level + 1);
709
 
            }
710
 
          }
711
 
 
712
 
          ++file_iter;
 
684
              break;
 
685
          }
 
686
 
 
687
          if (*tmp_ext)
 
688
          {
 
689
            fn_format(tmp, search_file->name, ptr, "",
 
690
                      MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
691
 
 
692
            search_default_file_with_ext(opt_handler, handler_ctx, "", "", tmp,
 
693
                                         recursion_level + 1);
 
694
          }
713
695
        }
 
696
 
 
697
        my_dirend(search_dir);
714
698
      }
715
699
      else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
716
 
               my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(include_keyword)-1]))
 
700
               my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1]))
717
701
      {
718
702
        if (!(ptr= get_argument(include_keyword,
719
703
                                sizeof(include_keyword), ptr,
738
722
        goto err;
739
723
      }
740
724
      /* Remove end space */
741
 
      for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
 
725
      for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
742
726
      end[0]=0;
743
727
 
744
 
      strncpy(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
745
 
      curr_gr[min((size_t)(end-ptr)+1, sizeof(curr_gr)-1)] = '\0';
 
728
      strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
746
729
 
747
730
      /* signal that a new group is found */
748
731
      opt_handler(handler_ctx, curr_gr, NULL);
756
739
              name,line);
757
740
      goto err;
758
741
    }
759
 
 
760
 
 
 
742
    
 
743
   
761
744
    end= remove_end_comment(ptr);
762
745
    if ((value= strchr(ptr, '=')))
763
746
      end= value;                               /* Option without argument */
764
 
    for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) || end[-1]== '\n'; end--) ;
 
747
    for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
765
748
    if (!value)
766
749
    {
767
 
      strncpy(strcpy(option,"--")+2,ptr,strlen(ptr)+1);
 
750
      strmake(strmov(option,"--"),ptr, (size_t) (end-ptr));
768
751
      if (opt_handler(handler_ctx, curr_gr, option))
769
752
        goto err;
770
753
    }
772
755
    {
773
756
      /* Remove pre- and end space */
774
757
      char *value_end;
775
 
      for (value++ ; my_isspace(&my_charset_utf8_general_ci,*value); value++) ;
776
 
      value_end= strchr(value, '\0');
 
758
      for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ;
 
759
      value_end=strend(value);
777
760
      /*
778
 
       We don't have to test for value_end >= value as we know there is
779
 
       an '=' before
 
761
        We don't have to test for value_end >= value as we know there is
 
762
        an '=' before
780
763
      */
781
 
      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--) ;
782
765
      if (value_end < value)                    /* Empty string */
783
 
        value_end=value;
 
766
        value_end=value;
784
767
 
785
768
      /* remove quotes around argument */
786
769
      if ((*value == '\"' || *value == '\'') && /* First char is quote */
787
770
          (value + 1 < value_end ) && /* String is longer than 1 */
788
771
          *value == value_end[-1] ) /* First char is equal to last char */
789
772
      {
790
 
        value++;
791
 
        value_end--;
 
773
        value++;
 
774
        value_end--;
792
775
      }
793
 
      
794
 
      memset(option,0,2+(size_t)(end-ptr)+1);
795
 
      ptr= strncpy(strcpy(option,"--")+2,ptr,(size_t) (end-ptr));
796
 
      ptr[end-ptr]= '\0';
797
 
      ptr+= strlen(ptr);
 
776
      ptr=strnmov(strmov(option,"--"),ptr,(size_t) (end-ptr));
798
777
      *ptr++= '=';
799
778
 
800
779
      for ( ; value != value_end; value++)
840
819
        goto err;
841
820
    }
842
821
  }
843
 
  fclose(fp);
 
822
  my_fclose(fp,MYF(0));
844
823
  return(0);
845
824
 
846
825
 err:
847
 
  fclose(fp);
848
 
 
 
826
  my_fclose(fp,MYF(0));
849
827
  return -1;                                    /* Fatal error */
850
828
}
851
829
 
875
853
  return ptr;
876
854
}
877
855
 
 
856
#include <help_start.h>
 
857
 
878
858
void my_print_default_files(const char *conf_file)
879
859
{
880
860
  const char *empty_list[]= { "", 0 };
881
 
  bool have_ext= fn_ext(conf_file)[0] != 0;
 
861
  my_bool have_ext= fn_ext(conf_file)[0] != 0;
882
862
  const char **exts_to_use= have_ext ? empty_list : f_extensions;
883
863
  char name[FN_REFLEN], **ext;
884
864
  const char **dirs;
902
882
          pos= my_defaults_extra_file;
903
883
        else
904
884
          continue;
905
 
        end= convert_dirname(name, pos, NULL);
 
885
        end= convert_dirname(name, pos, NullS);
906
886
        if (name[0] == FN_HOMELIB)      /* Add . to filenames in home */
907
887
          *end++='.';
908
 
  sprintf(end,"%s%s ",conf_file, *ext);
 
888
        strxmov(end, conf_file, *ext, " ", NullS);
909
889
        fputs(name,stdout);
910
890
      }
911
891
    }
936
916
    }
937
917
  }
938
918
  puts("\nThe following options may be given as the first argument:\n\
939
 
  --no-defaults         Don't read default options from any options file\n\
940
 
  --defaults-file=#     Only read default options from the given file #\n\
941
 
  --defaults-extra-file=# Read this file after the global files are read");
 
919
--print-defaults        Print the program argument list and exit\n\
 
920
--no-defaults           Don't read default options from any options file\n\
 
921
--defaults-file=#       Only read default options from the given file #\n\
 
922
--defaults-extra-file=# Read this file after the global files are read");
942
923
}
943
924
 
 
925
#include <help_end.h>
 
926
 
 
927
 
944
928
/*
945
929
  This extra complexity is to avoid declaring 'rc' if it won't be
946
930
  used.
947
931
*/
948
 
#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, \
949
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
 
950
945
 
951
946
#define ADD_COMMON_DIRECTORIES() \
952
947
  do { \
953
 
    const char *env; \
954
 
    if ((env= getenv("DRIZZLE_HOME"))) \
 
948
    char *env; \
 
949
    if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV)))) \
955
950
      ADD_DIRECTORY(env); \
956
951
    /* Placeholder for --defaults-extra-file=<path> */ \
957
952
    ADD_DIRECTORY(""); \
963
958
 
964
959
  @details
965
960
    1. /etc/
966
 
    2. /etc/drizzle/
 
961
    2. /etc/mysql/
967
962
    3. --sysconfdir=<path> (compile-time option)
968
 
    4. getenv("DRIZZLE_HOME")
 
963
    4. getenv(DEFAULT_HOME_ENV)
969
964
    5. --defaults-extra-file=<path> (run-time option)
970
965
    6. "~/"
971
966
*/
972
967
 
973
 
static void init_default_directories(void)
 
968
static void init_default_directories_unix(void)
974
969
{
975
 
  memset(default_directories, 0, sizeof(default_directories));
 
970
  bzero((char *) default_directories, sizeof(default_directories));
976
971
  ADD_DIRECTORY("/etc/");
977
 
  ADD_DIRECTORY("/etc/drizzle/");
978
 
  ADD_DIRECTORY(SYSCONFDIR);
 
972
  ADD_DIRECTORY("/etc/mysql/");
 
973
#if defined(DEFAULT_SYSCONFDIR)
 
974
    ADD_DIRECTORY(DEFAULT_SYSCONFDIR);
 
975
#endif
979
976
  ADD_COMMON_DIRECTORIES();
980
977
  ADD_DIRECTORY("~/");
981
978
}
982
979
 
983
 
} /* namespace internal */
984
 
} /* namespace drizzled */
 
980
static void (*init_default_directories)(void)= init_default_directories_unix;