Add the possibility to set the input that the commandline builtin operates on

darcs-hash:20061004184939-ac50b-f2c3e2161a5bf77834a566462ac9942571c9d6ea.gz
This commit is contained in:
axel 2006-10-05 04:49:39 +10:00
parent 53a2c017fe
commit 7d73349889

View file

@ -52,15 +52,15 @@ enum
} }
; ;
static wchar_t *current_buffer=0;
static int current_cursor_pos = -1;
/** /**
Returns the current commandline buffer. Returns the current commandline buffer.
*/ */
static const wchar_t *get_buffer() static const wchar_t *get_buffer()
{ {
const wchar_t *buff = builtin_complete_get_temporary_buffer(); return current_buffer;
if( !buff )
buff = reader_get_buffer();
return buff;
} }
/** /**
@ -68,11 +68,7 @@ static const wchar_t *get_buffer()
*/ */
static int get_cursor_pos() static int get_cursor_pos()
{ {
const wchar_t *buff = builtin_complete_get_temporary_buffer(); return current_cursor_pos;
if( buff )
return wcslen( buff );
else
return reader_get_cursor_pos();
} }
@ -211,6 +207,17 @@ static int builtin_commandline( wchar_t **argv )
int tokenize = 0; int tokenize = 0;
current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
if( current_buffer )
{
current_cursor_pos = wcslen( current_buffer );
}
else
{
current_buffer = reader_get_buffer();
current_cursor_pos = reader_get_cursor_pos();
}
if( !get_buffer() ) if( !get_buffer() )
{ {
sb_append2( sb_err, sb_append2( sb_err,
@ -272,6 +279,10 @@ static int builtin_commandline( wchar_t **argv )
L"help", no_argument, 0, 'h' L"help", no_argument, 0, 'h'
} }
, ,
{
L"input", required_argument, 0, 'I'
}
,
{ {
0, 0, 0, 0 0, 0, 0, 0
} }
@ -282,7 +293,7 @@ static int builtin_commandline( wchar_t **argv )
int opt = wgetopt_long( argc, int opt = wgetopt_long( argc,
argv, argv,
L"aijpctwforh", L"aijpctwforhI:",
long_options, long_options,
&opt_index ); &opt_index );
if( opt == -1 ) if( opt == -1 )
@ -337,6 +348,12 @@ static int builtin_commandline( wchar_t **argv )
tokenize=1; tokenize=1;
break; break;
case 'I':
current_buffer = woptarg;
current_cursor_pos = wcslen( woptarg );
break;
case 'h': case 'h':
builtin_print_help( argv[0], sb_out ); builtin_print_help( argv[0], sb_out );
return 0; return 0;
@ -470,7 +487,7 @@ static int builtin_commandline( wchar_t **argv )
{ {
case STRING_MODE: case STRING_MODE:
{ {
begin = (wchar_t *)get_buffer(); begin = get_buffer();
end = begin+wcslen(begin); end = begin+wcslen(begin);
break; break;
} }