~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/linebuffer.cc

  • Committer: Brian Aker
  • Date: 2009-08-04 06:21:17 UTC
  • mfrom: (1108.2.2 merge)
  • Revision ID: brian@gaz-20090804062117-fef8x6y3ydzrvab3
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* readline for batch mode */
17
17
 
18
 
#include "config.h"
19
 
#include "drizzled/internal/my_sys.h"
 
18
#include <drizzled/global.h>
 
19
#include <mysys/my_sys.h>
20
20
#include "client/linebuffer.h"
21
 
#include <boost/version.hpp>
22
21
 
23
22
#include <vector>
24
23
 
25
24
using namespace std;
26
 
using namespace drizzled;
27
25
 
28
26
LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file)
29
27
  :
30
28
    file(my_file),
31
 
    max_size(my_max_size)
 
29
    line(),
 
30
    max_size(my_max_size),
 
31
    eof(false)
32
32
{
33
 
  if (my_file)
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
 
  */
40
 
#if BOOST_VERSION < 104400
41
 
    file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), true);
42
 
#else
43
 
    file_stream = new boost::iostreams::stream<boost::iostreams::file_descriptor>(fileno(my_file), boost::iostreams::never_close_handle);
44
 
#endif
45
 
  else
46
 
    file_stream = new std::stringstream;
47
33
  line.reserve(max_size);
48
34
}
49
35
 
50
36
void LineBuffer::addString(const string &str)
51
37
{
52
 
  (*file_stream) << str << endl;
 
38
  buffer << str << endl;
53
39
}
54
40
 
55
41
char *LineBuffer::readline()
56
42
{
57
 
  file_stream->getline(&line[0], max_size);
58
 
 
59
 
  if (file_stream->fail())
 
43
  uint32_t read_count;
 
44
 
 
45
  if (file && !eof)
 
46
  {
 
47
    if ((read_count= my_read(fileno(file),
 
48
                             (unsigned char *) (&line[0]),
 
49
                             max_size-1,MYF(MY_WME))))
 
50
    {
 
51
      line[read_count+1]= '\0';
 
52
      buffer << &line[0];
 
53
    }
 
54
    else
 
55
      eof= true;
 
56
  }
 
57
 
 
58
  buffer.getline(&line[0],max_size);
 
59
 
 
60
  if (buffer.eof())
60
61
    return 0;
61
62
  else
62
63
    return &line[0];