xref: /netbsd-src/external/gpl2/grep/dist/intl/intl-compat.c (revision a8fa202a6440953be7b92a8960a811bff58203f4)
1*a8fa202aSchristos /*	$NetBSD: intl-compat.c,v 1.1.1.1 2016/01/10 21:36:17 christos Exp $	*/
2*a8fa202aSchristos 
3*a8fa202aSchristos /* intl-compat.c - Stub functions to call gettext functions from GNU gettext
4*a8fa202aSchristos    Library.
5*a8fa202aSchristos    Copyright (C) 1995, 2000, 2001 Software Foundation, Inc.
6*a8fa202aSchristos 
7*a8fa202aSchristos    This program is free software; you can redistribute it and/or modify it
8*a8fa202aSchristos    under the terms of the GNU Library General Public License as published
9*a8fa202aSchristos    by the Free Software Foundation; either version 2, or (at your option)
10*a8fa202aSchristos    any later version.
11*a8fa202aSchristos 
12*a8fa202aSchristos    This program is distributed in the hope that it will be useful,
13*a8fa202aSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a8fa202aSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15*a8fa202aSchristos    Library General Public License for more details.
16*a8fa202aSchristos 
17*a8fa202aSchristos    You should have received a copy of the GNU Library General Public
18*a8fa202aSchristos    License along with this program; if not, write to the Free Software
19*a8fa202aSchristos    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20*a8fa202aSchristos    USA.  */
21*a8fa202aSchristos 
22*a8fa202aSchristos #ifdef HAVE_CONFIG_H
23*a8fa202aSchristos # include <config.h>
24*a8fa202aSchristos #endif
25*a8fa202aSchristos 
26*a8fa202aSchristos #include "libgnuintl.h"
27*a8fa202aSchristos #include "gettextP.h"
28*a8fa202aSchristos 
29*a8fa202aSchristos /* @@ end of prolog @@ */
30*a8fa202aSchristos 
31*a8fa202aSchristos /* This file redirects the gettext functions (without prefix or suffix) to
32*a8fa202aSchristos    those defined in the included GNU gettext library (with "__" suffix).
33*a8fa202aSchristos    It is compiled into libintl when the included GNU gettext library is
34*a8fa202aSchristos    configured --with-included-gettext.
35*a8fa202aSchristos 
36*a8fa202aSchristos    This redirection works also in the case that the system C library or
37*a8fa202aSchristos    the system libintl library contain gettext/textdomain/... functions.
38*a8fa202aSchristos    If it didn't, we would need to add preprocessor level redirections to
39*a8fa202aSchristos    libgnuintl.h of the following form:
40*a8fa202aSchristos 
41*a8fa202aSchristos #    define gettext gettext__
42*a8fa202aSchristos #    define dgettext dgettext__
43*a8fa202aSchristos #    define dcgettext dcgettext__
44*a8fa202aSchristos #    define ngettext ngettext__
45*a8fa202aSchristos #    define dngettext dngettext__
46*a8fa202aSchristos #    define dcngettext dcngettext__
47*a8fa202aSchristos #    define textdomain textdomain__
48*a8fa202aSchristos #    define bindtextdomain bindtextdomain__
49*a8fa202aSchristos #    define bind_textdomain_codeset bind_textdomain_codeset__
50*a8fa202aSchristos 
51*a8fa202aSchristos    How does this redirection work? There are two cases.
52*a8fa202aSchristos    A. When libintl.a is linked into an executable, it works because
53*a8fa202aSchristos       functions defined in the executable always override functions in
54*a8fa202aSchristos       the shared libraries.
55*a8fa202aSchristos    B. When libintl.so is used, it works because
56*a8fa202aSchristos       1. those systems defining gettext/textdomain/... in the C library
57*a8fa202aSchristos          (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer) are
58*a8fa202aSchristos          ELF systems and define these symbols as weak, thus explicitly
59*a8fa202aSchristos          letting other shared libraries override it.
60*a8fa202aSchristos       2. those systems defining gettext/textdomain/... in a standalone
61*a8fa202aSchristos          libintl.so library (namely, Solaris 2.3 and newer) have this
62*a8fa202aSchristos          shared library in /usr/lib, and the linker will search /usr/lib
63*a8fa202aSchristos          *after* the directory where the GNU gettext library is installed.
64*a8fa202aSchristos 
65*a8fa202aSchristos    A third case, namely when libintl.a is linked into a shared library
66*a8fa202aSchristos    whose name is not libintl.so, is not supported. In this case, on
67*a8fa202aSchristos    Solaris, when -lintl precedes the linker option for the shared library
68*a8fa202aSchristos    containing GNU gettext, the system's gettext would indeed override
69*a8fa202aSchristos    the GNU gettext. Anyone doing this kind of stuff must be clever enough
70*a8fa202aSchristos    to 1. compile libintl.a with -fPIC, 2. remove -lintl from his linker
71*a8fa202aSchristos    command line.  */
72*a8fa202aSchristos 
73*a8fa202aSchristos 
74*a8fa202aSchristos #undef gettext
75*a8fa202aSchristos #undef dgettext
76*a8fa202aSchristos #undef dcgettext
77*a8fa202aSchristos #undef ngettext
78*a8fa202aSchristos #undef dngettext
79*a8fa202aSchristos #undef dcngettext
80*a8fa202aSchristos #undef textdomain
81*a8fa202aSchristos #undef bindtextdomain
82*a8fa202aSchristos #undef bind_textdomain_codeset
83*a8fa202aSchristos 
84*a8fa202aSchristos 
85*a8fa202aSchristos char *
gettext(msgid)86*a8fa202aSchristos gettext (msgid)
87*a8fa202aSchristos      const char *msgid;
88*a8fa202aSchristos {
89*a8fa202aSchristos   return gettext__ (msgid);
90*a8fa202aSchristos }
91*a8fa202aSchristos 
92*a8fa202aSchristos 
93*a8fa202aSchristos char *
dgettext(domainname,msgid)94*a8fa202aSchristos dgettext (domainname, msgid)
95*a8fa202aSchristos      const char *domainname;
96*a8fa202aSchristos      const char *msgid;
97*a8fa202aSchristos {
98*a8fa202aSchristos   return dgettext__ (domainname, msgid);
99*a8fa202aSchristos }
100*a8fa202aSchristos 
101*a8fa202aSchristos 
102*a8fa202aSchristos char *
dcgettext(domainname,msgid,category)103*a8fa202aSchristos dcgettext (domainname, msgid, category)
104*a8fa202aSchristos      const char *domainname;
105*a8fa202aSchristos      const char *msgid;
106*a8fa202aSchristos      int category;
107*a8fa202aSchristos {
108*a8fa202aSchristos   return dcgettext__ (domainname, msgid, category);
109*a8fa202aSchristos }
110*a8fa202aSchristos 
111*a8fa202aSchristos 
112*a8fa202aSchristos char *
ngettext(msgid1,msgid2,n)113*a8fa202aSchristos ngettext (msgid1, msgid2, n)
114*a8fa202aSchristos      const char *msgid1;
115*a8fa202aSchristos      const char *msgid2;
116*a8fa202aSchristos      unsigned long int n;
117*a8fa202aSchristos {
118*a8fa202aSchristos   return ngettext__ (msgid1, msgid2, n);
119*a8fa202aSchristos }
120*a8fa202aSchristos 
121*a8fa202aSchristos 
122*a8fa202aSchristos char *
dngettext(domainname,msgid1,msgid2,n)123*a8fa202aSchristos dngettext (domainname, msgid1, msgid2, n)
124*a8fa202aSchristos      const char *domainname;
125*a8fa202aSchristos      const char *msgid1;
126*a8fa202aSchristos      const char *msgid2;
127*a8fa202aSchristos      unsigned long int n;
128*a8fa202aSchristos {
129*a8fa202aSchristos   return dngettext__ (domainname, msgid1, msgid2, n);
130*a8fa202aSchristos }
131*a8fa202aSchristos 
132*a8fa202aSchristos 
133*a8fa202aSchristos char *
dcngettext(domainname,msgid1,msgid2,n,category)134*a8fa202aSchristos dcngettext (domainname, msgid1, msgid2, n, category)
135*a8fa202aSchristos      const char *domainname;
136*a8fa202aSchristos      const char *msgid1;
137*a8fa202aSchristos      const char *msgid2;
138*a8fa202aSchristos      unsigned long int n;
139*a8fa202aSchristos      int category;
140*a8fa202aSchristos {
141*a8fa202aSchristos   return dcngettext__ (domainname, msgid1, msgid2, n, category);
142*a8fa202aSchristos }
143*a8fa202aSchristos 
144*a8fa202aSchristos 
145*a8fa202aSchristos char *
textdomain(domainname)146*a8fa202aSchristos textdomain (domainname)
147*a8fa202aSchristos      const char *domainname;
148*a8fa202aSchristos {
149*a8fa202aSchristos   return textdomain__ (domainname);
150*a8fa202aSchristos }
151*a8fa202aSchristos 
152*a8fa202aSchristos 
153*a8fa202aSchristos char *
bindtextdomain(domainname,dirname)154*a8fa202aSchristos bindtextdomain (domainname, dirname)
155*a8fa202aSchristos      const char *domainname;
156*a8fa202aSchristos      const char *dirname;
157*a8fa202aSchristos {
158*a8fa202aSchristos   return bindtextdomain__ (domainname, dirname);
159*a8fa202aSchristos }
160*a8fa202aSchristos 
161*a8fa202aSchristos 
162*a8fa202aSchristos char *
bind_textdomain_codeset(domainname,codeset)163*a8fa202aSchristos bind_textdomain_codeset (domainname, codeset)
164*a8fa202aSchristos      const char *domainname;
165*a8fa202aSchristos      const char *codeset;
166*a8fa202aSchristos {
167*a8fa202aSchristos   return bind_textdomain_codeset__ (domainname, codeset);
168*a8fa202aSchristos }
169