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; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
25 |
using namespace drizzled; |
520.4.43
by mordred
A set of Solaris fixes. |
26 |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
27 |
LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file) |
1095.2.4
by Robert Klahn
changes from code review feedback |
28 |
:
|
29 |
file(my_file), |
|
30 |
line(), |
|
31 |
max_size(my_max_size), |
|
32 |
eof(false) |
|
33 |
{
|
|
34 |
line.reserve(max_size); |
|
35 |
}
|
|
36 |
||
37 |
void LineBuffer::addString(const string &str) |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
38 |
{
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
39 |
buffer << str << endl; |
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
40 |
}
|
41 |
||
42 |
char *LineBuffer::readline() |
|
1
by brian
clean slate |
43 |
{
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
44 |
uint32_t read_count; |
45 |
||
46 |
if (file && !eof) |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
47 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
48 |
if ((read_count= internal::my_read(fileno(file), |
1095.2.5
by Robert Klahn
more changes from code review feedback |
49 |
(unsigned char *) (&line[0]), |
50 |
max_size-1,MYF(MY_WME)))) |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
51 |
{
|
1095.2.4
by Robert Klahn
changes from code review feedback |
52 |
line[read_count+1]= '\0'; |
53 |
buffer << &line[0]; |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
54 |
}
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
55 |
else
|
56 |
eof= true; |
|
57 |
}
|
|
58 |
||
1095.2.4
by Robert Klahn
changes from code review feedback |
59 |
buffer.getline(&line[0],max_size); |
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
60 |
|
61 |
if (buffer.eof()) |
|
62 |
return 0; |
|
63 |
else
|
|
1095.2.4
by Robert Klahn
changes from code review feedback |
64 |
return &line[0]; |
1
by brian
clean slate |
65 |
}
|
66 |