97
97
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
98
98
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
100
static uint start_lineno= 0; /* Start line of current command */
101
static uint my_end_arg= 0;
100
static uint32_t start_lineno= 0; /* Start line of current command */
101
static uint32_t my_end_arg= 0;
103
103
/* Number of lines of the result to include in failure report */
104
static uint opt_tail_lines= 0;
104
static uint32_t opt_tail_lines= 0;
106
106
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
107
static uint delimiter_length= 1;
107
static uint32_t delimiter_length= 1;
109
109
static char TMPDIR[FN_REFLEN];
397
397
VAR* var_get(const char *var_name, const char** var_name_end,
398
398
bool raw, bool ignore_not_existing);
399
399
void eval_expr(VAR* v, const char *p, const char** p_end);
400
bool match_delimiter(int c, const char *delim, uint length);
400
bool match_delimiter(int c, const char *delim, uint32_t length);
401
401
void dump_result_to_reject_file(char *buf, int size);
402
402
void dump_result_to_log_file(const char *buf, int size);
403
403
void dump_warning_messages(void);
435
435
void replace_append_mem(string *ds, const char *val,
437
437
void replace_append(string *ds, const char *val);
438
void replace_append_uint(string *ds, uint val);
438
void replace_append_uint(string *ds, uint32_t val);
439
439
void append_sorted(string* ds, string* ds_input);
441
441
void handle_error(struct st_command*,
444
444
void handle_no_error(struct st_command*);
447
#define do_send_query(cn,q,q_len,flags) drizzle_send_query(&cn->drizzle, q, q_len)
447
#define do_send_query(cn,q,q_len,flags) drizzleclient_send_query(&cn->drizzle, q, q_len)
449
449
void do_eval(string *query_eval, const char *query,
450
450
const char *query_end, bool pass_through_escape_chars)
570
if (drizzle_query(drizzle, query))
570
if (drizzleclient_query(drizzle, query))
572
572
log_msg("Error running query '%s': %d %s",
573
query, drizzle_errno(drizzle), drizzle_error(drizzle));
573
query, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
577
if ((res= drizzle_store_result(drizzle)) == NULL)
577
if ((res= drizzleclient_store_result(drizzle)) == NULL)
579
579
/* No result set returned */
586
586
unsigned int row_num= 0;
587
unsigned int num_fields= drizzle_num_fields(res);
588
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
587
unsigned int num_fields= drizzleclient_num_fields(res);
588
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
590
590
fprintf(stderr, "=== %s ===\n", query);
591
while ((row= drizzle_fetch_row(res)))
591
while ((row= drizzleclient_fetch_row(res)))
593
uint32_t *lengths= drizzle_fetch_lengths(res);
593
uint32_t *lengths= drizzleclient_fetch_lengths(res);
596
596
fprintf(stderr, "---- %d. ----\n", row_num);
636
if (drizzle_query(drizzle, query))
636
if (drizzleclient_query(drizzle, query))
638
638
log_msg("Error running query '%s': %d %s",
639
query, drizzle_errno(drizzle), drizzle_error(drizzle));
639
query, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
643
if ((res= drizzle_store_result(drizzle)) == NULL)
643
if ((res= drizzleclient_store_result(drizzle)) == NULL)
645
645
/* No result set returned */
649
if (drizzle_num_rows(res) <= 1)
649
if (drizzleclient_num_rows(res) <= 1)
651
651
/* Don't display the last row, it's "last error" */
656
656
unsigned int row_num= 0;
657
unsigned int num_fields= drizzle_num_fields(res);
657
unsigned int num_fields= drizzleclient_num_fields(res);
659
659
fprintf(stderr, "\nWarnings from just before the error:\n");
660
while ((row= drizzle_fetch_row(res)))
660
while ((row= drizzleclient_fetch_row(res)))
663
uint32_t *lengths= drizzle_fetch_lengths(res);
663
uint32_t *lengths= drizzleclient_fetch_lengths(res);
665
if (++row_num >= drizzle_num_rows(res))
665
if (++row_num >= drizzleclient_num_rows(res))
667
667
/* Don't display the last row, it's "last error" */
1758
1758
Store an integer (typically the returncode of the last SQL)
1759
statement in the drizzletest builtin variable $drizzle_errno
1759
statement in the drizzletest builtin variable $drizzleclient_errno
1762
1762
static void var_set_errno(int sql_errno)
1764
var_set_int("$drizzle_errno", sql_errno);
1764
var_set_int("$drizzleclient_errno", sql_errno);
1769
Update $drizzle_get_server_version variable with version
1769
Update $drizzleclient_get_server_version variable with version
1770
1770
of the currently connected server
1773
static void var_set_drizzle_get_server_version(DRIZZLE *drizzle)
1773
static void var_set_drizzleclient_get_server_version(DRIZZLE *drizzle)
1775
var_set_int("$drizzle_get_server_version", drizzle_get_server_version(drizzle));
1775
var_set_int("$drizzleclient_get_server_version", drizzleclient_get_server_version(drizzle));
1818
1818
/* Eval the query, thus replacing all environment variables */
1819
1819
do_eval(&ds_query, query, end, false);
1821
if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1821
if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1822
1822
die("Error running query '%s': %d %s", ds_query.c_str(),
1823
drizzle_errno(drizzle), drizzle_error(drizzle));
1824
if (!(res= drizzle_store_result(drizzle)))
1823
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
1824
if (!(res= drizzleclient_store_result(drizzle)))
1825
1825
die("Query '%s' didn't return a result set", ds_query.c_str());
1827
if ((row= drizzle_fetch_row(res)) && row[0])
1827
if ((row= drizzleclient_fetch_row(res)) && row[0])
1830
1830
Concatenate all fields in the first row with tab in between
1913
1913
ds_query.append(unstripped_query);
1915
1915
/* Run the query */
1916
if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1916
if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1917
1917
die("Error running query '%s': %d %s", ds_query.c_str(),
1918
drizzle_errno(drizzle), drizzle_error(drizzle));
1919
if (!(res= drizzle_store_result(drizzle)))
1918
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
1919
if (!(res= drizzleclient_store_result(drizzle)))
1920
1920
die("Query '%s' didn't return a result set", ds_query.c_str());
1923
1923
/* Find column number from the given column name */
1925
uint num_fields= drizzle_num_fields(res);
1926
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
1925
uint32_t num_fields= drizzleclient_num_fields(res);
1926
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
1928
1928
for (i= 0; i < num_fields; i++)
2872
2872
if (!ds_db.length())
2873
2873
ds_db.append(drizzle->db);
2875
if (drizzle_change_user(drizzle, ds_user.c_str(),
2875
if (drizzleclient_change_user(drizzle, ds_user.c_str(),
2876
2876
ds_passwd.c_str(), ds_db.c_str()))
2877
die("change user failed: %s", drizzle_error(drizzle));
2877
die("change user failed: %s", drizzleclient_error(drizzle));
3006
3006
DRIZZLE_ROW row;
3009
if (drizzle_query(drizzle,"show status like 'Slave_running'") ||
3010
!(res=drizzle_store_result(drizzle)))
3009
if (drizzleclient_query(drizzle,"show status like 'Slave_running'") ||
3010
!(res=drizzleclient_store_result(drizzle)))
3011
3011
die("Query failed while probing slave for stop: %s",
3012
drizzle_error(drizzle));
3013
if (!(row=drizzle_fetch_row(res)) || !row[1])
3012
drizzleclient_error(drizzle));
3013
if (!(row=drizzleclient_fetch_row(res)) || !row[1])
3015
drizzle_free_result(res);
3015
drizzleclient_free_result(res);
3016
3016
die("Strange result from query while probing slave for stop");
3018
3018
done = !strcmp(row[1],"OFF");
3019
drizzle_free_result(res);
3019
drizzleclient_free_result(res);
3022
3022
usleep(SLAVE_POLL_INTERVAL);
3042
3042
wait_for_position:
3044
if (drizzle_query(drizzle, query_buf))
3045
die("failed in '%s': %d: %s", query_buf, drizzle_errno(drizzle),
3046
drizzle_error(drizzle));
3044
if (drizzleclient_query(drizzle, query_buf))
3045
die("failed in '%s': %d: %s", query_buf, drizzleclient_errno(drizzle),
3046
drizzleclient_error(drizzle));
3048
if (!(res= drizzle_store_result(drizzle)))
3049
die("drizzle_store_result() returned NULL for '%s'", query_buf);
3050
if (!(row= drizzle_fetch_row(res)))
3048
if (!(res= drizzleclient_store_result(drizzle)))
3049
die("drizzleclient_store_result() returned NULL for '%s'", query_buf);
3050
if (!(row= drizzleclient_fetch_row(res)))
3052
drizzle_free_result(res);
3052
drizzleclient_free_result(res);
3053
3053
die("empty result in %s", query_buf);
3104
3104
const char *query;
3107
if (drizzle_query(drizzle, query= "show master status"))
3107
if (drizzleclient_query(drizzle, query= "show master status"))
3108
3108
die("failed in 'show master status': %d %s",
3109
drizzle_errno(drizzle), drizzle_error(drizzle));
3109
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3111
if (!(res = drizzle_store_result(drizzle)))
3112
die("drizzle_store_result() retuned NULL for '%s'", query);
3113
if (!(row = drizzle_fetch_row(res)))
3111
if (!(res = drizzleclient_store_result(drizzle)))
3112
die("drizzleclient_store_result() retuned NULL for '%s'", query);
3113
if (!(row = drizzleclient_fetch_row(res)))
3114
3114
die("empty result in show master status");
3115
3115
strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3116
3116
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3117
drizzle_free_result(res);
3117
drizzleclient_free_result(res);
3260
3260
command->last_argument= p;
3261
charset_info= get_charset_by_csname(charset_name,MY_CS_PRIMARY,MYF(MY_WME));
3261
charset_info= get_charset_by_csname(charset_name, MY_CS_PRIMARY);
3262
3262
if (!charset_info)
3263
3263
abort_not_supported_test("Test requires charset '%s'", charset_name);
3266
static uint get_errcode_from_name(char *error_name, char *error_end)
3266
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3268
3268
/* SQL error as string */
3269
3269
st_error *e= global_error_names;
3595
3595
static uint32_t connection_retry_sleep= 100000; /* Microseconds */
3598
while(!drizzle_connect(drizzle, host, user, pass, db, port, NULL,
3598
while(!drizzleclient_connect(drizzle, host, user, pass, db, port, NULL,
3599
3599
CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS))
3606
3606
on protocol/connection type
3609
if ((drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
3610
drizzle_errno(drizzle) == CR_CONNECTION_ERROR) &&
3609
if ((drizzleclient_errno(drizzle) == CR_CONN_HOST_ERROR ||
3610
drizzleclient_errno(drizzle) == CR_CONNECTION_ERROR) &&
3611
3611
failed_attempts < opt_max_connect_retries)
3613
3613
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3614
opt_max_connect_retries, drizzle_errno(drizzle),
3615
drizzle_error(drizzle));
3614
opt_max_connect_retries, drizzleclient_errno(drizzle),
3615
drizzleclient_error(drizzle));
3616
3616
usleep(connection_retry_sleep);
3620
3620
if (failed_attempts > 0)
3621
3621
die("Could not open connection '%s' after %d attempts: %d %s", name,
3622
failed_attempts, drizzle_errno(drizzle), drizzle_error(drizzle));
3622
failed_attempts, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3624
3624
die("Could not open connection '%s': %d %s", name,
3625
drizzle_errno(drizzle), drizzle_error(drizzle));
3625
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3627
3627
failed_attempts++;
3684
3684
ds_res.append(delimiter);
3685
3685
ds_res.append("\n");
3687
if (!drizzle_connect(con, host, user, pass, db, port, 0,
3687
if (!drizzleclient_connect(con, host, user, pass, db, port, 0,
3688
3688
CLIENT_MULTI_STATEMENTS))
3690
var_set_errno(drizzle_errno(con));
3691
handle_error(command, drizzle_errno(con), drizzle_error(con),
3692
drizzle_sqlstate(con), &ds_res);
3690
var_set_errno(drizzleclient_errno(con));
3691
handle_error(command, drizzleclient_errno(con), drizzleclient_error(con),
3692
drizzleclient_sqlstate(con), &ds_res);
3693
3693
return 0; /* Not connected */
3817
3817
(int) (sizeof(connections)/sizeof(struct st_connection)));
3820
if (!drizzle_create(&con_slot->drizzle))
3821
die("Failed on drizzle_create()");
3820
if (!drizzleclient_create(&con_slot->drizzle))
3821
die("Failed on drizzleclient_create()");
3822
3822
if (opt_compress || con_compress)
3823
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NULL);
3824
drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
3823
drizzleclient_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NULL);
3824
drizzleclient_options(&con_slot->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
3826
3826
/* Use default db name */
3827
3827
if (ds_database.length() == 0)
4813
4813
Append the result for one field to the dynamic string ds
4816
static void append_field(string *ds, uint col_idx, const DRIZZLE_FIELD* field,
4816
static void append_field(string *ds, uint32_t col_idx, const DRIZZLE_FIELD* field,
4817
4817
const char* val, uint64_t len, bool is_null)
4819
4819
if (col_idx < max_replace_column && replace_column[col_idx])
4851
4851
static void append_result(string *ds, DRIZZLE_RES *res)
4853
4853
DRIZZLE_ROW row;
4854
uint32_t num_fields= drizzle_num_fields(res);
4855
const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4854
uint32_t num_fields= drizzleclient_num_fields(res);
4855
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
4856
4856
uint32_t *lengths;
4858
while ((row = drizzle_fetch_row(res)))
4858
while ((row = drizzleclient_fetch_row(res)))
4861
lengths = drizzle_fetch_lengths(res);
4861
lengths = drizzleclient_fetch_lengths(res);
4862
4862
for (i = 0; i < num_fields; i++)
4863
4863
append_field(ds, i, &fields[i],
4864
4864
(const char*)row[i], lengths[i], !row[i]);
4979
4979
through PS API we should not issue SHOW WARNINGS until
4980
4980
we have not read all results...
4982
assert(!drizzle_more_results(drizzle));
4984
if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
4985
die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
4987
if (!(warn_res= drizzle_store_result(drizzle)))
4982
assert(!drizzleclient_more_results(drizzle));
4984
if (drizzleclient_real_query(drizzle, "SHOW WARNINGS", 13))
4985
die("Error running query \"SHOW WARNINGS\": %s", drizzleclient_error(drizzle));
4987
if (!(warn_res= drizzleclient_store_result(drizzle)))
4988
4988
die("Warning count is %u but didn't get any warnings",
5024
5024
if (do_send_query(cn, query, query_len, flags))
5026
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5027
drizzle_sqlstate(drizzle), ds);
5026
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5027
drizzleclient_sqlstate(drizzle), ds);
5037
When on first result set, call drizzle_read_query_result to retrieve
5037
When on first result set, call drizzleclient_read_query_result to retrieve
5038
5038
answer to the query sent earlier
5040
if ((counter==0) && drizzle_read_query_result(drizzle))
5040
if ((counter==0) && drizzleclient_read_query_result(drizzle))
5042
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5043
drizzle_sqlstate(drizzle), ds);
5042
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5043
drizzleclient_sqlstate(drizzle), ds);
5049
5049
Store the result of the query if it will return any fields
5051
if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
5051
if (drizzleclient_field_count(drizzle) && ((res= drizzleclient_store_result(drizzle)) == 0))
5053
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5054
drizzle_sqlstate(drizzle), ds);
5053
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5054
drizzleclient_sqlstate(drizzle), ds);
5077
Need to call drizzle_affected_rows() before the "new"
5077
Need to call drizzleclient_affected_rows() before the "new"
5078
5078
query to find the warnings
5080
5080
if (!disable_info)
5081
affected_rows= drizzle_affected_rows(drizzle);
5081
affected_rows= drizzleclient_affected_rows(drizzle);
5084
5084
Add all warnings to the result. We can't do this if we are in
5085
5085
the middle of processing results from multi-statement, because
5086
5086
this will break protocol.
5088
if (!disable_warnings && !drizzle_more_results(drizzle))
5088
if (!disable_warnings && !drizzleclient_more_results(drizzle))
5090
5090
if (append_warnings(ds_warnings, drizzle) || ds_warnings->length())
5097
5097
if (!disable_info)
5098
append_info(ds, affected_rows, drizzle_info(drizzle));
5098
append_info(ds, affected_rows, drizzleclient_info(drizzle));
5103
drizzle_free_result(res);
5103
drizzleclient_free_result(res);
5107
} while (!(err= drizzle_next_result(drizzle)));
5107
} while (!(err= drizzleclient_next_result(drizzle)));
5110
/* We got an error from drizzle_next_result, maybe expected */
5111
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5112
drizzle_sqlstate(drizzle), ds);
5110
/* We got an error from drizzleclient_next_result, maybe expected */
5111
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5112
drizzleclient_sqlstate(drizzle), ds);
5115
5115
assert(err == -1); /* Successful and there are no more results */
5527
5527
1024, 0, 0, get_var_key, var_free, MYF(0)))
5528
5528
die("Variable hash initialization failed");
5530
var_set_string("$DRIZZLE_SERVER_VERSION", drizzle_get_client_info());
5530
var_set_string("$DRIZZLE_SERVER_VERSION", drizzleclient_get_client_info());
5532
5532
memset(&master_pos, 0, sizeof(master_pos));
5552
5552
cur_file->lineno= 1;
5554
5554
cur_con= connections;
5555
if (!( drizzle_create(&cur_con->drizzle)))
5556
die("Failed in drizzle_create()");
5555
if (!( drizzleclient_create(&cur_con->drizzle)))
5556
die("Failed in drizzleclient_create()");
5557
5557
if (opt_compress)
5558
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5559
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5558
drizzleclient_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5559
drizzleclient_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5561
5561
if (!(cur_con->name = strdup("default")))
5562
5562
die("Out of memory");
5568
5568
timer_start= timer_now();
5571
Initialize $drizzle_errno with -1, so we can
5571
Initialize $drizzleclient_errno with -1, so we can
5572
5572
- distinguish it from valid values ( >= 0 ) and
5573
5573
- detect if there was never a command sent to the server
5575
5575
var_set_errno(-1);
5577
/* Update $drizzle_get_server_version to that of current connection */
5578
var_set_drizzle_get_server_version(&cur_con->drizzle);
5577
/* Update $drizzleclient_get_server_version to that of current connection */
5578
var_set_drizzleclient_get_server_version(&cur_con->drizzle);
5580
5580
if (opt_include)
6042
6042
TYPELIB typelib; /* Pointer to strings */
6043
6043
unsigned char *str; /* Strings is here */
6044
6044
uint8_t *flag; /* Flag about each var. */
6045
uint array_allocs,max_count,length,max_length;
6045
uint32_t array_allocs,max_count,length,max_length;
6046
6046
} POINTER_ARRAY;
6048
6048
struct st_replace;
6049
struct st_replace *init_replace(char * *from, char * *to, uint count,
6049
struct st_replace *init_replace(char * *from, char * *to, uint32_t count,
6050
6050
char * word_end_chars);
6051
6051
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6052
6052
void replace_strings_append(struct st_replace *rep, string* ds,
6096
6096
*pos=0; /* End pointer */
6097
6097
if (!(glob_replace= init_replace((char**) from_array.typelib.type_names,
6098
6098
(char**) to_array.typelib.type_names,
6099
(uint) from_array.typelib.count,
6099
(uint32_t) from_array.typelib.count,
6100
6100
word_end_chars)))
6101
6101
die("Can't initialize replace from '%s'", command->query);
6102
6102
free_pointer_array(&from_array);
6485
6485
#ifndef WORD_BIT
6486
#define WORD_BIT (8*sizeof(uint))
6486
#define WORD_BIT (8*sizeof(uint32_t))
6489
6489
#define SET_MALLOC_HUNC 64
6490
6490
#define LAST_CHAR_CODE 259
6492
6492
typedef struct st_rep_set {
6493
uint *bits; /* Pointer to used sets */
6493
uint32_t *bits; /* Pointer to used sets */
6494
6494
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6495
uint found_len; /* Best match to date */
6495
uint32_t found_len; /* Best match to date */
6496
6496
int found_offset;
6498
uint size_of_bits; /* For convinience */
6497
uint32_t table_offset;
6498
uint32_t size_of_bits; /* For convinience */
6501
6501
typedef struct st_rep_sets {
6502
uint count; /* Number of sets */
6503
uint extra; /* Extra sets in buffer */
6504
uint invisible; /* Sets not chown */
6502
uint32_t count; /* Number of sets */
6503
uint32_t extra; /* Extra sets in buffer */
6504
uint32_t invisible; /* Sets not chown */
6505
uint32_t size_of_bits;
6506
6506
REP_SET *set,*set_buffer;
6507
uint32_t *bit_buffer;
6510
6510
typedef struct st_found_set {
6511
uint32_t table_offset;
6512
6512
int found_offset;
6515
6515
typedef struct st_follow {
6517
uint32_t table_offset;
6522
int init_sets(REP_SETS *sets,uint states);
6522
int init_sets(REP_SETS *sets,uint32_t states);
6523
6523
REP_SET *make_new_set(REP_SETS *sets);
6524
6524
void make_sets_invisible(REP_SETS *sets);
6525
6525
void free_last_set(REP_SETS *sets);
6526
6526
void free_sets(REP_SETS *sets);
6527
void internal_set_bit(REP_SET *set, uint bit);
6528
void internal_clear_bit(REP_SET *set, uint bit);
6527
void internal_set_bit(REP_SET *set, uint32_t bit);
6528
void internal_clear_bit(REP_SET *set, uint32_t bit);
6529
6529
void or_bits(REP_SET *to,REP_SET *from);
6530
6530
void copy_bits(REP_SET *to,REP_SET *from);
6531
6531
int cmp_bits(REP_SET *set1,REP_SET *set2);
6532
int get_next_bit(REP_SET *set,uint lastpos);
6532
int get_next_bit(REP_SET *set,uint32_t lastpos);
6533
6533
int find_set(REP_SETS *sets,REP_SET *find);
6534
int find_found(FOUND_SET *found_set,uint table_offset,
6534
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6535
6535
int found_offset);
6536
uint start_at_word(char * pos);
6537
uint end_of_word(char * pos);
6539
static uint found_sets=0;
6542
static uint replace_len(char * str)
6536
uint32_t start_at_word(char * pos);
6537
uint32_t end_of_word(char * pos);
6539
static uint32_t found_sets=0;
6542
static uint32_t replace_len(char * str)
6547
6547
if (str[0] == '\\' && str[1])
6555
6555
/* Init a replace structure for further calls */
6557
REPLACE *init_replace(char * *from, char * *to,uint count,
6557
REPLACE *init_replace(char * *from, char * *to,uint32_t count,
6558
6558
char * word_end_chars)
6560
6560
static const int SPACE_CHAR= 256;
6561
6561
static const int START_OF_LINE= 257;
6562
6562
static const int END_OF_LINE= 258;
6564
uint i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
6564
uint32_t i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
6565
6565
int used_sets,chr,default_state;
6566
6566
char used_chars[LAST_CHAR_CODE],is_word_end[256];
6567
6567
char * pos, *to_pos, **to_array;
6842
int init_sets(REP_SETS *sets,uint states)
6842
int init_sets(REP_SETS *sets,uint32_t states)
6844
6844
memset(sets, 0, sizeof(*sets));
6845
6845
sets->size_of_bits=((states+7)/8);
6846
6846
if (!(sets->set_buffer=(REP_SET*) malloc(sizeof(REP_SET)*SET_MALLOC_HUNC)))
6848
if (!(sets->bit_buffer=(uint*) malloc(sizeof(uint)*sets->size_of_bits*
6848
if (!(sets->bit_buffer=(uint*) malloc(sizeof(uint32_t)*sets->size_of_bits*
6849
6849
SET_MALLOC_HUNC)))
6851
6851
free(sets->set);
6866
6866
REP_SET *make_new_set(REP_SETS *sets)
6868
uint i,count,*bit_buffer;
6868
uint32_t i,count,*bit_buffer;
6870
6870
if (sets->extra)
6873
6873
set=sets->set+ sets->count++;
6874
memset(set->bits, 0, sizeof(uint)*sets->size_of_bits);
6874
memset(set->bits, 0, sizeof(uint32_t)*sets->size_of_bits);
6875
6875
memset(&set->next[0], 0, sizeof(set->next[0])*LAST_CHAR_CODE);
6876
6876
set->found_offset=0;
6877
6877
set->found_len=0;
6915
void internal_set_bit(REP_SET *set, uint bit)
6915
void internal_set_bit(REP_SET *set, uint32_t bit)
6917
6917
set->bits[bit / WORD_BIT] |= 1 << (bit % WORD_BIT);
6921
void internal_clear_bit(REP_SET *set, uint bit)
6921
void internal_clear_bit(REP_SET *set, uint32_t bit)
6923
6923
set->bits[bit / WORD_BIT] &= ~ (1 << (bit % WORD_BIT));
6936
6936
void copy_bits(REP_SET *to,REP_SET *from)
6938
6938
memcpy(to->bits,from->bits,
6939
(size_t) (sizeof(uint) * to->size_of_bits));
6939
(size_t) (sizeof(uint32_t) * to->size_of_bits));
6942
6942
int cmp_bits(REP_SET *set1,REP_SET *set2)
6944
return memcmp(set1->bits,set2->bits, sizeof(uint) * set1->size_of_bits);
6944
return memcmp(set1->bits,set2->bits, sizeof(uint32_t) * set1->size_of_bits);
6948
6948
/* Get next set bit from set. */
6950
int get_next_bit(REP_SET *set,uint lastpos)
6950
int get_next_bit(REP_SET *set,uint32_t lastpos)
6952
uint pos,*start,*end,bits;
6952
uint32_t pos,*start,*end,bits;
6954
6954
start=set->bits+ ((lastpos+1) / WORD_BIT);
6955
6955
end=set->bits + set->size_of_bits;
6993
6993
set->next[] == -1 is reserved for end without replaces.
6996
int find_found(FOUND_SET *found_set,uint table_offset, int found_offset)
6996
int find_found(FOUND_SET *found_set,uint32_t table_offset, int found_offset)
6999
for (i=0 ; (uint) i < found_sets ; i++)
6999
for (i=0 ; (uint32_t) i < found_sets ; i++)
7000
7000
if (found_set[i].table_offset == table_offset &&
7001
7001
found_set[i].found_offset == found_offset)
7009
7009
/* Return 1 if regexp starts with \b or ends with \b*/
7011
uint start_at_word(char * pos)
7011
uint32_t start_at_word(char * pos)
7013
7013
return (((!memcmp(pos, "\\b",2) && pos[2]) ||
7014
7014
!memcmp(pos, "\\^", 2)) ? 1 : 0);
7017
uint end_of_word(char * pos)
7017
uint32_t end_of_word(char * pos)
7019
7019
char * end= strchr(pos, '\0');
7020
7020
return ((end > pos+2 && !memcmp(end-2, "\\b", 2)) ||
7147
7147
replace_append_mem(ds, val, strlen(val));
7150
/* Append uint to ds, with optional replace */
7151
void replace_append_uint(string *ds, uint val)
7150
/* Append uint32_t to ds, with optional replace */
7151
void replace_append_uint(string *ds, uint32_t val)
7153
7153
char buff[22]; /* This should be enough for any int */
7154
7154
char *end= int64_t10_to_str(val, buff, 10);