~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.c

  • Committer: Brian Aker
  • Date: 2008-07-24 01:17:13 UTC
  • mfrom: (202.1.18 codestyle)
  • Revision ID: brian@tangent.org-20080724011713-5jceruz4bd4oawaq
Merge Monty's work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 **/
35
35
 
36
36
#include "client_priv.h"
 
37
#include <my_sys.h>
37
38
#include <m_ctype.h>
38
39
#include <stdarg.h>
39
40
#include <my_dir.h>
49
50
#include <locale.h>
50
51
#endif
51
52
 
52
 
#include <glib.h>
53
 
 
54
53
const char *VER= "14.14";
55
54
 
56
55
/* Don't try to make a nice table if the data is too big */
95
94
 
96
95
#include <readline/readline.h>
97
96
 
 
97
/**
 
98
 Make the old readline interface look like the new one.
 
99
*/
 
100
#ifndef USE_NEW_READLINE_INTERFACE
 
101
typedef CPPFunction rl_completion_func_t;
 
102
typedef Function rl_compentry_func_t;
 
103
#define rl_completion_matches(str, func) \
 
104
  completion_matches((char *)str, (CPFunction *)func)
 
105
#endif
 
106
 
98
107
 
99
108
#if !defined(HAVE_VIDATTR)
100
109
#undef vidattr
153
162
  *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
154
163
static char *histfile;
155
164
static char *histfile_tmp;
156
 
static GString *glob_buffer;
157
 
static GString *processed_prompt= NULL;
158
 
static GString *default_prompt= NULL;
 
165
static DYNAMIC_STRING *glob_buffer;
 
166
static DYNAMIC_STRING *processed_prompt= NULL;
 
167
static char *default_prompt= NULL;
159
168
static char *full_username=0,*part_username=0;
160
169
static int wait_time = 5;
161
170
static STATUS status;
199
208
static int get_options(int argc,char **argv);
200
209
bool get_one_option(int optid, const struct my_option *opt,
201
210
                    char *argument);
202
 
static int com_quit(GString *str,char*),
203
 
  com_go(GString *str,char*), com_ego(GString *str,char*),
204
 
  com_print(GString *str,char*),
205
 
  com_help(GString *str,char*), com_clear(GString *str,char*),
206
 
  com_connect(GString *str,char*), com_status(GString *str,char*),
207
 
  com_use(GString *str,char*), com_source(GString *str, char*),
208
 
  com_rehash(GString *str, char*), com_tee(GString *str, char*),
209
 
  com_notee(GString *str, char*), com_charset(GString *str,char*),
210
 
  com_prompt(GString *str, char*), com_delimiter(GString *str, char*),
211
 
  com_warnings(GString *str, char*), com_nowarnings(GString *str, char*),
212
 
  com_nopager(GString *str, char*), com_pager(GString *str, char*);
 
211
static int com_quit(DYNAMIC_STRING *str,char*),
 
212
  com_go(DYNAMIC_STRING *str,char*), com_ego(DYNAMIC_STRING *str,char*),
 
213
  com_print(DYNAMIC_STRING *str,char*),
 
214
  com_help(DYNAMIC_STRING *str,char*), com_clear(DYNAMIC_STRING *str,char*),
 
215
  com_connect(DYNAMIC_STRING *str,char*), com_status(DYNAMIC_STRING *str,char*),
 
216
  com_use(DYNAMIC_STRING *str,char*), com_source(DYNAMIC_STRING *str, char*),
 
217
  com_rehash(DYNAMIC_STRING *str, char*), com_tee(DYNAMIC_STRING *str, char*),
 
218
  com_notee(DYNAMIC_STRING *str, char*), com_charset(DYNAMIC_STRING *str,char*),
 
219
  com_prompt(DYNAMIC_STRING *str, char*), com_delimiter(DYNAMIC_STRING *str, char*),
 
220
  com_warnings(DYNAMIC_STRING *str, char*), com_nowarnings(DYNAMIC_STRING *str, char*),
 
221
  com_nopager(DYNAMIC_STRING *str, char*), com_pager(DYNAMIC_STRING *str, char*);
213
222
 
