The world's most popular open source database
#include <my_global.h>#include <my_sys.h>#include <m_string.h>#include "my_readline.h"Include dependency graph for readline.cc:

Go to the source code of this file.
Functions | |
| static bool | init_line_buffer (LINE_BUFFER *buffer, File file, ulong size, ulong max_size) |
| static bool | init_line_buffer_from_string (LINE_BUFFER *buffer, my_string str) |
| static uint | fill_buffer (LINE_BUFFER *buffer) |
| static char * | intern_read_line (LINE_BUFFER *buffer, ulong *out_length) |
| LINE_BUFFER * | batch_readline_init (ulong max_size, FILE *file) |
| char * | batch_readline (LINE_BUFFER *line_buff) |
| void | batch_readline_end (LINE_BUFFER *line_buff) |
| LINE_BUFFER * | batch_readline_command (LINE_BUFFER *line_buff, my_string str) |
| char* batch_readline | ( | LINE_BUFFER * | line_buff | ) |
Definition at line 46 of file readline.cc.
References intern_read_line(), out_length, pos(), and st_line_buffer::read_length.
Referenced by read_and_execute().
00047 { 00048 char *pos; 00049 ulong out_length; 00050 00051 if (!(pos=intern_read_line(line_buff,&out_length))) 00052 return 0; 00053 if (out_length && pos[out_length-1] == '\n') 00054 out_length--; /* Remove '\n' */ 00055 line_buff->read_length=out_length; 00056 pos[out_length]=0; 00057 return pos; 00058 }
Here is the call graph for this function:

Here is the caller graph for this function:

