~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/linebuffer.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* readline for batch mode */
17
17
 
18
 
#include "config.h"
19
 
#include "drizzled/internal/my_sys.h"
20
 
#include "client/linebuffer.h"
 
18
#include <config.h>
 
19
#include <drizzled/internal/my_sys.h>
 
20
#include <client/linebuffer.h>
 
21
#include <boost/version.hpp>
21
22
 
22
23
#include <vector>
23
24
 
27
28
LineBuffer::LineBuffer(uint32_t my_max_size,FILE *my_file)
28
29
  :
29
30
    file(my_file),
30
 
    line(),
31
 
    max_size(my_max_size),
32
 
    eof(false)
 
31
    max_size(my_max_size)
33
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;
34
47
  line.reserve(max_size);
35
48
}
36
49
 
37
50
void LineBuffer::addString(const string &str)
38
51
{
39
 
  buffer << str << endl;
 
52
  (*file_stream) << str << endl;
40
53
}
41
54
 
42
55
char *LineBuffer::readline()
43
56
{
44
 
  uint32_t read_count;
45
 
 
46
 
  if (file && !eof)
47
 
  {
48
 
    if ((read_count= read(fileno(file), (&line[0]), max_size-1)))
49
 
    {
50
 
      line[read_count+1]= '\0';
51
 
      buffer << &line[0];
52
 
    }
53
 
    else
54
 
      eof= true;
55
 
  }
56
 
 
57
 
  buffer.getline(&line[0],max_size);
58
 
 
59
 
  if (buffer.eof())
 
57
  file_stream->getline(&line[0], max_size);
 
58
 
 
59
  if (file_stream->fail())
60
60
    return 0;
61
61
  else
62
62
    return &line[0];