214
223
static int read_and_execute(bool interactive);
215
224
static int sql_connect(char *host,char *database,char *user,char *password,
236
245
typedef struct {
237
246
  const char *name;             /* User printable name of the function. */
238
247
  char cmd_char;                /* msql command character */
239
 
  int (*func)(GString *str,char *); /* Function to call to do the job. */
 
248
  int (*func)(DYNAMIC_STRING *str,char *); /* Function to call to do the job. */
240
249
  bool takes_params;            /* Max parameters for command */
241
250
  const char *doc;              /* Documentation for this function.  */
242
251
} COMMANDS;
995
1004
int history_length;
996
1005
static int not_in_history(const char *line);
997
1006
static void initialize_readline (const char *name);
998
 
static void fix_history(GString *final_command);
 
1007
static void fix_history(DYNAMIC_STRING *final_command);
999
1008
 
1000
1009
static COMMANDS *find_command(char *name,char cmd_name);
1001
 
static bool add_line(GString *buffer,char *line,char *in_string,
 
1010
static bool add_line(DYNAMIC_STRING *buffer,char *line,char *in_string,
1002
1011
                     bool *ml_comment);
1003
 
static void remove_cntrl(GString *buffer);
 
1012
static void remove_cntrl(DYNAMIC_STRING *buffer);
1004
1013
static void print_table_data(MYSQL_RES *result);
1005
1014
static void print_table_data_html(MYSQL_RES *result);
1006
1015
static void print_table_data_xml(MYSQL_RES *result);
1023
1032
 
1024
1033
  MY_INIT(argv[0]);
1025
1034
  delimiter_str= delimiter;
1026
 
  default_prompt = g_string_new(g_strdup(getenv("DRIZZLE_PS1") ?
1027
 
                                         getenv("DRIZZLE_PS1") :
1028
 
                                         "drizzle>> "));
1029
 
  current_prompt = g_strdup(default_prompt->str);
1030
 
  processed_prompt = g_string_sized_new(16);
 
1035
  default_prompt= my_strdup(getenv("DRIZZLE_PS1") ?
 
1036
                            getenv("DRIZZLE_PS1") :
 
1037
                            "drizzle>> ", MYF(0));
 
1038
  current_prompt= my_strdup(default_prompt, MYF(0));
 
1039
 
 
1040
  processed_prompt= (DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
 
1041
  init_dynamic_string(processed_prompt, "", 32, 32);
 
1042
 
1031
1043
  prompt_counter=0;
1032
1044
 
1033
1045
  outfile[0]=0;                 // no (default) outfile
1114
1126
 
1115
1127
  put_info("Welcome to the Drizzle client..  Commands end with ; or \\g.",
1116
1128
           INFO_INFO,0,0);
1117
 
  glob_buffer = g_string_sized_new(512);
1118
 
  g_string_printf(glob_buffer,
1119
 
                  "Your Drizzle connection id is %u\nServer version: %s\n",
1120
 
                  mysql_thread_id(&mysql), server_version_string(&mysql));
1121
 
  put_info(glob_buffer->str,INFO_INFO,0,0);
1122
 
  g_string_truncate(glob_buffer,0);
 
1129
 
 
1130
  glob_buffer= (DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
 
1131
  init_dynamic_string(glob_buffer, "", 512, 512);
 
1132
 
 
1133
  /* this is a slight abuse of the DYNAMIC_STRING interface. deal. */
 
1134
  sprintf(glob_buffer->str,
 
1135
          "Your Drizzle connection id is %u\nServer version: %s\n",
 
1136
          mysql_thread_id(&mysql), server_version_string(&mysql));
 
1137
  put_info(glob_buffer->str, INFO_INFO, 0, 0);
 
1138
  dynstr_set(glob_buffer, NULL);
1123
1139
 
1124
1140
  initialize_readline(my_progname);
1125
1141
  if (!status.batch && !quick && !opt_html && !opt_xml)
1126
1142
  {
1127
1143
    /* read-history from file, default ~/.mysql_history*/
1128
1144
    if (getenv("MYSQL_HISTFILE"))
1129
 
      histfile=g_strdup(getenv("MYSQL_HISTFILE"));
 
1145
      histfile= strdup(getenv("MYSQL_HISTFILE"));
1130
1146
    else if (getenv("HOME"))
1131
1147
    {
1132
1148
      histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
1187
1203
 
1188
1204
  if (sig >= 0)
1189
1205
    put_info(sig ? "Aborted" : "Bye", INFO_RESULT,0,0);
1190
 
  assert(glob_buffer != NULL);
1191
 
  g_string_free(glob_buffer,true);
1192
 
  assert(processed_prompt != NULL);
1193
 
  g_string_free(processed_prompt,true);
1194
 
  assert(default_prompt != NULL);
1195
 
  g_string_free(default_prompt,true);
 
1206
  if (glob_buffer)
 
1207
    dynstr_free(glob_buffer);
 
1208
  my_free(glob_buffer, MYF(MY_ALLOW_ZERO_PTR));
 
1209
  if (processed_prompt)
 
1210
    dynstr_free(processed_prompt);
 
1211
  my_free(processed_prompt,MYF(MY_ALLOW_ZERO_PTR));
1196
1212
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
1197
1213
  my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR));
1198
1214
  my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
1546
1562
                                    opt->name);
1547
1563
    break;
1548
1564
  case OPT_SERVER_ARG:
1549
 
#ifdef EMBEDDED_LIBRARY
1550
 
    /*
1551
 
      When the embedded server is being tested, the client needs to be
1552
 
      able to pass command-line arguments to the embedded server so it can
1553
 
      locate the language files and data directory.
1554
 
    */
1555
 
    if (!embedded_server_arg_count)
1556
 
    {
1557
 
      embedded_server_arg_count= 1;
1558
 
      embedded_server_args[0]= (char*) "";
1559
 
    }
1560
 
    if (embedded_server_arg_count == MAX_SERVER_ARGS-1 ||
1561
 
        !(embedded_server_args[embedded_server_arg_count++]=
1562
 
          g_strdup(argument)))
1563
 
    {
1564
 
      put_info("Can't use server argument", INFO_ERROR);
1565
 
      return 0;
1566
 
    }
1567
 
#else /*EMBEDDED_LIBRARY */
1568
1565
    printf("WARNING: --server-arg option not supported in this configuration.\n");
1569
 
#endif
1570
1566
    break;
1571
1567
  case 'A':
1572
1568
    opt_rehash= 0;
1595
1591
    {
1596
1592
      char *start= argument;
1597
1593
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1598
 
      opt_password= g_strdup(argument);
 
1594
      opt_password= strdup(argument);
1599
1595
      while (*argument) *argument++= 'x';               // Destroy argument
1600
1596
      if (*start)
1601
1597
        start[1]=0 ;
1687
1683
  {
1688
1684
    skip_updates= 0;
1689
1685
    my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
1690
 
    current_db= g_strdup(*argv);
 
1686
    current_db= strdup(*argv);
1691
1687
  }
1692
1688
  if (tty_password)
1693
1689
    opt_password= get_tty_password(NullS);
1724
1720
          (uchar) line[2] == 0xBF)
1725
1721
        line+= 3;
1726
1722
      line_number++;
1727
 
      if (glob_buffer->len!=0)
 
1723
      if (glob_buffer->length!=0)
1728
1724
        status.query_start_line=line_number;
1729
1725
    }
1730
1726
    else
1731
1727
    {
1732
1728
      char *prompt= (char*) (ml_comment ? "   /*> " :
1733
 
                             (glob_buffer->len == 0) ?  construct_prompt() :
 
1729
                             (glob_buffer->length == 0) ?  construct_prompt() :
1734
1730
                             !in_string ? "    -> " :
1735
1731
                             in_string == '\'' ?
1736
1732
                             "    '> " : (in_string == '`' ?
1737
1733
                                          "    `> " :
1738
1734
                                          "    \"> "));
1739
 
      if (opt_outfile && (glob_buffer->len==0))
 
1735
      if (opt_outfile && (glob_buffer->length==0))
1740
1736
        fflush(OUTFILE);
1741
1737
 
1742
1738
      if (opt_outfile)
1760
1756
      Check if line is a mysql command line
1761
1757
      (We want to allow help, print and clear anywhere at line start
1762
1758
    */
1763
 
    if ((named_cmds || (glob_buffer->len==0))
 
1759
    if ((named_cmds || (glob_buffer->length==0))
1764
1760
        && !ml_comment && !in_string && (com=find_command(line,0)))
1765
1761
    {
1766
1762
      if ((*com->func)(glob_buffer,line) > 0)
1767
1763
        break;
1768
1764
      // If buffer was emptied
1769
 
      if (glob_buffer->len==0)
 
1765
      if (glob_buffer->length==0)
1770
1766
        in_string=0;
1771
1767
      if (interactive && status.add_to_history && not_in_history(line))
1772
1768
        add_history(line);
1780
1776
  if (!interactive && !status.exit_status)
1781
1777
  {
1782
1778
    remove_cntrl(glob_buffer);
1783
 
    if (glob_buffer->len != 0)
 
1779
    if (glob_buffer->length != 0)
1784
1780
    {
1785
1781
      status.exit_status=1;
1786
1782
      if (com_go(glob_buffer,line) <= 0)
1842
1838
}
1843
1839
 
1844
1840
 
1845
 
static bool add_line(GString *buffer,char *line,char *in_string,
 
1841
static bool add_line(DYNAMIC_STRING *buffer,char *line,char *in_string,
1846
1842
                        bool *ml_comment)
1847
1843
{
1848
1844
  uchar inchar;
1852
1848
  bool ss_comment= 0;
1853
1849
 
1854
1850
 
1855
 
  if (!line[0] && (buffer->len==0))
 
1851
  if (!line[0] && (buffer->length==0))
1856
1852
    return(0);
1857
1853
  if (status.add_to_history && line[0] && not_in_history(line))
1858
1854
    add_history(line);
1864
1860
    {
1865
1861
      // Skip spaces at the beggining of a statement
1866
1862
      if (my_isspace(charset_info,inchar) && (out == line) &&
1867
 
          (buffer->len==0))
 
1863
          (buffer->length==0))
1868
1864
        continue;
1869
1865
    }
1870
1866
 
1903
1899
        // Flush previously accepted characters
1904
1900
        if (out != line)
1905
1901
        {
1906
 
          g_string_append_len(buffer, line, (gssize) (out-line));
 
1902
          dynstr_append_mem(buffer, line, (out-line));
1907
1903
          out= line;
1908
1904
        }
1909
1905
 
1953
1949
      // Flush previously accepted characters
1954
1950
      if (out != line)
1955
1951
      {
1956
 
        g_string_append_len(buffer, line, (gssize) (out - line));
 
1952
        dynstr_append_mem(buffer, line, (out - line));
1957
1953
        out= line;
1958
1954
      }
1959
1955
 
1960
1956
      // Flush possible comments in the buffer
1961
 
      if (buffer->len != 0)
 
1957
      if (buffer->length != 0)
1962
1958
      {
1963
1959
        if (com_go(buffer, 0) > 0) // < 0 is not fatal
1964
1960
          return(1);
1965
1961
        assert(buffer!=NULL);
1966
 
        g_string_truncate(buffer,0);
 
1962
        dynstr_set(buffer, NULL);
1967
1963
      }
1968
1964
 
1969
1965
      /*
1970
1966
        Delimiter wants the get rest of the given line as argument to
1971
1967
        allow one to change ';' to ';;' and back
1972
1968
      */
1973
 
      g_string_append(buffer,pos);
 
1969
      dynstr_append(buffer,pos);
1974
1970
      if (com_delimiter(buffer, pos) > 0)
1975
1971
        return(1);
1976
1972
 
1977
 
      g_string_truncate(buffer,0);
 
1973
      dynstr_set(buffer, NULL);
1978
1974
      break;
1979
1975
    }
1980
1976
    else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
1990
1986
      // Flush previously accepted characters
1991
1987
      if (out != line)
1992
1988
      {
1993
 
        g_string_append_len(buffer, line, (gssize) (out-line));
 
1989
        dynstr_append_mem(buffer, line, (out-line));
1994
1990
        out= line;
1995
1991
      }
1996
1992
 
2000
1996
                                 my_isspace(charset_info, pos[2]))))
2001
1997
      {
2002
1998
        // Add trailing single line comments to this statement
2003
 
        g_string_append(buffer, pos);
 
1999
        dynstr_append(buffer, pos);
2004
2000
        pos+= strlen(pos);
2005
2001
      }
2006
2002
 
2017
2013
        if (com_go(buffer, 0) > 0)             // < 0 is not fatal
2018
2014
          return(1);
2019
2015
      }
2020
 
      g_string_truncate(buffer,0);
 
2016
      dynstr_set(buffer, NULL);
2021
2017
    }
2022
2018
    else if (!*ml_comment
2023
2019
             && (!*in_string
2029
2025
      // Flush previously accepted characters
2030
2026
      if (out != line)
2031
2027
      {
2032
 
        g_string_append_len(buffer, line, (gssize) (out - line));
 
2028
        dynstr_append_mem(buffer, line, (out - line));
2033
2029
        out= line;
2034
2030
      }
2035
2031
 
2036
2032
      // comment to end of line
2037
2033
      if (preserve_comments)
2038
 
        g_string_append(buffer,pos);
 
2034
        dynstr_append(buffer,pos);
2039
2035
 
2040
2036
      break;
2041
2037
    }
2052
2048
      *ml_comment= 1;
2053
2049
      if (out != line)
2054
2050
      {
2055
 
        g_string_append_len(buffer, line, (gssize) (out-line));
 
2051
        dynstr_append_mem(buffer, line, (out-line));
2056
2052
        out=line;
2057
2053
      }
2058
2054
    }
2068
2064
      *ml_comment= 0;
2069
2065
      if (out != line)
2070
2066
      {
2071
 
        g_string_append_len(buffer, line, (gssize) (out - line));
 
2067
        dynstr_append_mem(buffer, line, (out - line));
2072
2068
        out= line;
2073
2069
      }
2074
2070
      // Consumed a 2 chars or more, and will add 1 at most,
2097
2093
      }
2098
2094
    }
