mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
Remove translate.c. The gettext fallback functionality is moved to fallback.c, the wide wrapper is moved to wutil.c
darcs-hash:20060719225549-ac50b-0a55e805b04f4fe0afa99ea580901d62f39cdef5.gz
This commit is contained in:
parent
1dc033f71c
commit
b2e2743195
33 changed files with 187 additions and 192 deletions
|
@ -67,7 +67,7 @@ FISH_OBJS := function.o builtin.o complete.o env.o exec.o \
|
||||||
expand.o highlight.o history.o kill.o parser.o proc.o reader.o \
|
expand.o highlight.o history.o kill.o parser.o proc.o reader.o \
|
||||||
sanity.o tokenizer.o wildcard.o wgetopt.o wutil.o input.o \
|
sanity.o tokenizer.o wildcard.o wgetopt.o wutil.o input.o \
|
||||||
output.o intern.o env_universal.o env_universal_common.o \
|
output.o intern.o env_universal.o env_universal_common.o \
|
||||||
input_common.o event.o signal.o io.o translate.o parse_util.o common.o \
|
input_common.o event.o signal.o io.o parse_util.o common.o \
|
||||||
|
|
||||||
# Additional files used by builtin.o
|
# Additional files used by builtin.o
|
||||||
BUILTIN_FILES := builtin_help.c builtin_set.c builtin_commandline.c \
|
BUILTIN_FILES := builtin_help.c builtin_set.c builtin_commandline.c \
|
||||||
|
@ -76,7 +76,7 @@ BUILTIN_FILES := builtin_help.c builtin_set.c builtin_commandline.c \
|
||||||
# All objects that the system needs to build fish_pager
|
# All objects that the system needs to build fish_pager
|
||||||
FISH_PAGER_OBJS := fish_pager.o output.o wutil.o \
|
FISH_PAGER_OBJS := fish_pager.o output.o wutil.o \
|
||||||
tokenizer.o input_common.o env_universal.o env_universal_common.o \
|
tokenizer.o input_common.o env_universal.o env_universal_common.o \
|
||||||
translate.o common.o
|
common.o
|
||||||
|
|
||||||
# All objects that the system needs to build fish_tests
|
# All objects that the system needs to build fish_tests
|
||||||
FISH_TESTS_OBJS := $(FISH_OBJS) fish_tests.o
|
FISH_TESTS_OBJS := $(FISH_OBJS) fish_tests.o
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
#include "intern.h"
|
#include "intern.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "halloc.h"
|
#include "halloc.h"
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
|
|
|
@ -26,7 +26,7 @@ Functions used for implementing the commandline builtin.
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
#include "input_common.h"
|
#include "input_common.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,7 +23,7 @@ Functions used for implementing the complete builtin.
|
||||||
#include "wgetopt.h"
|
#include "wgetopt.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Internal storage for the builtin_get_temporary_buffer() function.
|
Internal storage for the builtin_get_temporary_buffer() function.
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wgetopt.h"
|
#include "wgetopt.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Print modes for the jobs builtin
|
Print modes for the jobs builtin
|
||||||
|
|
|
@ -24,7 +24,7 @@ Functions used for implementing the set builtin.
|
||||||
#include "wgetopt.h"
|
#include "wgetopt.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Error message for invalid path operations
|
Error message for invalid path operations
|
||||||
|
|
|
@ -20,7 +20,7 @@ Functions used for implementing the ulimit builtin.
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wgetopt.h"
|
#include "wgetopt.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Struct describing a resource limit
|
Struct describing a resource limit
|
||||||
|
|
10
common.h
10
common.h
|
@ -96,6 +96,16 @@ extern wchar_t *program_name;
|
||||||
exit(1); \
|
exit(1); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shorthand for wgettext call
|
||||||
|
*/
|
||||||
|
#define _(wstr) wgettext(wstr)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Noop, used to tell xgettext that a string should be translated, even though it is not directly sent to wgettext.
|
||||||
|
*/
|
||||||
|
#define N_(wstr) wstr
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Take an array_list_t containing wide strings and converts them to a
|
Take an array_list_t containing wide strings and converts them to a
|
||||||
single null-terminated wchar_t **. The array is allocated using
|
single null-terminated wchar_t **. The array is allocated using
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "intern.h"
|
#include "intern.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
#include "halloc.h"
|
#include "halloc.h"
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
|
|
|
@ -244,7 +244,7 @@ AC_DEFINE([HAVE_TRANSLATE_H], [1],
|
||||||
[Define to 1 if the wgettext function should be used for translating strings.])
|
[Define to 1 if the wgettext function should be used for translating strings.])
|
||||||
|
|
||||||
# Check for presense of various libraries
|
# Check for presense of various libraries
|
||||||
AC_SEARCH_LIBS( gettext, intl, AC_SUBST( HAVE_GETTEXT, [1] ), AC_SUBST( HAVE_GETTEXT, [0] ) )
|
AC_SEARCH_LIBS( gettext, intl,,)
|
||||||
AC_SEARCH_LIBS( connect, socket, , [AC_MSG_ERROR([Cannot find the socket library, needed to build this package.] )] )
|
AC_SEARCH_LIBS( connect, socket, , [AC_MSG_ERROR([Cannot find the socket library, needed to build this package.] )] )
|
||||||
AC_SEARCH_LIBS( nanosleep, rt, , [AC_MSG_ERROR([Cannot find the rt library, needed to build this package.] )] )
|
AC_SEARCH_LIBS( nanosleep, rt, , [AC_MSG_ERROR([Cannot find the rt library, needed to build this package.] )] )
|
||||||
AC_SEARCH_LIBS( setupterm, [ncurses curses], , [AC_MSG_ERROR([Could not find a curses implementation, needed to build fish])] )
|
AC_SEARCH_LIBS( setupterm, [ncurses curses], , [AC_MSG_ERROR([Could not find a curses implementation, needed to build fish])] )
|
||||||
|
|
2
env.c
2
env.c
|
@ -49,7 +49,7 @@
|
||||||
#include "env_universal.h"
|
#include "env_universal.h"
|
||||||
#include "input_common.h"
|
#include "input_common.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "complete.h"
|
#include "complete.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
2
event.c
2
event.c
|
@ -23,7 +23,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
2
exec.c
2
exec.c
|
@ -39,7 +39,7 @@
|
||||||
#include "expand.h"
|
#include "expand.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "env_universal.h"
|
#include "env_universal.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "halloc.h"
|
#include "halloc.h"
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
|
|
2
expand.c
2
expand.c
|
@ -42,7 +42,7 @@ parameter expansion.
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
#include "complete.h"
|
#include "complete.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
|
|
||||||
|
|
19
fallback.c
19
fallback.c
|
@ -1029,6 +1029,25 @@ int futimes(int fd, const struct timeval *times)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_GETTEXT
|
||||||
|
|
||||||
|
char * gettext (const char * msgid)
|
||||||
|
{
|
||||||
|
return msgid;
|
||||||
|
}
|
||||||
|
|
||||||
|
char * bindtextdomain (const char * domainname, const char * dirname)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char * textdomain (const char * domainname)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -325,5 +325,14 @@ int futimes(int fd, const struct timeval *times);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_GETTEXT
|
||||||
|
|
||||||
|
char * gettext (const char * msgid);
|
||||||
|
char * bindtextdomain (const char * domainname, const char * dirname);
|
||||||
|
char * textdomain (const char * domainname);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "intern.h"
|
#include "intern.h"
|
||||||
|
|
2
input.c
2
input.c
|
@ -59,7 +59,7 @@ implementation in fish is as of yet incomplete.
|
||||||
#include "expand.h"
|
#include "expand.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "intern.h"
|
#include "intern.h"
|
||||||
|
|
||||||
|
|
2
io.c
2
io.c
|
@ -39,7 +39,7 @@ Utilities for io redirection.
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "halloc.h"
|
#include "halloc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
2
main.c
2
main.c
|
@ -58,7 +58,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "intern.h"
|
#include "intern.h"
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "wildcard.h"
|
#include "wildcard.h"
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
|
|
||||||
|
|
2
parser.c
2
parser.c
|
@ -37,7 +37,7 @@ The fish parser. Contains functions for parsing code.
|
||||||
#include "sanity.h"
|
#include "sanity.h"
|
||||||
#include "env_universal.h"
|
#include "env_universal.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "intern.h"
|
#include "intern.h"
|
||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
#include "halloc.h"
|
#include "halloc.h"
|
||||||
|
|
2
proc.c
2
proc.c
|
@ -55,7 +55,7 @@ Some of the code in this file is based on code from the Glibc manual.
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "halloc.h"
|
#include "halloc.h"
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
|
|
2
reader.c
2
reader.c
|
@ -82,7 +82,7 @@ commence.
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "translate.h"
|
|
||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
2
sanity.c
2
sanity.c
|
@ -25,7 +25,7 @@
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "kill.h"
|
#include "kill.h"
|
||||||
#include "wutil.h"
|
#include "wutil.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Status from earlier sanity checks
|
Status from earlier sanity checks
|
||||||
|
|
2
signal.c
2
signal.c
|
@ -24,7 +24,7 @@ The library for various signal related issues
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Struct describing an entry for the lookup table used to convert
|
Struct describing an entry for the lookup table used to convert
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wildcard.h"
|
#include "wildcard.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Error string for unexpected end of string
|
Error string for unexpected end of string
|
||||||
|
|
144
translate.c
144
translate.c
|
@ -1,144 +0,0 @@
|
||||||
/** \file translate.c
|
|
||||||
|
|
||||||
Translation library, internally uses catgets
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <wchar.h>
|
|
||||||
|
|
||||||
#if HAVE_LIBINTL_H
|
|
||||||
#include <libintl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "fallback.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
#include "halloc_util.h"
|
|
||||||
|
|
||||||
#if HAVE_GETTEXT
|
|
||||||
|
|
||||||
/**
|
|
||||||
Number of string_buffer_t in the ring of buffers
|
|
||||||
*/
|
|
||||||
#define BUFF_COUNT 64
|
|
||||||
|
|
||||||
/**
|
|
||||||
The ring of string_buffer_t
|
|
||||||
*/
|
|
||||||
static string_buffer_t buff[BUFF_COUNT];
|
|
||||||
/**
|
|
||||||
Current position in the ring
|
|
||||||
*/
|
|
||||||
static int curr_buff=0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Buffer used by translate_wcs2str
|
|
||||||
*/
|
|
||||||
static char *wcs2str_buff=0;
|
|
||||||
/**
|
|
||||||
Size of buffer used by translate_wcs2str
|
|
||||||
*/
|
|
||||||
static size_t wcs2str_buff_count=0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Flag to tell whether the translation library has been initialized
|
|
||||||
*/
|
|
||||||
static int is_init = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Internal shutdown function. Automatically called on shutdown if the library has been initialized.
|
|
||||||
*/
|
|
||||||
static void internal_destroy()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if( !is_init )
|
|
||||||
return;
|
|
||||||
|
|
||||||
is_init = 0;
|
|
||||||
|
|
||||||
for(i=0; i<BUFF_COUNT; i++ )
|
|
||||||
sb_destroy( &buff[i] );
|
|
||||||
|
|
||||||
free( wcs2str_buff );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Internal init function. Automatically called when a translation is first requested.
|
|
||||||
*/
|
|
||||||
static void internal_init()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
is_init = 1;
|
|
||||||
|
|
||||||
for(i=0; i<BUFF_COUNT; i++ )
|
|
||||||
{
|
|
||||||
sb_init( &buff[i] );
|
|
||||||
}
|
|
||||||
halloc_register_function_void( global_context, &internal_destroy );
|
|
||||||
|
|
||||||
bindtextdomain( PACKAGE_NAME, LOCALEDIR );
|
|
||||||
textdomain( PACKAGE_NAME );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Wide to narrow character conversion. Internal implementation that
|
|
||||||
avoids exessive calls to malloc
|
|
||||||
*/
|
|
||||||
static char *translate_wcs2str( const wchar_t *in )
|
|
||||||
{
|
|
||||||
size_t len = MAX_UTF8_BYTES*wcslen(in)+1;
|
|
||||||
if( len > wcs2str_buff_count )
|
|
||||||
{
|
|
||||||
wcs2str_buff = realloc( wcs2str_buff, len );
|
|
||||||
if( wcs2str_buff == 0 )
|
|
||||||
{
|
|
||||||
DIE_MEM();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wcstombs( wcs2str_buff,
|
|
||||||
in,
|
|
||||||
MAX_UTF8_BYTES*wcslen(in)+1 );
|
|
||||||
|
|
||||||
return wcs2str_buff;
|
|
||||||
}
|
|
||||||
|
|
||||||
const wchar_t *wgettext( const wchar_t *in )
|
|
||||||
{
|
|
||||||
if( !in )
|
|
||||||
return in;
|
|
||||||
|
|
||||||
if( !is_init )
|
|
||||||
internal_init();
|
|
||||||
|
|
||||||
char *mbs_in = translate_wcs2str( in );
|
|
||||||
char *out = gettext( mbs_in );
|
|
||||||
wchar_t *wres=0;
|
|
||||||
|
|
||||||
sb_clear( &buff[curr_buff] );
|
|
||||||
|
|
||||||
sb_printf( &buff[curr_buff], L"%s", out );
|
|
||||||
wres = (wchar_t *)buff[curr_buff].buff;
|
|
||||||
curr_buff = (curr_buff+1)%BUFF_COUNT;
|
|
||||||
|
|
||||||
return wres;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
const wchar_t *wgettext( const wchar_t *in )
|
|
||||||
{
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
21
translate.h
21
translate.h
|
@ -1,21 +0,0 @@
|
||||||
/** \file translate.h
|
|
||||||
|
|
||||||
Translation library, internally uses catgets
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
Shorthand for wgettext call
|
|
||||||
*/
|
|
||||||
#define _(wstr) wgettext(wstr)
|
|
||||||
|
|
||||||
/**
|
|
||||||
Noop, used to tell xgettext that a string should be translated, even though it is not directly sent to wgettext.
|
|
||||||
*/
|
|
||||||
#define N_(wstr) wstr
|
|
||||||
|
|
||||||
/**
|
|
||||||
Wide character wwrapper around the gettext function
|
|
||||||
*/
|
|
||||||
const wchar_t *wgettext( const wchar_t *in );
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ static char *posixly_correct;
|
||||||
Use translation functions if available
|
Use translation functions if available
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_TRANSLATE_H
|
#ifdef HAVE_TRANSLATE_H
|
||||||
#include "translate.h"
|
|
||||||
#define _(wstr) wgettext(wstr)
|
#define _(wstr) wgettext(wstr)
|
||||||
#else
|
#else
|
||||||
#define _(wstr) wstr
|
#define _(wstr) wstr
|
||||||
|
|
|
@ -29,7 +29,7 @@ wildcards using **.
|
||||||
#include "complete.h"
|
#include "complete.h"
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "expand.h"
|
#include "expand.h"
|
||||||
#include "translate.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This flag is set in the flags parameter of wildcard_expand if the
|
This flag is set in the flags parameter of wildcard_expand if the
|
||||||
|
|
114
wutil.c
114
wutil.c
|
@ -20,6 +20,9 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#if HAVE_LIBINTL_H
|
||||||
|
#include <libintl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "fallback.h"
|
#include "fallback.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -76,6 +79,38 @@ static int wutil_calls = 0;
|
||||||
*/
|
*/
|
||||||
static struct wdirent my_wdirent;
|
static struct wdirent my_wdirent;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
For wgettext: Number of string_buffer_t in the ring of buffers
|
||||||
|
*/
|
||||||
|
#define BUFF_COUNT 64
|
||||||
|
|
||||||
|
/**
|
||||||
|
For wgettext: The ring of string_buffer_t
|
||||||
|
*/
|
||||||
|
static string_buffer_t buff[BUFF_COUNT];
|
||||||
|
/**
|
||||||
|
For wgettext: Current position in the ring
|
||||||
|
*/
|
||||||
|
static int curr_buff=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
For wgettext: Buffer used by translate_wcs2str
|
||||||
|
*/
|
||||||
|
static char *wcs2str_buff=0;
|
||||||
|
/**
|
||||||
|
For wgettext: Size of buffer used by translate_wcs2str
|
||||||
|
*/
|
||||||
|
static size_t wcs2str_buff_count=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
For wgettext: Flag to tell whether the translation library has been initialized
|
||||||
|
*/
|
||||||
|
static int wgettext_is_init = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void wutil_init()
|
void wutil_init()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -404,3 +439,82 @@ wchar_t *wbasename( const wchar_t *path )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
For wgettext: Internal shutdown function. Automatically called on shutdown if the library has been initialized.
|
||||||
|
*/
|
||||||
|
static void wgettext_destroy()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if( !wgettext_is_init )
|
||||||
|
return;
|
||||||
|
|
||||||
|
wgettext_is_init = 0;
|
||||||
|
|
||||||
|
for(i=0; i<BUFF_COUNT; i++ )
|
||||||
|
sb_destroy( &buff[i] );
|
||||||
|
|
||||||
|
free( wcs2str_buff );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
For wgettext: Internal init function. Automatically called when a translation is first requested.
|
||||||
|
*/
|
||||||
|
static void wgettext_init()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
wgettext_is_init = 1;
|
||||||
|
|
||||||
|
for(i=0; i<BUFF_COUNT; i++ )
|
||||||
|
{
|
||||||
|
sb_init( &buff[i] );
|
||||||
|
}
|
||||||
|
|
||||||
|
halloc_register_function_void( global_context, &wgettext_destroy );
|
||||||
|
|
||||||
|
bindtextdomain( PACKAGE_NAME, LOCALEDIR );
|
||||||
|
textdomain( PACKAGE_NAME );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
For wgettext: Wide to narrow character conversion. Internal implementation that
|
||||||
|
avoids exessive calls to malloc
|
||||||
|
*/
|
||||||
|
static char *wgettext_wcs2str( const wchar_t *in )
|
||||||
|
{
|
||||||
|
size_t len = MAX_UTF8_BYTES*wcslen(in)+1;
|
||||||
|
if( len > wcs2str_buff_count )
|
||||||
|
{
|
||||||
|
wcs2str_buff = realloc( wcs2str_buff, len );
|
||||||
|
if( !wcs2str_buff )
|
||||||
|
{
|
||||||
|
DIE_MEM();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wcs2str_internal( in, wcs2str_buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
const wchar_t *wgettext( const wchar_t *in )
|
||||||
|
{
|
||||||
|
if( !in )
|
||||||
|
return in;
|
||||||
|
|
||||||
|
if( !wgettext_is_init )
|
||||||
|
wgettext_init();
|
||||||
|
|
||||||
|
char *mbs_in = wgettext_wcs2str( in );
|
||||||
|
char *out = gettext( mbs_in );
|
||||||
|
wchar_t *wres=0;
|
||||||
|
|
||||||
|
sb_clear( &buff[curr_buff] );
|
||||||
|
|
||||||
|
sb_printf( &buff[curr_buff], L"%s", out );
|
||||||
|
wres = (wchar_t *)buff[curr_buff].buff;
|
||||||
|
curr_buff = (curr_buff+1)%BUFF_COUNT;
|
||||||
|
|
||||||
|
return wres;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
9
wutil.h
9
wutil.h
|
@ -118,5 +118,14 @@ wchar_t *wdirname( const wchar_t *path );
|
||||||
*/
|
*/
|
||||||
wchar_t *wbasename( const wchar_t *path );
|
wchar_t *wbasename( const wchar_t *path );
|
||||||
|
|
||||||
|
/**
|
||||||
|
Wide character wrapper around the gettext function. For historic
|
||||||
|
reasons, unlike the real gettext function, wgettext takes care of
|
||||||
|
setting the correct domain, etc. using the textdomain and
|
||||||
|
bindtextdomain functions. This should probably be moved out of
|
||||||
|
wgettext, so that wgettext will be nothing more than a wrapper
|
||||||
|
around gettext, like all other functions in this file.
|
||||||
|
*/
|
||||||
|
const wchar_t *wgettext( const wchar_t *in );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue