1
#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_H
2
#define INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_H
3
/* Copyright (C) 2004 MySQL AB
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include <my_global.h>
31
Command *parse_command(const char *text);
33
bool parse_option_value(const char *text, size_t *text_len, char **value);
35
void skip_spaces(const char **text);
37
/* define kinds of the word seek method */
38
enum enum_seek_method { ALPHANUM= 1, NONSPACE, OPTION_NAME };
40
/************************************************************************/
46
The purpose of these methods is just to have one method for
47
allocating/deallocating memory for strings for Named_value.
50
static inline char *alloc_str(const LEX_STRING *str);
51
static inline char *alloc_str(const char *str);
52
static inline void free_str(char **str);
56
inline Named_value(char *name_arg, char *value_arg);
58
inline char *get_name();
59
inline char *get_value();
68
inline char *Named_value::alloc_str(const LEX_STRING *str)
70
return my_strndup(str->str, str->length, MYF(0));
73
inline char *Named_value::alloc_str(const char *str)
75
return my_strdup(str, MYF(0));
78
inline void Named_value::free_str(char **str)
80
my_free(*str, MYF(MY_ALLOW_ZERO_PTR));
84
inline Named_value::Named_value()
85
:name(NULL), value(NULL)
88
inline Named_value::Named_value(char *name_arg, char *value_arg)
89
:name(name_arg), value(value_arg)
92
inline char *Named_value::get_name()
97
inline char *Named_value::get_value()
102
void Named_value::free()
108
/************************************************************************/
110
class Named_value_arr
118
inline int get_size() const;
119
inline Named_value get_element(int idx) const;
120
inline void remove_element(int idx);
121
inline bool add_element(Named_value *option);
122
inline bool replace_element(int idx, Named_value *option);
130
inline int Named_value_arr::get_size() const
136
inline Named_value Named_value_arr::get_element(int idx) const
138
DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements);
141
get_dynamic((DYNAMIC_ARRAY *) &arr, (uchar*) &option, idx);
147
inline void Named_value_arr::remove_element(int idx)
149
DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements);
151
get_element(idx).free();
153
delete_dynamic_element(&arr, idx);
157
inline bool Named_value_arr::add_element(Named_value *option)
159
return insert_dynamic(&arr, (uchar*) option);
163
inline bool Named_value_arr::replace_element(int idx, Named_value *option)
165
DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements);
167
get_element(idx).free();
169
return set_dynamic(&arr, (uchar*) option, idx);
172
/************************************************************************/
175
tries to find next word in the text
176
if found, returns the beginning and puts word length to word_len argument.
177
if not found returns pointer to first non-space or to '\0', word_len == 0
180
inline void get_word(const char **text, size_t *word_len,
181
enum_seek_method seek_method= ALPHANUM)
183
const char *word_end;
186
while (my_isspace(default_charset_info, **text))
191
switch (seek_method) {
193
while (my_isalnum(default_charset_info, *word_end))
197
while (!my_isspace(default_charset_info, *word_end) &&
202
while (my_isalnum(default_charset_info, *word_end) ||
209
*word_len= (uint) (word_end - *text);
212
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_H */