~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Jay Pipes
  • Date: 2009-03-01 03:08:20 UTC
  • mto: (910.2.6 mordred-noatomics)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: jpipes@serialcoder-20090301030820-8kxgypvo3yexa9d1
Final removal of timezones

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include <string>
46
46
#include <vector>
47
47
 
48
 
#include <pcre.h>
 
48
#include PCRE_HEADER
49
49
 
50
50
#include <mysys/hash.h>
51
51
#include <stdarg.h>
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;
99
99
 
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;
102
102
 
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;
105
105
 
106
106
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
107
 
static uint delimiter_length= 1;
 
107
static uint32_t delimiter_length= 1;
108
108
 
109
109
static char TMPDIR[FN_REFLEN];
110
110
 
130
130
{
131
131
  FILE* file;
132
132
  const char *file_name;
133
 
  uint lineno; /* Current line in file */
 
133
  uint32_t lineno; /* Current line in file */
134
134
};
135
135
 
136
136
static struct st_test_file file_stack[16];
350
350
  enum match_err_type type;
351
351
  union
352
352
  {
353
 
    uint errnum;
 
353
    uint32_t errnum;
354
354
    char sqlstate[SQLSTATE_LENGTH+1];  /* \0 terminated string */
355
355
  } code;
356
356
};
358
358
struct st_expected_errors
359
359
{
360
360
  struct st_match_err err[10];
361
 
  uint count;
 
361
  uint32_t count;
362
362
};
363
363
static struct st_expected_errors saved_expected_errors;
364
364
 
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);
410
410
 
411
411
/* For replace_column */
412
412
static char *replace_column[MAX_COLUMNS];
413
 
static uint max_replace_column= 0;
 
413
static uint32_t max_replace_column= 0;
414
414
void do_get_replace_column(struct st_command*);
415
415
void free_replace_column(void);
416
416
 
435
435
void replace_append_mem(string *ds, const char *val,
436
436
                        int len);
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);
440
440
 
441
441
void handle_error(struct st_command*,
444
444
void handle_no_error(struct st_command*);
445
445
 
446
446
 
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)
448
448
 
449
449
void do_eval(string *query_eval, const char *query,
450
450
             const char *query_end, bool pass_through_escape_chars)
519
519
void append_os_quoted(string *str, const char *append, ...)
520
520
{
521
521
  const char *quote_str= "\'";
522
 
  const uint  quote_len= 1;
 
522
  const uint32_t  quote_len= 1;
523
523
 
524
524
  va_list dirty_text;
525
525
 
567
567
  if (!drizzle)
568
568
    return;
569
569
 
570
 
  if (drizzle_query(drizzle, query))
 
570
  if (drizzleclient_query(drizzle, query))
571
571
  {
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));
574
574
    return;
575
575
  }
576
576
 
577
 
  if ((res= drizzle_store_result(drizzle)) == NULL)
 
577
  if ((res= drizzleclient_store_result(drizzle)) == NULL)
578
578
  {
579
579
    /* No result set returned */
580
580
    return;
584
584
    DRIZZLE_ROW row;
585
585
    unsigned int i;
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);
589
589
 
590
590
    fprintf(stderr, "=== %s ===\n", query);
591
 
    while ((row= drizzle_fetch_row(res)))
 
591
    while ((row= drizzleclient_fetch_row(res)))
592
592
    {
593
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
593
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
594
594
      row_num++;
595
595
 
596
596
      fprintf(stderr, "---- %d. ----\n", row_num);
605
605
      fprintf(stderr, "=");
606
606
    fprintf(stderr, "\n\n");
607
607
  }
608
 
  drizzle_free_result(res);
 
608
  drizzleclient_free_result(res);
609
609
 
610
610
  return;
611
611
}
633
633
  if (!drizzle)
634
634
    return;
635
635
 
636
 
  if (drizzle_query(drizzle, query))
 
636
  if (drizzleclient_query(drizzle, query))
637
637
  {
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));
640
640
    return;
641
641
  }
642
642
 
643
 
  if ((res= drizzle_store_result(drizzle)) == NULL)
 
643
  if ((res= drizzleclient_store_result(drizzle)) == NULL)
644
644
  {
645
645
    /* No result set returned */
646
646
    return;
647
647
  }
648
648
 
649
 
  if (drizzle_num_rows(res) <= 1)
 
649
  if (drizzleclient_num_rows(res) <= 1)
650
650
  {
651
651
    /* Don't display the last row, it's "last error" */
652
652
  }
654
654
  {
655
655
    DRIZZLE_ROW row;
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);
658
658
 
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)))
661
661
    {
662
662
      uint32_t i;
663
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
663
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
664
664
 
665
 
      if (++row_num >= drizzle_num_rows(res))
 
665
      if (++row_num >= drizzleclient_num_rows(res))
666
666
      {
667
667
        /* Don't display the last row, it's "last error" */
668
668
        break;
676
676
      fprintf(stderr, "\n");
677
677
    }
678
678
  }
