Daily bump.
[official-gcc.git] / gcc / intl.c
blobf76dbada97b45517737f5fd9432941cffa005b56
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
9 version.
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
14 for more details.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "intl.h"
26 #ifdef HAVE_LANGINFO_CODESET
27 #include <langinfo.h>
28 #endif
30 /* Opening quotation mark for diagnostics. */
31 const char *open_quote = "'";
33 /* Closing quotation mark for diagnostics. */
34 const char *close_quote = "'";
36 #ifdef ENABLE_NLS
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. */
43 void
44 gcc_init_libintl (void)
46 #ifdef HAVE_LC_MESSAGES
47 setlocale (LC_CTYPE, "");
48 setlocale (LC_MESSAGES, "");
49 #else
50 setlocale (LC_ALL, "");
51 #endif
53 (void) bindtextdomain ("gcc", LOCALEDIR);
54 (void) textdomain ("gcc");
56 /* Opening quotation mark. */
57 open_quote = _("`");
59 /* Closing quotation mark. */
60 close_quote = _("'");
62 if (!strcmp (open_quote, "`") && !strcmp (close_quote, "'"))
64 #if defined HAVE_LANGINFO_CODESET
65 const char *encoding;
66 #endif
67 /* Untranslated quotes that it may be possible to replace with
68 U+2018 and U+2019; but otherwise use "'" instead of "`" as
69 opening quote. */
70 open_quote = "'";
71 #if defined HAVE_LANGINFO_CODESET
72 encoding = nl_langinfo (CODESET);
73 if (encoding != NULL
74 && (!strcasecmp (encoding, "utf-8")
75 || !strcasecmp (encoding, "utf8")))
77 open_quote = "\xe2\x80\x98";
78 close_quote = "\xe2\x80\x99";
80 #endif
84 #if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH
85 #include <wchar.h>
87 /* Returns the width in columns of MSGSTR, which came from gettext.
88 This is for indenting subsequent output. */
90 size_t
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. */
105 size_t
106 gcc_gettext_width (const char *msgstr)
108 return strlen (msgstr);
111 #endif
113 #endif /* ENABLE_NLS */