~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to server-tools/instance-manager/parse.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_H
 
2
#define INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_H
 
3
/* Copyright (C) 2004 MySQL AB
 
4
 
 
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.
 
8
 
 
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.
 
13
 
 
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 */
 
17
 
 
18
#include <my_global.h>
 
19
#include <my_sys.h>
 
20
#include <m_string.h>
 
21
 
 
22
class Command;
 
23
 
 
24
enum Log_type
 
25
{
 
26
  IM_LOG_ERROR= 0,
 
27
  IM_LOG_GENERAL,
 
28
  IM_LOG_SLOW
 
29
};
 
30
 
 
31
Command *parse_command(const char *text);
 
32
 
 
33
bool parse_option_value(const char *text, size_t *text_len, char **value);
 
34
 
 
35
void skip_spaces(const char **text);
 
36
 
 
37
/* define kinds of the word seek method */
 
38
enum enum_seek_method { ALPHANUM= 1, NONSPACE, OPTION_NAME };
 
39
 
 
40
/************************************************************************/
 
41
 
 
42
class Named_value
 
43
{
 
44
public:
 
45
  /*
 
46
    The purpose of these methods is just to have one method for
 
47
    allocating/deallocating memory for strings for Named_value.
 
48
  */
 
49
 
 
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);
 
53
 
 
54
public:
 
55
  inline Named_value();
 
56
  inline Named_value(char *name_arg, char *value_arg);
 
57
 
 
58
  inline char *get_name();
 
59
  inline char *get_value();
 
60
 
 
61
  inline void free();
 
62
 
 
63
private:
 
64
  char *name;
 
65
  char *value;
 
66
};
 
67
 
 
68
inline char *Named_value::alloc_str(const LEX_STRING *str)
 
69
{
 
70
  return my_strndup(str->str, str->length, MYF(0));
 
71
}
 
72
 
 
73
inline char *Named_value::alloc_str(const char *str)
 
74
{
 
75
  return my_strdup(str, MYF(0));
 
76
}
 
77
 
 
78
inline void Named_value::free_str(char **str)
 
79
{
 
80
  my_free(*str, MYF(MY_ALLOW_ZERO_PTR));
 
81
  *str= NULL;
 
82
}
 
83
 
 
84
inline Named_value::Named_value()
 
85
  :name(NULL), value(NULL)
 
86
{ }
 
87
 
 
88
inline Named_value::Named_value(char *name_arg, char *value_arg)
 
89
  :name(name_arg), value(value_arg)
 
90
{ }
 
91
 
 
92
inline char *Named_value::get_name()
 
93
{
 
94
  return name;
 
95
}
 
96
 
 
97
inline char *Named_value::get_value()
 
98
{
 
99
  return value;
 
100
}
 
101
 
 
102
void Named_value::free()
 
103
{
 
104
  free_str(&name);
 
105
  free_str(&value);
 
106
}
 
107
 
 
108
/************************************************************************/
 
109
 
 
110
class Named_value_arr
 
111
{
 
112
public:
 
113
  Named_value_arr();
 
114
  ~Named_value_arr();
 
115
 
 
116
  bool init();
 
117
 
 
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);
 
123
 
 
124
private:
 
125
  bool initialized;
 
126
  DYNAMIC_ARRAY arr;
 
127
};
 
128
 
 
129
 
 
130
inline int Named_value_arr::get_size() const
 
131
{
 
132
  return arr.elements;
 
133
}
 
134
 
 
135
 
 
136
inline Named_value Named_value_arr::get_element(int idx) const
 
137
{
 
138
  DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements);
 
139
 
 
140
  Named_value option;
 
141
  get_dynamic((DYNAMIC_ARRAY *) &arr, (uchar*) &option, idx);
 
142
 
 
143
  return option;
 
144
}
 
145
 
 
146
 
 
147
inline void Named_value_arr::remove_element(int idx)
 
148
{
 
149
  DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements);
 
150
 
 
151
  get_element(idx).free();
 
152
 
 
153
  delete_dynamic_element(&arr, idx);
 
154
}
 
155
 
 
156
 
 
157
inline bool Named_value_arr::add_element(Named_value *option)
 
158
{
 
159
  return insert_dynamic(&arr, (uchar*) option);
 
160
}
 
161
 
 
162
 
 
163
inline bool Named_value_arr::replace_element(int idx, Named_value *option)
 
164
{
 
165
  DBUG_ASSERT(0 <= idx && (uint) idx < arr.elements);
 
166
 
 
167
  get_element(idx).free();
 
168
 
 
169
  return set_dynamic(&arr, (uchar*) option, idx);
 
170
}
 
171
 
 
172
/************************************************************************/
 
173
 
 
174
/*
 
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
 
178
*/
 
179
 
 
180
inline void get_word(const char **text, size_t *word_len,
 
181
                     enum_seek_method seek_method= ALPHANUM)
 
182
{
 
183
  const char *word_end;
 
184
 
 
185
  /* skip space */
 
186
  while (my_isspace(default_charset_info, **text))
 
187
    ++(*text);
 
188
 
 
189
  word_end= *text;
 
190
 
 
191
  switch (seek_method) {
 
192
  case ALPHANUM:
 
193
    while (my_isalnum(default_charset_info, *word_end))
 
194
      ++word_end;
 
195
    break;
 
196
  case NONSPACE:
 
197
    while (!my_isspace(default_charset_info, *word_end) &&
 
198
           (*word_end != '\0'))
 
199
      ++word_end;
 
200
    break;
 
201
  case OPTION_NAME:
 
202
    while (my_isalnum(default_charset_info, *word_end) ||
 
203
           *word_end == '-' ||
 
204
           *word_end == '_')
 
205
      ++word_end;
 
206
    break;
 
207
  }
 
208
 
 
209
  *word_len= (uint) (word_end - *text);
 
210
}
 
211
 
 
212
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_PARSE_H */