679
 
  drizzle_free_result(res);
 
679
  drizzleclient_free_result(res);
680
680
 
681
681
  return;
682
682
}
767
767
}
768
768
 
769
769
 
770
 
static void handle_command_error(struct st_command *command, uint error)
 
770
static void handle_command_error(struct st_command *command, uint32_t error)
771
771
{
772
772
 
773
773
  if (error != 0)
774
774
  {
775
 
    uint i;
 
775
    uint32_t i;
776
776
 
777
777
    if (command->abort_on_error)
778
778
      die("command \"%.*s\" failed with error %d",
805
805
 
806
806
  for (--next_con; next_con >= connections; --next_con)
807
807
  {
808
 
    drizzle_close(&next_con->drizzle);
 
808
    drizzleclient_close(&next_con->drizzle);
809
809
    if (next_con->util_drizzle)
810
 
      drizzle_close(next_con->util_drizzle);
 
810
      drizzleclient_close(next_con->util_drizzle);
811
811
    free(next_con->name);
812
812
  }
813
813
  return;
832
832
 
833
833
static void free_used_memory(void)
834
834
{
835
 
  uint i;
 
835
  uint32_t i;
836
836
 
837
837
 
838
838
  close_connections();
1079
1079
static void cat_file(string* ds, const char* filename)
1080
1080
{
1081
1081
  int fd;
1082
 
  uint len;
 
1082
  uint32_t len;
1083
1083
  char buff[512];
1084
1084
 
1085
1085
  if ((fd= my_open(filename, O_RDONLY, MYF(0))) < 0)
1286
1286
{
1287
1287
  int error= RESULT_OK;
1288
1288
  File fd2;
1289
 
  uint len, len2;
 
1289
  uint32_t len, len2;
1290
1290
  char buff[512], buff2[512];
1291
1291
  const char *fname= filename2;
1292
1292
  string tmpfile;
1637
1637
  if (digit < 0 || digit >= 10)
1638
1638
  {
1639
1639
    const char *save_var_name = var_name, *end;
1640
 
    uint length;
 
1640
    uint32_t length;
1641
1641
    end = (var_name_end) ? *var_name_end : 0;
1642
1642
    while (my_isvar(charset_info,*var_name) && var_name != end)
1643
1643
      var_name++;
1647
1647
        return(0);
1648
1648
      die("Empty variable");
1649
1649
    }
1650
 
    length= (uint) (var_name - save_var_name);
 
1650
    length= (uint32_t) (var_name - save_var_name);
1651
1651
    if (length >= MAX_VAR_NAME_LENGTH)
1652
1652
      die("Too long variable name: %s", save_var_name);
1653
1653
 
1712
1712
  digit= *var_name - '0';
1713
1713
  if (!(digit < 10 && digit >= 0))
1714
1714
  {
1715
 
    v= var_obtain(var_name, (uint) (var_name_end - var_name));
 
1715
    v= var_obtain(var_name, (uint32_t) (var_name_end - var_name));
1716
1716
  }
1717
1717
  else
1718
1718
    v= var_reg + digit;
1756
1756
 
1757
1757
/*
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
1760
1760
*/
1761
1761
 
1762
1762
static void var_set_errno(int sql_errno)
1763
1763
{
1764
 
  var_set_int("$drizzle_errno", sql_errno);
 
1764
  var_set_int("$drizzleclient_errno", sql_errno);
1765
1765
}
1766
1766
 
1767
1767
 
1768
1768
/*
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
1771
1771
*/
1772
1772
 
1773
 
static void var_set_drizzle_get_server_version(DRIZZLE *drizzle)
 
1773
static void var_set_drizzleclient_get_server_version(DRIZZLE *drizzle)
1774
1774
{
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));
1776
1776
}
1777
1777
 
1778
1778
 
1818
1818
  /* Eval the query, thus replacing all environment variables */
1819
1819
  do_eval(&ds_query, query, end, false);
1820
1820
 
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());
1826
1826
 
1827
 
  if ((row= drizzle_fetch_row(res)) && row[0])
 
1827
  if ((row= drizzleclient_fetch_row(res)) && row[0])
1828
1828
  {
1829
1829
    /*
1830
1830
      Concatenate all fields in the first row with tab in between
1834
1834
    uint32_t i;
1835
1835
    uint32_t *lengths;
1836
1836
 
1837
 
    lengths= drizzle_fetch_lengths(res);
1838
 
    for (i= 0; i < drizzle_num_fields(res); i++)
 
1837
    lengths= drizzleclient_fetch_lengths(res);
 
1838
    for (i= 0; i < drizzleclient_num_fields(res); i++)
1839
1839
    {
1840
1840
      if (row[i])
1841
1841
      {
1850
1850
  else
1851
1851
    eval_expr(var, "", 0);
1852
1852
 
1853
 
  drizzle_free_result(res);
 
1853
  drizzleclient_free_result(res);
1854
1854
  return;
1855
1855
}
1856
1856
 
1913
1913
  ds_query.append(unstripped_query);
1914
1914
 
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());
1921
1921
 
1922
1922
  {
1923
1923
    /* Find column number from the given column name */
1924
 
    uint i;
1925
 
    uint num_fields= drizzle_num_fields(res);
1926
 
    const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
 
1924
    uint32_t i;
 
1925
    uint32_t num_fields= drizzleclient_num_fields(res);
 
1926
    const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
1927
1927
 
1928
1928
    for (i= 0; i < num_fields; i++)
1929
1929
    {
1936
1936
    }
1937
1937
    if (col_no == -1)
1938
1938
    {
1939
 
      drizzle_free_result(res);
 
1939
      drizzleclient_free_result(res);
1940
1940
      die("Could not find column '%s' in the result of '%s'",
1941
1941
          ds_col.c_str(), ds_query.c_str());
1942
1942
    }
1948
1948
    long rows= 0;
1949
1949
    const char* value= "No such row";
1950
1950
 
1951
 
    while ((row= drizzle_fetch_row(res)))
 
1951
    while ((row= drizzleclient_fetch_row(res)))
1952
1952
    {
1953
1953
      if (++rows == row_no)
1954
1954
      {
1964
1964
    }
1965
1965
    eval_expr(var, value, 0);
1966
1966
  }
1967
 
  drizzle_free_result(res);
 
1967
  drizzleclient_free_result(res);
1968
1968
 
1969
1969
  return;
1970
1970
}
2228
2228
  error= pclose(res_file);
2229
2229
  if (error > 0)
2230
2230
  {
2231
 
    uint status= WEXITSTATUS(error), i;
 
2231
    uint32_t status= WEXITSTATUS(error), i;
2232
2232
    bool ok= 0;
2233
2233
 
2234
2234
    if (command->abort_on_error)
2872
2872
  if (!ds_db.length())
2873
2873
    ds_db.append(drizzle->db);
2874
2874
 
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));
2878
2878
 
2879
2879
 
2880
2880
  return;
3006
3006
    DRIZZLE_ROW row;
3007
3007
    int done;
3008
3008
 
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])
3014
3014
    {
3015
 
      drizzle_free_result(res);
 
3015
      drizzleclient_free_result(res);
3016
3016
      die("Strange result from query while probing slave for stop");
3017
3017
    }
