1 /* gettext.c -- wrap some i18n functions when available
2 Copyright (C) 1999 John Harper <john@dcs.warwick.ac.uk>
3 $Id$
4
5 This file is part of librep.
6
7 librep is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 librep is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with librep; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20
21 #define _GNU_SOURCE
22
23 #include <config.h>
24 #include <rep.h>
25
26 #ifdef LIBC_GETTEXT
27 # ifdef HAVE_LIBINTL_H
28 # include <libintl.h>
29 # endif
30 # define gnu_gettext gettext
31 # define gnu_textdomain textdomain
32 # define gnu_bindtextdomain bindtextdomain
33 # define gnu_bind_textdomain_codeset bind_textdomain_codeset
34 #else
35 # define gnu_gettext gettext__
36 # define gnu_textdomain textdomain__
37 # define gnu_bindtextdomain bindtextdomain__
38 # ifdef FIXME_SOMEONE_PLEASE
39 # define gnu_bind_textdomain_codeset bind_textdomain_codeset__
40 # endif
41 extern char *gnu_gettext (const char *msgid);
42 extern char *gnu_textdomain (const char *domainname);
43 extern char *gnu_bindtextdomain (const char *domainname, const char *dirname);
44 extern char *gnu_bind_textdomain_codeset (const char *domainname, const char *codeset);
45 #endif
46
47 DEFUN("gettext", Fgettext, Sgettext, (repv in), rep_Subr1)
48 {
49 char *out;
50 rep_DECLARE1(in, rep_STRINGP);
51
52 out = gnu_gettext (rep_STR(in));
53 if (out == 0 || (char *) out == rep_STR(in))
54 return in;
55 else
56 return rep_string_dup (out);
57 }
58
59 DEFUN("bindtextdomain", Fbindtextdomain,
60 Sbindtextdomain, (repv dom, repv dir), rep_Subr2)
61 {
62 char *domainname = 0, *dirname = 0, *out;
63
64 if (rep_STRINGP(dom))
65 domainname = rep_STR(dom);
66 if (rep_STRINGP(dir))
67 dirname = rep_STR(dir);
68
69 out = gnu_bindtextdomain (domainname, dirname);
70 return out ? rep_string_dup (out) : Qnil;
71 }
72
73
74 DEFUN("bindtextdomaincodeset", Fbindtextdomaincodeset,
75 Sbindtextdomaincodeset, (repv dom, repv cod), rep_Subr2)
76 {
77 char *domainname = 0, *codeset = 0, *out;
78
79 if (rep_STRINGP(dom))
80 domainname = rep_STR(dom);
81 if (rep_STRINGP(cod))
82 codeset = rep_STR(cod);
83
84 #ifdef gnu_bind_textdomain_codeset
85 out = gnu_bind_textdomain_codeset (domainname, codeset);
86 #else
87 out = NULL;
88 #endif
89
90 return out ? rep_string_dup (out) : Qnil;
91 }
92
93
94 DEFUN("textdomain", Ftextdomain, Stextdomain, (repv dom), rep_Subr1)
95 {
96 char *domainname = 0, *out;
97
98 if (rep_STRINGP(dom))
99 domainname = rep_STR(dom);
100
101 out = gnu_textdomain (domainname);
102 return out ? rep_string_dup (out) : Qnil;
103 }
104
105
106
107 /* DL hooks */
108
109 DEFSTRING(underscore, "_");
110
111 repv
rep_dl_init(void)112 rep_dl_init(void)
113 {
114 repv tem = rep_push_structure ("rep.i18n.gettext"), ret;
115 /* ::alias:gettext rep.i18n.gettext:: */
116 rep_alias_structure ("gettext");
117 rep_ADD_SUBR(Sgettext);
118 rep_ADD_SUBR(Sbindtextdomain);
119 rep_ADD_SUBR(Sbindtextdomaincodeset);
120 rep_ADD_SUBR(Stextdomain);
121 ret = rep_pop_structure (tem);
122
123 /* Update binding of `_' in `rep' structure to point at the
124 gettext function */
125 tem = rep_push_structure ("rep");
126 Fset (Fintern (rep_VAL (&underscore), Qnil), rep_VAL (&Sgettext));
127 rep_pop_structure (tem);
128
129 return ret;
130 }
131