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 |
{
|
1567.3.14
by Monty Taylor
Removed the need for drizzled::internal usage in drizzle.cc. |
48 |
if ((read_count= read(fileno(file), (&line[0]), max_size-1))) |
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
49 |
{
|
1095.2.4
by Robert Klahn
changes from code review feedback |
50 |
line[read_count+1]= '\0'; |
51 |
buffer << &line[0]; |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
52 |
}
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
53 |
else
|
54 |
eof= true; |
|
55 |
}
|
|
56 |
||
1095.2.4
by Robert Klahn
changes from code review feedback |
57 |
buffer.getline(&line[0],max_size); |
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
58 |
|
59 |
if (buffer.eof()) |
|
60 |
return 0; |
|
61 |
else
|
|
1095.2.4
by Robert Klahn
changes from code review feedback |
62 |
return &line[0]; |
1
by brian
clean slate |
63 |
}
|
64 |