3018
3018
    done = !strcmp(row[1],"OFF");
3019
 
    drizzle_free_result(res);
 
3019
    drizzleclient_free_result(res);
3020
3020
    if (done)
3021
3021
      break;
3022
3022
    usleep(SLAVE_POLL_INTERVAL);
3041
3041
 
3042
3042
wait_for_position:
3043
3043
 
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));
3047
3047
 
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)))
3051
3051
  {
3052
 
    drizzle_free_result(res);
 
3052
    drizzleclient_free_result(res);
3053
3053
    die("empty result in %s", query_buf);
3054
3054
  }
3055
3055
  if (!row[0])
3058
3058
      It may be that the slave SQL thread has not started yet, though START
3059
3059
      SLAVE has been issued ?
3060
3060
    */
3061
 
    drizzle_free_result(res);
 
3061
    drizzleclient_free_result(res);
3062
3062
    if (tries++ == 30)
3063
3063
    {
3064
3064
      show_query(drizzle, "SHOW MASTER STATUS");
3068
3068
    sleep(1); /* So at most we will wait 30 seconds and make 31 tries */
3069
3069
    goto wait_for_position;
3070
3070
  }
3071
 
  drizzle_free_result(res);
 
3071
  drizzleclient_free_result(res);
3072
3072
  return;
3073
3073
}
3074
3074
 
3104
3104
  const char *query;
3105
3105
 
3106
3106
 
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));
3110
3110
 
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);
3118
3118
  return(0);
3119
3119
}
3120
3120
 
3229
3229
 
3230
3230
 
3231
3231
static void do_get_file_name(struct st_command *command,
3232
 
                             char* dest, uint dest_max_len)
 
3232
                             char* dest, uint32_t dest_max_len)
3233
3233
{
3234
3234
  char *p= command->first_argument, *name;
3235
3235
  if (!*p)
3258
3258
  if(*p)
3259
3259
    *p++= 0;
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);
3264
3264
}
3265
3265
 
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)
3267
3267
{
3268
3268
  /* SQL error as string */
3269
3269
  st_error *e= global_error_names;
3277
3277
      (as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT).
3278
3278
    */
3279
3279
    if (!strncmp(error_name, e->name, (int) (error_end - error_name)) &&
3280
 
        (uint) strlen(e->name) == (uint) (error_end - error_name))
 
3280
        (uint32_t) strlen(e->name) == (uint32_t) (error_end - error_name))
3281
3281
    {
3282
3282
      return(e->code);
3283
3283
    }
