1 /* Implementation of the bindtextdomain(3) function
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. */
18 #include "intlconfig.h"
20 #if defined STDC_HEADERS || defined _LIBC
30 #if defined HAVE_STRING_H || defined _LIBC
35 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
42 # include "libgettext.h"
47 /* @@ end of prolog @@ */
49 /* Contains the default location of the message catalogs. */
50 extern const char _nl_default_dirname[];
52 /* List with bindings of specific domains. */
53 extern struct binding *_nl_domain_bindings;
56 /* Names for the libintl functions are a problem. They must not clash
57 with existing names and they should follow ANSI C. But this source
58 code is also used in GNU C Library where the names have a __
59 prefix. So we have to make a difference here. */
61 # define BINDTEXTDOMAIN __bindtextdomain
63 # define strdup(str) __strdup (str)
66 # define BINDTEXTDOMAIN bindtextdomain__
69 /* Specify that the DOMAINNAME message catalog will be found
70 in DIRNAME rather than in the system locale data base. */
72 BINDTEXTDOMAIN (domainname, dirname_IN) /* FRANCO */
73 const char *domainname;
74 const char *dirname_IN;
76 struct binding *binding;
78 char *dirname_MOD,*pos;
85 if((len>0) && (pos=strchr(dirname,'\\'))){ /* SUBST DOS LIKE \ into UNIX like / */
86 #if defined _LIBC || defined HAVE_STRDUP
87 dirname_MOD = strdup (dirname);
88 if (dirname_MOD == NULL)
91 size_t len1 = strlen (dirname) + 1;
92 dirname_MOD = (char *) malloc (len1);
93 if (dirname_MOD == NULL)
95 memcpy (dirname_MOD, dirname, len1);
99 while( pos=strchr(pos,'\\')){
104 /* Some sanity checks. */
105 if (domainname == NULL || domainname[0] == '\0'){
106 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
110 for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next)
112 int compare = strcmp (domainname, binding->domainname);
118 /* It is not in the list. */
125 /* The current binding has be to returned. */
126 return binding == NULL ? (char *) _nl_default_dirname : binding->dirname;
130 /* The domain is already bound. If the new value and the old
131 one are equal we simply do nothing. Otherwise replace the
133 if (strcmp (dirname, binding->dirname) != 0)
137 if (strcmp (dirname, _nl_default_dirname) == 0)
138 new_dirname = (char *) _nl_default_dirname;
141 #if defined _LIBC || defined HAVE_STRDUP
142 new_dirname = strdup (dirname);
143 if (new_dirname == NULL){
144 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
148 size_t len = strlen (dirname) + 1;
149 new_dirname = (char *) malloc (len);
150 if (new_dirname == NULL){
151 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
155 memcpy (new_dirname, dirname, len);
159 if (binding->dirname != _nl_default_dirname)
160 free (binding->dirname);
162 binding->dirname = new_dirname;
167 /* We have to create a new binding. */
168 #if !defined _LIBC && !defined HAVE_STRDUP
171 struct binding *new_binding =
172 (struct binding *) malloc (sizeof (*new_binding));
174 if (new_binding == NULL){
175 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
179 #if defined _LIBC || defined HAVE_STRDUP
180 new_binding->domainname = strdup (domainname);
181 if (new_binding->domainname == NULL){
182 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
186 len = strlen (domainname) + 1;
187 new_binding->domainname = (char *) malloc (len);
188 if (new_binding->domainname == NULL){
189 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
192 memcpy (new_binding->domainname, domainname, len);
195 if (strcmp (dirname, _nl_default_dirname) == 0)
196 new_binding->dirname = (char *) _nl_default_dirname;
199 #if defined _LIBC || defined HAVE_STRDUP
200 new_binding->dirname = strdup (dirname);
201 if (new_binding->dirname == NULL){
202 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
206 len = strlen (dirname) + 1;
207 new_binding->dirname = (char *) malloc (len);
208 if (new_binding->dirname == NULL){
209 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
212 memcpy (new_binding->dirname, dirname, len);
216 /* Now enqueue it. */
217 if (_nl_domain_bindings == NULL
218 || strcmp (domainname, _nl_domain_bindings->domainname) < 0)
220 new_binding->next = _nl_domain_bindings;
221 _nl_domain_bindings = new_binding;
225 binding = _nl_domain_bindings;
226 while (binding->next != NULL
227 && strcmp (domainname, binding->next->domainname) > 0)
228 binding = binding->next;
230 new_binding->next = binding->next;
231 binding->next = new_binding;
234 binding = new_binding;
237 if(dirname_MOD)free(dirname_MOD); /*FRANCO*/
239 return binding->dirname;
243 /* Alias for function name in GNU C Library. */
244 weak_alias (__bindtextdomain, bindtextdomain);