OSDN Git Service

* c-common.h (enum rid): Remove RID_BOUNDED, RID_UNBOUNDED.
[pf3gnuchains/gcc-fork.git] / gcc / intl.c
1 /* Message translation utilities.
2    Copyright (C) 2001 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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
9 version.
10
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.
15
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
19 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "intl.h"
26
27 #ifdef ENABLE_NLS
28
29 /* Initialize the translation library for GCC.  This performs the
30    appropriate sequence of calls - setlocale, bindtextdomain,
31    textdomain.  LC_CTYPE determines the character set used by the
32    terminal, so it has be set to output messages correctly.  */
33
34 void
35 gcc_init_libintl ()
36 {
37 #ifdef HAVE_LC_MESSAGES
38   setlocale (LC_CTYPE, "");
39   setlocale (LC_MESSAGES, "");
40 #else
41   setlocale (LC_ALL, "");
42 #endif
43
44   (void) bindtextdomain ("gcc", LOCALEDIR);
45   (void) textdomain ("gcc");
46 }
47
48 #if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH
49 #include <wchar.h>
50
51 /* Returns the width in columns of MSGSTR, which came from gettext.
52    This is for indenting subsequent output.  */
53
54 size_t
55 gcc_gettext_width (msgstr)
56      const char *msgstr;
57 {
58   size_t nwcs = mbstowcs (0, msgstr, 0);
59   wchar_t *wmsgstr = alloca ((nwcs + 1) * sizeof (wchar_t));
60
61   mbstowcs (wmsgstr, msgstr, nwcs + 1);
62   return wcswidth (wmsgstr, nwcs);
63 }
64
65 #else  /* no wcswidth */
66
67 /* We don't have any way of knowing how wide the string is.  Guess
68    the length of the string.  */
69
70 size_t
71 gcc_gettext_width (msgstr)
72      const char *msgstr;
73 {
74   return strlen (msgstr);
75 }
76
77 #endif
78
79 #endif /* ENABLE_NLS */