removed some string_buffer

This commit is contained in:
ridiculousfish 2012-03-03 19:37:55 -08:00
parent 0a5680c3e8
commit a0bb2cdc6e
8 changed files with 31 additions and 200 deletions

View file

@ -917,97 +917,6 @@ void write_screen( const wcstring &msg, wcstring &buff )
buff.push_back(L'\n');
}
void write_screen( const wcstring &msg, string_buffer_t *buff )
{
const wchar_t *start, *pos;
int line_width = 0;
int tok_width = 0;
int screen_width = common_get_width();
CHECK( buff, );
if( screen_width )
{
start = pos = msg.c_str();
while( 1 )
{
int overflow = 0;
tok_width=0;
/*
Tokenize on whitespace, and also calculate the width of the token
*/
while( *pos && ( !wcschr( L" \n\r\t", *pos ) ) )
{
/*
Check is token is wider than one line.
If so we mark it as an overflow and break the token.
*/
if((tok_width + wcwidth(*pos)) > (screen_width-1))
{
overflow = 1;
break;
}
tok_width += wcwidth( *pos );
pos++;
}
/*
If token is zero character long, we don't do anything
*/
if( pos == start )
{
start = pos = pos+1;
}
else if( overflow )
{
/*
In case of overflow, we print a newline, except if we already are at position 0
*/
wchar_t *token = wcsndup( start, pos-start );
if( line_width != 0 )
sb_append_char( buff, L'\n' );
sb_printf( buff, L"%ls-\n", token );
free( token );
line_width=0;
}
else
{
/*
Print the token
*/
wchar_t *token = wcsndup( start, pos-start );
if( (line_width + (line_width!=0?1:0) + tok_width) > screen_width )
{
sb_append_char( buff, L'\n' );
line_width=0;
}
sb_printf( buff, L"%ls%ls", line_width?L" ":L"", token );
free( token );
line_width += (line_width!=0?1:0) + tok_width;
}
/*
Break on end of string
*/
if( !*pos )
{
break;
}
start=pos;
}
}
else
{
sb_printf( buff, L"%ls", msg.c_str() );
}
sb_append_char( buff, L'\n' );
}
/**
Perform string escaping of a strinng by only quoting it. Assumes
the string has already been checked for characters that can not be
@ -1856,49 +1765,6 @@ void bugreport()
PACKAGE_BUGREPORT );
}
void sb_format_size( string_buffer_t *sb,
long long sz )
{
const wchar_t *sz_name[]=
{
L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0
}
;
if( sz < 0 )
{
sb_append( sb, L"unknown" );
}
else if( sz < 1 )
{
sb_append( sb, _( L"empty" ) );
}
else if( sz < 1024 )
{
sb_printf( sb, L"%lldB", sz );
}
else
{
int i;
for( i=0; sz_name[i]; i++ )
{
if( sz < (1024*1024) || !sz_name[i+1] )
{
int isz = sz/1024;
if( isz > 9 )
sb_printf( sb, L"%d%ls", isz, sz_name[i] );
else
sb_printf( sb, L"%.1f%ls", (double)sz/1024, sz_name[i] );
break;
}
sz /= 1024;
}
}
}
wcstring format_size(long long sz)
{
wcstring result;

View file

@ -636,7 +636,6 @@ void common_handle_winch( int signal );
Write paragraph of output to the specified stringbuffer, and redo
the linebreaks to fit the current screen.
*/
void write_screen( const wcstring &msg, string_buffer_t *buff );
void write_screen( const wcstring &msg, wcstring &buff );
/**
@ -660,7 +659,6 @@ int create_directory( const wcstring &d );
void bugreport();
/** Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer. */
void sb_format_size( string_buffer_t *sb, long long sz );
wcstring format_size(long long sz);
/** Version of format_size that does not allocate memory. */

View file