3291
3291
{
3292
3292
  struct st_match_err *to= saved_expected_errors.err;
3293
3293
  char *p= command->first_argument;
3294
 
  uint count= 0;
 
3294
  uint32_t count= 0;
3295
3295
 
3296
3296
 
3297
3297
 
3370
3370
      if (!str2int(start, 10, (long) INT_MIN, (long) INT_MAX, &val))
3371
3371
        die("Invalid argument to error: '%s'", command->first_argument);
3372
3372
 
3373
 
      to->code.errnum= (uint) val;
 
3373
      to->code.errnum= (uint32_t) val;
3374
3374
      to->type= ERR_ERRNO;
3375
3375
    }
3376
3376
    to++;
3481
3481
{
3482
3482
  bool reconnect= val;
3483
3483
 
3484
 
  drizzle_options(drizzle, DRIZZLE_OPT_RECONNECT, (char *)&reconnect);
 
3484
  drizzleclient_options(drizzle, DRIZZLE_OPT_RECONNECT, (char *)&reconnect);
3485
3485
 
3486
3486
  return;
3487
3487
}
3492
3492
  if (!(cur_con= find_connection_by_name(name)))
3493
3493
    die("connection '%s' not found in connection pool", name);
3494
3494
 
3495
 
  /* Update $drizzle_get_server_version to that of current connection */
3496
 
  var_set_drizzle_get_server_version(&cur_con->drizzle);
 
3495
  /* Update $drizzleclient_get_server_version to that of current connection */
 
3496
  var_set_drizzleclient_get_server_version(&cur_con->drizzle);
3497
3497
 
3498
3498
  return(0);
3499
3499
}
3539
3539
  {
3540
3540
    if (con->drizzle.net.vio)
3541
3541
    {
3542
 
      net_close(&(con->drizzle.net));
 
3542
      drizzleclient_net_close(&(con->drizzle.net));
3543
3543
    }
3544
3544
  }
3545
3545
 
3546
 
  drizzle_close(&con->drizzle);
 
3546
  drizzleclient_close(&con->drizzle);
3547
3547
 
3548
3548
  if (con->util_drizzle)
3549
 
    drizzle_close(con->util_drizzle);
 
3549
    drizzleclient_close(con->util_drizzle);
3550
3550
  con->util_drizzle= 0;
3551
3551
 
3552
3552
  free(con->name);
3595
3595
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
3596
3596
 
3597
3597
 
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))
3600
3600
  {
3601
3601
    /*
3606
3606
      on protocol/connection type
3607
3607
    */
3608
3608
 
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)
3612
3612
    {
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);
3617
3617
    }
3618
3618
    else
3619
3619
    {
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));
3623
3623
      else
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));
3626
3626
    }
3627
3627
    failed_attempts++;
3628
3628
  }
3684
3684
    ds_res.append(delimiter);
3685
3685
    ds_res.append("\n");
3686
3686
  }
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))
3689
3689
  {
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 */
3694
3694
  }
3695
3695
 
3817
3817
          (int) (sizeof(connections)/sizeof(struct st_connection)));
3818
3818
  }
3819
3819
 
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);
3825
3825
 
3826
3826
  /* Use default db name */
3827
3827
  if (ds_database.length() == 0)
3844
3844
      next_con++; /* if we used the next_con slot, advance the pointer */
3845
3845
  }
3846
3846
 
3847
 
  /* Update $drizzle_get_server_version to that of current connection */
3848
 
  var_set_drizzle_get_server_version(&cur_con->drizzle);
 
3847
  /* Update $drizzleclient_get_server_version to that of current connection */
 
3848
  var_set_drizzleclient_get_server_version(&cur_con->drizzle);
3849
3849
 
3850
3850
  return;
3851
3851
}
3985
3985
}
3986
3986
 
3987
3987
 
3988
 
bool match_delimiter(int c, const char *delim, uint length)
 
3988
bool match_delimiter(int c, const char *delim, uint32_t length)
3989
3989
{
3990
 
  uint i;
 
3990
  uint32_t i;
3991
3991
  char tmp[MAX_DELIMITER_LENGTH];
3992
3992
 
3993
3993
  if (c != *delim)
4287
4287
        ptr[2] && ptr[2] == '-' &&
4288
4288
        ptr[3])
