annotate intl/textdomain.c @ 1697:23ad4f7b644f

[gaim-migrate @ 1707] fprintf is probably better in this case than g_print. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Wed, 11 Apr 2001 04:36:21 +0000
parents d64101dc5c7e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
347
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /* Implementation of the textdomain(3) function.
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 any later version.
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 GNU General Public License for more details.
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 #ifdef HAVE_CONFIG_H
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 # include <config.h>
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 #endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 #if defined STDC_HEADERS || defined _LIBC
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 # include <stdlib.h>
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 #endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 #if defined STDC_HEADERS || defined HAVE_STRING_H || defined _LIBC
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 # include <string.h>
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 #else
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 # include <strings.h>
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 # ifndef memcpy
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 # endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 #endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 #ifdef _LIBC
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 # include <libintl.h>
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 #else
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 # include "libgettext.h"
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 #endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 /* @@ end of prolog @@ */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 /* Name of the default text domain. */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 extern const char _nl_default_default_domain[];
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 /* Default text domain in which entries for gettext(3) are to be found. */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 extern const char *_nl_current_default_domain;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 /* Names for the libintl functions are a problem. They must not clash
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 with existing names and they should follow ANSI C. But this source
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 code is also used in GNU C Library where the names have a __
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 prefix. So we have to make a difference here. */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 #ifdef _LIBC
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 # define TEXTDOMAIN __textdomain
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 # ifndef strdup
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 # define strdup(str) __strdup (str)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 # endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 #else
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 # define TEXTDOMAIN textdomain__
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 #endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 /* Set the current default message catalog to DOMAINNAME.
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 If DOMAINNAME is null, return the current default.
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 If DOMAINNAME is "", reset to the default of "messages". */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 char *
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 TEXTDOMAIN (domainname)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 const char *domainname;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 {
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 char *old;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 /* A NULL pointer requests the current setting. */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 if (domainname == NULL)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 return (char *) _nl_current_default_domain;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 old = (char *) _nl_current_default_domain;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 /* If domain name is the null string set to default domain "messages". */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 if (domainname[0] == '\0'
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 || strcmp (domainname, _nl_default_default_domain) == 0)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 _nl_current_default_domain = _nl_default_default_domain;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 else
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 {
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 /* If the following malloc fails `_nl_current_default_domain'
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 will be NULL. This value will be returned and so signals we
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 are out of core. */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 #if defined _LIBC || defined HAVE_STRDUP
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 _nl_current_default_domain = strdup (domainname);
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 #else
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 size_t len = strlen (domainname) + 1;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 char *cp = (char *) malloc (len);
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 if (cp != NULL)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 memcpy (cp, domainname, len);
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 _nl_current_default_domain = cp;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 #endif
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 }
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 if (old != _nl_default_default_domain)
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 free (old);
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 return (char *) _nl_current_default_domain;
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 }
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 #ifdef _LIBC
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 /* Alias for function name in GNU C Library. */
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 weak_alias (__textdomain, textdomain);
d64101dc5c7e [gaim-migrate @ 357]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 #endif