Removed buffer_t

This commit is contained in:
ridiculousfish 2012-03-04 02:45:51 -08:00
parent 191221eec5
commit 2c5001a5b3
4 changed files with 20 additions and 111 deletions

View File

@ -1113,16 +1113,13 @@ static void destroy()
*/
static void read_array( FILE* file, wcstring_list_t &comp )
{
buffer_t buffer;
std::vector<char> buffer;
int c;
char cc;
wchar_t *wcs;
b_init( &buffer );
while( !feof( file ) )
{
buffer.used=0;
buffer.clear();
while( 1 )
{
@ -1137,17 +1134,14 @@ static void read_array( FILE* file, wcstring_list_t &comp )
break;
}
cc=c;
b_append( &buffer, &cc, 1 );
buffer.push_back(static_cast<char>(c));
}
if( buffer.used )
if( ! buffer.empty() )
{
cc=0;
b_append( &buffer, &cc, 1 );
buffer.push_back(0);
wcs = str2wcs( buffer.buff );
wcs = str2wcs( &buffer.at(0) );
if( wcs )
{
wcstring tmp = wcs;
@ -1160,8 +1154,6 @@ static void read_array( FILE* file, wcstring_list_t &comp )
}
}
b_destroy( &buffer );
}
static int get_fd( const char *str )

View File

@ -42,6 +42,7 @@ efficient way for transforming that to the desired screen content.
#include <time.h>
#include <assert.h>
#include <vector>
#include "fallback.h"
@ -63,7 +64,8 @@ efficient way for transforming that to the desired screen content.
tputs. Since tputs external function can only take an integer and
not a pointer as parameter we need a static storage buffer.
*/
static buffer_t *s_writeb_buffer=0;
typedef std::vector<char> data_buffer_t;
static data_buffer_t *s_writeb_buffer=0;
/**
Tests if the specified narrow character sequence is present at the
@ -428,7 +430,7 @@ static void s_desired_append_char( screen_t *s,
*/
static int s_writeb( char c )
{
b_append( s_writeb_buffer, &c, 1 );
s_writeb_buffer->push_back(c);
return 0;
}
@ -442,7 +444,7 @@ static int s_writeb( char c )
\param new_x the new x position
\param new_y the new y position
*/
static void s_move( screen_t *s, buffer_t *b, int new_x, int new_y )
static void s_move( screen_t *s, data_buffer_t *b, int new_x, int new_y )
{
int i;
int x_steps, y_steps;
@ -492,8 +494,7 @@ static void s_move( screen_t *s, buffer_t *b, int new_x, int new_y )
if( x_steps && new_x == 0 )
{
char c = '\r';
b_append( b, &c, 1 );
b->push_back('\r');
x_steps = 0;
}
@ -521,7 +522,7 @@ static void s_move( screen_t *s, buffer_t *b, int new_x, int new_y )
/**
Set the pen color for the terminal
*/
static void s_set_color( screen_t *s, buffer_t *b, int c )
static void s_set_color( screen_t *s, data_buffer_t *b, int c )
{
int (*writer_old)(char) = output_get_writer();
@ -541,7 +542,7 @@ static void s_set_color( screen_t *s, buffer_t *b, int c )
Convert a wide character to a multibyte string and append it to the
buffer.
*/
static void s_write_char( screen_t *s, buffer_t *b, wchar_t c )
static void s_write_char( screen_t *s, data_buffer_t *b, wchar_t c )
{
int (*writer_old)(char) = output_get_writer();
@ -558,7 +559,7 @@ static void s_write_char( screen_t *s, buffer_t *b, wchar_t c )
Send the specified string through tputs and append the output to
the specified buffer.
*/
static void s_write_mbs( buffer_t *b, char *s )
static void s_write_mbs( data_buffer_t *b, char *s )
{
int (*writer_old)(char) = output_get_writer();
@ -574,7 +575,7 @@ static void s_write_mbs( buffer_t *b, char *s )
Convert a wide string to a multibyte string and append it to the
buffer.
*/
static void s_write_str( buffer_t *b, const wchar_t *s )
static void s_write_str( data_buffer_t *b, const wchar_t *s )
{
int (*writer_old)(char) = output_get_writer();
@ -596,13 +597,10 @@ static void s_update( screen_t *scr, const wchar_t *prompt )
int current_width=0;
int screen_width = common_get_width();
int need_clear = scr->need_clear;
buffer_t output;
data_buffer_t output;
scr->need_clear = 0;
b_init( &output );
if( scr->actual_width != screen_width )
{
need_clear = 1;
@ -691,13 +689,11 @@ static void s_update( screen_t *scr, const wchar_t *prompt )
s_set_color( scr, &output, 0xffffffff);
if( output.used )
if( ! output.empty() )
{
write_loop( 1, output.buff, output.used );
write_loop( 1, &output.at(0), output.size() );
}
b_destroy( &output );
}
/**

View File

@ -166,62 +166,6 @@ int wcsfilecmp( const wchar_t *a, const wchar_t *b )
return res;
}
void b_init( buffer_t *b)
{
CHECK( b, );
memset( b,0,sizeof(buffer_t));
}
void b_destroy( buffer_t *b )
{
CHECK( b, );
free( b->buff );
}
int b_append( buffer_t *b, const void *d, ssize_t len )
{
if( len<=0 )
return 0;
CHECK( b, -1 );
if( !b )
{
return 0;
}
if( !d )
{
return 0;
}
if( b->length <= (b->used + len) )
{
size_t l = maxi( b->length*2,
b->used+len+MIN_SIZE );
void *d = realloc( b->buff, l );
if( !d )
{
oom_handler( b );
return -1;
}
b->buff=(char *)d;
b->length = l;
}
memcpy( ((char*)b->buff)+b->used,
d,
len );
// fwprintf( stderr, L"Copy %s, new value %s\n", d, b->buff );
b->used+=len;
return 1;
}
long long get_time()
{
struct timeval time_struct;

23
util.h
View File

@ -87,29 +87,6 @@ int mini( int a, int b );
*/
int wcsfilecmp( const wchar_t *a, const wchar_t *b );
/*
Buffer functions
*/
/**
Initialize the specified buffer_t
*/
void b_init( buffer_t *b);
/**
Destroy the specified buffer_t
*/
void b_destroy( buffer_t *b );
/**
Add data of the specified length to the specified buffer_t
\return 0 on error, non-zero otherwise
*/
int b_append( buffer_t *b, const void *d, ssize_t len );
/**
Get the current time in microseconds since Jan 1, 1970
*/