2099
2095
  }
2100
 
  if (out != line || (buffer->len > 0))
 
2096
  if (out != line || (buffer->length > 0))
2101
2097
  {
2102
2098
    *out++='\n';
2103
2099
    uint length=(uint) (out-line);
2104
2100
    if ((!*ml_comment || preserve_comments)
2105
 
        && (g_string_append_len(buffer, line, length) == NULL))
 
2101
        && dynstr_append_mem(buffer, line, length))
2106
2102
      return(1);
2107
2103
  }
2108
2104
  return(0);
2113
2109
******************************************************************/
2114
2110
 
2115
2111
 
 
2112
static char **mysql_completion (const char *text, int start, int end);
2116
2113
static char *new_command_generator(const char *text, int);
2117
 
extern char **new_mysql_completion (const char *text, int start, int end);
 
2114
 
2118
2115
 
2119
2116
/*
2120
2117
  Tell the GNU Readline library how to complete.  We want to try to complete
2121
2118
  on command names if this is the first word in the line, or on filenames
2122
2119
  if not.
2123
2120
*/
2124
 
 
2125
 
#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE)
2126
 
extern char *no_completion(const char*,int);
2127
 
#else
2128
 
char *no_completion(void);
2129
 
char *no_completion(void)
 
2121
static char *no_completion(const char * a __attribute__((unused)),
 
2122
                           int b __attribute__((unused)))
