~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/readline.c

  • Committer: Monty Taylor
  • Date: 2008-07-22 05:48:51 UTC
  • mto: (202.1.3 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: monty@inaugust.com-20080722054851-airxt73370725p7x
Re-enabled optimizations for the normal build, and added back the --with-debug option to turn them off. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* readline for batch mode */
17
17
 
18
 
#include "client_priv.h"
19
 
#include <mysys/my_sys.h>
20
 
#include <mystrings/m_string.h>
 
18
#include <my_global.h>
 
19
#include <my_sys.h>
 
20
#include <m_string.h>
21
21
#include "my_readline.h"
22
22
 
23
 
static bool init_line_buffer(LINE_BUFFER *buffer,File file,uint32_t size,
24
 
                            uint32_t max_size);
 
23
static bool init_line_buffer(LINE_BUFFER *buffer,File file,ulong size,
 
24
                            ulong max_size);
25
25
static bool init_line_buffer_from_string(LINE_BUFFER *buffer,char * str);
26
26
static size_t fill_buffer(LINE_BUFFER *buffer);
27
 
static char *intern_read_line(LINE_BUFFER *buffer,uint32_t *out_length);
28
 
 
29
 
 
30
 
LINE_BUFFER *batch_readline_init(uint32_t max_size,FILE *file)
 
27
static char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length);
 
28
 
 
29
 
 
30
LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
31
31
{
32
32
  LINE_BUFFER *line_buff;
33
33
  if (!(line_buff=(LINE_BUFFER*)
35
35
    return 0;
36
36
  if (init_line_buffer(line_buff,fileno(file),IO_SIZE,max_size))
37
37
  {
38
 
    free(line_buff);
 
38
    my_free(line_buff,MYF(0));
39
39
    return 0;
40
40
  }
41
41
  return line_buff;
45
45
char *batch_readline(LINE_BUFFER *line_buff)
46
46
{
47
47
  char *pos;
48
 
  uint32_t out_length;
 
48
  ulong out_length;
49
49
 
50
50
  if (!(pos=intern_read_line(line_buff,&out_length)))
51
51
    return 0;
62
62
{
63
63
  if (line_buff)
64
64
  {
65
 
    free(line_buff->buffer);
66
 
    free(line_buff);
 
65
    my_free(line_buff->buffer,MYF(MY_ALLOW_ZERO_PTR));
 
66
    my_free(line_buff,MYF(0));
67
67
  }
68
68
}
69
69
 
76
76
      return 0;
77
77
  if (init_line_buffer_from_string(line_buff,str))
78
78
  {
79
 
    free(line_buff);
 
79
    my_free(line_buff,MYF(0));
80
80
    return 0;
81
81
  }
82
82
  return line_buff;
88
88
******************************************************************************/
89
89
 
90
90
static bool
91
 
init_line_buffer(LINE_BUFFER *buffer,File file,uint32_t size,uint32_t max_buffer)
 
91
init_line_buffer(LINE_BUFFER *buffer,File file,ulong size,ulong max_buffer)
92
92
{
93
93
  buffer->file=file;
94
94
  buffer->bufread=size;
111
111
  uint old_length=(uint)(buffer->end - buffer->buffer);
112
112
  uint length= (uint) strlen(str);
113
113
  if (!(buffer->buffer= buffer->start_of_line= buffer->end_of_line=
114
 
        (char*) my_realloc((unsigned char*) buffer->buffer, old_length+length+2,
 
114
        (char*) my_realloc((uchar*) buffer->buffer, old_length+length+2,
115
115
                           MYF(MY_FAE|MY_ALLOW_ZERO_PTR))))
116
116
    return 1;
117
117
  buffer->end= buffer->buffer + old_length;
161
161
  /* Shift stuff down. */
162
162
  if (buffer->start_of_line != buffer->buffer)
163
163
  {
164
 
    memcpy(buffer->buffer, buffer->start_of_line, (uint) bufbytes);
 
164
    bmove(buffer->buffer,buffer->start_of_line,(uint) bufbytes);
165
165
    buffer->end=buffer->buffer+bufbytes;
166
166
  }
167
167
 
168
168
  /* Read in new stuff. */
169
 
  if ((read_count= my_read(buffer->file, (unsigned char*) buffer->end, read_count,
 
169
  if ((read_count= my_read(buffer->file, (uchar*) buffer->end, read_count,
170
170
                           MYF(MY_WME))) == MY_FILE_ERROR)
171
171
    return (size_t) -1;
172
172
 
184
184
 
185
185
 
186
186
 
187
 
char *intern_read_line(LINE_BUFFER *buffer,uint32_t *out_length)
 
187
char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length)
188
188
{
189
189
  char *pos;
190
190
  size_t length;
207
207
      pos--;                                    /* break line here */
208
208
    }
209
209
    buffer->end_of_line=pos+1;
210
 
    *out_length=(uint32_t) (pos + 1 - buffer->eof - buffer->start_of_line);
 
210
    *out_length=(ulong) (pos + 1 - buffer->eof - buffer->start_of_line);
211
211
    return(buffer->start_of_line);
212
212
  }
213
213
}