| LINE_BUFFER* batch_readline_command | ( | LINE_BUFFER * | line_buff, | |
| my_string | str | |||
| ) |
Definition at line 71 of file readline.cc.
References init_line_buffer_from_string(), my_free, my_malloc(), MY_WME, MY_ZEROFILL, and MYF.
Referenced by get_one_option().
00072 { 00073 if (!line_buff) 00074 if (!(line_buff=(LINE_BUFFER*) 00075 my_malloc(sizeof(*line_buff),MYF(MY_WME | MY_ZEROFILL)))) 00076 return 0; 00077 if (init_line_buffer_from_string(line_buff,str)) 00078 { 00079 my_free((char*) line_buff,MYF(0)); 00080 return 0; 00081 } 00082 return line_buff; 00083 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void batch_readline_end | ( | LINE_BUFFER * | line_buff | ) |
Definition at line 61 of file readline.cc.
References st_line_buffer::buffer, MY_ALLOW_ZERO_PTR, my_free, and MYF.
Referenced by com_source(), and mysql_end().
00062 { 00063 if (line_buff) 00064 { 00065 my_free((gptr) line_buff->buffer,MYF(MY_ALLOW_ZERO_PTR)); 00066 my_free((char*) line_buff,MYF(0)); 00067 } 00068 }
Here is the caller graph for this function:

| LINE_BUFFER* batch_readline_init | ( | ulong | max_size, | |
| FILE * | file | |||
| ) |
Definition at line 31 of file readline.cc.
References init_line_buffer(), IO_SIZE, my_free, my_malloc(), MY_WME, MY_ZEROFILL, and MYF.
Referenced by com_source(), and main().
00032 { 00033 LINE_BUFFER *line_buff; 00034 if (!(line_buff=(LINE_BUFFER*) 00035 my_malloc(sizeof(*line_buff),MYF(MY_WME | MY_ZEROFILL)))) 00036 return 0; 00037 if (init_line_buffer(line_buff,fileno(file),IO_SIZE,max_size)) 00038 { 00039 my_free((char*) line_buff,MYF(0)); 00040 return 0; 00041 } 00042 return line_buff; 00043 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static uint fill_buffer | ( | LINE_BUFFER * | buffer | ) | [static] |
Definition at line 136 of file readline.cc.
References bmove(), bufbytes, buffer, IO_SIZE, MY_FAE, my_realloc(), MY_WME, MYF, and start_offset.
Referenced by fill_and_get_bits(), and intern_read_line().
00137 { 00138 uint read_count; 00139 uint bufbytes= (uint) (buffer->end - buffer->start_of_line); 00140 00141 if (buffer->eof) 00142 return 0; /* Everything read */ 00143 00144 /* See if we need to grow the buffer. */ 00145 00146 for (;;) 00147 { 00148 uint start_offset=(uint) (buffer->start_of_line - buffer->buffer); 00149 read_count=(buffer->bufread - bufbytes)/IO_SIZE; 00150 if ((read_count*=IO_SIZE)) 00151 break; 00152 buffer->bufread *= 2; 00153 if (!(buffer->buffer = (char*) my_realloc(buffer->buffer, 00154 buffer->bufread+1, 00155 MYF(MY_WME | MY_FAE)))) 00156 return (uint) -1; 00157 buffer->start_of_line=buffer->buffer+start_offset; 00158 buffer->end=buffer->buffer+bufbytes; 00159 } 00160 00161 /* Shift stuff down. */ 00162 if (buffer->start_of_line != buffer->buffer) 00163 { 00164 bmove(buffer->buffer,buffer->start_of_line,(uint) bufbytes); 00165 buffer->end=buffer->buffer+bufbytes; 00166 } 00167 00168 /* Read in new stuff. */ 00169 if ((read_count= my_read(buffer->file, (byte*) buffer->end, read_count, 00170 MYF(MY_WME))) == MY_FILE_ERROR) 00171 return read_count; 00172 00173 DBUG_PRINT("fill_buff", ("Got %d bytes", read_count)); 00174 00175 /* Kludge to pretend every nonempty file ends with a newline. */ 00176 if (!read_count && bufbytes && buffer->end[-1] != '\n') 00177 { 00178 buffer->eof = read_count = 1; 00179 *buffer->end = '\n'; 00180 } 00181 buffer->end_of_line=(buffer->start_of_line=buffer->buffer)+bufbytes; 00182 buffer->end+=read_count; 00183 *buffer->end=0; /* Sentinel */ 00184 return read_count; 00185 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool init_line_buffer | ( | LINE_BUFFER * | buffer, | |
| File | file, | |||
| ulong | size, | |||
| ulong | max_size | |||
| ) | [static] |
Definition at line 91 of file readline.cc.
References buffer, MY_FAE, my_malloc(), MY_WME, and MYF.
Referenced by batch_readline_init().
00092 { 00093 buffer->file=file; 00094 buffer->bufread=size; 00095 buffer->max_size=max_buffer; 00096 if (!(buffer->buffer = (char*) my_malloc(buffer->bufread+1, 00097 MYF(MY_WME | MY_FAE)))) 00098 return 1; 00099 buffer->end_of_line=buffer->end=buffer->buffer; 00100 buffer->buffer[0]=0; /* For easy start test */ 00101 return 0; 00102 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool init_line_buffer_from_string | ( | LINE_BUFFER * | buffer, | |
| my_string | str | |||
| ) | [static] |
Definition at line 109 of file readline.cc.
References buffer, memcpy, MY_ALLOW_ZERO_PTR, MY_FAE, my_realloc(), MYF, and strlen().
Referenced by batch_readline_command().
00110 { 00111 uint old_length=(uint)(buffer->end - buffer->buffer); 00112 uint length= (uint) strlen(str); 00113 if (!(buffer->buffer= buffer->start_of_line= buffer->end_of_line= 00114 (char*)my_realloc(buffer->buffer, old_length+length+2, 00115 MYF(MY_FAE|MY_ALLOW_ZERO_PTR)))) 00116 return 1; 00117 buffer->end= buffer->buffer + old_length; 00118 if (old_length) 00119 buffer->end[-1]=' '; 00120 memcpy(buffer->end, str, length); 00121 buffer->end[length]= '\n'; 00122 buffer->end[length+1]= 0; 00123 buffer->end+= length+1; 00124 buffer->eof=1; 00125 buffer->max_size=1; 00126 return 0; 00127 }
Here is the call graph for this function:

Here is the caller graph for this function:

| char * intern_read_line | ( | LINE_BUFFER * | buffer, | |
| ulong * | out_length | |||
| ) | [static] |
Definition at line 189 of file readline.cc.
References buffer, DBUG_ENTER, DBUG_RETURN, fill_buffer(), and pos().
Referenced by batch_readline().
00190 { 00191 char *pos; 00192 uint length; 00193 DBUG_ENTER("intern_read_line"); 00194 00195 buffer->start_of_line=buffer->end_of_line; 00196 for (;;) 00197 { 00198 pos=buffer->end_of_line; 00199 while (*pos != '\n' && *pos) 00200 pos++; 00201 if (pos == buffer->end) 00202 { 00203 if ((uint) (pos - buffer->start_of_line) < buffer->max_size) 00204 { 00205 if (!(length=fill_buffer(buffer)) || length == (uint) -1) 00206 DBUG_RETURN(0); 00207 continue; 00208 } 00209 pos--; /* break line here */ 00210 } 00211 buffer->end_of_line=pos+1; 00212 *out_length=(ulong) (pos + 1 - buffer->eof - buffer->start_of_line); 00213 DBUG_RETURN(buffer->start_of_line); 00214 } 00215 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

