mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Rewrite small amount of code in parameter expansion to use wide character strings, not narrow
darcs-hash:20060521214601-ac50b-bb3937f5abd2780a7ecf8ab13975a0f6b622323f.gz
This commit is contained in:
parent
df5cc6f858
commit
07e14ed7a8
2 changed files with 30 additions and 39 deletions
67
expand.c
67
expand.c
|
@ -260,28 +260,19 @@ wchar_t *expand_escape_variable( const wchar_t *in )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Tests if all characters in the string are numeric
|
|
||||||
*/
|
|
||||||
static int isnumeric( const char *n )
|
|
||||||
{
|
|
||||||
if( *n == '\0' )
|
|
||||||
return 1;
|
|
||||||
if( *n < '0' || *n > '9' )
|
|
||||||
return 0;
|
|
||||||
return isnumeric( n+1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Tests if all characters in the wide string are numeric
|
Tests if all characters in the wide string are numeric
|
||||||
*/
|
*/
|
||||||
static int iswnumeric( const wchar_t *n )
|
static int iswnumeric( const wchar_t *n )
|
||||||
{
|
{
|
||||||
if( *n == L'\0' )
|
for( ; *n; n++ )
|
||||||
return 1;
|
{
|
||||||
if( *n < L'0' || *n > L'9' )
|
if( *n < L'0' || *n > L'9' )
|
||||||
return 0;
|
{
|
||||||
return iswnumeric( n+1 );
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,9 +347,9 @@ static int find_process( const wchar_t *proc,
|
||||||
array_list_t *out )
|
array_list_t *out )
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *next;
|
struct wdirent *next;
|
||||||
char *pdir_name;
|
wchar_t *pdir_name;
|
||||||
char *pfile_name;
|
wchar_t *pfile_name;
|
||||||
wchar_t *cmd=0;
|
wchar_t *cmd=0;
|
||||||
int sz=0;
|
int sz=0;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
@ -494,20 +485,20 @@ static int find_process( const wchar_t *proc,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdir_name = malloc( 256 );
|
pdir_name = malloc( sizeof(wchar_t)*256 );
|
||||||
pfile_name = malloc( 64 );
|
pfile_name = malloc( sizeof(wchar_t)*64 );
|
||||||
strcpy( pdir_name, "/proc/" );
|
wcscpy( pdir_name, L"/proc/" );
|
||||||
|
|
||||||
while( (next=readdir(dir))!=0 )
|
while( (next=wreaddir(dir))!=0 )
|
||||||
{
|
{
|
||||||
char *name = next->d_name;
|
wchar_t *name = next->d_name;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
if( !isnumeric( name ) )
|
if( !iswnumeric( name ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
strcpy( pdir_name + 6, name );
|
wcscpy( pdir_name + 6, name );
|
||||||
if( stat( pdir_name, &buf ) )
|
if( wstat( pdir_name, &buf ) )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -515,17 +506,17 @@ static int find_process( const wchar_t *proc,
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strcpy( pfile_name, pdir_name );
|
wcscpy( pfile_name, pdir_name );
|
||||||
strcat( pfile_name, "/cmdline" );
|
wcscat( pfile_name, L"/cmdline" );
|
||||||
|
|
||||||
if( !stat( pfile_name, &buf ) )
|
if( !wstat( pfile_name, &buf ) )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
the 'cmdline' file exists, it should contain the commandline
|
the 'cmdline' file exists, it should contain the commandline
|
||||||
*/
|
*/
|
||||||
FILE *cmdfile;
|
FILE *cmdfile;
|
||||||
|
|
||||||
if((cmdfile=fopen( pfile_name, "r" ))==0)
|
if((cmdfile=wfopen( pfile_name, "r" ))==0)
|
||||||
{
|
{
|
||||||
wperror( L"fopen" );
|
wperror( L"fopen" );
|
||||||
continue;
|
continue;
|
||||||
|
@ -540,15 +531,15 @@ static int find_process( const wchar_t *proc,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef SunOS
|
#ifdef SunOS
|
||||||
strcpy( pfile_name, pdir_name );
|
wcscpy( pfile_name, pdir_name );
|
||||||
strcat( pfile_name, "/psinfo" );
|
wcscat( pfile_name, L"/psinfo" );
|
||||||
if( !stat( pfile_name, &buf ) )
|
if( !wstat( pfile_name, &buf ) )
|
||||||
{
|
{
|
||||||
psinfo_t info;
|
psinfo_t info;
|
||||||
|
|
||||||
FILE *psfile;
|
FILE *psfile;
|
||||||
|
|
||||||
if((psfile=fopen( pfile_name, "r" ))==0)
|
if((psfile=wfopen( pfile_name, "r" ))==0)
|
||||||
{
|
{
|
||||||
wperror( L"fopen" );
|
wperror( L"fopen" );
|
||||||
continue;
|
continue;
|
||||||
|
@ -587,7 +578,7 @@ static int find_process( const wchar_t *proc,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wchar_t *res = str2wcs(name);
|
wchar_t *res = wcsdup(name);
|
||||||
if( res )
|
if( res )
|
||||||
al_push( out, res );
|
al_push( out, res );
|
||||||
}
|
}
|
||||||
|
|
2
parser.c
2
parser.c
|
@ -2711,7 +2711,7 @@ int parser_test_args(const wchar_t * buff,
|
||||||
current_tokenizer_pos = tok_get_pos( &tok );
|
current_tokenizer_pos = tok_get_pos( &tok );
|
||||||
switch( tok_last_type( &tok ) )
|
switch( tok_last_type( &tok ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
case TOK_STRING:
|
case TOK_STRING:
|
||||||
{
|
{
|
||||||
err |= parser_test_argument( tok_last( &tok ), babble );
|
err |= parser_test_argument( tok_last( &tok ), babble );
|
||||||
|
|
Loading…
Reference in a new issue