@ -36,8 +36,15 @@
*/
#define KILL_MAX 8192
/** Last kill string */
static ll_node_t *kill_last=0;
/** Current kill string */
static ll_node_t *kill_current=0;
/** Kill ring */
//static std::vector<wcstring> kill_list;
static ll_node_t /** Last kill string */*kill_last=0, /** Current kill string */*kill_current =0;
/**
Contents of the X clipboard, at last time we checked it
*/
@ -65,22 +72,22 @@ static int has_xsel()
/**
Add the string to the internal killring
*/
static void kill_add_internal( wchar_t *str )
static void kill_add_internal( const wcstring &str )
{
if( wcslen( str ) == 0 )
if (str.empty())
return;
if( kill_last == 0 )
if (kill_last == 0)
{
kill_current = kill_last=(ll_node_t *)malloc( sizeof( ll_node_t ) );
kill_current->data = wcsdup(str);
kill_current->data = wcsdup(str.c_str());
kill_current->prev = kill_current;
}
else
{
kill_current = (ll_node_t *)malloc( sizeof( ll_node_t ) );
kill_current->data = kill_last->data;
kill_last->data = wcsdup(str);
kill_last->data = wcsdup(str.c_str());
kill_current->prev = kill_last->prev;
kill_last->prev = kill_current;
kill_current = kill_last;
@ -88,7 +95,7 @@ static void kill_add_internal( wchar_t *str )
}
void kill_add( wchar_t *str )
void kill_add( const wcstring &str )
{
wchar_t *cmd = NULL;
wchar_t *escaped_str;
@ -106,7 +113,7 @@ void kill_add( wchar_t *str )
const env_var_t clipboard_wstr = env_get_string(L"FISH_CLIPBOARD_CMD");
if( !clipboard_wstr.missing() )
{
escaped_str = escape( str, 1 );
escaped_str = escape( str.c_str(), 1 );
cmd = wcsdupcat(L"echo -n ", escaped_str, clipboard_wstr.c_str());
}
else
@ -119,7 +126,7 @@ void kill_add( wchar_t *str )
const env_var_t disp_wstr = env_get_string( L"DISPLAY" );
if( !disp_wstr.missing() )
{
escaped_str = escape( str, 1 );
escaped_str = escape( str.c_str(), 1 );
cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
}
}
@ -170,7 +177,7 @@ static void kill_remove_node( ll_node_t *n )
/**
Remove first match for specified string from circular list
*/
static void kill_remove( wchar_t *s )
static void kill_remove( const wcstring &s )
{
ll_node_t *n, *next=0;
@ -183,7 +190,7 @@ static void kill_remove( wchar_t *s )
n!=kill_last || next == 0 ;
n=n->prev )
{
if( wcscmp( (wchar_t *)n->data, s ) == 0 )
if( wcscmp( (wchar_t *)n->data, s.c_str() ) == 0 )
{
kill_remove_node( n );
break;
@ -194,7 +201,7 @@ static void kill_remove( wchar_t *s )
void kill_replace( wchar_t *old, wchar_t *newv )
void kill_replace( const wcstring &old, const wcstring &newv )
{
kill_remove( old );
kill_add( newv );

8
kill.h
View file

@ -12,13 +12,11 @@
/**
Replace the specified string in the killring
*/
void kill_replace( wchar_t *old, wchar_t *newv );
void kill_replace( const wcstring &old, const wcstring &newv );
/**
Add a string to the top of the killring
*/
void kill_add( wchar_t *str );
/** Add a string to the top of the killring */
void kill_add( const wcstring &str );
/**
Rotate the killring
*/

View file

@ -284,10 +284,8 @@ class reader_data_t
*/
bool prev_end_loop;
/**
The current contents of the top item in the kill ring.
*/
string_buffer_t kill_item;
/** The current contents of the top item in the kill ring. */
wcstring kill_item;
/**
Pointer to previous reader_data
@ -459,29 +457,25 @@ static void reader_kill( size_t begin_idx, int length, int mode, int newv )
const wchar_t *begin = data->command_line.c_str() + begin_idx;
if( newv )
{
sb_clear( &data->kill_item );
sb_append_substring( &data->kill_item, begin, length );
kill_add( (wchar_t *)data->kill_item.buff );
data->kill_item = wcstring(begin, length);
kill_add(data->kill_item);
}
else
{
wchar_t *old = wcsdup( (wchar_t *)data->kill_item.buff);
wcstring old = data->kill_item;
if( mode == KILL_APPEND )
{
sb_append_substring( &data->kill_item, begin, length );
data->kill_item.append(begin, length);
}
else
{
sb_clear( &data->kill_item );
sb_append_substring( &data->kill_item, begin, length );
sb_append( &data->kill_item, old );
data->kill_item = wcstring(begin, length);
data->kill_item.append(old);
}
kill_replace( old, (wchar_t *)data->kill_item.buff );
free( old );
kill_replace( old, data->kill_item );
}
if( data->buff_pos > begin_idx ) {
@ -2307,7 +2301,6 @@ void reader_push( const wchar_t *name )
n->history = & history_t::history_with_name(name);
n->app_name = name;
n->next = data;
sb_init( &n->kill_item );
data=n;
@ -2337,7 +2330,6 @@ void reader_pop()
}
data=data->next;
sb_destroy( &n->kill_item );
/* Invoke the destructor to balance our new */
delete n;

View file

@ -183,20 +183,6 @@ void sb_init( string_buffer_t * b)
b->used -= sizeof(wchar_t);
}
string_buffer_t *sb_new()
{
string_buffer_t *res = (string_buffer_t *)malloc( sizeof( string_buffer_t ) );
if( !res )
{
oom_handler( 0 );
return 0;
}
sb_init( res );
return res;
}
void sb_append_substring( string_buffer_t *b, const wchar_t *s, size_t l )
{
wchar_t tmp=0;

5
util.h
View file

@ -162,11 +162,6 @@ int wcsfilecmp( const wchar_t *a, const wchar_t *b );
*/
void sb_init( string_buffer_t * );
/**
Allocate memory for storing a stringbuffer and init it
*/
string_buffer_t *sb_new();
/**
Append a part of a string to the buffer.
*/

View file

@ -712,9 +712,6 @@ static int wildcard_expand_internal( const wchar_t *wc,
/* Sligtly mangled version of base_dir */
const wchar_t *dir_string;
/* Description for completions */
string_buffer_t sb_desc;
// debug( 3, L"WILDCARD_EXPAND %ls in %ls", wc, base_dir );
@ -765,9 +762,6 @@ static int wildcard_expand_internal( const wchar_t *wc,
wc_recursive = wcschr( wc, ANY_STRING_RECURSIVE );
is_recursive = ( wc_recursive && (!wc_end || wc_recursive < wc_end));
if( flags & ACCEPT_INCOMPLETE )
sb_init( &sb_desc );
/*
Is this segment of the wildcard the last?
*/
@ -1048,11 +1042,6 @@ static int wildcard_expand_internal( const wchar_t *wc,
free( new_dir );
}
closedir( dir );
if( flags & ACCEPT_INCOMPLETE )
{
sb_destroy( &sb_desc );
}
return res;
}