4289
4289
    {
4290
 
      uint type;
 
4290
      uint32_t type;
4291
4291
      char save;
4292
4292
      char *end, *start= (char*)ptr+3;
4293
4293
      /* Skip leading spaces */
4434
4434
  p= command->query;
4435
4435
  while (*p && !my_isspace(charset_info, *p) && *p != '(')
4436
4436
    p++;
4437
 
  command->first_word_len= (uint) (p - command->query);
 
4437
  command->first_word_len= (uint32_t) (p - command->query);
4438
4438
 
4439
4439
  /* Skip spaces between command and first argument */
4440
4440
  while (*p && my_isspace(charset_info, *p))
4530
4530
static void print_version(void)
4531
4531
{
4532
4532
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4533
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
4533
         drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
4534
4534
}
4535
4535
 
4536
4536
static void usage(void)
4717
4717
  if (argc == 1)
4718
4718
    opt_db= *argv;
4719
4719
  if (tty_password)
4720
 
    opt_pass= get_tty_password(NULL);          /* purify tested */
 
4720
    opt_pass= drizzleclient_get_tty_password(NULL);          /* purify tested */
4721
4721
  if (debug_info_flag)
4722
4722
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
4723
4723
  if (debug_check_flag)
4813
4813
  Append the result for one field to the dynamic string ds
4814
4814
*/
4815
4815
 
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)
4818
4818
{
4819
4819
  if (col_idx < max_replace_column && replace_column[col_idx])
4851
4851
static void append_result(string *ds, DRIZZLE_RES *res)
4852
4852
{
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;
4857
4857
 
4858
 
  while ((row = drizzle_fetch_row(res)))
 
4858
  while ((row = drizzleclient_fetch_row(res)))
4859
4859
  {
4860
4860
    uint32_t i;
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]);
4875
4875
 
4876
4876
static void append_metadata(string *ds,
4877
4877
                            const DRIZZLE_FIELD *field,
4878
 
                            uint num_fields)
 
4878
                            uint32_t num_fields)
4879
4879
{
4880
4880
  const DRIZZLE_FIELD *field_end;
4881
4881
  ds->append("Catalog\tDatabase\tTable\tTable_alias\tColumn\t"
4946
4946
 
4947
4947
static void append_table_headings(string *ds,
4948
4948
                                  const DRIZZLE_FIELD *field,
4949
 
                                  uint num_fields)
 
4949
                                  uint32_t num_fields)
4950
4950
{
4951
 
  uint col_idx;
 
4951
  uint32_t col_idx;
4952
4952
  for (col_idx= 0; col_idx < num_fields; col_idx++)
4953
4953
  {
4954
4954
    if (col_idx)
4967
4967
 
4968
4968
static int append_warnings(string *ds, DRIZZLE *drizzle)
4969
4969
{
4970
 
  uint count;
 
4970
  uint32_t count;
4971
4971
  DRIZZLE_RES *warn_res;
4972
4972
 
4973
4973
 
4974
 
  if (!(count= drizzle_warning_count(drizzle)))
 
4974
  if (!(count= drizzleclient_warning_count(drizzle)))
4975
4975
    return(0);
4976
4976
 
4977
4977
  /*
4979
4979
    through PS API we should not issue SHOW WARNINGS until
4980
4980
    we have not read all results...
4981
4981
  */
4982
 
  assert(!drizzle_more_results(drizzle));
4983
 
 
4984
 
  if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
4985
 
    die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
4986
 
 
4987
 
  if (!(warn_res= drizzle_store_result(drizzle)))
 
4982
  assert(!drizzleclient_more_results(drizzle));
 
4983
 
 
4984
  if (drizzleclient_real_query(drizzle, "SHOW WARNINGS", 13))
 
4985
    die("Error running query \"SHOW WARNINGS\": %s", drizzleclient_error(drizzle));
 
4986
 
 
4987
  if (!(warn_res= drizzleclient_store_result(drizzle)))
4988
4988
    die("Warning count is %u but didn't get any warnings",
4989
4989
        count);
4990
4990
 
5023
5023
     */
5024
5024
    if (do_send_query(cn, query, query_len, flags))
5025
5025
    {
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);
5028
5028
      goto end;
5029
5029
    }
5030
5030
  }
5034
5034
  do
5035
5035
  {
5036
5036
    /*
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
5039
5039
    */
5040
 
    if ((counter==0) && drizzle_read_query_result(drizzle))
 
5040
    if ((counter==0) && drizzleclient_read_query_result(drizzle))
5041
5041
    {
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);
5044
5044
      goto end;
5045
5045
 
5046
5046
    }
5048
5048
    /*
5049
5049
      Store the result of the query if it will return any fields
5050
5050
    */
5051
 
    if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
 
5051
    if (drizzleclient_field_count(drizzle) && ((res= drizzleclient_store_result(drizzle)) == 0))
5052
5052
    {
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);
5055
5055
      goto end;
5056
5056
    }
5057
5057
 
5061
5061
 
5062
5062
      if (res)
5063
5063
      {
5064
 
        const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
5065
 
        uint num_fields= drizzle_num_fields(res);
 
5064
        const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
 
5065
        uint32_t num_fields= drizzleclient_num_fields(res);
5066
5066
 
5067
5067
        if (display_metadata)
5068
5068
          append_metadata(ds, fields, num_fields);
5074
5074
      }
5075
5075
 
5076
5076
      /*
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
5079
5079
      */
5080
5080
      if (!disable_info)
5081
 
        affected_rows= drizzle_affected_rows(drizzle);
 
5081
        affected_rows= drizzleclient_affected_rows(drizzle);
5082
5082
 
5083
5083
      /*
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.
5087
5087
      */
5088
 
      if (!disable_warnings && !drizzle_more_results(drizzle))
 
5088
      if (!disable_warnings && !drizzleclient_more_results(drizzle))
5089
5089
      {
5090
5090
        if (append_warnings(ds_warnings, drizzle) || ds_warnings->length())
5091
5091
        {
5095
5095
      }
5096
5096
 
5097
5097
      if (!disable_info)
5098
 
        append_info(ds, affected_rows, drizzle_info(drizzle));
 
5098
        append_info(ds, affected_rows, drizzleclient_info(drizzle));
5099
5099
    }
5100
5100
 
5101
5101
    if (res)
5102
5102
    {
5103
 
      drizzle_free_result(res);
 
5103
      drizzleclient_free_result(res);
5104
5104
      res= 0;
5105
5105
    }
5106
5106
    counter++;
5107
 
  } while (!(err= drizzle_next_result(drizzle)));
 
