Skip to content

Commit

Permalink
remove dependency on dcgettext()
Browse files Browse the repository at this point in the history
While fixing issue #3110 I noticed there is exactly one place we use
dcgettext() and that use is completely unnecessary. So remove it.
  • Loading branch information
Kurtis Rader committed Jun 6, 2016
1 parent 0b385f1 commit 9f21e37
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 56 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -305,7 +305,7 @@ AC_CHECK_FUNCS( futimens clock_gettime )
AC_CHECK_DECL( [mkostemp], [ AC_CHECK_FUNCS([mkostemp]) ] )

if test x$local_gettext != xno; then
AC_CHECK_FUNCS( gettext dcgettext )
AC_CHECK_FUNCS( gettext )

#
# The Makefile also needs to know if we have gettext, so it knows if
Expand Down
10 changes: 5 additions & 5 deletions src/env.cpp
Expand Up @@ -9,7 +9,9 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#ifdef HAVE__NL_MSG_CAT_CNTR
#include <string.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Expand Down Expand Up @@ -191,15 +193,13 @@ static void handle_locale(const wchar_t *env_var_name) {
const char *new_msg_locale = setlocale(LC_MESSAGES, NULL);
debug(3, L"old LC_MESSAGES locale: '%s'", old_msg_locale);
debug(3, L"new LC_MESSAGES locale: '%s'", new_msg_locale);
#ifdef HAVE__NL_MSG_CAT_CNTR
if (strcmp(old_msg_locale, new_msg_locale)) {
// Try to make change known to gettext. Both changing _nl_msg_cat_cntr and calling dcgettext
// might potentially tell some gettext implementation that the translation strings should be
// reloaded. We do both and hope for the best.
debug(2, L"changing message locale from '%s' to '%s'", old_msg_locale, new_msg_locale);
// Make change known to GNU gettext.
extern int _nl_msg_cat_cntr;
_nl_msg_cat_cntr++;
fish_dcgettext("fish", "Changing language to English", LC_MESSAGES);
}
#endif
}

/// Check if the specified variable is a locale variable.
Expand Down
41 changes: 0 additions & 41 deletions src/fallback.cpp
Expand Up @@ -171,7 +171,6 @@ wchar_t *wcsndup(const wchar_t *in, size_t c) {
#endif

#ifndef HAVE_WCSLCPY

/*$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $*/

/*
Expand All @@ -189,7 +188,6 @@ wchar_t *wcsndup(const wchar_t *in, size_t c) {
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) {
register wchar_t *d = dst;
register const wchar_t *s = src;
Expand All @@ -212,11 +210,9 @@ size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) {
return s - src - 1;
// Count does not include NUL.
}

#endif

#ifndef HAVE_LRAND48_R

int lrand48_r(struct drand48_data *buffer, long int *result) {
*result = rand_r(&buffer->seed);
return 0;
Expand All @@ -226,20 +222,16 @@ int srand48_r(long int seedval, struct drand48_data *buffer) {
buffer->seed = (unsigned int)seedval;
return 0;
}

#endif

#ifndef HAVE_FUTIMES

int futimes(int fd, const struct timeval *times) {
errno = ENOSYS;
return -1;
}

#endif

#if HAVE_GETTEXT

char *fish_gettext(const char *msgid) {
return gettext(msgid);
;
Expand All @@ -250,35 +242,10 @@ char *fish_bindtextdomain(const char *domainname, const char *dirname) {
}

char *fish_textdomain(const char *domainname) { return textdomain(domainname); }

#else

char *fish_gettext(const char *msgid) { return (char *)msgid; }

char *fish_bindtextdomain(const char *domainname, const char *dirname) { return NULL; }

char *fish_textdomain(const char *domainname) { return NULL; }

#endif

#if HAVE_DCGETTEXT

char *fish_dcgettext(const char *domainname, const char *msgid, int category) {
return dcgettext(domainname, msgid, category);
}

#else

char *fish_dcgettext(const char *domainname, const char *msgid, int category) {
return (char *)msgid;
}

#endif

#ifndef HAVE__NL_MSG_CAT_CNTR

int _nl_msg_cat_cntr = 0;

#endif

#ifndef HAVE_KILLPG
Expand All @@ -299,18 +266,12 @@ double nan(char *tagp) { return 0.0 / 0.0; }
#endif

#if !HAVE_BROKEN_WCWIDTH

int fish_wcwidth(wchar_t wc) { return wcwidth(wc); }

int fish_wcswidth(const wchar_t *str, size_t n) { return wcswidth(str, n); }

#else

static int mk_wcwidth(wchar_t wc);
static int mk_wcswidth(const wchar_t *pwcs, size_t n);

int fish_wcwidth(wchar_t wc) { return mk_wcwidth(wc); }

int fish_wcswidth(const wchar_t *str, size_t n) { return mk_wcswidth(str, n); }

/*
Expand Down Expand Up @@ -373,7 +334,6 @@ int fish_wcswidth(const wchar_t *str, size_t n) { return mk_wcswidth(str, n); }
*
* Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
*/

struct interval {
int first;
int last;
Expand Down Expand Up @@ -502,5 +462,4 @@ static int mk_wcswidth(const wchar_t *pwcs, size_t n) {
}
return width;
}

#endif // HAVE_BROKEN_WCWIDTH
9 changes: 0 additions & 9 deletions src/fallback.h
Expand Up @@ -120,15 +120,6 @@ char *fish_bindtextdomain(const char *domainname, const char *dirname);
/// Cover for textdomain().
char *fish_textdomain(const char *domainname);

/// Cover for dcgettext.
char *fish_dcgettext(const char *domainname, const char *msgid, int category);

#ifndef HAVE__NL_MSG_CAT_CNTR
/// Some gettext implementation use have this variable, and by increasing it, one can tell the
/// system that the translations need to be reloaded.
extern int _nl_msg_cat_cntr;
#endif

#ifndef HAVE_KILLPG
/// Send specified signal to specified process group.
int killpg(int pgr, int sig);
Expand Down

0 comments on commit 9f21e37

Please sign in to comment.