1 /* Message translation utilities.
2 Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "coretypes.h"
27 #ifdef HAVE_LANGINFO_CODESET
31 /* Opening quotation mark for diagnostics. */
32 const char *open_quote
= "'";
34 /* Closing quotation mark for diagnostics. */
35 const char *close_quote
= "'";
39 /* Initialize the translation library for GCC. This performs the
40 appropriate sequence of calls - setlocale, bindtextdomain,
41 textdomain. LC_CTYPE determines the character set used by the
42 terminal, so it has be set to output messages correctly. */
45 gcc_init_libintl (void)
47 #ifdef HAVE_LC_MESSAGES
48 setlocale (LC_CTYPE
, "");
49 setlocale (LC_MESSAGES
, "");
51 setlocale (LC_ALL
, "");
54 (void) bindtextdomain (PACKAGE
, LOCALEDIR
);
55 (void) textdomain (PACKAGE
);
57 /* Opening quotation mark. */
60 /* Closing quotation mark. */
63 if (!strcmp (open_quote
, "`") && !strcmp (close_quote
, "'"))
65 #if defined HAVE_LANGINFO_CODESET
68 /* Untranslated quotes that it may be possible to replace with
69 U+2018 and U+2019; but otherwise use "'" instead of "`" as
72 #if defined HAVE_LANGINFO_CODESET
73 encoding
= nl_langinfo (CODESET
);
75 && (!strcasecmp (encoding
, "utf-8")
76 || !strcasecmp (encoding
, "utf8")))
78 open_quote
= "\xe2\x80\x98";
79 close_quote
= "\xe2\x80\x99";
85 #if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH
88 /* Returns the width in columns of MSGSTR, which came from gettext.
89 This is for indenting subsequent output. */
92 gcc_gettext_width (const char *msgstr
)
94 size_t nwcs
= mbstowcs (0, msgstr
, 0);
95 wchar_t *wmsgstr
= alloca ((nwcs
+ 1) * sizeof (wchar_t));
97 mbstowcs (wmsgstr
, msgstr
, nwcs
+ 1);
98 return wcswidth (wmsgstr
, nwcs
);
101 #else /* no wcswidth */
103 /* We don't have any way of knowing how wide the string is. Guess
104 the length of the string. */
107 gcc_gettext_width (const char *msgstr
)
109 return strlen (msgstr
);
114 #endif /* ENABLE_NLS */