From 603b784efd1db88ed1432bcd3b149b45d3b51e89 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Thu, 12 Jun 2003 14:24:26 +0000 Subject: moved i18n.hh and .cc files to I18n.hh .cc --- src/I18n.cc | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/I18n.hh | 70 +++++++++++++++++++++++++++++++ src/i18n.cc | 136 ----------------------------------------------------------- src/i18n.hh | 70 ------------------------------- 4 files changed, 207 insertions(+), 206 deletions(-) create mode 100644 src/I18n.cc create mode 100644 src/I18n.hh delete mode 100644 src/i18n.cc delete mode 100644 src/i18n.hh diff --git a/src/I18n.cc b/src/I18n.cc new file mode 100644 index 0000000..1d3cf8b --- /dev/null +++ b/src/I18n.cc @@ -0,0 +1,137 @@ +// I18n.hh for Fluxbox Window Manager +// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) +// +// I18n.cc for Blackbox - an X11 Window manager +// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: I18n.cc,v 1.1 2003/06/12 14:24:26 fluxgen Exp $ + +//usr GNU extensions +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif // _GNU_SOURCE + +#include "I18n.hh" + +#include + +#include +#include +#include + +#ifdef HAVE_LOCALE_H +#include +#endif // HAVE_LOCALE_H + +#include +using std::cerr; +using std::endl; +using std::string; + +void NLSInit(const char *catalog) { + I18n *i18n = I18n::instance(); + i18n->openCatalog(catalog); +} + + +I18n::I18n():m_multibyte(false), m_catalog_fd((nl_catd)(-1)) { +#ifdef HAVE_SETLOCALE + //make sure we don't get 0 to m_locale string + char *temp = setlocale(LC_ALL, ""); + m_locale = ( temp ? temp : ""); + if (m_locale.size() == 0) { + cerr<<"Warning: Failed to set locale, reverting to \"C\""< 1) + m_multibyte = true; + + // truncate any encoding off the end of the locale + + // remove everything after @ + string::size_type index = m_locale.find('@'); + if (index != string::npos) + m_locale.erase(index); //erase all characters starting at index + // remove everything after . + index = m_locale.find('.'); + if (index != string::npos) + m_locale.erase(index); //erase all characters starting at index + } +#endif // HAVE_SETLOCALE +} + + +I18n::~I18n() { + +#if defined(NLS) && defined(HAVE_CATCLOSE) + if (m_catalog_fd != (nl_catd)-1) + catclose(m_catalog_fd); +#endif // HAVE_CATCLOSE +} + +I18n *I18n::instance() { + static I18n singleton; //singleton object + return &singleton; +} + +void I18n::openCatalog(const char *catalog) { +#if defined(NLS) && defined(HAVE_CATOPEN) + + string catalog_filename = LOCALEPATH; + catalog_filename += '/'; + catalog_filename += m_locale; + catalog_filename += '/'; + catalog_filename += catalog; + +#ifdef MCLoadBySet + m_catalog_fd = catopen(catalog_filename.c_str(), MCLoadBySet); +#else // !MCLoadBySet + m_catalog_fd = catopen(catalog_filename.c_str(), NL_CAT_LOCALE); +#endif // MCLoadBySet + + if (m_catalog_fd == (nl_catd)-1) { + cerr<<"Warning: Failed to open file("< +#endif // HAVE_LOCALE_H + +#ifdef HAVE_NL_TYPES_H +// this is needed for linux libc5 systems +extern "C" { +#include +} +#endif // HAVE_NL_TYPES_H + +#include + +class I18n { +public: + static I18n *instance(); + inline const char *getLocale() const { return m_locale.c_str(); } + inline bool multibyte() const { return m_multibyte; } + inline const nl_catd &getCatalogFd() const { return m_catalog_fd; } + + const char *getMessage(int set_number, int message_number, + const char *default_messsage = 0); + void openCatalog(const char *catalog); +private: + I18n(); + ~I18n(); + std::string m_locale; + bool m_multibyte; + nl_catd m_catalog_fd; + +}; + +void NLSInit(const char *); + +#endif // I18N_HH diff --git a/src/i18n.cc b/src/i18n.cc deleted file mode 100644 index 833a094..0000000 --- a/src/i18n.cc +++ /dev/null @@ -1,136 +0,0 @@ -// i18n.hh for Fluxbox Window Manager -// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) -// -// i18n.cc for Blackbox - an X11 Window manager -// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: i18n.cc,v 1.10 2003/05/16 00:17:16 fluxgen Exp $ - -//usr GNU extensions -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif // _GNU_SOURCE - -#include "i18n.hh" - -#include - -#include -#include -#include - -#ifdef HAVE_LOCALE_H -#include -#endif // HAVE_LOCALE_H - -#include -using std::cerr; -using std::endl; -using std::string; - -void NLSInit(const char *catalog) { - I18n *i18n = I18n::instance(); - i18n->openCatalog(catalog); -} - - -I18n::I18n():m_multibyte(false), m_catalog_fd((nl_catd)(-1)) { -#ifdef HAVE_SETLOCALE - //make sure we don't get 0 to m_locale string - char *temp = setlocale(LC_ALL, ""); - m_locale = ( temp ? temp : ""); - if (m_locale.size() == 0) { - cerr<<"Warning: Failed to set locale, reverting to \"C\""< 1) - m_multibyte = true; - - // truncate any encoding off the end of the locale - - string::size_type index = m_locale.find('@'); - if (index != string::npos) - m_locale.erase(index); //erase all characters starting at index - - index = m_locale.find('.'); - if (index != string::npos) - m_locale.erase(index); //erase all characters starting at index - } -#endif // HAVE_SETLOCALE -} - - -I18n::~I18n() { - -#if defined(NLS) && defined(HAVE_CATCLOSE) - if (m_catalog_fd != (nl_catd)-1) - catclose(m_catalog_fd); -#endif // HAVE_CATCLOSE -} - -I18n *I18n::instance() { - static I18n singleton; //singleton object - return &singleton; -} - -void I18n::openCatalog(const char *catalog) { -#if defined(NLS) && defined(HAVE_CATOPEN) - - string catalog_filename = LOCALEPATH; - catalog_filename += '/'; - catalog_filename += m_locale; - catalog_filename += '/'; - catalog_filename += catalog; - -#ifdef MCLoadBySet - m_catalog_fd = catopen(catalog_filename.c_str(), MCLoadBySet); -#else // !MCLoadBySet - m_catalog_fd = catopen(catalog_filename.c_str(), NL_CAT_LOCALE); -#endif // MCLoadBySet - - if (m_catalog_fd == (nl_catd)-1) { - cerr<<"Warning: Failed to open file("< -#endif // HAVE_LOCALE_H - -#ifdef HAVE_NL_TYPES_H -// this is needed for linux libc5 systems -extern "C" { -#include -} -#endif // HAVE_NL_TYPES_H - -#include - -class I18n { -public: - static I18n *instance(); - inline const char *getLocale() const { return m_locale.c_str(); } - inline bool multibyte() const { return m_multibyte; } - inline const nl_catd &getCatalogFd() const { return m_catalog_fd; } - - const char *getMessage(int set_number, int message_number, - const char *default_messsage = 0); - void openCatalog(const char *catalog); -private: - I18n(); - ~I18n(); - std::string m_locale; - bool m_multibyte; - nl_catd m_catalog_fd; - -}; - -void NLSInit(const char *); - -#endif // I18N_HH -- cgit v0.11.2