5107
  } while (!(err= drizzleclient_next_result(drizzle)));
5108
5108
  if (err > 0)
5109
5109
  {
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);
5113
5113
    goto end;
5114
5114
  }
5115
5115
  assert(err == -1); /* Successful and there are no more results */
5120
5120
end:
5121
5121
 
5122
5122
  /*
5123
 
    We save the return code (drizzle_errno(drizzle)) from the last call sent
5124
 
    to the server into the drizzletest builtin variable $drizzle_errno. This
 
5123
    We save the return code (drizzleclient_errno(drizzle)) from the last call sent
 
5124
    to the server into the drizzletest builtin variable $drizzleclient_errno. This
5125
5125
    variable then can be used from the test case itself.
5126
5126
  */
5127
 
  var_set_errno(drizzle_errno(drizzle));
 
5127
  var_set_errno(drizzleclient_errno(drizzle));
5128
5128
  return;
5129
5129
}
5130
5130
 
5149
5149
                  unsigned int err_errno, const char *err_error,
5150
5150
                  const char *err_sqlstate, string *ds)
5151
5151
{
5152
 
  uint i;
 
5152
  uint32_t i;
5153
5153
 
5154
5154
 
5155
5155
  if (command->require_file[0])
5172
5172
  if (command->abort_on_error)
5173
5173
    die("query '%s' failed: %d: %s", command->query, err_errno, err_error);
5174
5174
 
5175
 
  for (i= 0 ; (uint) i < command->expected_errors.count ; i++)
 
5175
  for (i= 0 ; (uint32_t) i < command->expected_errors.count ; i++)
5176
5176
  {
5177
5177
    if (((command->expected_errors.err[i].type == ERR_ERRNO) &&
5178
5178
         (command->expected_errors.err[i].code.errnum == err_errno)) ||
5373
5373
static void get_command_type(struct st_command* command)
5374
5374
{
5375
5375
  char save;
5376
 
  uint type;
 
5376
  uint32_t type;
5377
5377
 
5378
5378
 
5379
5379
  if (*command->query == '}')
5492
5492
{
5493
5493
  struct st_command *command;
5494
5494
  bool q_send_flag= 0, abort_flag= 0;
5495
 
  uint command_executed= 0, last_command_executed= 0;
 
5495
  uint32_t command_executed= 0, last_command_executed= 0;
5496
5496
  char save_file[FN_REFLEN];
5497
5497
  struct stat res_info;
5498
5498
  MY_INIT(argv[0]);
5527
5527
                1024, 0, 0, get_var_key, var_free, MYF(0)))
5528
5528
    die("Variable hash initialization failed");
5529
5529
 
5530
 
  var_set_string("$DRIZZLE_SERVER_VERSION", drizzle_get_client_info());
 
5530
  var_set_string("$DRIZZLE_SERVER_VERSION", drizzleclient_get_client_info());
5531
5531
 
5532
5532
  memset(&master_pos, 0, sizeof(master_pos));
5533
5533
 
5552
5552
    cur_file->lineno= 1;
5553
5553
  }
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);
5560
5560
 
5561
5561
  if (!(cur_con->name = strdup("default")))
5562
5562
    die("Out of memory");
5568
5568
  timer_start= timer_now();
5569
5569
 
5570
5570
  /*
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
5574
5574
  */
5575
5575
  var_set_errno(-1);
5576
5576
 
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);
5579
5579
 
5580
5580
  if (opt_include)
