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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
/* readline for batch mode */
|
|
17 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
18 |
#include <config.h> |
19 |
#include <drizzled/internal/my_sys.h> |
|
20 |
#include <client/linebuffer.h> |
|
1934.3.1
by Andrew Hutchings
Work around Fedora 14 boost compiled without depreated iostream functions |
21 |
#include <boost/version.hpp> |
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
22 |
|
1095.2.4
by Robert Klahn
changes from code review feedback |
23 |
#include <vector> |
1
by brian
clean slate |
24 |
|
520.4.43
by mordred
A set of Solaris fixes. |
25 |
using namespace std; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
using namespace drizzled; |
520.4.43
by mordred
A set of Solaris fixes. |
27 |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
28 |
LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file) |
1095.2.4
by Robert Klahn
changes from code review feedback |
29 |
:
|
30 |
file(my_file), |
|
1909.5.1
by Andrew Hutchings
Re-write of linebuffer to stop buffer overrrun and hopefully improve performance |
31 |
max_size(my_max_size) |
1095.2.4
by Robert Klahn
changes from code review feedback |
32 |
{
|
1909.5.1
by Andrew Hutchings
Re-write of linebuffer to stop buffer overrrun and hopefully improve performance |
33 |
if (my_file) |
1937.2.1
by Andrew Hutchings
Cleanup after bug fix |
34 |
|
35 |
/*
|
|
36 |
if here beacuse the old way of using file_descriptor is deprecated in boost
|
|
37 |
1.44. There is a #define to re-enable the function but this is broken in
|
|
38 |
Fedora 14. See https://bugzilla.redhat.com/show_bug.cgi?id=654480
|
|
39 |
*/
|
|
1934.3.1
by Andrew Hutchings
Work around Fedora 14 boost compiled without depreated iostream functions |
40 |
#if BOOST_VERSION < 104400
|
1914.1.2
by Andrew Hutchings
Another attempt at fixing this |
41 |
file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), true); |
1934.3.1
by Andrew Hutchings
Work around Fedora 14 boost compiled without depreated iostream functions |
42 |
#else
|
43 |
file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), boost::iostreams::never_close_handle); |
|
44 |
#endif
|
|
1909.5.1
by Andrew Hutchings
Re-write of linebuffer to stop buffer overrrun and hopefully improve performance |
45 |
else
|
46 |
file_stream = new std::stringstream; |
|
1095.2.4
by Robert Klahn
changes from code review feedback |
47 |
line.reserve(max_size); |
48 |
}
|
|
49 |
||
50 |
void LineBuffer::addString(const string &str) |
|
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
51 |
{
|
1909.5.1
by Andrew Hutchings
Re-write of linebuffer to stop buffer overrrun and hopefully improve performance |
52 |
(*file_stream) << str << endl; |
1095.2.1
by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic |
53 |
}
|
54 |
||
55 |
char *LineBuffer::readline() |
|
1
by brian
clean slate |
56 |
{
|
1909.5.1
by Andrew Hutchings
Re-write of linebuffer to stop buffer overrrun and hopefully improve performance |
57 |
file_stream->getline(&line[0], max_size); |
58 |
||
59 |
if (file_stream->fail()) |
|
1095.2.2
by Robert Klahn
convert logic to use std::stringstream for buffer |
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 |