#include "mysys_priv.h"#include "m_string.h"#include "m_ctype.h"#include <my_dir.h>#include <help_start.h>#include <help_end.h>Include dependency graph for default.c:

Go to the source code of this file.
Classes | |
| struct | handle_option_ctx |
Defines | |
| #define | MAX_DEFAULT_DIRS 7 |
| #define | NEWLINE "\n" |
Functions | |
| static int | handle_default_option (void *in_ctx, const char *group_name, const char *option) |
| static int | search_default_file (Process_option_func func, void *func_ctx, const char *dir, const char *config_file) |
| static int | search_default_file_with_ext (Process_option_func func, void *func_ctx, const char *dir, const char *ext, const char *config_file, int recursion_level) |
| static void | init_default_directories () |
| static char * | remove_end_comment (char *ptr) |
| int | my_search_option_files (const char *conf_file, int *argc, char ***argv, uint *args_used, Process_option_func func, void *func_ctx) |
| int | get_defaults_options (int argc, char **argv, char **defaults, char **extra_defaults, char **group_suffix) |
| int | load_defaults (const char *conf_file, const char **groups, int *argc, char ***argv) |
| void | free_defaults (char **argv) |
| static char * | get_argument (const char *keyword, uint kwlen, char *ptr, char *name, uint line) |
| void | my_print_default_files (const char *conf_file) |
| void | print_defaults (const char *conf_file, const char **groups) |
Variables | |
| const char * | defaults_file = 0 |
| const char * | defaults_group_suffix = 0 |
| char * | defaults_extra_file = 0 |
| const char * | default_directories [MAX_DEFAULT_DIRS+1] |
| static const char * | f_extensions [] = { ".cnf", 0 } |
| void free_defaults | ( | char ** | argv | ) |
Definition at line 473 of file default.c.
References free_root(), memcpy_fixed, and MYF.
Referenced by clean_up(), Options::cleanup(), free_used_memory(), main(), mysql_end(), and mysql_read_default_options().
00474 { 00475 MEM_ROOT ptr; 00476 memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr)); 00477 free_root(&ptr,MYF(0)); 00478 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static char* get_argument | ( | const char * | keyword, | |
| uint | kwlen, | |||
| char * | ptr, | |||
| char * | name, | |||
| uint | line | |||
| ) | [static] |
Definition at line 518 of file default.c.
References my_charset_latin1, my_isspace, and strlen().
00520 { 00521 char *end; 00522 00523 /* Skip over "include / includedir keyword" and following whitespace */ 00524 00525 for (ptr+= kwlen - 1; 00526 my_isspace(&my_charset_latin1, ptr[0]); 00527 ptr++) 00528 {} 00529 00530 /* 00531 Trim trailing whitespace from directory name 00532 The -1 below is for the newline added by fgets() 00533 Note that my_isspace() is true for \r and \n 00534 */ 00535 for (end= ptr + strlen(ptr) - 1; 00536 my_isspace(&my_charset_latin1, *(end - 1)); 00537 end--) 00538 {} 00539 end[0]= 0; /* Cut off end space */ 00540 00541 /* Print error msg if there is nothing after !include* directive */ 00542 if (end <= ptr) 00543 { 00544 fprintf(stderr, 00545 "error: Wrong '!%s' directive in config file: %s at line %d\n", 00546 keyword, name, line); 00547 return 0; 00548 } 00549 return ptr; 00550 }
Here is the call graph for this function:

| int get_defaults_options | ( | int | argc, | |
| char ** | argv, | |||
| char ** | defaults, | |||
| char ** | extra_defaults, | |||
| char ** | group_suffix | |||
| ) |
Definition at line 299 of file default.c.
References is_prefix().
Referenced by main(), and my_search_option_files().
00303 { 00304 int org_argc= argc, prev_argc= 0; 00305 *defaults= *extra_defaults= *group_suffix= 0; 00306 00307 while (argc >= 2 && argc != prev_argc) 00308 { 00309 /* Skip program name or previously handled argument */ 00310 argv++; 00311 prev_argc= argc; /* To check if we found */ 00312 if (!*defaults && is_prefix(*argv,"--defaults-file=")) 00313 { 00314 *defaults= *argv + sizeof("--defaults-file=")-1; 00315 argc--; 00316 continue; 00317 } 00318 if (!*extra_defaults && is_prefix(*argv,"--defaults-extra-file=")) 00319 { 00320 *extra_defaults= *argv + sizeof("--defaults-extra-file=")-1; 00321 argc--; 00322 continue; 00323 } 00324 if (!*group_suffix && is_prefix(*argv, "--defaults-group-suffix=")) 00325 { 00326 *group_suffix= *argv + sizeof("--defaults-group-suffix=")-1; 00327 argc--; 00328 continue; 00329 } 00330 } 00331 return org_argc - argc; 00332 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int handle_default_option | ( | void * | in_ctx, | |
| const char * | group_name, | |||
| const char * | option | |||
| ) | [static] |
Definition at line 261 of file default.c.
References alloc_root(), ctx, find_type(), insert_dynamic(), strlen(), and strmov().
00263 { 00264 char *tmp; 00265 struct handle_option_ctx *ctx= (struct handle_option_ctx *) in_ctx; 00266 00267 if (!option) 00268 return 0; 00269 00270 if (find_type((char *)group_name, ctx->group, 3)) 00271 { 00272 if (!(tmp= alloc_root(ctx->alloc, (uint) strlen(option) + 1))) 00273 return 1; 00274 if (insert_dynamic(ctx->args, (gptr) &tmp)) 00275 return 1; 00276 strmov(tmp, option); 00277 } 00278 00279 return 0; 00280 }
Here is the call graph for this function:

| static void init_default_directories | ( | ) | [static] |
Definition at line 997 of file default.c.
References default_directories, DEFAULT_HOME_ENV, FN_LIBCHAR, getenv(), NULL, strcmp(), strend(), and STRINGIFY_ARG.
00998 { 00999 const char *env, **ptr= default_directories; 01000 01001 #ifdef __WIN__ 01002 *ptr++= "C:/"; 01003 01004 if (GetWindowsDirectory(system_dir,sizeof(system_dir))) 01005 *ptr++= (char*)&system_dir; 01006 if (my_get_system_windows_directory(shared_system_dir, 01007 sizeof(shared_system_dir)) && 01008 strcmp(system_dir, shared_system_dir)) 01009 *ptr++= (char *)&shared_system_dir; 01010 01011 #elif defined(__NETWARE__) 01012 *ptr++= "sys:/etc/"; 01013 #else 01014 *ptr++= "/etc/"; 01015 #endif 01016 if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV)))) 01017 *ptr++= env; 01018 *ptr++= ""; /* Place for defaults_extra_file */ 01019 #if !defined(__WIN__) && !defined(__NETWARE__) 01020 *ptr++= "~/";; 01021 #elif defined(__WIN__) 01022 if (GetModuleFileName(NULL, config_dir, sizeof(config_dir))) 01023 { 01024 char *last= NULL, *end= strend(config_dir); 01025 /* 01026 Look for the second-to-last \ in the filename, but hang on 01027 to a pointer after the last \ in case we're in the root of 01028 a drive. 01029 */ 01030 for ( ; end > config_dir; end--) 01031 { 01032 if (*end == FN_LIBCHAR) 01033 { 01034 if (last) 01035 { 01036 if (end != config_dir) 01037 { 01038 /* Keep the last '\' as this works both with D:\ and a directory */ 01039 end[1]= 0; 01040 } 01041 else 01042 { 01043 /* No parent directory (strange). Use current dir + '\' */ 01044 last[1]= 0; 01045 } 01046 break; 01047 } 01048 last= end; 01049 } 01050 } 01051 *ptr++= (char *)&config_dir; 01052 } 01053 #endif 01054 #ifdef DEFAULT_SYSCONFDIR 01055 if (DEFAULT_SYSCONFDIR != "") 01056 *ptr++= DEFAULT_SYSCONFDIR; 01057 #endif 01058 *ptr= 0; /* end marker */ 01059 }
Here is the call graph for this function:

| int load_defaults | ( | const char * | conf_file, | |
| const char ** | groups, | |||
| int * | argc, | |||
| char *** | argv | |||
| ) |
Definition at line 366 of file default.c.
References handle_option_ctx::alloc, alloc_root(), args, st_typelib::count, ctx, DBUG_ENTER, DBUG_RETURN, delete_dynamic(), err, error, exit, handle_option_ctx::group, handle_default_option(), init_alloc_root(), init_default_directories(), memcpy, my_init_dynamic_array, my_search_option_files(), st_typelib::name, strcmp(), and st_typelib::type_names.
Referenced by get_options(), Configuration::init(), init_common_variables(), Options::load(), load_defaults(), InitConfigFileParser::load_mycnf_groups(), main(), mysql_read_default_options(), parse_args(), InitConfigFileParser::parse_mycnf(), and readArguments().
00368 { 00369 DYNAMIC_ARRAY args; 00370 TYPELIB group; 00371 my_bool found_print_defaults= 0; 00372 uint args_used= 0; 00373 int error= 0; 00374 MEM_ROOT alloc; 00375 char *ptr,**res; 00376 struct handle_option_ctx ctx; 00377 DBUG_ENTER("load_defaults"); 00378 00379 init_default_directories(); 00380 init_alloc_root(&alloc,512,0); 00381 /* 00382 Check if the user doesn't want any default option processing 00383 --no-defaults is always the first option 00384 */ 00385 if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults")) 00386 { 00387 /* remove the --no-defaults argument and return only the other arguments */ 00388 uint i; 00389 if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+ 00390 (*argc + 1)*sizeof(char*)))) 00391 goto err; 00392 res= (char**) (ptr+sizeof(alloc)); 00393 res[0]= **argv; /* Copy program name */ 00394 for (i=2 ; i < (uint) *argc ; i++) 00395 res[i-1]=argv[0][i]; 00396 res[i-1]=0; /* End pointer */ 00397 (*argc)--; 00398 *argv=res; 00399 *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ 00400 DBUG_RETURN(0); 00401 } 00402 00403 group.count=0; 00404 group.name= "defaults"; 00405 group.type_names= groups; 00406 00407 for (; *groups ; groups++) 00408 group.count++; 00409 00410 if (my_init_dynamic_array(&args, sizeof(char*),*argc, 32)) 00411 goto err; 00412 00413 ctx.alloc= &alloc; 00414 ctx.args= &args; 00415 ctx.group= &group; 00416 00417 error= my_search_option_files(conf_file, argc, argv, &args_used, 00418 handle_default_option, (void *) &ctx); 00419 /* 00420 Here error contains <> 0 only if we have a fully specified conf_file 00421 or a forced default file 00422 */ 00423 if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+ 00424 (args.elements + *argc +1) *sizeof(char*)))) 00425 goto err; 00426 res= (char**) (ptr+sizeof(alloc)); 00427 00428 /* copy name + found arguments + command line arguments to new array */ 00429 res[0]= argv[0][0]; /* Name MUST be set, even by embedded library */ 00430 memcpy((gptr) (res+1), args.buffer, args.elements*sizeof(char*)); 00431 /* Skip --defaults-xxx options */ 00432 (*argc)-= args_used; 00433 (*argv)+= args_used; 00434 00435 /* 00436 Check if we wan't to see the new argument list 00437 This options must always be the last of the default options 00438 */ 00439 if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults")) 00440 { 00441 found_print_defaults=1; 00442 --*argc; ++*argv; /* skip argument */ 00443 } 00444 00445 if (*argc) 00446 memcpy((gptr) (res+1+args.elements), (char*) ((*argv)+1), 00447 (*argc-1)*sizeof(char*)); 00448 res[args.elements+ *argc]=0; /* last null */ 00449 00450 (*argc)+=args.elements; 00451 *argv= (char**) res; 00452 *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ 00453 delete_dynamic(&args); 00454 if (found_print_defaults) 00455 { 00456 int i; 00457 printf("%s would have been started with the following arguments:\n", 00458 **argv); 00459 for (i=1 ; i < *argc ; i++) 00460 printf("%s ", (*argv)[i]); 00461 puts(""); 00462 exit(0); 00463 } 00464 DBUG_RETURN(error); 00465 00466 err: 00467 fprintf(stderr,"Fatal error in defaults handling. Program aborted\n"); 00468 exit(1); 00469 return 0; /* Keep compiler happy */ 00470 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void my_print_default_files | ( | const char * | conf_file | ) |
Definition at line 855 of file default.c.
References convert_dirname(), default_directories, defaults_extra_file, dirname_length(), f_extensions, fn_ext(), FN_HOMELIB, FN_REFLEN, init_default_directories(), NullS, pos(), and strxmov().
Referenced by print_defaults(), and usage().
00856 { 00857 const char *empty_list[]= { "", 0 }; 00858 my_bool have_ext= fn_ext(conf_file)[0] != 0; 00859 const char **exts_to_use= have_ext ? empty_list : f_extensions; 00860 char name[FN_REFLEN], **ext; 00861 const char **dirs; 00862 00863 init_default_directories(); 00864 puts("\nDefault options are read from the following files in the given order:"); 00865 00866 if (dirname_length(conf_file)) 00867 fputs(conf_file,stdout); 00868 else 00869 { 00870 for (dirs=default_directories ; *dirs; dirs++) 00871 { 00872 for (ext= (char**) exts_to_use; *ext; *ext++) 00873 { 00874 const char *pos; 00875 char *end; 00876 if (**dirs) 00877 pos= *dirs; 00878 else if (defaults_extra_file) 00879 pos= defaults_extra_file; 00880 else 00881 continue; 00882 end= convert_dirname(name, pos, NullS); 00883 if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ 00884 *end++='.'; 00885 strxmov(end, conf_file, *ext, " ", NullS); 00886 fputs(name,stdout); 00887 } 00888 } 00889 puts(""); 00890 } 00891 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int my_search_option_files | ( | const char * | conf_file, | |
| int * | argc, | |||
| char *** | argv, | |||
| uint * | args_used, | |||
| Process_option_func | func, | |||
| void * | func_ctx | |||
| ) |
Definition at line 124 of file default.c.
References alloc_root(), st_typelib::count, ctx, DBUG_ENTER, DBUG_RETURN, default_directories, DEFAULT_GROUP_SUFFIX_ENV, defaults_extra_file, defaults_file, defaults_group_suffix, dirname_length(), err, error, exit, get_defaults_options(), getenv(), handle_option_ctx::group, handle_default_option(), memcpy, NullS, search_default_file(), search_default_file_with_ext(), STRINGIFY_ARG, strlen(), and st_typelib::type_names.
Referenced by Instance_map::load(), and load_defaults().
00127 { 00128 const char **dirs, *forced_default_file, *forced_extra_defaults; 00129 int error= 0; 00130 DBUG_ENTER("my_search_option_files"); 00131 00132 /* Check if we want to force the use a specific default file */ 00133 *args_used+= get_defaults_options(*argc - *args_used, *argv + *args_used, 00134 (char **) &forced_default_file, 00135 (char **) &forced_extra_defaults, 00136 (char **) &defaults_group_suffix); 00137 00138 if (! defaults_group_suffix) 00139 defaults_group_suffix= getenv(STRINGIFY_ARG(DEFAULT_GROUP_SUFFIX_ENV)); 00140 00141 if (forced_extra_defaults) 00142 defaults_extra_file= (char *) forced_extra_defaults; 00143 00144 if (forced_default_file) 00145 defaults_file= forced_default_file; 00146 00147 /* 00148 We can only handle 'defaults-group-suffix' if we are called from 00149 load_defaults() as otherwise we can't know the type of 'func_ctx' 00150 */ 00151 00152 if (defaults_group_suffix && func == handle_default_option) 00153 { 00154 /* Handle --defaults-group-suffix= */ 00155 uint i; 00156 const char **extra_groups; 00157 const uint instance_len= strlen(defaults_group_suffix); 00158 struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx; 00159 char *ptr; 00160 TYPELIB *group= ctx->group; 00161 00162 if (!(extra_groups= 00163 (const char**)alloc_root(ctx->alloc, 00164 (2*group->count+1)*sizeof(char*)))) 00165 goto err; 00166 00167 for (i= 0; i < group->count; i++) 00168 { 00169 uint len; 00170 extra_groups[i]= group->type_names[i]; 00172 len= strlen(extra_groups[i]); 00173 if (!(ptr= alloc_root(ctx->alloc, len+instance_len+1))) 00174 goto err; 00175 00176 extra_groups[i+group->count]= ptr; 00177 00179 memcpy(ptr, extra_groups[i], len); 00180 memcpy(ptr+len, defaults_group_suffix, instance_len+1); 00181 } 00182 00183 group->count*= 2; 00184 group->type_names= extra_groups; 00185 group->type_names[group->count]= 0; 00186 } 00187 00188 if (forced_default_file) 00189 { 00190 if ((error= search_default_file_with_ext(func, func_ctx, "", "", 00191 forced_default_file, 0)) < 0) 00192 goto err; 00193 if (error > 0) 00194 { 00195 fprintf(stderr, "Could not open required defaults file: %s\n", 00196 forced_default_file); 00197 goto err; 00198 } 00199 } 00200 else if (dirname_length(conf_file)) 00201 { 00202 if ((error= search_default_file(func, func_ctx, NullS, conf_file)) < 0) 00203 goto err; 00204 } 00205 else 00206 { 00207 for (dirs= default_directories ; *dirs; dirs++) 00208 { 00209 if (**dirs) 00210 { 00211 if (search_default_file(func, func_ctx, *dirs, conf_file) < 0) 00212 goto err; 00213 } 00214 else if (defaults_extra_file) 00215 { 00216 if ((error= search_default_file_with_ext(func, func_ctx, "", "", 00217 defaults_extra_file, 0)) < 0) 00218 goto err; /* Fatal error */ 00219 if (error > 0) 00220 { 00221 fprintf(stderr, "Could not open required defaults file: %s\n", 00222 defaults_extra_file); 00223 goto err; 00224 } 00225 } 00226 } 00227 } 00228 00229 DBUG_RETURN(error); 00230 00231 err: 00232 fprintf(stderr,"Fatal error in defaults handling. Program aborted\n"); 00233 exit(1); 00234 return 0; /* Keep compiler happy */ 00235 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void print_defaults | ( | const char * | conf_file, | |
| const char ** | groups | |||
| ) |
Definition at line 893 of file default.c.
References defaults_group_suffix, and my_print_default_files().
Referenced by usage().
00894 { 00895 const char **groups_save= groups; 00896 my_print_default_files(conf_file); 00897 00898 fputs("The following groups are read:",stdout); 00899 for ( ; *groups ; groups++) 00900 { 00901 fputc(' ',stdout); 00902 fputs(*groups,stdout); 00903 } 00904 00905 if (defaults_group_suffix) 00906 { 00907 groups= groups_save; 00908 for ( ; *groups ; groups++) 00909 { 00910 fputc(' ',stdout); 00911 fputs(*groups,stdout); 00912 fputs(defaults_group_suffix,stdout); 00913 } 00914 } 00915 puts("\nThe following options may be given as the first argument:\n\ 00916 --print-defaults Print the program argument list and exit\n\ 00917 --no-defaults Don't read default options from any options file\n\ 00918 --defaults-file=# Only read default options from the given file #\n\ 00919 --defaults-extra-file=# Read this file after the global files are read"); 00920 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static char * remove_end_comment | ( | char * | ptr | ) | [static] |
Definition at line 828 of file default.c.
00829 { 00830 char quote= 0; /* we are inside quote marks */ 00831 char escape= 0; /* symbol is protected by escape chagacter */ 00832 00833 for (; *ptr; ptr++) 00834 { 00835 if ((*ptr == '\'' || *ptr == '\"') && !escape) 00836 { 00837 if (!quote) 00838 quote= *ptr; 00839 else if (quote == *ptr) 00840 quote= 0; 00841 } 00842 /* We are not inside a string */ 00843 if (!quote && *ptr == '#') 00844 { 00845 *ptr= 0; 00846 return ptr; 00847 } 00848 escape= (quote && *ptr == '\\' && !escape); 00849 } 00850 return ptr; 00851 }
| static int search_default_file | ( | Process_option_func | func, | |
| void * | func_ctx, | |||
| const char * | dir, | |||
| const char * | config_file | |||
| ) | [static] |
Definition at line 481 of file default.c.
References error, f_extensions, fn_ext(), and search_default_file_with_ext().
00485 { 00486 char **ext; 00487 const char *empty_list[]= { "", 0 }; 00488 my_bool have_ext= fn_ext(config_file)[0] != 0; 00489 const char **exts_to_use= have_ext ? empty_list : f_extensions; 00490 00491 for (ext= (char**) exts_to_use; *ext; *ext++) 00492 { 00493 int error; 00494 if ((error= search_default_file_with_ext(opt_handler, handler_ctx, 00495 dir, *ext, 00496 config_file, 0)) < 0) 00497 return error; 00498 } 00499 return 0; 00500 }
Here is the call graph for this function:

| static int search_default_file_with_ext | ( | Process_option_func | func, | |
| void * | func_ctx, | |||
| const char * | dir, | |||
| const char * | ext, | |||
| const char * | config_file, | |||
| int | recursion_level | |||
| ) | [static] |
Definition at line 575 of file default.c.
References convert_dirname(), st_my_dir::dir_entry, err, f_extensions, fn_ext(), fn_format(), FN_HOMELIB, FN_REFLEN, get_argument(), min, my_charset_latin1, my_dir(), my_dirend(), my_fclose(), my_fopen(), my_isspace, MY_SAFE_PATH, my_stat(), MY_STAT, MY_UNPACK_FILENAME, MY_WME, MYF, fileinfo::name, NULL, NullS, st_my_dir::number_off_files, remove_end_comment(), S_IFMT, S_IWOTH, search_default_file_with_ext(), strchr(), strcmp(), strend(), strlen(), strmake(), strmov(), strnmov(), strxmov(), and value.
00581 { 00582 char name[FN_REFLEN + 10], buff[4096], curr_gr[4096], *ptr, *end, **tmp_ext; 00583 char *value, option[4096], tmp[FN_REFLEN]; 00584 static const char includedir_keyword[]= "includedir"; 00585 static const char include_keyword[]= "include"; 00586 const int max_recursion_level= 10; 00587 FILE *fp; 00588 uint line=0; 00589 my_bool found_group=0; 00590 uint i; 00591 MY_DIR *search_dir; 00592 FILEINFO *search_file; 00593 00594 if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3) 00595 return 0; /* Ignore wrong paths */ 00596 if (dir) 00597 { 00598 end=convert_dirname(name, dir, NullS); 00599 if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */ 00600 *end++='.'; 00601 strxmov(end,config_file,ext,NullS); 00602 } 00603 else 00604 { 00605 strmov(name,config_file); 00606 } 00607 fn_format(name,name,"","",4); 00608 #if !defined(__WIN__) && !defined(__NETWARE__) 00609 { 00610 MY_STAT stat_info; 00611 if (!my_stat(name,&stat_info,MYF(0))) 00612 return 1; 00613 /* 00614 Ignore world-writable regular files. 00615 This is mainly done to protect us to not read a file created by 00616 the mysqld server, but the check is still valid in most context. 00617 */ 00618 if ((stat_info.st_mode & S_IWOTH) && 00619 (stat_info.st_mode & S_IFMT) == S_IFREG) 00620 { 00621 fprintf(stderr, "Warning: World-writable config file '%s' is ignored\n", 00622 name); 00623 return 0; 00624 } 00625 } 00626 #endif 00627 if (!(fp= my_fopen(name, O_RDONLY, MYF(0)))) 00628 return 1; /* Ignore wrong files */ 00629 00630 while (fgets(buff, sizeof(buff) - 1, fp)) 00631 { 00632 line++; 00633 /* Ignore comment and empty lines */ 00634 for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++) 00635 {} 00636 00637 if (*ptr == '#' || *ptr == ';' || !*ptr) 00638 continue; 00639 00640 /* Configuration File Directives */ 00641 if ((*ptr == '!')) 00642 { 00643 if (recursion_level >= max_recursion_level) 00644 { 00645 for (end= ptr + strlen(ptr) - 1; 00646 my_isspace(&my_charset_latin1, *(end - 1)); 00647 end--) 00648 {} 00649 end[0]= 0; 00650 fprintf(stderr, 00651 "Warning: skipping '%s' directive as maximum include" 00652 "recursion level was reached in file %s at line %d\n", 00653 ptr, name, line); 00654 continue; 00655 } 00656 00657 /* skip over `!' and following whitespace */ 00658 for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++) 00659 {} 00660 00661 if ((!strncmp(ptr, includedir_keyword, 00662 sizeof(includedir_keyword) - 1)) && 00663 my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1])) 00664 { 00665 if (!(ptr= get_argument(includedir_keyword, 00666 sizeof(includedir_keyword), 00667 ptr, name, line))) 00668 goto err; 00669 00670 if (!(search_dir= my_dir(ptr, MYF(MY_WME)))) 00671 goto err; 00672 00673 for (i= 0; i < (uint) search_dir->number_off_files; i++) 00674 { 00675 search_file= search_dir->dir_entry + i; 00676 ext= fn_ext(search_file->name); 00677 00678 /* check extension */ 00679 for (tmp_ext= (char**) f_extensions; *tmp_ext; *tmp_ext++) 00680 { 00681 if (!strcmp(ext, *tmp_ext)) 00682 break; 00683 } 00684 00685 if (*tmp_ext) 00686 { 00687 fn_format(tmp, search_file->name, ptr, "", 00688 MY_UNPACK_FILENAME | MY_SAFE_PATH); 00689 00690 search_default_file_with_ext(opt_handler, handler_ctx, "", "", tmp, 00691 recursion_level + 1); 00692 } 00693 } 00694 00695 my_dirend(search_dir); 00696 } 00697 else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) && 00698 my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1])) 00699 { 00700 if (!(ptr= get_argument(include_keyword, 00701 sizeof(include_keyword), ptr, 00702 name, line))) 00703 goto err; 00704 00705 search_default_file_with_ext(opt_handler, handler_ctx, "", "", ptr, 00706 recursion_level + 1); 00707 } 00708 00709 continue; 00710 } 00711 00712 if (*ptr == '[') /* Group name */ 00713 { 00714 found_group=1; 00715 if (!(end=(char *) strchr(++ptr,']'))) 00716 { 00717 fprintf(stderr, 00718 "error: Wrong group definition in config file: %s at line %d\n", 00719 name,line); 00720 goto err; 00721 } 00722 for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;/* Remove end space */ 00723 end[0]=0; 00724 00725 strnmov(curr_gr, ptr, min((uint) (end-ptr)+1, 4096)); 00726 00727 /* signal that a new group is found */ 00728 opt_handler(handler_ctx, curr_gr, NULL); 00729 00730 continue; 00731 } 00732 if (!found_group) 00733 { 00734 fprintf(stderr, 00735 "error: Found option without preceding group in config file: %s at line: %d\n", 00736 name,line); 00737 goto err; 00738 } 00739 00740 00741 end= remove_end_comment(ptr); 00742 if ((value= strchr(ptr, '='))) 00743 end= value; /* Option without argument */ 00744 for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ; 00745 if (!value) 00746 { 00747 strmake(strmov(option,"--"),ptr,(uint) (end-ptr)); 00748 if (opt_handler(handler_ctx, curr_gr, option)) 00749 goto err; 00750 } 00751 else 00752 { 00753 /* Remove pre- and end space */ 00754 char *value_end; 00755 for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ; 00756 value_end=strend(value); 00757 /* 00758 We don't have to test for value_end >= value as we know there is 00759 an '=' before 00760 */ 00761 for ( ; my_isspace(&my_charset_latin1,value_end[-1]) ; value_end--) ; 00762 if (value_end < value) /* Empty string */ 00763 value_end=value; 00764 00765 /* remove quotes around argument */ 00766 if ((*value == '\"' || *value == '\'') && /* First char is quote */ 00767 (value + 1 < value_end ) && /* String is longer than 1 */ 00768 *value == value_end[-1] ) /* First char is equal to last char */ 00769 { 00770 value++; 00771 value_end--; 00772 } 00773 ptr=strnmov(strmov(option,"--"),ptr,(uint) (end-ptr)); 00774 *ptr++= '='; 00775 00776 for ( ; value != value_end; value++) 00777 { 00778 if (*value == '\\' && value != value_end-1) 00779 { 00780 switch(*++value) { 00781 case 'n': 00782 *ptr++='\n'; 00783 break; 00784 case 't': 00785 *ptr++= '\t'; 00786 break; 00787 case 'r': 00788 *ptr++ = '\r'; 00789 break; 00790 case 'b': 00791 *ptr++ = '\b'; 00792 break; 00793 case 's': 00794 *ptr++= ' '; /* space */ 00795 break; 00796 case '\"': 00797 *ptr++= '\"'; 00798 break; 00799 case '\'': 00800 *ptr++= '\''; 00801 break; 00802 case '\\': 00803 *ptr++= '\\'; 00804 break; 00805 default: /* Unknown; Keep '\' */ 00806 *ptr++= '\\'; 00807 *ptr++= *value; 00808 break; 00809 } 00810 } 00811 else 00812 *ptr++= *value; 00813 } 00814 *ptr=0; 00815 if (opt_handler(handler_ctx, curr_gr, option)) 00816 goto err; 00817 } 00818 } 00819 my_fclose(fp,MYF(0)); 00820 return(0); 00821 00822 err: 00823 my_fclose(fp,MYF(0)); 00824 return -1; /* Fatal error */ 00825 }
Here is the call graph for this function:

| const char* default_directories[MAX_DEFAULT_DIRS+1] |
| char* defaults_extra_file = 0 |
Definition at line 47 of file default.c.
Referenced by load_defaults(), my_print_default_files(), and my_search_option_files().
| const char* defaults_file = 0 |
Definition at line 45 of file default.c.
Referenced by create_defaults_file(), load_defaults(), and my_search_option_files().
| const char* defaults_group_suffix = 0 |
Definition at line 46 of file default.c.
Referenced by load_defaults(), main(), my_search_option_files(), and print_defaults().
const char* f_extensions[] = { ".cnf", 0 } [static] |
1.4.7