2130
2123
{
2131
2124
  /* No filename completion */
2132
2125
  return 0;
2133
2126
}
2134
 
#endif
 
2127
 
2135
2128
 
2136
2129
/* glues pieces of history back together if in pieces   */
2137
 
static void fix_history(GString *final_command)
 
2130
static void fix_history(DYNAMIC_STRING *final_command)
2138
2131
{
2139
2132
  int total_lines = 1;
2140
2133
  const char *ptr = final_command->str;
 
2134
  char str_char = '\0';  /* Character if we are in a string or not */
 
2135
 
2141
2136
  /* Converted buffer */
2142
 
  GString * fixed_buffer;
2143
 
  fixed_buffer = g_string_sized_new(16);
2144
 
  char str_char = '\0';  /* Character if we are in a string or not */
 
2137
  DYNAMIC_STRING *fixed_buffer=
 
2138
    (DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
 
2139
 
 
2140
  init_dynamic_string(fixed_buffer, "", 512, 512);
2145
2141
 
2146
2142
  /* find out how many lines we have and remove newlines */
2147
2143
  while (*ptr != '\0')
2156
2152
        str_char = *ptr;
2157
2153
      else if (str_char == *ptr)   /* close string */
2158
2154
        str_char = '\0';
2159
 
      g_string_append_len(fixed_buffer, ptr, 1);
 
2155
      dynstr_append_mem(fixed_buffer, ptr, 1);
2160
2156
      break;
2161
2157
    case '\n':
2162
2158
      /*
2163
2159
        not in string, change to space
2164
2160
        if in string, leave it alone
2165
2161
      */
2166
 
      g_string_append(fixed_buffer,(str_char == '\0') ? " " : "\n");
 
2162
      dynstr_append(fixed_buffer,(str_char == '\0') ? " " : "\n");
2167
2163
      total_lines++;
2168
2164
      break;
2169
2165
    case '\\':
2170
 
      g_string_append_c(fixed_buffer, '\\');
 
2166
      dynstr_append(fixed_buffer, "\\");
2171
2167
      /* need to see if the backslash is escaping anything */
2172
2168
      if (str_char)
2173
2169
      {
2174
2170
        ptr++;
2175
2171
        /* special characters that need escaping */
2176
2172
        if (*ptr == '\'' || *ptr == '"' || *ptr == '\\')
2177
 
          g_string_append_len(fixed_buffer, ptr, 1);
 
2173
          dynstr_append_mem(fixed_buffer, ptr, 1);
2178
2174
        else
2179
2175
          ptr--;
2180
2176
      }
2181
2177
      break;
2182
2178
    default:
2183
 
      g_string_append_len(fixed_buffer, ptr, 1);
 
2179
      dynstr_append_mem(fixed_buffer, ptr, 1);
2184
2180
    }
2185
2181
    ptr++;
2186
2182
  }
2206
2202
static void initialize_readline (const char *name)
2207
2203
{
2208
2204
  /* Allow conditional parsing of the ~/.inputrc file. */
2209
 
  rl_readline_name= name;
 
2205
  rl_readline_name= (char *)name;
2210
2206
 
2211
2207
  /* Tell the completer that we want a crack first. */
2212
 
  rl_attempted_completion_function= (rl_completion_func_t*)&new_mysql_completion;
 
2208
  rl_attempted_completion_function= (rl_completion_func_t*)&mysql_completion;
2213
2209
  rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
2214
2210
}
2215
2211
 
 
2212
 
2216
2213
/*
2217
2214
  Attempt to complete on the contents of TEXT.  START and END show the
2218
2215
  region of TEXT that contains the word to complete.  We can use the
2219
2216
  entire line in case we want to do some simple parsing.  Return the
2220
2217
  array of matches, or NULL if there aren't any.
2221
2218
*/
2222
 
 
2223
 
char **new_mysql_completion (const char *text,
2224
 
                             int start __attribute__((unused)),
2225
 
                             int end __attribute__((unused)))
 
2219
char **mysql_completion (const char *text,
 
2220
                        int start __attribute__((unused)),
 
2221
                        int end __attribute__((unused)))
2226
2222
{
2227
2223
  if (!status.batch && !quick)
2228
2224
    return rl_completion_matches(text, new_command_generator);
2230
2226
    return (char**) 0;
2231
2227
}
2232
2228
 
 
2229
 
2233
2230
static char *new_command_generator(const char *text,int state)
2234
2231
{
2235
2232
  static int textlen;
2255
2252
 
2256
2253
    if (e)
2257
2254
    {
2258
 
      ptr= g_strdup(e->str);
 
2255
      ptr= strdup(e->str);
2259
2256
      e = e->pNext;
2260
2257
      return ptr;
2261
2258
    }
2280
2277
    while (e && !ptr)
2281
2278
    {                                   /* find valid entry in bucket */
2282
2279
      if ((uint) strlen(e->str) == b->nKeyLength)
2283
 
        ptr = g_strdup(e->str);
 
2280
        ptr = strdup(e->str);
2284
2281
      /* find the next used entry */
2285
2282
      e = e->pNext;
2286
2283
      if (!e)
2465
2462
  if (opt_reconnect)
2466
2463
  {
2467
2464
    put_info("No connection. Trying to reconnect...",INFO_INFO,0,0);
2468
 
    (void) com_connect((GString *) 0, 0);
 
2465
    (void) com_connect((DYNAMIC_STRING *) 0, 0);
2469
2466
    if (opt_rehash)
2470
2467
      com_rehash(NULL, NULL);
2471
2468
  }
2487
2484
  {
2488
2485
    MYSQL_ROW row= mysql_fetch_row(res);
2489
2486
    if (row[0])
2490
 
      current_db= g_strdup(row[0]);
 
2487
      current_db= strdup(row[0]);
2491
2488
    mysql_free_result(res);
2492
2489
  }
2493
2490
}
2534
2531
}
2535
2532
 
