1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/* readline for batch mode */
|
|
17 |
||
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
18 |
#include "config.h" |
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
19 |
#include "drizzled/internal/my_sys.h" |
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
20 |
#include "client/linebuffer.h" |
21 |
||
1095.2.4
by Robert Klahn
changes from code review feedback |
22 |
#include <vector> |
1
by brian
clean slate |
23 |
|
520.4.43
by mordred
A set of Solaris fixes. |
24 |
using namespace std; |
25 |
||
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
26 |
LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file) |
1095.2.4
by Robert Klahn
changes from code review feedback |
27 |
:
|
28 |
file(my_file), |
|
29 |
line(), |
|
30 |
max_size(my_max_size), |
|
31 |
eof(false) |
|
32 |
{
|
|
33 |
line.reserve(max_size); |
|
34 |
}
|
|
35 |
||
36 |
void LineBuffer::addString(const string &str) |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
37 |
{
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
38 |
buffer << str << endl; |
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
39 |
}
|
40 |
||
41 |
char *LineBuffer::readline() |
|
1
by brian
clean slate |
42 |
{
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
43 |
uint32_t read_count; |
44 |
||
45 |
if (file && !eof) |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
46 |
{
|
1095.2.5
by Robert Klahn
more changes from code review feedback |
47 |
if ((read_count= my_read(fileno(file), |
48 |
(unsigned char *) (&line[0]), |
|
49 |
max_size-1,MYF(MY_WME)))) |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
50 |
{
|
1095.2.4
by Robert Klahn
changes from code review feedback |
51 |
line[read_count+1]= '\0'; |
52 |
buffer << &line[0]; |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
53 |
}
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
54 |
else
|
55 |
eof= true; |
|
56 |
}
|
|
57 |
||
1095.2.4
by Robert Klahn
changes from code review feedback |
58 |
buffer.getline(&line[0],max_size); |
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
59 |
|
60 |
if (buffer.eof()) |
|
61 |
return 0; |
|
62 |
else
|
|
1095.2.4
by Robert Klahn
changes from code review feedback |
63 |
return &line[0]; |
1
by brian
clean slate |
64 |
}
|
65 |