aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-01-09 09:00:49 +1000
committerGravatar axel <axel@liljencrantz.se>2006-01-09 09:00:49 +1000
commit906495d713fa6e773ccd093143c34336361f28c8 (patch)
tree0af3bca4ae92a1d12ea8ebee539d9668175a38ee /common.c
parent690648e1b0a04db179d113e2900dde52d0e7f67f (diff)
Improve locale implementation (should now behave identically to bash) and document locale variables behaviour
darcs-hash:20060108230049-ac50b-403f1d00c8483fc4fecc275b62e40b1c3d51bfc1.gz
Diffstat (limited to 'common.c')
-rw-r--r--common.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/common.c b/common.c
index 746b829c..9a12d41d 100644
--- a/common.c
+++ b/common.c
@@ -104,8 +104,17 @@ static struct winsize termsize;
*/
static int block_count=0;
+static string_buffer_t *setlocale_buff=0;
+
+
void common_destroy()
{
+ if( setlocale_buff )
+ {
+ sb_destroy( setlocale_buff );
+ free( setlocale_buff );
+ }
+
debug( 3, L"Calls: wcsdupcat %d, wcsdupcat2 %d, wcsndup %d, str2wcs %d, wcs2str %d", c1, c2, c3, c4, c5 );
}
@@ -719,27 +728,33 @@ wchar_t *quote_end( const wchar_t *in )
}
-void fish_setlocale(int category, const wchar_t *locale)
+const wchar_t *wsetlocale(int category, const wchar_t *locale)
{
- char *lang = wcs2str( locale );
- setlocale(category,lang);
+
+ char *lang = locale?wcs2str( locale ):0;
+ char * res = setlocale(category,lang);
free( lang );
+
/*
Use ellipsis if on known unicode system, otherwise use $
*/
- if( wcslen( locale ) )
- {
- ellipsis_char = wcsstr( locale, L".UTF")?L'\u2026':L'$';
- }
- else
+ char *ctype = setlocale( LC_CTYPE, (void *)0 );
+ ellipsis_char = (strstr( ctype, ".UTF")||strstr( ctype, ".utf") )?L'\u2026':L'$';
+
+ if( !res )
+ return 0;
+
+ if( !setlocale_buff )
{
- char *lang = getenv( "LANG" );
- if( lang )
- ellipsis_char = strstr( lang, ".UTF")?L'\u2026':L'$';
- else
- ellipsis_char = L'$';
+ setlocale_buff = malloc( sizeof(string_buffer_t) );
+ sb_init( setlocale_buff);
}
+
+ sb_clear( setlocale_buff );
+ sb_printf( setlocale_buff, L"%s", res );
+
+ return (wchar_t *)setlocale_buff->buff;
}
int contains_str( const wchar_t *a, ... )