1 /* Message translation utilities.
2 Copyright (C) 2001, 2003, 2004, 2005, 2007 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 3, 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 COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
26 #ifdef HAVE_LANGINFO_CODESET
30 /* Opening quotation mark for diagnostics. */
31 const char *open_quote = "'";
33 /* Closing quotation mark for diagnostics. */
34 const char *close_quote = "'";
38 /* Initialize the translation library for GCC. This performs the
39 appropriate sequence of calls - setlocale, bindtextdomain,
40 textdomain. LC_CTYPE determines the character set used by the
41 terminal, so it has be set to output messages correctly. */
44 gcc_init_libintl (void)
46 #ifdef HAVE_LC_MESSAGES
47 setlocale (LC_CTYPE, "");
48 setlocale (LC_MESSAGES, "");
50 setlocale (LC_ALL, "");
53 (void) bindtextdomain ("gcc", LOCALEDIR);
54 (void) textdomain ("gcc");
56 /* Opening quotation mark. */
59 /* Closing quotation mark. */
62 if (!strcmp (open_quote, "`") && !strcmp (close_quote, "'"))
64 #if defined HAVE_LANGINFO_CODESET
67 /* Untranslated quotes that it may be possible to replace with
68 U+2018 and U+2019; but otherwise use "'" instead of "`" as
71 #if defined HAVE_LANGINFO_CODESET
72 encoding = nl_langinfo (CODESET);
74 && (!strcasecmp (encoding, "utf-8")
75 || !strcasecmp (encoding, "utf8")))
77 open_quote = "\xe2\x80\x98";
78 close_quote = "\xe2\x80\x99";
84 #if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH
87 /* Returns the width in columns of MSGSTR, which came from gettext.
88 This is for indenting subsequent output. */
91 gcc_gettext_width (const char *msgstr)
93 size_t nwcs = mbstowcs (0, msgstr, 0);
94 wchar_t *wmsgstr = alloca ((nwcs + 1) * sizeof (wchar_t));
96 mbstowcs (wmsgstr, msgstr, nwcs + 1);
97 return wcswidth (wmsgstr, nwcs);
100 #else /* no wcswidth */
102 /* We don't have any way of knowing how wide the string is. Guess
103 the length of the string. */
106 gcc_gettext_width (const char *msgstr)
108 return strlen (msgstr);
113 #endif /* ENABLE_NLS */