diff --git a/fallback.cpp b/fallback.cpp index 2095a88c9..4a0d85668 100644 --- a/fallback.cpp +++ b/fallback.cpp @@ -1122,21 +1122,38 @@ int futimes(int fd, const struct timeval *times) #endif -#ifndef HAVE_GETTEXT +#if HAVE_GETTEXT -char * gettext(const char * msgid) +char * fish_gettext(const char * msgid) +{ + return gettext(msgid);; +} + +char * fish_bindtextdomain(const char * domainname, const char * dirname) +{ + return bindtextdomain(domainname, dirname); +} + +char * fish_textdomain(const char * domainname) +{ + return textdomain(domainname); +} + +#else + +char * fish_gettext(const char * msgid) { return (char *)msgid; } -char * bindtextdomain(const char * domainname, const char * dirname) +char * fish_bindtextdomain(const char * domainname, const char * dirname) { - return 0; + return NULL; } -char * textdomain(const char * domainname) +char * fish_textdomain(const char * domainname) { - return 0; + return NULL; } #endif diff --git a/fallback.h b/fallback.h index 9d52498e2..503bf07c7 100644 --- a/fallback.h +++ b/fallback.h @@ -387,24 +387,16 @@ int futimes(int fd, const struct timeval *times); #endif -#ifndef HAVE_GETTEXT +/* autoconf may fail to detect gettext (645), so don't define a function call gettext or we'll get build errors */ -/** - Fallback implementation of gettext. Just returns the original string. -*/ -char * gettext(const char * msgid); +/** Fallback implementation of gettext. Just returns the original string. */ +char * fish_gettext(const char * msgid); -/** - Fallback implementation of bindtextdomain. Does nothing. -*/ -char * bindtextdomain(const char * domainname, const char * dirname); +/** Fallback implementation of bindtextdomain. Does nothing. */ +char * fish_bindtextdomain(const char * domainname, const char * dirname); -/** - Fallback implementation of textdomain. Does nothing. -*/ -char * textdomain(const char * domainname); - -#endif +/** Fallback implementation of textdomain. Does nothing. */ +char * fish_textdomain(const char * domainname); #ifndef HAVE_DCGETTEXT diff --git a/fish_tests.cpp b/fish_tests.cpp index 94679facf..86b2365d8 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -1698,6 +1698,12 @@ void history_tests_t::test_history_speed(void) */ int main(int argc, char **argv) { + std::string tmp = "sldfjsdlkfjsdlkfjlf"; + for (size_t i=0; i < 1000000; i++) { + str2wcstring(tmp); + } + exit(0); + setlocale(LC_ALL, ""); srand(time(0)); configure_thread_assertions_for_testing(); @@ -1714,6 +1720,7 @@ int main(int argc, char **argv) builtin_init(); reader_init(); env_init(); + test_format(); test_escape(); diff --git a/history.cpp b/history.cpp index 9f99c4857..af76caf3d 100644 --- a/history.cpp +++ b/history.cpp @@ -662,13 +662,13 @@ static bool extract_prefix_and_unescape_yaml(std::string &key, std::string &valu size_t where = line.find(":"); if (where != std::string::npos) { - key = line.substr(0, where); + key.assign(line, 0, where); // skip a space after the : if necessary size_t val_start = where + 1; if (val_start < line.size() && line.at(val_start) == ' ') val_start++; - value = line.substr(val_start); + value.assign(line, val_start, line.size() - val_start); unescape_yaml(key); unescape_yaml(value); @@ -717,12 +717,10 @@ history_item_t history_t::decode_item_fish_2_0(const char *base, size_t len) if (key == "when") { - /* Parse an int from the timestamp */ - long tmp = 0; - if (sscanf(value.c_str(), "%ld", &tmp) > 0) - { - when = tmp; - } + /* Parse an int from the timestamp. Should this fail, strtol returns 0; that's acceptable. */ + char *end = NULL; + long tmp = strtol(value.c_str(), &end, 0); + when = tmp; } else if (key == "paths") { diff --git a/mimedb.cpp b/mimedb.cpp index 9f8d93809..cf02c70c5 100644 --- a/mimedb.cpp +++ b/mimedb.cpp @@ -156,7 +156,7 @@ static int launch_pos=0; gettext alias */ #ifdef USE_GETTEXT -#define _(string) gettext(string) +#define _(string) fish_gettext(string) #else #define _(string) (string) #endif @@ -1210,8 +1210,8 @@ static void launch(char *filter, const string_list_t &files, size_t fileno) static void locale_init() { setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE_NAME, LOCALEDIR); - textdomain(PACKAGE_NAME); + fish_bindtextdomain(PACKAGE_NAME, LOCALEDIR); + fish_textdomain(PACKAGE_NAME); } diff --git a/wutil.cpp b/wutil.cpp index fe5a3f49f..03b55c89a 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -439,8 +439,8 @@ wcstring wbasename(const wcstring &path) static void wgettext_really_init() { pthread_mutex_init(&wgettext_lock, NULL); - bindtextdomain(PACKAGE_NAME, LOCALEDIR); - textdomain(PACKAGE_NAME); + fish_bindtextdomain(PACKAGE_NAME, LOCALEDIR); + fish_textdomain(PACKAGE_NAME); } /** @@ -469,7 +469,7 @@ const wchar_t *wgettext(const wchar_t *in) if (val == NULL) { cstring mbs_in = wcs2string(key); - char *out = gettext(mbs_in.c_str()); + char *out = fish_gettext(mbs_in.c_str()); val = new wcstring(format_string(L"%s", out)); } errno = err;