mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Correctly handle locale changes through scope expiry, as well as locale changes in completion code
darcs-hash:20060113010012-ac50b-81cde216bd6b92f7b1374e5f6452695618185f95.gz
This commit is contained in:
parent
f0b2d7532a
commit
2b7781d3cb
2 changed files with 43 additions and 10 deletions
|
@ -1371,11 +1371,17 @@ static void complete_from_args( const wchar_t *str,
|
|||
const wchar_t *desc,
|
||||
array_list_t *comp_out )
|
||||
{
|
||||
int was_interactive = is_interactive;
|
||||
is_interactive=0;
|
||||
|
||||
array_list_t possible_comp;
|
||||
al_init( &possible_comp );
|
||||
|
||||
eval_args( args, &possible_comp );
|
||||
|
||||
is_interactive=was_interactive;
|
||||
|
||||
|
||||
debug( 3, L"desc is '%ls', %d long\n", desc, wcslen(desc) );
|
||||
|
||||
copy_strings_with_prefix( comp_out, str, desc, 0, &possible_comp );
|
||||
|
|
47
env.c
47
env.c
|
@ -42,6 +42,7 @@
|
|||
#include "input_common.h"
|
||||
#include "event.h"
|
||||
#include "translate.h"
|
||||
#include "complete.h"
|
||||
|
||||
/**
|
||||
Command used to start fishd
|
||||
|
@ -214,12 +215,25 @@ static mode_t get_umask()
|
|||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
List of all locale variable names
|
||||
*/
|
||||
static const wchar_t *locale_variable[] =
|
||||
{
|
||||
L"LANG", L"LC_ALL", L"LC_COLLATE", L"LC_CTYPE", L"LC_MESSAGES", L"LC_MONETARY", L"LC_NUMERIC", L"LC_TIME", (void *)0
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Checks if the specified variable is a locale variable
|
||||
*/
|
||||
static int is_locale( const wchar_t *key )
|
||||
{
|
||||
return contains_str( key, L"LANG", L"LC_ALL", L"LC_COLLATE", L"LC_CTYPE", L"LC_MESSAGES", L"LC_MONETARY", L"LC_NUMERIC", L"LC_TIME", (void *)0);
|
||||
int i;
|
||||
for( i=0; locale_variable[i]; i++ )
|
||||
if( wcscmp(locale_variable[i], key ) == 0 )
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,15 +245,13 @@ static void handle_locale()
|
|||
const wchar_t *lang;
|
||||
int i;
|
||||
wchar_t *old = wcsdup(wsetlocale( LC_MESSAGES, (void *)0 ));
|
||||
|
||||
static const wchar_t *lc[] =
|
||||
{
|
||||
L"LC_COLLATE", L"LC_CTYPE", L"LC_MESSAGES", L"LC_MONETARY", L"LC_NUMERIC", L"LC_TIME", (void *)0
|
||||
}
|
||||
;
|
||||
|
||||
/*
|
||||
Array of locale constants corresponding to the local variable names defined in locale_variable
|
||||
*/
|
||||
static const int cat[] =
|
||||
{
|
||||
LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME
|
||||
0, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -255,9 +267,9 @@ static void handle_locale()
|
|||
wsetlocale( LC_ALL, lang );
|
||||
}
|
||||
|
||||
for( i=0; lc[i]; i++ )
|
||||
for( i=2; locale_variable[i]; i++ )
|
||||
{
|
||||
const wchar_t *val = env_get( lc[i] );
|
||||
const wchar_t *val = env_get( locale_variable[i] );
|
||||
if( val )
|
||||
wsetlocale( cat[i], val );
|
||||
}
|
||||
|
@ -978,8 +990,20 @@ void env_pop()
|
|||
{
|
||||
if( &top->env != global )
|
||||
{
|
||||
int i;
|
||||
int locale_changed = 0;
|
||||
|
||||
env_node_t *killme = top;
|
||||
|
||||
for( i=0; locale_variable[i]; i++ )
|
||||
{
|
||||
if( hash_get( &killme->env, locale_variable[i] ) )
|
||||
{
|
||||
locale_changed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( killme->new_scope )
|
||||
{
|
||||
has_changed |= killme->export || local_scope_exports( killme->next );
|
||||
|
@ -989,6 +1013,9 @@ void env_pop()
|
|||
hash_foreach( &killme->env, &clear_hash_entry );
|
||||
hash_destroy( &killme->env );
|
||||
free( killme );
|
||||
|
||||
if( locale_changed )
|
||||
handle_locale();
|
||||
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue