33
33
--print-defaults ; Print the modified command line and exit
34
34
****************************************************************************/
38
#include "drizzled/internal/my_sys.h"
39
#include "drizzled/internal/m_string.h"
40
#include "drizzled/charset_info.h"
36
#include "mysys_priv.h"
37
#include <mystrings/m_string.h>
38
#include <mystrings/m_ctype.h>
39
#include <mysys/my_dir.h>
41
40
#include <drizzled/configmake.h>
42
#include <drizzled/gettext.h>
44
#include "drizzled/cached_directory.h"
46
#ifdef HAVE_SYS_STAT_H
47
# include <sys/stat.h>
60
44
const char *my_defaults_file=0;
61
45
const char *my_defaults_group_suffix=0;
175
159
/* Handle --defaults-group-suffix= */
177
161
const char **extra_groups;
178
const size_t instance_len= strlen(my_defaults_group_suffix);
162
const uint32_t instance_len= strlen(my_defaults_group_suffix);
179
163
struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
181
165
TYPELIB *group= ctx->group;
324
308
int org_argc= argc, prev_argc= 0;
325
309
*defaults= *extra_defaults= *group_suffix= 0;
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=");
331
311
while (argc >= 2 && argc != prev_argc)
333
313
/* Skip program name or previously handled argument */
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="))
340
*defaults= *argv + DEFAULTS_FILE.size();
318
*defaults= *argv + sizeof("--defaults-file=")-1;
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="))
348
*extra_defaults= *argv + DEFAULTS_EXTRA_FILE.size();
324
*extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
352
if (!*group_suffix && (strncmp(*argv,
353
DEFAULTS_GROUP_SUFFIX.c_str(),
354
DEFAULTS_GROUP_SUFFIX.size()) == 0))
328
if (!*group_suffix && is_prefix(*argv, "--defaults-group-suffix="))
357
*group_suffix= *argv + DEFAULTS_GROUP_SUFFIX.size();
330
*group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
402
375
bool found_print_defaults= 0;
403
376
uint32_t args_used= 0;
407
380
struct handle_option_ctx ctx;
409
382
init_default_directories();
410
init_alloc_root(&alloc,512);
383
init_alloc_root(&alloc,512,0);
412
385
Check if the user doesn't want any default option processing
413
386
--no-defaults is always the first option
477
450
memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
478
451
res[args.elements+ *argc]=0; /* last null */
480
(*argc)+=int(args.elements);
481
*argv= static_cast<char**>(res);
482
*(memory::Root*) ptr= alloc; /* Save alloc root for free */
453
(*argc)+=args.elements;
455
*(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */
483
456
delete_dynamic(&args);
484
457
if (found_print_defaults)
692
668
ptr, name, line)))
695
CachedDirectory dir_cache(ptr);
697
if (dir_cache.fail())
701
* Since clients still use this code, we use fprintf here.
702
* This fprintf needs to be turned into errmsg_printf
703
* as soon as the client programs no longer use mysys
704
* and can use the pluggable error message system.
706
fprintf(stderr, _("error: could not open directory: %s\n"), ptr);
671
if (!(search_dir= my_dir(ptr, MYF(MY_WME))))
710
CachedDirectory::Entries files= dir_cache.getEntries();
711
CachedDirectory::Entries::iterator file_iter= files.begin();
713
while (file_iter != files.end())
674
for (i= 0; i < (uint32_t) search_dir->number_off_files; i++)
715
CachedDirectory::Entry *entry= *file_iter;
716
ext= fn_ext(entry->filename.c_str());
676
search_file= search_dir->dir_entry + i;
677
ext= fn_ext(search_file->name);
718
679
/* check extension */
719
680
for (tmp_ext= (char**) f_extensions; *tmp_ext; tmp_ext++)
721
682
if (!strcmp(ext, *tmp_ext))
723
fn_format(tmp, entry->filename.c_str(), ptr, "",
724
MY_UNPACK_FILENAME | MY_SAFE_PATH);
726
search_default_file_with_ext(opt_handler, handler_ctx, "", "",
727
tmp, recursion_level + 1);
688
fn_format(tmp, search_file->name, ptr, "",
689
MY_UNPACK_FILENAME | MY_SAFE_PATH);
691
search_default_file_with_ext(opt_handler, handler_ctx, "", "", tmp,
692
recursion_level + 1);
696
my_dirend(search_dir);
734
698
else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
735
699
my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(include_keyword)-1]))
760
724
for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
763
strncpy(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
764
curr_gr[min((size_t)(end-ptr)+1, sizeof(curr_gr)-1)] = '\0';
727
strncpy(curr_gr, ptr, cmin((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
728
curr_gr[cmin((size_t)(end-ptr)+1, sizeof(curr_gr)-1)] = '\0';
766
730
/* signal that a new group is found */
767
731
opt_handler(handler_ctx, curr_gr, NULL);
957
921
puts("\nThe following options may be given as the first argument:\n\
958
--print-defaults Print the program argument list and exit\n\
959
--no-defaults Don't read default options from any options file\n\
960
--defaults-file=# Only read default options from the given file #\n\
961
--defaults-extra-file=# Read this file after the global files are read");
922
--print-defaults Print the program argument list and exit\n\
923
--no-defaults Don't read default options from any options file\n\
924
--defaults-file=# Only read default options from the given file #\n\
925
--defaults-extra-file=# Read this file after the global files are read");