~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-28 14:09:50 UTC
  • mfrom: (2207 bootstrap)
  • mto: (2209.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2210.
  • Revision ID: olafvdspek@gmail.com-20110228140950-2nu0hyzhuww3wssx
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
using namespace std;
84
84
using namespace drizzled;
85
85
 
86
 
extern "C"
87
86
unsigned char *get_var_key(const unsigned char* var, size_t *len, bool);
88
87
 
89
88
int get_one_option(int optid, const struct option *, char *argument);
6195
6194
 
6196
6195
/* Definitions for replace result */
6197
6196
 
6198
 
typedef struct st_pointer_array {    /* when using array-strings */
 
6197
class POINTER_ARRAY
 
6198
{    /* when using array-strings */
 
6199
public:
 
6200
  ~POINTER_ARRAY();
 
6201
  int insert(char* name);
 
6202
 
 
6203
  POINTER_ARRAY()
 
6204
  {
 
6205
    memset(this, 0, sizeof(*this));
 
6206
  }
 
6207
 
6199
6208
  TYPELIB typelib;        /* Pointer to strings */
6200
 
  unsigned char  *str;          /* Strings is here */
6201
 
  uint8_t *flag;          /* Flag about each var. */
6202
 
  uint32_t  array_allocs,max_count,length,max_length;
6203
 
} POINTER_ARRAY;
 
6209
  unsigned char *str;          /* Strings is here */
 
6210
  uint8_t* flag;          /* Flag about each var. */
 
6211
  uint32_t array_allocs;
 
6212
  uint32_t max_count;
 
6213
  uint32_t length;
 
6214
  uint32_t max_length;
 
6215
};
6204
6216
 
6205
6217
struct st_replace;
6206
6218
struct st_replace *init_replace(const char **from, const char **to, uint32_t count,
6207
6219
                                char *word_end_chars);
6208
 
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
 
6220
 
6209
6221
void replace_strings_append(struct st_replace *rep, string* ds,
6210
6222
                            const char *from, int len);
6211
6223
 
6220
6232
  variable is replaced.
6221
6233
*/
6222
6234
 
6223
 
static void free_pointer_array(POINTER_ARRAY *pa)
 
6235
POINTER_ARRAY::~POINTER_ARRAY()
6224
6236
{
6225
 
  if (!pa->typelib.count)
 
6237
  if (!typelib.count)
6226
6238
    return;
6227
 
  pa->typelib.count=0;
6228
 
  free((char*) pa->typelib.type_names);
6229
 
  pa->typelib.type_names=0;
6230
 
  free(pa->str);
 
6239
  typelib.count= 0;
 
6240
  free((char*) typelib.type_names);
 
6241
  typelib.type_names=0;
 
6242
  free(str);
6231
6243
}
6232
6244
 
6233
 
void do_get_replace(struct st_command *command)
 
6245
void do_get_replace(st_command *command)
6234
6246
{
6235
 
  uint32_t i;
6236
6247
  char *from= command->first_argument;
6237
 
  char *buff, *start;
6238
 
  char word_end_chars[256], *pos;
 
6248
  if (!*from)
 
6249
    die("Missing argument in %s", command->query);
 
6250
  free_replace();
6239
6251
  POINTER_ARRAY to_array, from_array;
6240
 
 
6241
 
 
6242
 
  free_replace();
6243
 
 
6244
 
  memset(&to_array, 0, sizeof(to_array));
6245
 
  memset(&from_array, 0, sizeof(from_array));
6246
 
  if (!*from)
6247
 
    die("Missing argument in %s", command->query);
6248
 
  start= buff= (char *)malloc(strlen(from)+1);
 
6252
  char* start= (char*)malloc(strlen(from) + 1);
 
6253
  char* buff= start;
6249
6254
  while (*from)
6250
6255
  {
6251
 
    char *to= buff;
6252
 
    to= get_string(&buff, &from, command);
 
6256
    char *to= get_string(&buff, &from, command);
6253
6257
    if (!*from)
6254
 
      die("Wrong number of arguments to replace_result in '%s'",
6255
 
          command->query);
6256
 
    insert_pointer_name(&from_array,to);
 
6258
      die("Wrong number of arguments to replace_result in '%s'", command->query);
 
6259
    from_array.insert(to);
6257
6260
    to= get_string(&buff, &from, command);
6258
 
    insert_pointer_name(&to_array,to);
 
6261
    to_array.insert(to);
6259
6262
  }
6260
 
  for (i= 1,pos= word_end_chars ; i < 256 ; i++)
6261
 
    if (my_isspace(charset_info,i))
 
6263
  char word_end_chars[256];
 
6264
  char* pos= word_end_chars;
 
6265
  for (int i= 1; i < 256; i++)
 
6266
  {
 
6267
    if (my_isspace(charset_info, i))
6262
6268
      *pos++= i;
 
6269
  }
6263
6270
  *pos=0;          /* End pointer */
6264
6271
  if (!(glob_replace= init_replace(from_array.typelib.type_names,
6265
6272
                                   to_array.typelib.type_names,
6266
6273
                                   from_array.typelib.count,
6267
6274
                                   word_end_chars)))
6268
6275
    die("Can't initialize replace from '%s'", command->query);
6269
 
  free_pointer_array(&from_array);
6270
 
  free_pointer_array(&to_array);
6271
6276
  free(start);
6272
6277
  command->last_argument= command->end;
6273
6278
  return;
7177
7182
#define PC_MALLOC    256  /* Bytes for pointers */
7178
7183
#define PS_MALLOC    512  /* Bytes for data */
7179
7184
 
7180
 
int insert_pointer_name(POINTER_ARRAY *pa,char * name)
 
7185
static int insert_pointer_name(POINTER_ARRAY* pa, char* name)
7181
7186
{
7182
7187
  uint32_t i,length,old_count;
7183
7188
  unsigned char *new_pos;
7245
7250
  return(0);
7246
7251
} /* insert_pointer_name */
7247
7252
 
 
7253
int POINTER_ARRAY::insert(char* name)
 
7254
{
 
7255
  return insert_pointer_name(this, name);
 
7256
}
 
7257
 
7248
7258
 
7249
7259
/* Functions that uses replace and replace_regex */
7250
7260