diff --git a/Makefile.in b/Makefile.in index 9625f1680..275575ed1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 \ sanity.o tokenizer.o wildcard.o wgetopt.o wutil.o input.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 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 FISH_PAGER_OBJS := fish_pager.o output.o wutil.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 FISH_TESTS_OBJS := $(FISH_OBJS) fish_tests.o diff --git a/builtin.c b/builtin.c index a46fa6383..7bc08fb66 100644 --- a/builtin.c +++ b/builtin.c @@ -60,7 +60,7 @@ #include "intern.h" #include "event.h" #include "signal.h" -#include "translate.h" + #include "halloc.h" #include "halloc_util.h" #include "parse_util.h" diff --git a/builtin_commandline.c b/builtin_commandline.c index 42eb90166..fd7383eb4 100644 --- a/builtin_commandline.c +++ b/builtin_commandline.c @@ -26,7 +26,7 @@ Functions used for implementing the commandline builtin. #include "tokenizer.h" #include "input_common.h" #include "input.h" -#include "translate.h" + #include "parse_util.h" /** diff --git a/builtin_complete.c b/builtin_complete.c index 6531fd2b1..a9bf69e46 100644 --- a/builtin_complete.c +++ b/builtin_complete.c @@ -23,7 +23,7 @@ Functions used for implementing the complete builtin. #include "wgetopt.h" #include "parser.h" #include "reader.h" -#include "translate.h" + /** Internal storage for the builtin_get_temporary_buffer() function. diff --git a/builtin_jobs.c b/builtin_jobs.c index a527fdf0e..5a339cce9 100644 --- a/builtin_jobs.c +++ b/builtin_jobs.c @@ -24,7 +24,7 @@ #include "parser.h" #include "common.h" #include "wgetopt.h" -#include "translate.h" + /** Print modes for the jobs builtin diff --git a/builtin_set.c b/builtin_set.c index b53e4bbd3..9266d2ba0 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -24,7 +24,7 @@ Functions used for implementing the set builtin. #include "wgetopt.h" #include "proc.h" #include "parser.h" -#include "translate.h" + /** Error message for invalid path operations diff --git a/builtin_ulimit.c b/builtin_ulimit.c index 6b8c7b7ee..3dc11d6d9 100644 --- a/builtin_ulimit.c +++ b/builtin_ulimit.c @@ -20,7 +20,7 @@ Functions used for implementing the ulimit builtin. #include "builtin.h" #include "common.h" #include "wgetopt.h" -#include "translate.h" + /** Struct describing a resource limit diff --git a/common.h b/common.h index f08310775..84aa22c0a 100644 --- a/common.h +++ b/common.h @@ -96,6 +96,16 @@ extern wchar_t *program_name; 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 single null-terminated wchar_t **. The array is allocated using diff --git a/complete.c b/complete.c index 4cda7c8d5..48b80090f 100644 --- a/complete.c +++ b/complete.c @@ -39,7 +39,7 @@ #include "reader.h" #include "history.h" #include "intern.h" -#include "translate.h" + #include "parse_util.h" #include "halloc.h" #include "halloc_util.h" diff --git a/configure.ac b/configure.ac index b4eb2d264..86f86beb1 100644 --- a/configure.ac +++ b/configure.ac @@ -244,7 +244,7 @@ AC_DEFINE([HAVE_TRANSLATE_H], [1], [Define to 1 if the wgettext function should be used for translating strings.]) # 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( 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])] ) diff --git a/env.c b/env.c index 342c83092..2729af8f4 100644 --- a/env.c +++ b/env.c @@ -49,7 +49,7 @@ #include "env_universal.h" #include "input_common.h" #include "event.h" -#include "translate.h" + #include "complete.h" /** diff --git a/event.c b/event.c index bea6187f8..61e317c56 100644 --- a/event.c +++ b/event.c @@ -23,7 +23,7 @@ #include "common.h" #include "event.h" #include "signal.h" -#include "translate.h" + #include "halloc_util.h" /** diff --git a/exec.c b/exec.c index 168719080..17e3f9cd3 100644 --- a/exec.c +++ b/exec.c @@ -39,7 +39,7 @@ #include "expand.h" #include "signal.h" #include "env_universal.h" -#include "translate.h" + #include "halloc.h" #include "halloc_util.h" #include "parse_util.h" diff --git a/expand.c b/expand.c index c1d89fae9..a83dcfa37 100644 --- a/expand.c +++ b/expand.c @@ -42,7 +42,7 @@ parameter expansion. #include "signal.h" #include "tokenizer.h" #include "complete.h" -#include "translate.h" + #include "parse_util.h" #include "halloc_util.h" diff --git a/fallback.c b/fallback.c index 95889ede1..cad56171f 100644 --- a/fallback.c +++ b/fallback.c @@ -1029,6 +1029,25 @@ int futimes(int fd, const struct timeval *times) 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 + diff --git a/fallback.h b/fallback.h index 066539622..4ad55cfaa 100644 --- a/fallback.h +++ b/fallback.h @@ -325,5 +325,14 @@ int futimes(int fd, const struct timeval *times); #endif +#ifndef HAVE_GETTEXT + +char * gettext (const char * msgid); +char * bindtextdomain (const char * domainname, const char * dirname); +char * textdomain (const char * domainname); + +#endif + + #endif diff --git a/function.c b/function.c index 5989fd221..cc39d9eaf 100644 --- a/function.c +++ b/function.c @@ -16,7 +16,6 @@ #include "function.h" #include "proc.h" -#include "translate.h" #include "parser.h" #include "common.h" #include "intern.h" diff --git a/input.c b/input.c index 84ba51202..edd8aa200 100644 --- a/input.c +++ b/input.c @@ -59,7 +59,7 @@ implementation in fish is as of yet incomplete. #include "expand.h" #include "event.h" #include "signal.h" -#include "translate.h" + #include "output.h" #include "intern.h" diff --git a/io.c b/io.c index c657bce90..77e8e4fc9 100644 --- a/io.c +++ b/io.c @@ -39,7 +39,7 @@ Utilities for io redirection. #include "exec.h" #include "common.h" #include "io.h" -#include "translate.h" + #include "halloc.h" diff --git a/main.c b/main.c index 458c6841f..eb8b452bb 100644 --- a/main.c +++ b/main.c @@ -58,7 +58,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "exec.h" #include "event.h" #include "output.h" -#include "translate.h" + #include "halloc_util.h" #include "history.h" diff --git a/parse_util.c b/parse_util.c index 164269c02..482cae347 100644 --- a/parse_util.c +++ b/parse_util.c @@ -29,7 +29,7 @@ #include "intern.h" #include "exec.h" #include "env.h" -#include "translate.h" + #include "wildcard.h" #include "halloc_util.h" diff --git a/parser.c b/parser.c index 1ab7972f8..188390e53 100644 --- a/parser.c +++ b/parser.c @@ -37,7 +37,7 @@ The fish parser. Contains functions for parsing code. #include "sanity.h" #include "env_universal.h" #include "event.h" -#include "translate.h" + #include "intern.h" #include "parse_util.h" #include "halloc.h" diff --git a/proc.c b/proc.c index f3c5eebcf..4c5e50dff 100644 --- a/proc.c +++ b/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 "signal.h" #include "event.h" -#include "translate.h" + #include "halloc.h" #include "halloc_util.h" #include "output.h" diff --git a/reader.c b/reader.c index 0779019e6..bca8bf864 100644 --- a/reader.c +++ b/reader.c @@ -82,7 +82,7 @@ commence. #include "function.h" #include "output.h" #include "signal.h" -#include "translate.h" + #include "parse_util.h" /** diff --git a/sanity.c b/sanity.c index 7a7040026..f7e203239 100644 --- a/sanity.c +++ b/sanity.c @@ -25,7 +25,7 @@ #include "reader.h" #include "kill.h" #include "wutil.h" -#include "translate.h" + /** Status from earlier sanity checks diff --git a/signal.c b/signal.c index 083478a82..1cd6e8830 100644 --- a/signal.c +++ b/signal.c @@ -24,7 +24,7 @@ The library for various signal related issues #include "event.h" #include "reader.h" #include "proc.h" -#include "translate.h" + /** Struct describing an entry for the lookup table used to convert diff --git a/tokenizer.c b/tokenizer.c index 75343a5c6..d2b18e2ce 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -23,7 +23,7 @@ #include "tokenizer.h" #include "common.h" #include "wildcard.h" -#include "translate.h" + /** Error string for unexpected end of string diff --git a/translate.c b/translate.c deleted file mode 100644 index 744ff10af..000000000 --- a/translate.c +++ /dev/null @@ -1,144 +0,0 @@ -/** \file translate.c - -Translation library, internally uses catgets - -*/ - -#include "config.h" - - -#include -#include -#include -#include - -#if HAVE_LIBINTL_H -#include -#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 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 diff --git a/translate.h b/translate.h deleted file mode 100644 index 191235870..000000000 --- a/translate.h +++ /dev/null @@ -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 ); - diff --git a/wgetopt.c b/wgetopt.c index a3432073d..1767b9a61 100644 --- a/wgetopt.c +++ b/wgetopt.c @@ -180,7 +180,7 @@ static char *posixly_correct; Use translation functions if available */ #ifdef HAVE_TRANSLATE_H -#include "translate.h" + #define _(wstr) wgettext(wstr) #else #define _(wstr) wstr diff --git a/wildcard.c b/wildcard.c index 3467faa29..982839930 100644 --- a/wildcard.c +++ b/wildcard.c @@ -29,7 +29,7 @@ wildcards using **. #include "complete.h" #include "reader.h" #include "expand.h" -#include "translate.h" + /** This flag is set in the flags parameter of wildcard_expand if the diff --git a/wutil.c b/wutil.c index ab49b2f4e..44ad5f59d 100644 --- a/wutil.c +++ b/wutil.c @@ -20,6 +20,9 @@ #include #include +#if HAVE_LIBINTL_H +#include +#endif #include "fallback.h" #include "util.h" @@ -76,6 +79,38 @@ static int wutil_calls = 0; */ 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() { } @@ -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 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; +} + diff --git a/wutil.h b/wutil.h index 666ae67ce..aeb581b5e 100644 --- a/wutil.h +++ b/wutil.h @@ -118,5 +118,14 @@ wchar_t *wdirname( 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