2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: MessageTable.C /main/1 1996/07/29 16:57:45 cde-hp $ */
24 // Copyright (c) 1996 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
32 #include "MessageTable.h"
34 #ifdef SP_NO_MESSAGE_TEXT
40 static HINSTANCE dllInstanceHandle = NULL;
43 namespace SP_NAMESPACE {
46 class WinMessageTable : public MessageTable {
48 Boolean getText(const MessageFragment &,
49 String<SP_TCHAR> &) const;
53 Boolean WinMessageTable::getText(const MessageFragment &frag,
54 String<SP_TCHAR> &str) const
56 static const int bufSize = 4096;
57 SP_TCHAR buf[bufSize];
58 int len = LoadString(frag.module() == MessageFragment::libModule
65 // The resource might be empty.
66 if (GetLastError() != 0)
77 const MessageTable *MessageTable::instance()
80 instance_ = new WinMessageTable;
90 BOOL WINAPI DllMain(HINSTANCE inst, ULONG reason, LPVOID)
92 if (reason == DLL_PROCESS_ATTACH)
93 dllInstanceHandle = inst;
98 #else /* not SP_NO_MESSAGE_TEXT */
100 #ifdef SP_HAVE_GETTEXT
102 extern char *dgettext(const char *, const char *);
103 extern char *gettext(const char *);
104 extern char *textdomain(const char *);
105 extern char *bindtextdomain(const char *, const char *);
110 #ifndef MESSAGE_DOMAIN
111 #define MESSAGE_DOMAIN "sp"
115 namespace SP_NAMESPACE {
118 class GettextMessageTable : public MessageTable {
120 GettextMessageTable();
121 Boolean getText(const MessageFragment &, String<SP_TCHAR> &) const;
125 GettextMessageTable::GettextMessageTable()
127 const char *dir = getenv("TEXTDOMAINDIR");
129 bindtextdomain(MESSAGE_DOMAIN, dir);
132 Boolean GettextMessageTable::getText(const MessageFragment &frag,
133 String<SP_TCHAR> &str) const
135 const char *s = frag.text();
138 s = dgettext(MESSAGE_DOMAIN, s);
141 str.assign(s, strlen(s));
145 const MessageTable *MessageTable::instance()
148 instance_ = new GettextMessageTable;
156 #else /* not SP_HAVE_GETTEXT */
159 namespace SP_NAMESPACE {
162 class DefaultMessageTable : public MessageTable {
164 Boolean getText(const MessageFragment &, String<SP_TCHAR> &) const;
167 Boolean DefaultMessageTable::getText(const MessageFragment &frag,
168 String<SP_TCHAR> &str) const
173 for (const char *s = frag.text(); *s; s++)
174 str += SP_TCHAR((unsigned char)*s);
178 const MessageTable *MessageTable::instance()
181 instance_ = new DefaultMessageTable;
189 #endif /* not SP_HAVE_GETTEXT */
191 #endif /* not SP_NO_MESSAGE_TEXT */
194 namespace SP_NAMESPACE {
197 MessageTable *MessageTable::instance_ = 0;