]>
Commit | Line | Data |
---|---|---|
191bf464 | 1 | /* Message translation utilities. |
66647d44 JJ |
2 | Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008 |
3 | Free Software Foundation, Inc. | |
e44d06c3 | 4 | |
191bf464 ZW |
5 | This file is part of GCC. |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
191bf464 ZW |
10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
191bf464 ZW |
20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
4977bab6 ZW |
23 | #include "coretypes.h" |
24 | #include "tm.h" | |
e44d06c3 JL |
25 | #include "intl.h" |
26 | ||
a668adb2 JM |
27 | #ifdef HAVE_LANGINFO_CODESET |
28 | #include <langinfo.h> | |
29 | #endif | |
30 | ||
31 | /* Opening quotation mark for diagnostics. */ | |
32 | const char *open_quote = "'"; | |
33 | ||
34 | /* Closing quotation mark for diagnostics. */ | |
35 | const char *close_quote = "'"; | |
36 | ||
191bf464 ZW |
37 | #ifdef ENABLE_NLS |
38 | ||
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. */ | |
43 | ||
44 | void | |
3d7aafde | 45 | gcc_init_libintl (void) |
191bf464 ZW |
46 | { |
47 | #ifdef HAVE_LC_MESSAGES | |
48 | setlocale (LC_CTYPE, ""); | |
49 | setlocale (LC_MESSAGES, ""); | |
50 | #else | |
51 | setlocale (LC_ALL, ""); | |
52 | #endif | |
53 | ||
a1286ef5 ZW |
54 | (void) bindtextdomain ("gcc", LOCALEDIR); |
55 | (void) textdomain ("gcc"); | |
a668adb2 JM |
56 | |
57 | /* Opening quotation mark. */ | |
58 | open_quote = _("`"); | |
59 | ||
60 | /* Closing quotation mark. */ | |
61 | close_quote = _("'"); | |
62 | ||
63 | if (!strcmp (open_quote, "`") && !strcmp (close_quote, "'")) | |
64 | { | |
65 | #if defined HAVE_LANGINFO_CODESET | |
66 | const char *encoding; | |
67 | #endif | |
68 | /* Untranslated quotes that it may be possible to replace with | |
69 | U+2018 and U+2019; but otherwise use "'" instead of "`" as | |
70 | opening quote. */ | |
71 | open_quote = "'"; | |
72 | #if defined HAVE_LANGINFO_CODESET | |
73 | encoding = nl_langinfo (CODESET); | |
74 | if (encoding != NULL | |
75 | && (!strcasecmp (encoding, "utf-8") | |
76 | || !strcasecmp (encoding, "utf8"))) | |
77 | { | |
78 | open_quote = "\xe2\x80\x98"; | |
79 | close_quote = "\xe2\x80\x99"; | |
80 | } | |
81 | #endif | |
82 | } | |
191bf464 ZW |
83 | } |
84 | ||
39f6c4c8 | 85 | #if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH |
2bd02043 ZW |
86 | #include <wchar.h> |
87 | ||
88 | /* Returns the width in columns of MSGSTR, which came from gettext. | |
89 | This is for indenting subsequent output. */ | |
90 | ||
91 | size_t | |
3d7aafde | 92 | gcc_gettext_width (const char *msgstr) |
2bd02043 ZW |
93 | { |
94 | size_t nwcs = mbstowcs (0, msgstr, 0); | |
4dc6c528 | 95 | wchar_t *wmsgstr = XALLOCAVEC (wchar_t, nwcs + 1); |
2bd02043 ZW |
96 | |
97 | mbstowcs (wmsgstr, msgstr, nwcs + 1); | |
98 | return wcswidth (wmsgstr, nwcs); | |
99 | } | |
100 | ||
101 | #else /* no wcswidth */ | |
102 | ||
103 | /* We don't have any way of knowing how wide the string is. Guess | |
104 | the length of the string. */ | |
105 | ||
106 | size_t | |
3d7aafde | 107 | gcc_gettext_width (const char *msgstr) |
2bd02043 ZW |
108 | { |
109 | return strlen (msgstr); | |
110 | } | |
111 | ||
191bf464 | 112 | #endif |
2bd02043 ZW |
113 | |
114 | #endif /* ENABLE_NLS */ |