2536
2533
 
2537
 
static int com_server_help(GString *buffer,
 
2534
static int com_server_help(DYNAMIC_STRING *buffer,
2538
2535
                           char *line __attribute__((unused)),
2539
2536
                           char *help_arg)
2540
2537
{
2626
2623
}
2627
2624
 
2628
2625
static int
2629
 
com_help(GString *buffer __attribute__((unused)),
 
2626
com_help(DYNAMIC_STRING *buffer __attribute__((unused)),
2630
2627
         char *line __attribute__((unused)))
2631
2628
{
2632
2629
  register int i, j;
2658
2655
 
2659
2656
 
2660
2657
static int
2661
 
com_clear(GString *buffer,char *line __attribute__((unused)))
 
2658
com_clear(DYNAMIC_STRING *buffer,char *line __attribute__((unused)))
2662
2659
{
2663
2660
  if (status.add_to_history)
2664
2661
    fix_history(buffer);
2665
 
  g_string_truncate(buffer, 0);
 
2662
  dynstr_set(buffer, NULL);
2666
2663
  return 0;
2667
2664
}
2668
2665
 
2669
2666
static int
2670
 
com_charset(GString *buffer __attribute__((unused)), char *line)
 
2667
com_charset(DYNAMIC_STRING *buffer __attribute__((unused)), char *line)
2671
2668
{
2672
2669
  char buff[256], *param;
2673
2670
  CHARSET_INFO * new_cs;
2698
2695
  1  if fatal error
2699
2696
*/
2700
2697
static int
2701
 
com_go(GString *buffer,
 
2698
com_go(DYNAMIC_STRING *buffer,
2702
2699
       char *line __attribute__((unused)))
2703
2700
{
2704
2701
  char          buff[200]; /* about 110 chars used so far */
2713
2710
  /* Remove garbage for nicer messages */
2714
2711
  remove_cntrl(buffer);
2715
2712
 
2716
 
  if (buffer->len == 0)
 
2713
  if (buffer->length == 0)
2717
2714
  {
2718
2715
    // Ignore empty quries
2719
2716
    if (status.batch)
2724
2721
  if (!connected && reconnect())
2725
2722
  {
2726
2723
    // Remove query on error
2727
 
    g_string_truncate(buffer, 0);
 
2724
    dynstr_set(buffer, NULL);
2728
2725
    return opt_reconnect ? -1 : 1;          // Fatal error
2729
2726
  }
2730
2727
  if (verbose)
2731
2728
    (void) com_print(buffer, 0);
2732
2729
 
2733
2730
  if (skip_updates &&
2734
 
      ((buffer->len < 4)
2735
 
      || g_string_equal(g_string_new_len(buffer->str,4),
2736
 
                        g_string_new("SET "))))
 
2731
      ((buffer->length < 4) || !strncmp(buffer->str, "SET ", 4)))
2737
2732
  {
2738
2733
    (void) put_info("Ignoring query to other database",INFO_INFO,0,0);
2739
2734
    return 0;
2741
2736
 
2742
2737
  timer=start_timer();
2743
2738
  executing_query= 1;
2744
 
  error= mysql_real_query_for_lazy(buffer->str,buffer->len);
 
2739
  error= mysql_real_query_for_lazy(buffer->str,buffer->length);
2745
2740
 
2746
2741
  if (status.add_to_history)
2747
2742
  {
2748
 
    g_string_append(buffer, vertical ? "\\G" : delimiter);
 
2743
    dynstr_append(buffer, vertical ? "\\G" : delimiter);
2749
2744
    /* Append final command onto history */
2750
2745
    fix_history(buffer);
2751
2746
  }
2752
2747
 
2753
 
  g_string_truncate(buffer, 0);
 
2748
  dynstr_set(buffer, NULL);
2754
2749
 
2755
2750
  if (error)
2756
2751
    goto end;
2914
2909
 
2915
2910
 
2916
2911
static int
2917
 
com_ego(GString *buffer,char *line)
 
2912
com_ego(DYNAMIC_STRING *buffer,char *line)
2918
2913
{
2919
2914
  int result;
2920
2915
  bool oldvertical=vertical;
3013
3008
static void
3014
3009
print_table_data(MYSQL_RES *result)
3015
3010
{
3016
 
  GString       *separator = g_string_sized_new(256);
3017
3011
  MYSQL_ROW     cur;
3018
3012
  MYSQL_FIELD   *field;
3019
3013
  bool          *num_flag;
 
3014
  DYNAMIC_STRING *separator=
 
3015
    (DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
 
3016
  init_dynamic_string(separator, "", 256, 256);
3020
3017
 
3021
3018
  num_flag=(bool*) my_malloc(sizeof(bool)*mysql_num_fields(result),
3022
3019
                             MYF(MY_WME));
3027
3024
      return;
3028
3025
    mysql_field_seek(result,0);
3029
3026
  }
3030
 
  separator = g_string_append_c(separator, '+');
 
3027
  dynstr_append(separator, "+");
3031
3028
  while ((field = mysql_fetch_field(result)))
3032
3029
  {
3033
3030
    uint length= column_names ? field->name_length : 0;
3041
3038
    field->max_length=length;
3042
3039
    uint x;
3043
3040
    for (x=0; x< (length+2); x++)
3044
 
      g_string_append_c(separator, '-');
3045
 
    g_string_append_c(separator, '+');
 
3041
      dynstr_append(separator, "-");
 
3042
    dynstr_append(separator, "+");
3046
3043
  }
3047
 
  // End marker for \0
3048
 
  // TODO: Huh? Do we need this with GString?
3049
 
  g_string_append_c(separator, '\0');
3050
3044
 
3051
3045
  tee_puts((char*) separator->str, PAGER);
3052
3046
  if (column_names)
3258
3252
  mysql_field_seek(result,0);
3259
3253
 
3260
3254
  tee_fputs("<?xml version=\"1.0\"?>\n\n<resultset statement=\"", PAGER);
3261
 
  xmlencode_print(glob_buffer->str, glob_buffer->len);
 
3255
  xmlencode_print(glob_buffer->str, glob_buffer->length);
3262
3256
  tee_fputs("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
3263
3257
            PAGER);
3264
3258
 
3463
3457
}
3464
3458
 
3465
3459
static int
3466
 
com_tee(GString *buffer __attribute__((__unused__)), char *line )
 
3460
com_tee(DYNAMIC_STRING *buffer __attribute__((__unused__)), char *line )
3467
3461
{
3468
3462
  char file_name[FN_REFLEN], *end, *param;
3469
3463
 
3507
3501
 
3508
3502
 
3509
3503
static int
3510
 
com_notee(GString *buffer __attribute__((unused)),
 
3504
com_notee(DYNAMIC_STRING *buffer __attribute__((unused)),
3511
3505
          char *line __attribute__((unused)))
3512
3506
{
3513
3507
  if (opt_outfile)
3521
3515
*/
3522
3516
 
3523
3517
static int
3524
 
com_pager(GString *buffer __attribute__((__unused__)),
 
3518
com_pager(DYNAMIC_STRING *buffer __attribute__((__unused__)),
3525
3519
          char *line __attribute__((unused)))
3526
3520
{
3527
3521
  char pager_name[FN_REFLEN], *end, *param;
3565
3559
 
3566
3560
 
3567
3561
static int
3568
 
com_nopager(GString *buffer __attribute__((unused)),
 
3562
com_nopager(DYNAMIC_STRING *buffer __attribute__((unused)),
3569
3563
            char *line __attribute__((unused)))
3570
3564
{
3571
3565
  strmov(pager, "stdout");
3578
3572
/* If arg is given, exit without errors. This happens on command 'quit' */
3579
3573
 
3580
3574
static int
3581
 
com_quit(GString *buffer __attribute__((unused)),
 
3575
com_quit(DYNAMIC_STRING *buffer __attribute__((unused)),
3582
3576
         char *line __attribute__((unused)))
3583
3577
{
3584
3578
  /* let the screen auto close on a normal shutdown */
3587
3581
}
3588
3582
 
3589
3583
static int
3590
 
com_rehash(GString *buffer __attribute__((unused)),
 
3584
com_rehash(DYNAMIC_STRING *buffer __attribute__((unused)),
3591
3585
           char *line __attribute__((unused)))
3592
3586
{
3593
3587
  build_completion_hash(1, 0);
3597
3591
 
3598
3592
 
3599
3593
static int
3600
 
com_print(GString *buffer,char *line __attribute__((unused)))
 
3594
com_print(DYNAMIC_STRING *buffer,char *line __attribute__((unused)))
3601
3595
{
3602
3596
  tee_puts("--------------", stdout);
3603
3597
  (void) tee_fputs(buffer->str, stdout);
3604
 
  if ( (buffer->len == 0)
3605
 
       || (buffer->str)[(buffer->len)-1] != '\n')
 
3598
  if ( (buffer->length == 0)
 
3599
       || (buffer->str)[(buffer->length)-1] != '\n')
3606
3600
    tee_putc('\n', stdout);
3607
3601
  tee_puts("--------------\n", stdout);
3608
3602
  /* If empty buffer */
3611
3605
 
3612
3606
/* ARGSUSED */
3613
3607
static int
3614
 
com_connect(GString *buffer, char *line)
 
3608
com_connect(DYNAMIC_STRING *buffer, char *line)
3615
3609
{
3616
3610
  char *tmp, buff[256];
3617
3611
  bool save_rehash= opt_rehash;
3632
3626
    if (tmp && *tmp)
3633
3627
    {
3634
3628
      my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
3635
 
      current_db= g_strdup(tmp);
 
3629
      current_db= strdup(tmp);
3636
3630
      tmp= get_arg(buff, 1);
3637
3631
      if (tmp)
3638
3632
      {
3639
3633
        my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
3640
 
        current_host=g_strdup(tmp);
 
3634
        current_host=strdup(tmp);
3641
3635
      }
3642
3636
    }
3643
3637
    else
3647
3641
    }
3648
3642
    // command used
3649
3643
    assert(buffer!=NULL);
3650
 
    g_string_truncate(buffer, 0);
 
3644
    dynstr_set(buffer, NULL);
3651
3645
  }
3652
3646
  else
3653
3647
    opt_rehash= 0;
3666
3660
}
3667
3661
 
3668
3662
 
3669
 
static int com_source(GString *buffer __attribute__((__unused__)), char *line)
 
3663
static int com_source(DYNAMIC_STRING *buffer __attribute__((__unused__)), char *line)
3670
3664
{
3671
3665
  char source_name[FN_REFLEN], *end, *param;
3672
3666
  LINE_BUFFER *line_buff;
3712
3706
  status.file_name=source_name;
3713
3707
  // Empty command buffer
3714
3708
  assert(glob_buffer!=NULL);
3715
 
  g_string_truncate(glob_buffer, 0);
 
3709
  dynstr_set(glob_buffer, NULL);
3716
3710
  error= read_and_execute(false);
3717
3711
  // Continue as before
3718
3712
  status=old_status;
3724
3718
 
3725
3719
/* ARGSUSED */
3726
3720
static int
3727
 
com_delimiter(GString *buffer __attribute__((unused)), char *line)
 
3721
com_delimiter(DYNAMIC_STRING *buffer __attribute__((unused)), char *line)
3728
3722
{
3729
3723
  char buff[256], *tmp;
3730
3724
 
3754
3748
 
3755
3749
/* ARGSUSED */
3756
3750
static int
3757
 
com_use(GString *buffer __attribute__((unused)), char *line)
 
3751
com_use(DYNAMIC_STRING *buffer __attribute__((unused)), char *line)
3758
3752
{
3759
3753
  char *tmp, buff[FN_REFLEN + 1];
3760
3754
  int select_db;
3816
3810
        return put_error(&mysql);
3817
3811
    }
3818
3812
    my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
3819
 
    current_db=g_strdup(tmp);
 
3813
    current_db= strdup(tmp);
3820
3814
    if (select_db > 1)
3821
3815
      build_completion_hash(opt_rehash, 1);
3822
3816
  }
3826
3820
}
3827
3821
 
3828
3822
static int
3829
 
com_warnings(GString *buffer __attribute__((unused)),
 
3823
com_warnings(DYNAMIC_STRING *buffer __attribute__((unused)),
3830
3824
             char *line __attribute__((unused)))
3831
3825
{
3832
3826
  show_warnings = 1;
3835
3829
}
3836
3830
 
3837
3831
static int
3838
 
com_nowarnings(GString *buffer __attribute__((unused)),
 
3832
com_nowarnings(DYNAMIC_STRING *buffer __attribute__((unused)),
3839
3833
               char *line __attribute__((unused)))
3840
3834
{
3841
3835
  show_warnings = 0;
3997
3991
 
3998
3992
 
3999
3993
static int
4000
 
com_status(GString *buffer __attribute__((unused)),
 
3994
com_status(DYNAMIC_STRING *buffer __attribute__((unused)),
4001
3995
           char *line __attribute__((unused)))
4002
3996
{
4003
3997
  const char *status_str;
4070
4064
    tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
4071
4065
  }
4072
4066
 
4073
 
#ifndef EMBEDDED_LIBRARY
4074
4067
  if (strstr(mysql_get_host_info(&mysql),"TCP/IP") || ! mysql.unix_socket)
4075
4068
    tee_fprintf(stdout, "TCP port:\t\t%d\n", mysql.port);
4076
4069
  else
4077
4070
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", mysql.unix_socket);
4078
4071
  if (mysql.net.compress)
4079
4072
    tee_fprintf(stdout, "Protocol:\t\tCompressed\n");
4080
 
#endif
4081
4073
 
4082
4074
  if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
4083
4075
  {
4224
4216
}
4225
4217
 
4226
4218
 
4227
 
static void remove_cntrl(GString *buffer)
 
4219
static void remove_cntrl(DYNAMIC_STRING *buffer)
4228
4220
{
4229
4221
  char *start=  buffer->str;
4230
 
  char *end= start + (buffer->len);
 
4222
  char *end= start + (buffer->length);
4231
4223
  while (start < end && !my_isgraph(charset_info,end[-1]))
4232
4224
    end--;
4233
4225
  uint chars_to_truncate = end-start;
4234
 
  if (buffer->len > chars_to_truncate)
4235
 
    g_string_truncate(buffer, chars_to_truncate);
 
4226
  if (buffer->length > chars_to_truncate)
 
4227
    dynstr_trunc(buffer, chars_to_truncate);
4236
4228
}
4237
4229
 
4238
4230
 
4347
4339
{
4348
4340
  // Erase the old prompt
4349
4341
  assert(processed_prompt!=NULL);
4350
 
  g_string_truncate(processed_prompt, 0);
 
4342
  dynstr_set(processed_prompt, NULL);
4351
4343
 
4352
4344
  // Get the date struct
4353
4345
  time_t  lclock = time(NULL);
4358
4350
  {
4359
4351
    if (*c != PROMPT_CHAR)
4360
4352
    {
4361
 
      g_string_append_c(processed_prompt, c[0]);
 
4353
      dynstr_append_mem(processed_prompt, c, 1);
4362
4354
    }
4363
4355
    else
4364
4356
    {
4375
4367
        break;
4376
4368
      case 'v':
4377
4369
        if (connected)
4378
 
          g_string_append(processed_prompt, mysql_get_server_info(&mysql));
 
4370
          dynstr_append(processed_prompt, mysql_get_server_info(&mysql));
4379
4371
        else
4380
 
          g_string_append(processed_prompt, "not_connected");
 
4372
          dynstr_append(processed_prompt, "not_connected");
4381
4373
        break;
4382
4374
      case 'd':
4383
 
        g_string_append(processed_prompt, current_db ? current_db : "(none)");
 
4375
        dynstr_append(processed_prompt, current_db ? current_db : "(none)");
4384
4376
        break;
4385
4377
      case 'h':
4386
4378
      {
4387
4379
        const char *prompt;
4388
4380
        prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
4389
4381
        if (strstr(prompt, "Localhost"))
4390
 
          g_string_append(processed_prompt, "localhost");
 
4382
          dynstr_append(processed_prompt, "localhost");
4391
4383
        else
4392
4384
        {
4393
4385
          const char *end=strcend(prompt,' ');
4394
 
          g_string_append_len(processed_prompt, prompt, (gssize) (end-prompt));
 
4386
          dynstr_append_mem(processed_prompt, prompt, (end-prompt));
4395
4387
        }
4396
4388
        break;
4397
4389
      }
4399
4391
      {
4400
4392
        if (!connected)
4401
4393
        {
4402
 
          g_string_append(processed_prompt, "not_connected");
 
4394
          dynstr_append(processed_prompt, "not_connected");
4403
4395
          break;
4404
4396
        }
4405
4397
 
4406
4398
        const char *host_info = mysql_get_host_info(&mysql);
4407
4399
        if (strstr(host_info, "memory"))
4408
4400
        {
4409
 
          g_string_append(processed_prompt, mysql.host );
 
4401
          dynstr_append(processed_prompt, mysql.host);
4410
4402
        }
4411
4403
        else if (strstr(host_info,"TCP/IP") ||
4412
4404
                 !mysql.unix_socket)
4414
4406
        else
4415
4407
        {
4416
4408
          char *pos=strrchr(mysql.unix_socket,'/');
4417
 
          g_string_append(processed_prompt, pos ? pos+1 : mysql.unix_socket);
 
4409
          dynstr_append(processed_prompt, pos ? pos+1 : mysql.unix_socket);
4418
4410
        }
4419
4411
      }
4420
4412
      break;
4421
4413
      case 'U':
4422
4414
        if (!full_username)
4423
4415
          init_username();
4424
 
        g_string_append(processed_prompt, full_username ? full_username :
 
4416
        dynstr_append(processed_prompt, full_username ? full_username :
4425
4417
                        (current_user ?  current_user : "(unknown)"));
4426
4418
        break;
4427
4419
      case 'u':
4428
4420
        if (!full_username)
4429
4421
          init_username();
4430
 
        g_string_append(processed_prompt, part_username ? part_username :
 
4422
        dynstr_append(processed_prompt, part_username ? part_username :
4431
4423
                        (current_user ?  current_user : "(unknown)"));
4432
4424
        break;
4433
4425
      case PROMPT_CHAR:
4434
 
        g_string_append_c(processed_prompt, PROMPT_CHAR);
 
4426
        {
 
4427
          char c= PROMPT_CHAR;
 
4428
          dynstr_append_mem(processed_prompt, &c, 1);
 
4429
        }
4435
4430
        break;
4436
4431
      case 'n':
4437
 
        g_string_append_c(processed_prompt, '\n');
 
4432
        {
 
4433
          char c= '\n';
 
4434
          dynstr_append_mem(processed_prompt, &c, 1);
 
4435
        }
4438
4436
        break;
4439
4437
      case ' ':
4440
4438
      case '_':
4441
 
        g_string_append_c(processed_prompt, ' ');
 
4439
        {
 
4440
          char c= ' ';
 
4441
          dynstr_append_mem(processed_prompt, &c, 1);
 
4442
        }
4442
4443
        break;
4443
4444
      case 'R':
4444
4445
        if (t->tm_hour < 10)
4445
 
          g_string_append_c(processed_prompt, '0');
 
4446
          add_int_to_prompt(0);
4446
4447
        add_int_to_prompt(t->tm_hour);
4447
4448
        break;
4448
4449
      case 'r':
4450
4451
        if (getHour == 0)
4451
4452
          getHour=12;
4452
4453
        if (getHour < 10)
4453
 
          g_string_append_c(processed_prompt, '0');
 
4454
          add_int_to_prompt(0);
4454
4455
        add_int_to_prompt(getHour);
4455
4456
        break;
4456
4457
      case 'm':
4457
4458
        if (t->tm_min < 10)
4458
 
          g_string_append_c(processed_prompt, '0');
 
4459
          add_int_to_prompt(0);
4459
4460
        add_int_to_prompt(t->tm_min);
4460
4461
        break;
4461
4462
      case 'y':
4462
4463
        getYear = t->tm_year % 100;
4463
4464
        if (getYear < 10)
4464
 
          g_string_append_c(processed_prompt, '0');
 
4465
          add_int_to_prompt(0);
4465
4466
        add_int_to_prompt(getYear);
4466
4467
        break;
4467
4468
      case 'Y':
4469
4470
        break;
4470
4471
      case 'D':
4471
4472
        dateTime = ctime(&lclock);
4472
 
        g_string_append(processed_prompt, strtok(dateTime,"\n"));
 
4473
        dynstr_append(processed_prompt, strtok(dateTime,"\n"));
4473
4474
        break;
4474
4475
      case 's':
4475
4476
        if (t->tm_sec < 10)
4476
 
          g_string_append_c(processed_prompt, '0');
 
4477
          add_int_to_prompt(0);
4477
4478
        add_int_to_prompt(t->tm_sec);
4478
4479
        break;
4479
4480
      case 'w':
4480
 
        g_string_append(processed_prompt, (day_names[t->tm_wday]));
 
4481
        dynstr_append(processed_prompt, (day_names[t->tm_wday]));
4481
4482
        break;
4482
4483
      case 'P':
4483
 
        g_string_append(processed_prompt, t->tm_hour < 12 ? "am" : "pm");
 
4484
        dynstr_append(processed_prompt, t->tm_hour < 12 ? "am" : "pm");
4484
4485
        break;
4485
4486
      case 'o':
4486
4487
        add_int_to_prompt(t->tm_mon+1);
4487
4488
        break;
4488
4489
      case 'O':
4489
 
        g_string_append(processed_prompt, month_names[t->tm_mon]);
 
4490
        dynstr_append(processed_prompt, month_names[t->tm_mon]);
4490
4491
        break;
4491
4492
      case '\'':
4492
 
        g_string_append(processed_prompt, "'");
 
4493
        dynstr_append(processed_prompt, "'");
4493
4494
        break;
4494
4495
      case '"':
4495
 
        g_string_append_c(processed_prompt, '"');
 
4496
        dynstr_append(processed_prompt, "\"");
4496
4497
        break;
4497
4498
      case 'S':
4498
 
        g_string_append_c(processed_prompt, ';');
 
4499
        dynstr_append(processed_prompt, ";");
4499
4500
        break;
4500
4501
      case 't':
4501
 
        g_string_append_c(processed_prompt, '\t');
 
4502
        dynstr_append(processed_prompt, "\t");
4502
4503
        break;
4503
4504
      case 'l':
4504
 
        g_string_append(processed_prompt, delimiter_str);
 
4505
        dynstr_append(processed_prompt, delimiter_str);
4505
4506
        break;
4506
4507
      default:
4507
 
        g_string_append(processed_prompt, c);
 
4508
        dynstr_append_mem(processed_prompt, c, 1);
4508
4509
      }
4509
4510
    }
4510
4511
  }
4511
 
  // TODO: Is this needed with GString?
4512
 
  g_string_append_c(processed_prompt, '\0');
4513
4512
  return processed_prompt->str;
4514
4513
}
4515
4514
 
4517
4516
static void add_int_to_prompt(int toadd)
4518
4517
{
4519
4518
  char buffer[16];
4520
 
  int10_to_str(toadd,buffer,10);
4521
 
  g_string_append(processed_prompt, buffer);
 
4519
  int10_to_str(toadd, buffer, 10);
 
4520
  dynstr_append(processed_prompt, buffer);
4522
4521
}
4523
4522
 
4524
4523
static void init_username()
4531
4530
      (result=mysql_use_result(&mysql)))
4532
4531
  {
4533
4532
    MYSQL_ROW cur=mysql_fetch_row(result);
4534
 
    full_username=g_strdup(cur[0]);
4535
 
    part_username=g_strdup(strtok(cur[0],"@"));
 
4533
    full_username= strdup(cur[0]);
 
4534
    part_username= strdup(strtok(cur[0],"@"));
4536
4535
    (void) mysql_fetch_row(result);             // Read eof
4537
4536
  }
4538
4537
}
4539
4538
 
4540
 
static int com_prompt(GString *buffer __attribute__((__unused__)), char *line)
 
4539
static int com_prompt(DYNAMIC_STRING *buffer __attribute__((__unused__)), char *line)
4541
4540
{
4542
4541
  char *ptr=strchr(line, ' ');
4543
4542
  prompt_counter = 0;
4544
4543
  my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
4545
 
  current_prompt=g_strdup(ptr ? ptr+1 : default_prompt->str);
 
4544
  current_prompt= strdup(ptr ? ptr+1 : default_prompt);
4546
4545
  if (!ptr)
4547
4546
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4548
 
                default_prompt->str);
 
4547
                default_prompt);
4549
4548
  else
4550
4549
    tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
4551
4550
  return 0;