~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/charset.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:24:18 UTC
  • mfrom: (2159.1.1 remove-lint)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172418-vd210j88hiwk8jih
Removed the lint stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <config.h>
 
16
#include "config.h"
17
17
 
18
 
#include <drizzled/charset.h>
19
 
#include <drizzled/error.h>
20
 
#include <drizzled/charset_info.h>
21
 
#include <drizzled/internal/m_string.h>
 
18
#include "drizzled/charset.h"
 
19
#include "drizzled/error.h"
 
20
#include "drizzled/charset_info.h"
 
21
#include "drizzled/internal/m_string.h"
22
22
#include <drizzled/configmake.h>
23
23
#include <vector>
24
24
 
25
 
#include <drizzled/visibility.h>
 
25
#include "drizzled/visibility.h"
26
26
 
27
27
using namespace std;
28
28
 
32
32
/*
33
33
  We collect memory in this vector that we free on delete.
34
34
*/
35
 
static vector<unsigned char*> memory_vector;
 
35
static vector<void *>memory_vector;
36
36
 
37
37
/*
38
38
  The code below implements this functionality:
53
53
static uint
54
54
get_collation_number_internal(const char *name)
55
55
{
56
 
  for (CHARSET_INFO **cs= all_charsets;
57
 
       cs < all_charsets+array_elements(all_charsets)-1;
 
56
  CHARSET_INFO **cs;
 
57
  for (cs= all_charsets;
 
58
       cs < all_charsets+array_elements(all_charsets)-1 ;
58
59
       cs++)
59
60
  {
60
61
    if ( cs[0] && cs[0]->name && !my_strcasecmp(&my_charset_utf8_general_ci, cs[0]->name, name))
65
66
  return 0;
66
67
}
67
68
 
68
 
static unsigned char *cs_alloc(size_t size)
69
 
{
70
 
  memory_vector.push_back(new unsigned char[size]);
71
 
  return memory_vector.back();
72
 
}
73
69
 
74
70
static bool init_state_maps(CHARSET_INFO *cs)
75
71
{
76
 
  if (!(cs->state_map= cs_alloc(256)))
 
72
  uint32_t i;
 
73
  unsigned char *state_map;
 
74
  unsigned char *ident_map;
 
75
 
 
76
  if (!(cs->state_map= (unsigned char*) cs_alloc(256)))
77
77
    return 1;
78
78
    
79
 
  if (!(cs->ident_map= cs_alloc(256)))
 
79
  if (!(cs->ident_map= (unsigned char*) cs_alloc(256)))
80
80
    return 1;
81
81
 
82
 
  unsigned char *state_map= cs->state_map;
83
 
  unsigned char *ident_map= cs->ident_map;
 
82
  state_map= cs->state_map;
 
83
  ident_map= cs->ident_map;
84
84
 
85
85
  /* Fill state_map with states to get a faster parser */
86
 
  for (int i= 0; i < 256; i++)
 
86
  for (i=0; i < 256 ; i++)
87
87
  {
88
88
    if (my_isalpha(cs,i))
89
 
      state_map[i]= MY_LEX_IDENT;
 
89
      state_map[i]=(unsigned char) MY_LEX_IDENT;
90
90
    else if (my_isdigit(cs,i))
91
 
      state_map[i]= MY_LEX_NUMBER_IDENT;
 
91
      state_map[i]=(unsigned char) MY_LEX_NUMBER_IDENT;
92
92
    else if (my_mbcharlen(cs, i)>1)
93
 
      state_map[i]= MY_LEX_IDENT;
 
93
      state_map[i]=(unsigned char) MY_LEX_IDENT;
94
94
    else if (my_isspace(cs,i))
95
 
      state_map[i]= MY_LEX_SKIP;
 
95
      state_map[i]=(unsigned char) MY_LEX_SKIP;
96
96
    else
97
 
      state_map[i]= MY_LEX_CHAR;
 
97
      state_map[i]=(unsigned char) MY_LEX_CHAR;
98
98
  }
99
 
  state_map['_']=state_map['$']= MY_LEX_IDENT;
100
 
  state_map['\'']= MY_LEX_STRING;
101
 
  state_map['.']= MY_LEX_REAL_OR_POINT;
102
 
  state_map['>']=state_map['=']=state_map['!']=  MY_LEX_CMP_OP;
103
 
  state_map['<']=  MY_LEX_LONG_CMP_OP;
104
 
  state_map['&']=state_map['|']= MY_LEX_BOOL;
105
 
  state_map['#']= MY_LEX_COMMENT;
106
 
  state_map[';']= MY_LEX_SEMICOLON;
107
 
  state_map[':']= MY_LEX_SET_VAR;
108
 
  state_map[0]= MY_LEX_EOL;
109
 
  state_map['\\']=  MY_LEX_ESCAPE;
110
 
  state_map['/']=  MY_LEX_LONG_COMMENT;
111
 
  state_map['*']=  MY_LEX_END_LONG_COMMENT;
112
 
  state_map['@']=  MY_LEX_USER_END;
113
 
  state_map['`']=  MY_LEX_USER_VARIABLE_DELIMITER;
114
 
  state_map['"']=  MY_LEX_STRING_OR_DELIMITER;
 