5581
5581
  {
5763
5763
        command->last_argument= command->end;
5764
5764
        break;
5765
5765
      case Q_PING:
5766
 
        (void) drizzle_ping(&cur_con->drizzle);
 
5766
        (void) drizzleclient_ping(&cur_con->drizzle);
5767
5767
        break;
5768
5768
      case Q_EXEC:
5769
5769
        do_exec(command);
5997
5997
  while (*from)
5998
5998
  {
5999
5999
    char *to;
6000
 
    uint column_number;
 
6000
    uint32_t column_number;
6001
6001
 
6002
6002
    to= get_string(&buff, &from, command);
6003
6003
    if (!(column_number= atoi(to)) || column_number > MAX_COLUMNS)
6018
6018
 
6019
6019
void free_replace_column()
6020
6020
{
6021
 
  uint i;
 
6021
  uint32_t i;
6022
6022
  for (i=0 ; i < max_replace_column ; i++)
6023
6023
  {
6024
6024
    if (replace_column[i])
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;
6047
6047
 
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,
6065
6065
 
6066
6066
void do_get_replace(struct st_command *command)
6067
6067
{
6068
 
  uint i;
 
6068
  uint32_t i;
6069
6069
  char *from= command->first_argument;
6070
6070
  char *buff, *start;
6071
6071
  char word_end_chars[256], *pos;
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);
6127
6127
typedef struct st_replace_found {
6128
6128
  bool found;
6129
6129
  char *replace_string;
6130
 
  uint to_offset;
 
6130
  uint32_t to_offset;
6131
6131
  int from_offset;
6132
6132
} REPLACE_STRING;
6133
6133
 
6253
6253
  char* buf,*expr_end;
6254
6254
  char* p;
6255
6255
  char* buf_p;
6256
 
  uint expr_len= strlen(expr);
 
6256
  uint32_t expr_len= strlen(expr);
6257
6257
  char last_c = 0;
6258
6258
  struct st_regex reg;
6259
6259
 
6349
6349
 
6350
6350
static int multi_reg_replace(struct st_replace_regex* r,char* val)
6351
6351
{
6352
 
  uint i;
 
6352
  uint32_t i;
6353
6353
  char* in_buf, *out_buf;
6354
6354
  int* buf_len_p;
6355
6355
 
6483
6483
 
6484
6484
 
6485
6485
#ifndef WORD_BIT
6486
 
#define WORD_BIT (8*sizeof(uint))
 
6486
#define WORD_BIT (8*sizeof(uint32_t))
6487
6487
#endif
6488
6488
 
6489
6489
#define SET_MALLOC_HUNC 64
6490
6490
#define LAST_CHAR_CODE 259
6491
6491
 
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;
6497
 
  uint  table_offset;
6498
 
  uint  size_of_bits;      /* For convinience */
 
6497
  uint32_t  table_offset;
 
6498
  uint32_t  size_of_bits;      /* For convinience */
6499
6499
} REP_SET;
6500
6500
 
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 */
6505
 
  uint    size_of_bits;
 
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
 
  uint    *bit_buffer;
 
6507
  uint32_t    *bit_buffer;
6508
6508
} REP_SETS;
6509
6509
 
6510
6510
typedef struct st_found_set {
6511
 
  uint table_offset;
 
6511
  uint32_t table_offset;
6512
6512
  int found_offset;
6513
6513
} FOUND_SET;
6514
6514
 
6515
6515
typedef struct st_follow {
6516
6516
  int chr;
6517
 
  uint table_offset;
6518
 
  uint len;
 
6517
  uint32_t table_offset;
 
6518
  uint32_t len;
6519
6519
} FOLLOWS;
6520
6520
 
6521
6521
 
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);
6538
 
 
6539
 
static uint found_sets=0;
6540
 
 
6541
 
 
6542
 
static uint replace_len(char * str)
 
6536
uint32_t start_at_word(char * pos);
 
6537
uint32_t end_of_word(char * pos);
 
6538
 
 
6539
static uint32_t found_sets=0;
 
6540
 
 
6541
 
 
6542
static uint32_t replace_len(char * str)
6543
6543
{
6544
 
  uint len=0;
 
6544
  uint32_t len=0;
6545
6545
  while (*str)
6546
6546
  {
6547
6547
    if (str[0] == '\\' && str[1])
6554
6554
 
6555
6555
/* Init a replace structure for further calls */
6556
6556
 
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)
6559
6559
{
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;
6563
6563
 
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;
6583
6583
      return(0);
6584
6584
    }
6585
6585
    states+=len+1;
6586
 
    result_len+=(uint) strlen(to[i])+1;
 
6586
    result_len+=(uint32_t) strlen(to[i])+1;
6587
6587
    if (len > max_length)
6588
6588
      max_length=len;
6589
6589
  }
6681
6681
    follow_ptr->table_offset=i;
6682
6682
    follow_ptr->len=len;
6683
6683
    follow_ptr++;
6684
 
    states+=(uint) len+1;
 
6684
    states+=(uint32_t) len+1;
6685
6685
  }
6686
6686
 
6687
6687
 
6839
6839
}
6840
6840
 
6841
6841
 
6842
 
int init_sets(REP_SETS *sets,uint states)
 
6842
int init_sets(REP_SETS *sets,uint32_t states)
6843
6843
{
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)))
6847
6847
    return 1;
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)))
6850
6850
  {
6851
6851
    free(sets->set);
6865
6865
 
6866
6866
REP_SET *make_new_set(REP_SETS *sets)
6867
6867
{
6868
 
  uint i,count,*bit_buffer;
 
6868
  uint32_t i,count,*bit_buffer;
6869
6869
  REP_SET *set;
6870
6870
  if (sets->extra)
6871
6871
  {
6872
6872
    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;
6886
6886
  sets->set_buffer=set;
6887
6887
  sets->set=set+sets->invisible;
6888
6888
  if (!(bit_buffer=(uint*) realloc((unsigned char*) sets->bit_buffer,
6889
 
                                   (sizeof(uint)*sets->size_of_bits)*count)))
 
6889
                                   (sizeof(uint32_t)*sets->size_of_bits)*count)))
