Cleanup reader.cpp's usage of string_buffer, remove some other unused data structures

This commit is contained in:
ridiculousfish 2012-03-03 21:59:45 -08:00
parent dfba35aee8
commit a9313fc0c3
3 changed files with 17 additions and 85 deletions

View file

@ -149,7 +149,6 @@ int writeb( tputs_arg_t b );
*/ */
void output_set_writer( int (*writer)(char) ); void output_set_writer( int (*writer)(char) );
//typedef int (*func_ptr_t)(char);
/** /**
Return the current output writer Return the current output writer
*/ */

View file

@ -1074,8 +1074,7 @@ static void completion_insert( const wchar_t *val, int flags )
static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<completion_t> &comp ) static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<completion_t> &comp )
{ {
string_buffer_t cmd; wcstring msg;
string_buffer_t msg;
wchar_t * prefix_esc; wchar_t * prefix_esc;
char *foo; char *foo;
io_data_t *in; io_data_t *in;
@ -1091,15 +1090,12 @@ static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<complet
prefix_esc = escape( prefix,1); prefix_esc = escape( prefix,1);
} }
sb_init( &cmd ); wcstring cmd = format_string(L"fish_pager -c 3 -r 4 %ls -p %ls",
sb_init( &msg ); // L"valgrind --track-fds=yes --log-file=pager.txt --leak-check=full ./fish_pager %d %ls",
sb_printf( &cmd, is_quoted?L"-q":L"",
L"fish_pager -c 3 -r 4 %ls -p %ls", prefix_esc );
// L"valgrind --track-fds=yes --log-file=pager.txt --leak-check=full ./fish_pager %d %ls",
is_quoted?L"-q":L"",
prefix_esc );
free( prefix_esc ); free(prefix_esc);
in= io_buffer_create( 1 ); in= io_buffer_create( 1 );
in->fd = 3; in->fd = 3;
@ -1164,15 +1160,11 @@ static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<complet
} }
else if( baz ) else if( baz )
{ {
sb_printf( &msg, L"%ls%ls%ls\n", msg = format_string(L"%ls%ls%ls\n", foo, escaped_separator, baz);
foo,
escaped_separator,
baz );
} }
else else
{ {
sb_printf( &msg, L"%ls\n", msg = format_string(L"%ls\n", foo);
foo );
} }
free( foo ); free( foo );
@ -1181,7 +1173,7 @@ static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<complet
free( escaped_separator ); free( escaped_separator );
foo = wcs2str( (wchar_t *)msg.buff ); foo = wcs2str(msg.c_str());
b_append( in->param2.out_buffer, foo, strlen(foo) ); b_append( in->param2.out_buffer, foo, strlen(foo) );
free( foo ); free( foo );
@ -1192,14 +1184,11 @@ static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<complet
out->fd = 4; out->fd = 4;
parser_t &parser = parser_t::principal_parser(); parser_t &parser = parser_t::principal_parser();
parser.eval( (wchar_t *)cmd.buff, out, TOP); parser.eval( cmd, out, TOP);
term_steal(); term_steal();
io_buffer_read( out ); io_buffer_read( out );
sb_destroy( &cmd );
sb_destroy( &msg );
int nil=0; int nil=0;
b_append( out->param2.out_buffer, &nil, 1 ); b_append( out->param2.out_buffer, &nil, 1 );
@ -1805,31 +1794,21 @@ void reader_replace_current_token( const wchar_t *new_token )
{ {
const wchar_t *begin, *end; const wchar_t *begin, *end;
string_buffer_t sb;
int new_pos; int new_pos;
/* /* Find current token */
Find current token
*/
const wchar_t *buff = data->command_line.c_str(); const wchar_t *buff = data->command_line.c_str();
parse_util_token_extent( (wchar_t *)buff, data->buff_pos, &begin, &end, 0, 0 ); parse_util_token_extent( (wchar_t *)buff, data->buff_pos, &begin, &end, 0, 0 );
if( !begin || !end ) if( !begin || !end )
return; return;
/* /* Make new string */
Make new string wcstring new_buff(buff, begin - buff);
*/ new_buff.append(new_token);
sb_init( &sb ); new_buff.append(end);
sb_append_substring( &sb, buff, begin-buff );
sb_append( &sb, new_token );
sb_append( &sb, end );
new_pos = (begin-buff) + wcslen(new_token); new_pos = (begin-buff) + wcslen(new_token);
reader_set_buffer(new_buff, new_pos);
reader_set_buffer( (wchar_t *)sb.buff, new_pos );
sb_destroy( &sb );
} }

46
util.h
View file

@ -15,52 +15,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
/**
Typedef for a generic function pointer
*/
typedef void (*func_ptr_t)();
/**
A union of all types that can be stored in an array_list_t. This is
used to make sure that the pointer type can fit whatever we want to
insert.
*/
typedef union
{
/**
long value
*/
long long_val;
/**
pointer value
*/
void *ptr_val;
/**
function pointer value
*/
func_ptr_t func_val;
}
anything_t;
/**
Data structure for an automatically resizing dynamically allocated
priority queue. A priority queue allows quick retrieval of the
smallest element of a set (This implementation uses O(log n) time).
This implementation uses a heap for storing the queue.
*/
typedef struct priority_queue
{
/** Array contining the data */
void **arr;
/** Number of elements*/
int count;
/** Length of array */
int size;
/** Comparison function */
int (*compare)(void *e1, void *e2);
}
priority_queue_t;
/** /**
Buffer for concatenating arbitrary data. Buffer for concatenating arbitrary data.
*/ */