99
  state_map[(unsigned char)'_']=state_map[(unsigned char)'$']=(unsigned char) MY_LEX_IDENT;
 
100
  state_map[(unsigned char)'\'']=(unsigned char) MY_LEX_STRING;
 
101
  state_map[(unsigned char)'.']=(unsigned char) MY_LEX_REAL_OR_POINT;
 
102
  state_map[(unsigned char)'>']=state_map[(unsigned char)'=']=state_map[(unsigned char)'!']= (unsigned char) MY_LEX_CMP_OP;
 
103
  state_map[(unsigned char)'<']= (unsigned char) MY_LEX_LONG_CMP_OP;
 
104
  state_map[(unsigned char)'&']=state_map[(unsigned char)'|']=(unsigned char) MY_LEX_BOOL;
 
105
  state_map[(unsigned char)'#']=(unsigned char) MY_LEX_COMMENT;
 
106
  state_map[(unsigned char)';']=(unsigned char) MY_LEX_SEMICOLON;
 
107
  state_map[(unsigned char)':']=(unsigned char) MY_LEX_SET_VAR;
 
108
  state_map[0]=(unsigned char) MY_LEX_EOL;
 
109
  state_map[(unsigned char)'\\']= (unsigned char) MY_LEX_ESCAPE;
 
110
  state_map[(unsigned char)'/']= (unsigned char) MY_LEX_LONG_COMMENT;
 
111
  state_map[(unsigned char)'*']= (unsigned char) MY_LEX_END_LONG_COMMENT;
 
112
  state_map[(unsigned char)'@']= (unsigned char) MY_LEX_USER_END;
 
113
  state_map[(unsigned char) '`']= (unsigned char) MY_LEX_USER_VARIABLE_DELIMITER;
 
114
  state_map[(unsigned char)'"']= (unsigned char) MY_LEX_STRING_OR_DELIMITER;
115
115
 
116
116
  /*
117
117
    Create a second map to make it faster to find identifiers
118
118
  */
119
 
  for (int i= 0; i < 256; i++)
 
119
  for (i=0; i < 256 ; i++)
120
120
  {
121
 
    ident_map[i]= state_map[i] == MY_LEX_IDENT || state_map[i] == MY_LEX_NUMBER_IDENT;
 
121
    ident_map[i]= (unsigned char) (state_map[i] == MY_LEX_IDENT ||
 
122
                           state_map[i] == MY_LEX_NUMBER_IDENT);
122
123
  }
123
124
 
124
125
  /* Special handling of hex and binary strings */
125
 
  state_map['x']= state_map['X']=  MY_LEX_IDENT_OR_HEX;
126
 
  state_map['b']= state_map['B']=  MY_LEX_IDENT_OR_BIN;
 
126
  state_map[(unsigned char)'x']= state_map[(unsigned char)'X']= (unsigned char) MY_LEX_IDENT_OR_HEX;
 
127
  state_map[(unsigned char)'b']= state_map[(unsigned char)'B']= (unsigned char) MY_LEX_IDENT_OR_BIN;
127
128
  return 0;
128
129
}
129
130
 
 
131
 
130
132
static bool charset_initialized= false;
131
133
 
132
134
DRIZZLED_API CHARSET_INFO *all_charsets[256];
138
140
  cs->state|= MY_CS_AVAILABLE;
139
141
}
140
142
 
 
143
void *cs_alloc(size_t size)
 
144
{
 
145
  void *ptr= malloc(size);
 
146
 
 
147
  memory_vector.push_back(ptr);
 
148
 
 
149
  return ptr;
 
150
}
 
151
 
 
152
 
 
153
 
141
154
static bool init_available_charsets(myf myflags)
142
155
{
143
156
  bool error= false;
172
185
}
173
186
 
174
187
 
175
 
void free_charsets()
 
188
void free_charsets(void)
176
189
{
177
 
  charset_initialized= false;
 
190
  charset_initialized= true;
178
191
 
179
 
  while (not memory_vector.empty())
 
192
  while (memory_vector.empty() == false)
180
193
  {
181
 
    delete[] memory_vector.back();
 
194
    void *ptr= memory_vector.back();
182
195
    memory_vector.pop_back();
 
196
    free(ptr);
183
197
  }
 
198
  memory_vector.clear();
 
199
 
184
200
}
185
201
 
186
202
 
209
225
 
210
226
const char *get_charset_name(uint32_t charset_number)
211
227
{
 
228
  const CHARSET_INFO *cs;
212
229
  init_available_charsets(MYF(0));
213
230
 
214
 
  const CHARSET_INFO *cs= all_charsets[charset_number];
 
231
  cs=all_charsets[charset_number];
215
232
  if (cs && (cs->number == charset_number) && cs->name )
216
 
    return cs->name;
 
233
    return (char*) cs->name;
217
234
 
218
 
  return "?";   /* this mimics find_type() */
 
235
  return (char*) "?";   /* this mimics find_type() */
219
236
}
220
237
 
221
238
 
364
381
    }
365
382
  }
366
383
  *to= 0;
367
 
  return overflow ? UINT32_MAX : to - to_start;
 
384
  return overflow ? UINT32_MAX : (uint32_t) (to - to_start);
368
385
}
369
386
 
370
387
} /* namespace drizzled */