6890
6890
    return 0;
6891
6891
  sets->bit_buffer=bit_buffer;
6892
6892
  for (i=0 ; i < count ; i++)
6912
6912
  return;
6913
6913
}
6914
6914
 
6915
 
void internal_set_bit(REP_SET *set, uint bit)
 
6915
void internal_set_bit(REP_SET *set, uint32_t bit)
6916
6916
{
6917
6917
  set->bits[bit / WORD_BIT] |= 1 << (bit % WORD_BIT);
6918
6918
  return;
6919
6919
}
6920
6920
 
6921
 
void internal_clear_bit(REP_SET *set, uint bit)
 
6921
void internal_clear_bit(REP_SET *set, uint32_t bit)
6922
6922
{
6923
6923
  set->bits[bit / WORD_BIT] &= ~ (1 << (bit % WORD_BIT));
6924
6924
  return;
6927
6927
 
6928
6928
void or_bits(REP_SET *to,REP_SET *from)
6929
6929
{
6930
 
  register uint i;
 
6930
  register uint32_t i;
6931
6931
  for (i=0 ; i < to->size_of_bits ; i++)
6932
6932
    to->bits[i]|=from->bits[i];
6933
6933
  return;
6936
6936
void copy_bits(REP_SET *to,REP_SET *from)
6937
6937
{
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));
6940
6940
}
6941
6941
 
6942
6942
int cmp_bits(REP_SET *set1,REP_SET *set2)
6943
6943
{
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);
6945
6945
}
6946
6946
 
6947
6947
 
6948
6948
/* Get next set bit from set. */
6949
6949
 
6950
 
int get_next_bit(REP_SET *set,uint lastpos)
 
6950
int get_next_bit(REP_SET *set,uint32_t lastpos)
6951
6951
{
6952
 
  uint pos,*start,*end,bits;
 
6952
  uint32_t pos,*start,*end,bits;
6953
6953
 
6954
6954
  start=set->bits+ ((lastpos+1) / WORD_BIT);
6955
6955
  end=set->bits + set->size_of_bits;
6959
6959
    bits=start[0];
6960
6960
  if (!bits)
6961
6961
    return 0;
6962
 
  pos=(uint) (start-set->bits)*WORD_BIT;
 
6962
  pos=(uint32_t) (start-set->bits)*WORD_BIT;
6963
6963
  while (! (bits & 1))
6964
6964
  {
6965
6965
    bits>>=1;
6974
6974
 
6975
6975
int find_set(REP_SETS *sets,REP_SET *find)
6976
6976
{
6977
 
  uint i;
 
6977
  uint32_t i;
6978
6978
  for (i=0 ; i < sets->count-1 ; i++)
6979
6979
  {
6980
6980
    if (!cmp_bits(sets->set+i,find))
6993
6993
   set->next[] == -1 is reserved for end without replaces.
6994
6994
*/
6995
6995
 
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)
6997
6997
{
6998
6998
  int i;
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)
7002
7002
      return -i-2;
7008
7008
 
7009
7009
/* Return 1 if regexp starts with \b or ends with \b*/
7010
7010
 
7011
 
uint start_at_word(char * pos)
 
7011
uint32_t start_at_word(char * pos)
7012
7012
{
7013
7013
  return (((!memcmp(pos, "\\b",2) && pos[2]) ||
7014
7014
           !memcmp(pos, "\\^", 2)) ? 1 : 0);
7015
7015
}
7016
7016
 
7017
 
uint end_of_word(char * pos)
 
7017
uint32_t end_of_word(char * pos)
7018
7018
{
7019
7019
  char * end= strchr(pos, '\0');
7020
7020
  return ((end > pos+2 && !memcmp(end-2, "\\b", 2)) ||
7030
7030
 
7031
7031
int insert_pointer_name(POINTER_ARRAY *pa,char * name)
7032
7032
{
7033
 
  uint i,length,old_count;
 
7033
  uint32_t i,length,old_count;
7034
7034
  unsigned char *new_pos;
7035
7035
  const char **new_array;
7036
7036
 
7054
7054
    pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;
7055
7055
    pa->array_allocs=1;
7056
7056
  }
7057
 
  length=(uint) strlen(name)+1;
 
7057
  length=(uint32_t) strlen(name)+1;
7058
7058
  if (pa->length+length >= pa->max_length)
7059
7059
  {
7060
7060
    if (!(new_pos= (unsigned char*)realloc((unsigned char*)pa->str,
7147
7147
  replace_append_mem(ds, val, strlen(val));
7148
7148
}
7149
7149
 
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)
7152
7152
{
7153
7153
  char buff[22]; /* This should be enough for any int */
7154
7154
  char *end= int64_t10_to_str(val, buff, 10);