Support for numeric backslash escapes

darcs-hash:20050925223948-ac50b-fae1e578572f64386e831a0aa401edd7fab0afb9.gz
This commit is contained in:
axel 2005-09-26 08:39:48 +10:00
parent cb1f3eb53d
commit f392e3044c
4 changed files with 89 additions and 14 deletions

View File

@ -2,6 +2,10 @@
* parser.c: (parse_job, parser_skip_arguemnts, paresr_Test): No semicolon required after else and begin * parser.c: (parse_job, parser_skip_arguemnts, paresr_Test): No semicolon required after else and begin
* input_common.c (readb): Fix sign error
* input.c (input_expand_sequence): Add support for numeric backslash escapes
2005-09-24 Axel Liljencrantz <axel@liljencrantz.se> 2005-09-24 Axel Liljencrantz <axel@liljencrantz.se>

View File

@ -884,8 +884,6 @@ g++, javac, java, gcj, lpr, doxygen, whois, find)
version of a POSIX command version of a POSIX command
- Yanking weird characters from clipboard prints Unicode escapes - Yanking weird characters from clipboard prints Unicode escapes
- Prefix string in completion display is sometimes incorrect - Prefix string in completion display is sometimes incorrect
- Pressing escape when doing a token search breaks things
- Universal variables should be exportable
If you think you have found a bug not described here, please send a If you think you have found a bug not described here, please send a
report to <a href="mailto:axel@liljencrantz.se"> axel@liljencrantz.se report to <a href="mailto:axel@liljencrantz.se"> axel@liljencrantz.se

83
input.c
View File

@ -361,6 +361,7 @@ repaint();*/
*/ */
static wchar_t *input_expand_sequence( const wchar_t *in ) static wchar_t *input_expand_sequence( const wchar_t *in )
{ {
const wchar_t *in_orig=in;
wchar_t *res = malloc( sizeof( wchar_t)*(4*wcslen(in)+1)); wchar_t *res = malloc( sizeof( wchar_t)*(4*wcslen(in)+1));
wchar_t *out=res; wchar_t *out=res;
int error = 0; int error = 0;
@ -372,7 +373,6 @@ static wchar_t *input_expand_sequence( const wchar_t *in )
case L'\\': case L'\\':
{ {
in++; in++;
// fwprintf( stderr, L"Backslash\n" );
switch( *in ) switch( *in )
{ {
case L'\0': case L'\0':
@ -428,14 +428,76 @@ static wchar_t *input_expand_sequence( const wchar_t *in )
*(out++)=L'\v'; *(out++)=L'\v';
break; break;
/*
Parse numeric backslash escape
*/
case L'u':
case L'U':
case L'x':
case L'o':
{
int i;
wchar_t res=0;
int chars=2;
int base=16;
switch( *in++ )
{
case L'u':
base=16;
chars=4;
break;
case L'U':
base=16;
chars=8;
break;
case L'x':
base=16;
chars=2;
break;
case L'o':
base=8;
chars=3;
break;
}
wchar_t *ggg = in;
for( i=0; i<chars; i++ )
{
int d = convert_digit( *in++, base);
if( d < 0 )
{
break;
}
res=(res*base)|d;
}
in--;
debug( 4,
L"Got numeric key sequence %d",
res );
*(out++) = res;
break;
}
/*
Parse control sequence
*/
case L'C': case L'C':
{ {
//fwprintf( stderr, L"Control\n" );
in++; in++;
/* Make sure next key is a dash*/
if( *in != L'-' ) if( *in != L'-' )
{ {
error=1; error=1;
// fwprintf( stderr, L"no dash\n" );
break; break;
} }
in++; in++;
@ -459,6 +521,9 @@ static wchar_t *input_expand_sequence( const wchar_t *in )
break; break;
} }
/*
Parse meta sequence
*/
case L'M': case L'M':
{ {
in++; in++;
@ -510,6 +575,8 @@ static wchar_t *input_expand_sequence( const wchar_t *in )
in++; in++;
} }
if( error ) if( error )
{ {
// fwprintf( stderr, L"%ls had errors\n", in_orig ); // fwprintf( stderr, L"%ls had errors\n", in_orig );
@ -522,6 +589,12 @@ static wchar_t *input_expand_sequence( const wchar_t *in )
*out = L'\0'; *out = L'\0';
} }
if( wcslen( res ) == 0 )
{
debug( 1, L"Sequence '%ls' expanded to zero characters, skipped", in_orig );
error =1;
}
return res; return res;
} }
@ -1068,7 +1141,7 @@ static wint_t input_exec_binding( mapping *m, const wchar_t *seq )
case R_DUMP_FUNCTIONS: case R_DUMP_FUNCTIONS:
{ {
dump_functions(); dump_functions();
return input_readch(); return R_NULL;
} }
case R_SELF_INSERT: case R_SELF_INSERT:
{ {
@ -1121,9 +1194,9 @@ static wint_t input_try_mapping( mapping *m)
for( j=0; m->seq[j] != L'\0' && for( j=0; m->seq[j] != L'\0' &&
m->seq[j] == (c=input_common_readch( j>0 )); j++ ) m->seq[j] == (c=input_common_readch( j>0 )); j++ )
; ;
if( m->seq[j] == L'\0' ) if( m->seq[j] == L'\0' )
{ {
return input_exec_binding( m, m->seq ); return input_exec_binding( m, m->seq );
} }
else else

View File

@ -56,7 +56,7 @@ void input_common_destroy()
*/ */
static wint_t readb() static wint_t readb()
{ {
char arr[1]; unsigned char arr[1];
int do_loop = 0; int do_loop = 0;
do do