~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

Merge Robert's readline/linebuffer work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <algorithm>
39
39
#include <mystrings/m_ctype.h>
40
40
#include <stdarg.h>
41
 
#include "client/my_readline.h"
 
41
#include "client/linebuffer.h"
42
42
#include <signal.h>
43
43
#include <sys/ioctl.h>
44
44
#include <drizzled/configmake.h>
147
147
  int exit_status;
148
148
  uint32_t query_start_line;
149
149
  char *file_name;
150
 
  LINE_BUFFER *line_buff;
 
150
  LineBuffer *line_buff;
151
151
  bool batch,add_to_history;
152
152
} STATUS;
153
153
 
1240
1240
 
1241
1241
  if (status.batch && !status.line_buff)
1242
1242
  {
1243
 
    status.line_buff =batch_readline_init(opt_max_input_line+512, stdin);
 
1243
    status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line, stdin);
1244
1244
    if (status.line_buff == NULL)
1245
1245
    {
1246
1246
      free_defaults(defaults_argv);
1341
1341
    if (!write_history(histfile_tmp))
1342
1342
      my_rename(histfile_tmp, histfile, MYF(MY_WME));
1343
1343
  }
1344
 
  batch_readline_end(status.line_buff);
 
1344
  delete status.line_buff;
 
1345
  status.line_buff= 0;
1345
1346
 
1346
1347
  if (sig >= 0)
1347
1348
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1693
1694
  case 'e':
1694
1695
    status.batch= 1;
1695
1696
    status.add_to_history= 0;
1696
 
    if (!status.line_buff)
1697
 
      ignore_errors= 0;                         // do it for the first -e only
1698
 
    if (!(status.line_buff= batch_readline_command(status.line_buff, argument)))
1699
 
      return 1;
 
1697
    if (status.line_buff == NULL)
 
1698
      status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,NULL);
 
1699
    if (status.line_buff == NULL)
 
1700
    {
 
1701
      my_end(0);
 
1702
      exit(1);
 
1703
    }
 
1704
    status.line_buff->addString(argument);
1700
1705
    break;
1701
1706
  case 'o':
1702
1707
    if (argument == disabled_my_option)
1847
1852
  {
1848
1853
    if (!interactive)
1849
1854
    {
1850
 
      line=batch_readline(status.line_buff);
1851
 
      /*
1852
 
        Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
1853
 
        Editors like "notepad" put this marker in
1854
 
        the very beginning of a text file when
1855
 
        you save the file using "Unicode UTF-8" format.
1856
 
      */
1857
 
      if (!line_number &&
1858
 
          (unsigned char) line[0] == 0xEF &&
1859
 
          (unsigned char) line[1] == 0xBB &&
1860
 
          (unsigned char) line[2] == 0xBF)
1861
 
        line+= 3;
 
1855
      if (status.line_buff)
 
1856
        line= status.line_buff->readline();
 
1857
      else
 
1858
        line= 0;
 
1859
 
1862
1860
      line_number++;
1863
1861
      if (show_progress_size > 0)
1864
1862
      {
1866
1864
          fprintf(stderr, _("Processing line: %"PRIu32"\n"), line_number);
1867
1865
      }
1868
1866
      if (!glob_buffer->empty())
1869
 
        status.query_start_line=line_number;
 
1867
        status.query_start_line= line_number;
1870
1868
    }
1871
1869
    else
1872
1870
    {
3653
3651
{
3654
3652
  char source_name[FN_REFLEN], *end;
3655
3653
  const char *param;
3656
 
  LINE_BUFFER *line_buff;
 
3654
  LineBuffer *line_buff;
3657
3655
  int error;
3658
3656
  STATUS old_status;
3659
3657
  FILE *sql_file;
3681
3679
    return put_info(buff, INFO_ERROR, 0 ,0);
3682
3680
  }
3683
3681
 
3684
 
  if (!(line_buff=batch_readline_init(opt_max_input_line+512,sql_file)))
 
3682
  line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,sql_file);
 
3683
  if (line_buff == NULL)
3685
3684
  {
3686
3685
    fclose(sql_file);
3687
 
    return put_info("Can't initialize batch_readline", INFO_ERROR, 0 ,0);
 
3686
    return put_info("Can't initialize LineBuffer", INFO_ERROR, 0, 0);
3688
3687
  }
3689
3688
 
3690
3689
  /* Save old status */
3702
3701
  // Continue as before
3703
3702
  status=old_status;
3704
3703
  fclose(sql_file);
3705
 
  batch_readline_end(line_buff);
 
3704
  delete status.line_buff;
 
3705
  line_buff= status.line_buff= 0;
3706
3706
  return error;
3707
3707
}
3708
3708