gcc/gcc/intl.c

151 lines
3.5 KiB
C
Raw Normal View History

/* Message translation utilities.
Copyright (C) 2001-2017 Free Software Foundation, Inc.
1998-08-02 08:46:46 +02:00
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
1998-08-02 08:46:46 +02:00
#include "intl.h"
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
/* Opening quotation mark for diagnostics. */
const char *open_quote = "'";
/* Closing quotation mark for diagnostics. */
const char *close_quote = "'";
/* The name of the locale encoding. */
const char *locale_encoding = NULL;
/* Whether the locale is using UTF-8. */
bool locale_utf8 = false;
#ifdef ENABLE_NLS
/* Initialize the translation library for GCC. This performs the
appropriate sequence of calls - setlocale, bindtextdomain,
textdomain. LC_CTYPE determines the character set used by the
terminal, so it has be set to output messages correctly. */
void
gcc_init_libintl (void)
{
#ifdef HAVE_LC_MESSAGES
setlocale (LC_CTYPE, "");
setlocale (LC_MESSAGES, "");
#else
setlocale (LC_ALL, "");
#endif
gcc-version.m4: Delete. config: * gcc-version.m4: Delete. fastjar: * Makefile.am (fastjar_TEXINFOS): Add gcc-vers.texi. (BASEVER, DEVPHASE): New variables. (POD2MAN): Adjust setting of --release option. (fastjar.1, grepjar.1, gcc-vers.texi): New rules. * Makefile.in: Regenerate. * configure.ac: Do not invoke TL_AC_GCC_VERSION. * aclocal.m4, configure: Regenerate. gcc: * BASE-VER, DATESTAMP, DEV-PHASE: New files. * Makefile.in (gcc_version, gcc_version_trigger, ): Delete. (BASEVER, DEVPHASE, DATESTAMP, BASEVER_c, DEVPHASE_c, DATESTAMP_c) (BASEVER_s, DEVPHASE_s, DATESTAMP_s): New variables. (version): Define using $(BASEVER_c). (Makefile, config.status, build/gcov-iov.o): No longer depends on version.c. (version.o): Depend on version files; add custom generation command. (prefix.o): Define BASEVER on command line. (s-iov): Depend on version files; adjust command. (TEXI_CPP_FILES, TEX_IGCC_FILES, TEXI_GCCINT_FILES, TEXI_CPPINT_FILES): Add gcc-vers.texi. (gcc-vers.texi): New rule. (doc/%.info, doc/%.dvi): Add -I . to command line. (doc/gccinstall.dvi): Likewise. (PACKAGE): Delete. All uses replaced with "gcc". * aclocal.m4: Do not include gcc-version.m4. * configure.ac: Do not invoke TL_AC_GCC_VERSION. Do not AC_SUBST nor AC_DEFINE PACKAGE or VERSION. Set is_release based on contents of DEV-PHASE. Set gcc_version based on contents of BASE-VER. Define WIN32_REGISTRY_KEY only if the user overrode the default. * config.in, configure: Regenerate. * gccbug.in: Determine version of GCC in use at runtime. * gcov-iov.c: Get version number and development phase from command line, not by including version.c. * intl.c: Replace all uses of PACKAGE with "gcc". * libada-mk.in: Delete unused "gcc_version" variable. * prefix.c: Default WIN32_REGISTRY_KEY to BASEVER. * version.c: (VERSUFFIX): New hook for redistributors; adjust commentary to match. (version_string): Put together from pieces. * config/alpha/x-vms: Do not use $(gcc_version). * config/i386/t-nwld: Likewise. * doc/include/gcc-common.texi: Include gcc-vers.texi for version-GCC and DEVELOPMENT. gcc/ada: * Make-lang.in (doc/gnat_ugn_unw.info, doc/gnat_rm.info) (doc/gnat_ugn_unw.dvi, doc/gnat_rm.dvi): Add gcc-vers.texi to dependencies. gcc/fortran: * Make-lang.in (GFORTRAN_TEXI): Add gcc-vers.texi. gcc/java: * Make-lang.in (TEXI_JAVA_FILES): Add gcc-vers.texi. gcc/treelang: * Make-lang.in (TEXI_TREELANG_FILES): Add gcc-vers.texi. libstdc++-v3: * include/Makefile.am (c++config.h): Depend on DATESTAMP from gcc subdirectory. Generate #define of __GLIBCXX__ from contents of that file. * include/Makefile.in: Regenerate. * include/bits/c++config: Do not define __GLIBCXX__. maintainer-scripts: * README: Update. * gcc_release: Update gcc/DEV-PHASE if that file exists, instead of gcc/version.c. * update_version: Handle updating gcc/DATESTAMP. * update_web_docs: Generate gcc-vers.texi first. From-SVN: r96549
2005-03-16 07:04:10 +01:00
(void) bindtextdomain ("gcc", LOCALEDIR);
(void) textdomain ("gcc");
/* Opening quotation mark. */
open_quote = _("`");
/* Closing quotation mark. */
close_quote = _("'");
#if defined HAVE_LANGINFO_CODESET
locale_encoding = nl_langinfo (CODESET);
if (locale_encoding != NULL
&& (!strcasecmp (locale_encoding, "utf-8")
|| !strcasecmp (locale_encoding, "utf8")))
locale_utf8 = true;
#endif
if (!strcmp (open_quote, "`") && !strcmp (close_quote, "'"))
{
/* Untranslated quotes that it may be possible to replace with
U+2018 and U+2019; but otherwise use "'" instead of "`" as
opening quote. */
open_quote = "'";
#if defined HAVE_LANGINFO_CODESET
if (locale_utf8)
{
open_quote = "\xe2\x80\x98";
close_quote = "\xe2\x80\x99";
}
#endif
}
}
#if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH
#include <wchar.h>
/* Returns the width in columns of MSGSTR, which came from gettext.
This is for indenting subsequent output. */
size_t
gcc_gettext_width (const char *msgstr)
{
size_t nwcs = mbstowcs (0, msgstr, 0);
wchar_t *wmsgstr = XALLOCAVEC (wchar_t, nwcs + 1);
mbstowcs (wmsgstr, msgstr, nwcs + 1);
return wcswidth (wmsgstr, nwcs);
}
#else /* no wcswidth */
/* We don't have any way of knowing how wide the string is. Guess
the length of the string. */
size_t
gcc_gettext_width (const char *msgstr)
{
return strlen (msgstr);
}
#endif
#endif /* ENABLE_NLS */
[multiple changes] 2009-12-15 Paolo Bonzini <bonzini@gnu.org> Shujing Zhao <pearly.zhao@oracle.com> * intl.c (get_spaces): New. * intl.h (get_spaces): New. cp: 2009-12-15 Paolo Bonzini <bonzini@gnu.org> Shujing Zhao <pearly.zhao@oracle.com> * Makefile.in (cp/pt.o): Depend on intl.h * call.c (print_z_candidates): Make loop more compact, choose head string depending on number of candidates, extract creation of spaces string to intl.c. * pt.c (print_overloaded_functions): Replace with... (print_candidates_1): ... this rewrite. (print_candidates): Rewrite to call print_candidates_1. (most_specialized_class): Make loop more compact, choose head string depending on number of candidates, and size indents depending on translations. testsuite: 2009-12-15 Shujing Zhao <pearly.zhao@oracle.com> * g++.dg/other/error20.C: Adjust dg-message strings. * g++.dg/other/error31.C: Likewise. * g++.dg/rtti/typeid6.C: Likewise. * g++.dg/ext/ms-1.C: Likewise. * g++.dg/parse/error19.C: Likewise. * g++.dg/parse/crash5.C: Likewise. * g++.dg/cpp0x/explicit4.C: Likewise. * g++.dg/template/ptrmem4.C: Likewise. * g++.dg/template/crash37.C: Likewise. * g++.dg/template/qualttp5.C: Likewise. * g++.dg/template/local6.C: Likewise. * g++.dg/template/instantiate5.C: Likewise. * g++.old-deja/g++.brendan/overload1.C: Likewise. * g++.old-deja/g++.brendan/cvt3.C: Likewise. * g++.old-deja/g++.brendan/overload4.C: Likewise. * g++.old-deja/g++.jason/conversion11.C: Likewise. * g++.old-deja/g++.jason/scoping10.C: Likewise. * g++.old-deja/g++.other/expr1.C: Likewise. * g++.old-deja/g++.other/pmf3.C: Likewise. * g++.old-deja/g++.other/crash24.C: Likewise. * g++.old-deja/g++.niklas/t120.C: Likewise. * g++.old-deja/g++.niklas/t121.C: Likewise. * g++.old-deja/g++.law/operators9.C: Likewise. * g++.old-deja/g++.law/arm9.C: Likewise. * g++.old-deja/g++.law/enum4.C: Likewise. * g++.old-deja/g++.law/arg11.C: Likewise. * g++.old-deja/g++.benjamin/15800-1.C: Likewise. * g++.old-deja/g++.mike/p2431.C: Likewise. * g++.old-deja/g++.mike/p438.C: Likewise. * g++.old-deja/g++.mike/p9068.C: Likewise. * g++.old-deja/g++.mike/p11110.C: Likewise. * g++.old-deja/g++.bugs/900330_02.C: Likewise. From-SVN: r155245
2009-12-15 01:20:03 +01:00
#ifndef ENABLE_NLS
const char *
fake_ngettext (const char *singular, const char *plural, unsigned long n)
{
if (n == 1UL)
return singular;
return plural;
}
#endif
[multiple changes] 2009-12-15 Paolo Bonzini <bonzini@gnu.org> Shujing Zhao <pearly.zhao@oracle.com> * intl.c (get_spaces): New. * intl.h (get_spaces): New. cp: 2009-12-15 Paolo Bonzini <bonzini@gnu.org> Shujing Zhao <pearly.zhao@oracle.com> * Makefile.in (cp/pt.o): Depend on intl.h * call.c (print_z_candidates): Make loop more compact, choose head string depending on number of candidates, extract creation of spaces string to intl.c. * pt.c (print_overloaded_functions): Replace with... (print_candidates_1): ... this rewrite. (print_candidates): Rewrite to call print_candidates_1. (most_specialized_class): Make loop more compact, choose head string depending on number of candidates, and size indents depending on translations. testsuite: 2009-12-15 Shujing Zhao <pearly.zhao@oracle.com> * g++.dg/other/error20.C: Adjust dg-message strings. * g++.dg/other/error31.C: Likewise. * g++.dg/rtti/typeid6.C: Likewise. * g++.dg/ext/ms-1.C: Likewise. * g++.dg/parse/error19.C: Likewise. * g++.dg/parse/crash5.C: Likewise. * g++.dg/cpp0x/explicit4.C: Likewise. * g++.dg/template/ptrmem4.C: Likewise. * g++.dg/template/crash37.C: Likewise. * g++.dg/template/qualttp5.C: Likewise. * g++.dg/template/local6.C: Likewise. * g++.dg/template/instantiate5.C: Likewise. * g++.old-deja/g++.brendan/overload1.C: Likewise. * g++.old-deja/g++.brendan/cvt3.C: Likewise. * g++.old-deja/g++.brendan/overload4.C: Likewise. * g++.old-deja/g++.jason/conversion11.C: Likewise. * g++.old-deja/g++.jason/scoping10.C: Likewise. * g++.old-deja/g++.other/expr1.C: Likewise. * g++.old-deja/g++.other/pmf3.C: Likewise. * g++.old-deja/g++.other/crash24.C: Likewise. * g++.old-deja/g++.niklas/t120.C: Likewise. * g++.old-deja/g++.niklas/t121.C: Likewise. * g++.old-deja/g++.law/operators9.C: Likewise. * g++.old-deja/g++.law/arm9.C: Likewise. * g++.old-deja/g++.law/enum4.C: Likewise. * g++.old-deja/g++.law/arg11.C: Likewise. * g++.old-deja/g++.benjamin/15800-1.C: Likewise. * g++.old-deja/g++.mike/p2431.C: Likewise. * g++.old-deja/g++.mike/p438.C: Likewise. * g++.old-deja/g++.mike/p9068.C: Likewise. * g++.old-deja/g++.mike/p11110.C: Likewise. * g++.old-deja/g++.bugs/900330_02.C: Likewise. From-SVN: r155245
2009-12-15 01:20:03 +01:00
/* Return the indent for successive lines, using the width of
the STR. STR must have been translated already. The string
must be freed by the caller. */
char *
get_spaces (const char *str)
{
size_t len = gcc_gettext_width (str);
alloc-pool.c, [...]: Add missing whitespace before "(". gcc/ * alloc-pool.c, asan.c, auto-inc-dec.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, bt-load.c, builtins.c, calls.c, cfgcleanup.c, cfgexpand.c, cfghooks.c, cfgloop.c, cfgloopmanip.c, cfgrtl.c, cgraph.c, cgraph.h, cgraphbuild.c, cgraphclones.c, cgraphunit.c, collect2.c, combine-stack-adj.c, combine.c, compare-elim.c, context.c, context.h, cprop.c, cse.c, cselib.c, dbxout.c, dce.c, defaults.h, df-core.c, df-problems.c, df-scan.c, df.h, diagnostic.c, double-int.c, dse.c, dumpfile.c, dwarf2asm.c, dwarf2cfi.c, dwarf2out.c, emit-rtl.c, errors.c, except.c, expmed.c, expr.c, file-find.c, final.c, fixed-value.c, fold-const.c, function.c, fwprop.c, gcc-ar.c, gcc.c, gcov-io.c, gcov-io.h, gcov.c, gcse.c, genattr-common.c, genattr.c, genattrtab.c, genautomata.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, gengtype-state.c, gengtype.c, genmodes.c, genopinit.c, genoutput.c, genpeep.c, genpreds.c, genrecog.c, gensupport.c, ggc-common.c, ggc-page.c, gimple-fold.c, gimple-low.c, gimple-pretty-print.c, gimple-ssa-strength-reduction.c, gimple.c, gimple.h, godump.c, graphite-clast-to-gimple.c, graphite-optimize-isl.c, graphite-poly.h, graphite-sese-to-poly.c, graphite.c, haifa-sched.c, hash-table.c, hash-table.h, hwint.c, hwint.h, ifcvt.c, incpath.c, init-regs.c, input.h, intl.c, intl.h, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa-utils.c, ipa.c, ira-build.c, ira.c, jump.c, loop-doloop.c, loop-init.c, loop-invariant.c, loop-iv.c, lower-subreg.c, lto-cgraph.c, lto-streamer-in.c, lto-streamer-out.c, lto-wrapper.c, mcf.c, mode-switching.c, modulo-sched.c, omp-low.c, optabs.c, opts.c, pass_manager.h, passes.c, plugin.c, postreload-gcse.c, postreload.c, predict.c, prefix.c, pretty-print.c, print-rtl.c, print-tree.c, profile.c, read-md.c, real.c, real.h, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regmove.c, regrename.c, regs.h, regstat.c, reload1.c, reorg.c, rtl.c, rtl.h, rtlanal.c, sbitmap.c, sched-rgn.c, sdbout.c, sel-sched-ir.c, sel-sched.c, sparseset.c, stack-ptr-mod.c, statistics.c, stmt.c, stor-layout.c, store-motion.c, streamer-hooks.h, system.h, target-hooks-macros.h, targhooks.c, targhooks.h, toplev.c, tracer.c, trans-mem.c, tree-browser.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-data-ref.c, tree-data-ref.h, tree-eh.c, tree-emutls.c, tree-flow.h, tree-if-conv.c, tree-into-ssa.c, tree-iterator.c, tree-loop-distribution.c, tree-mudflap.c, tree-nested.c, tree-nomudflap.c, tree-nrv.c, tree-object-size.c, tree-optimize.c, tree-pass.h, tree-pretty-print.c, tree-profile.c, tree-scalar-evolution.c, tree-sra.c, tree-ssa-ccp.c, tree-ssa-coalesce.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-live.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-prefetch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-operands.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-threadedge.c, tree-ssa-threadupdate.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop-manip.c, tree-vect-stmts.c, tree-vectorizer.c, tree-vectorizer.h, tree-vrp.c, tree.c, tree.h, tsan.c, tsystem.h, value-prof.c, var-tracking.c, varasm.c, vec.h, vmsdbgout.c, vtable-verify.c, web.c: Add missing whitespace before "(". From-SVN: r203004
2013-09-28 10:42:34 +02:00
char *spaces = XNEWVEC (char, len + 1);
[multiple changes] 2009-12-15 Paolo Bonzini <bonzini@gnu.org> Shujing Zhao <pearly.zhao@oracle.com> * intl.c (get_spaces): New. * intl.h (get_spaces): New. cp: 2009-12-15 Paolo Bonzini <bonzini@gnu.org> Shujing Zhao <pearly.zhao@oracle.com> * Makefile.in (cp/pt.o): Depend on intl.h * call.c (print_z_candidates): Make loop more compact, choose head string depending on number of candidates, extract creation of spaces string to intl.c. * pt.c (print_overloaded_functions): Replace with... (print_candidates_1): ... this rewrite. (print_candidates): Rewrite to call print_candidates_1. (most_specialized_class): Make loop more compact, choose head string depending on number of candidates, and size indents depending on translations. testsuite: 2009-12-15 Shujing Zhao <pearly.zhao@oracle.com> * g++.dg/other/error20.C: Adjust dg-message strings. * g++.dg/other/error31.C: Likewise. * g++.dg/rtti/typeid6.C: Likewise. * g++.dg/ext/ms-1.C: Likewise. * g++.dg/parse/error19.C: Likewise. * g++.dg/parse/crash5.C: Likewise. * g++.dg/cpp0x/explicit4.C: Likewise. * g++.dg/template/ptrmem4.C: Likewise. * g++.dg/template/crash37.C: Likewise. * g++.dg/template/qualttp5.C: Likewise. * g++.dg/template/local6.C: Likewise. * g++.dg/template/instantiate5.C: Likewise. * g++.old-deja/g++.brendan/overload1.C: Likewise. * g++.old-deja/g++.brendan/cvt3.C: Likewise. * g++.old-deja/g++.brendan/overload4.C: Likewise. * g++.old-deja/g++.jason/conversion11.C: Likewise. * g++.old-deja/g++.jason/scoping10.C: Likewise. * g++.old-deja/g++.other/expr1.C: Likewise. * g++.old-deja/g++.other/pmf3.C: Likewise. * g++.old-deja/g++.other/crash24.C: Likewise. * g++.old-deja/g++.niklas/t120.C: Likewise. * g++.old-deja/g++.niklas/t121.C: Likewise. * g++.old-deja/g++.law/operators9.C: Likewise. * g++.old-deja/g++.law/arm9.C: Likewise. * g++.old-deja/g++.law/enum4.C: Likewise. * g++.old-deja/g++.law/arg11.C: Likewise. * g++.old-deja/g++.benjamin/15800-1.C: Likewise. * g++.old-deja/g++.mike/p2431.C: Likewise. * g++.old-deja/g++.mike/p438.C: Likewise. * g++.old-deja/g++.mike/p9068.C: Likewise. * g++.old-deja/g++.mike/p11110.C: Likewise. * g++.old-deja/g++.bugs/900330_02.C: Likewise. From-SVN: r155245
2009-12-15 01:20:03 +01:00
memset (spaces, ' ', len);
spaces[len] = '\0';
return spaces;
}