From c9d76b51cf004a8dd559c350dd21c1499dd5dc7a Mon Sep 17 00:00:00 2001 From: "jani@hynda.(none)" <> Date: Wed, 14 May 2003 16:47:55 +0300 Subject: [PATCH] Fixed a bug with having comments after options in config files. Bug ID: 235 --- mysys/default.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/mysys/default.c b/mysys/default.c index c47d2719ab..3ff240da3a 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -72,6 +72,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, const char *dir, const char *config_file, const char *ext, TYPELIB *group); +static char *remove_end_comment(char *ptr); void load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv) @@ -297,9 +298,11 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, } if (!read_values) continue; - if (!(end=value=strchr(ptr,'='))) - end=strend(ptr); /* Option without argument */ + end= remove_end_comment(ptr); + if ((value= strchr(ptr, '='))) + end= value; /* Option without argument */ for ( ; isspace(end[-1]) ; end--) ; + if (!value) { if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3))) @@ -368,6 +371,29 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, } +static char *remove_end_comment(char *ptr) +{ + char quote= 0; + + for (; *ptr; ptr++) + { + if (*ptr == '\'' || *ptr == '\"') + { + if (!quote) + quote= *ptr; + else if (quote == *ptr) + quote= 0; + } + if (!quote && *ptr == '#') /* We are not inside a comment */ + { + *ptr= 0; + return ptr; + } + } + return ptr; +} + + void print_defaults(const char *conf_file, const char **groups) { #ifdef __WIN__ -- 2.30.9