aboutsummaryrefslogtreecommitdiffhomepage
path: root/env.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-01-13 11:00:12 +1000
committerGravatar axel <axel@liljencrantz.se>2006-01-13 11:00:12 +1000
commit2b7781d3cb64e0696f70f9df225105d54407857d (patch)
tree940f963643aba4e85a50efa40a769b051da2430d /env.c
parentf0b2d7532a7020431ef447380154e5631e05d9da (diff)
Correctly handle locale changes through scope expiry, as well as locale changes in completion code
darcs-hash:20060113010012-ac50b-81cde216bd6b92f7b1374e5f6452695618185f95.gz
Diffstat (limited to 'env.c')
-rw-r--r--env.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/env.c b/env.c
index f547578a..e00c7b5a 100644
--- a/env.c
+++ b/env.c
@@ -42,6 +42,7 @@
#include "input_common.h"
#include "event.h"
#include "translate.h"
+#include "complete.h"
/**
Command used to start fishd
@@ -215,11 +216,24 @@ static mode_t get_umask()
}
/**
+ 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