intl.c revision 132718
1258945Sroberto/* Message translation utilities.
2280849Scy   Copyright (C) 2001, 2003 Free Software Foundation, Inc.
3258945Sroberto
4258945SrobertoThis file is part of GCC.
5258945Sroberto
6258945SrobertoGCC is free software; you can redistribute it and/or modify it under
7258945Srobertothe terms of the GNU General Public License as published by the Free
8258945SrobertoSoftware Foundation; either version 2, or (at your option) any later
9258945Srobertoversion.
10258945Sroberto
11258945SrobertoGCC is distributed in the hope that it will be useful, but WITHOUT ANY
12258945SrobertoWARRANTY; without even the implied warranty of MERCHANTABILITY or
13258945SrobertoFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14258945Srobertofor more details.
15258945Sroberto
16258945SrobertoYou should have received a copy of the GNU General Public License
17258945Srobertoalong with GCC; see the file COPYING.  If not, write to the Free
18280849ScySoftware Foundation, 59 Temple Place - Suite 330, Boston, MA
19258945Sroberto02111-1307, USA.  */
20258945Sroberto
21258945Sroberto#include "config.h"
22258945Sroberto#include "system.h"
23258945Sroberto#include "coretypes.h"
24258945Sroberto#include "tm.h"
25258945Sroberto#include "intl.h"
26258945Sroberto
27258945Sroberto#ifdef ENABLE_NLS
28258945Sroberto
29258945Sroberto/* Initialize the translation library for GCC.  This performs the
30258945Sroberto   appropriate sequence of calls - setlocale, bindtextdomain,
31258945Sroberto   textdomain.  LC_CTYPE determines the character set used by the
32258945Sroberto   terminal, so it has be set to output messages correctly.  */
33258945Sroberto
34258945Srobertovoid
35258945Srobertogcc_init_libintl (void)
36258945Sroberto{
37258945Sroberto#ifdef HAVE_LC_MESSAGES
38258945Sroberto  setlocale (LC_CTYPE, "");
39258945Sroberto  setlocale (LC_MESSAGES, "");
40258945Sroberto#else
41258945Sroberto  setlocale (LC_ALL, "");
42258945Sroberto#endif
43258945Sroberto
44258945Sroberto  (void) bindtextdomain ("gcc", LOCALEDIR);
45258945Sroberto  (void) textdomain ("gcc");
46258945Sroberto}
47258945Sroberto
48258945Sroberto#if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH
49258945Sroberto#include <wchar.h>
50258945Sroberto
51258945Sroberto/* Returns the width in columns of MSGSTR, which came from gettext.
52258945Sroberto   This is for indenting subsequent output.  */
53258945Sroberto
54258945Srobertosize_t
55258945Srobertogcc_gettext_width (const char *msgstr)
56258945Sroberto{
57258945Sroberto  size_t nwcs = mbstowcs (0, msgstr, 0);
58258945Sroberto  wchar_t *wmsgstr = alloca ((nwcs + 1) * sizeof (wchar_t));
59258945Sroberto
60258945Sroberto  mbstowcs (wmsgstr, msgstr, nwcs + 1);
61258945Sroberto  return wcswidth (wmsgstr, nwcs);
62258945Sroberto}
63280849Scy
64280849Scy#else  /* no wcswidth */
65280849Scy
66258945Sroberto/* We don't have any way of knowing how wide the string is.  Guess
67258945Sroberto   the length of the string.  */
68258945Sroberto
69258945Srobertosize_t
70258945Srobertogcc_gettext_width (const char *msgstr)
71258945Sroberto{
72258945Sroberto  return strlen (msgstr);
73258945Sroberto}
74258945Sroberto
75258945Sroberto#endif
76258945Sroberto
77258945Sroberto#endif /* ENABLE_NLS */
78280849Scy