annotate intl/textdomain.c @ 1652:62c5bff8a05b trunk

[svn] - more hammering
author nenolod
date Thu, 07 Sep 2006 22:00:35 -0700
parents 705d4c089fce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* Implementation of the textdomain(3) function.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 Copyright (C) 1995-1998, 2000, 2001, 2002 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 License along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 # include <config.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 # include <libintl.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 # include "libgnuintl.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include "gettextP.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 /* We have to handle multi-threaded applications. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 # include <bits/libc-lock.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 /* Provide dummy implementation if this is outside glibc. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 # define __libc_rwlock_define(CLASS, NAME)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 # define __libc_rwlock_wrlock(NAME)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 # define __libc_rwlock_unlock(NAME)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 /* The internal variables in the standalone libintl.a must have different
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 names than the internal variables in GNU libc, otherwise programs
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 using libintl.a cannot be linked statically. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 #if !defined _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 # define _nl_default_default_domain libintl_nl_default_default_domain
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 # define _nl_current_default_domain libintl_nl_current_default_domain
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 /* @@ end of prolog @@ */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 /* Name of the default text domain. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 extern const char _nl_default_default_domain[] attribute_hidden;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 /* Default text domain in which entries for gettext(3) are to be found. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 extern const char *_nl_current_default_domain attribute_hidden;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 /* Names for the libintl functions are a problem. They must not clash
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 with existing names and they should follow ANSI C. But this source
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 code is also used in GNU C Library where the names have a __
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 prefix. So we have to make a difference here. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 # define TEXTDOMAIN __textdomain
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 # ifndef strdup
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 # define strdup(str) __strdup (str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 # endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 # define TEXTDOMAIN libintl_textdomain
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 /* Lock variable to protect the global data in the gettext implementation. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 __libc_rwlock_define (extern, _nl_state_lock attribute_hidden)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 /* Set the current default message catalog to DOMAINNAME.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 If DOMAINNAME is null, return the current default.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 If DOMAINNAME is "", reset to the default of "messages". */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 char *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 TEXTDOMAIN (domainname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 const char *domainname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 char *new_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 char *old_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 /* A NULL pointer requests the current setting. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 if (domainname == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 return (char *) _nl_current_default_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 __libc_rwlock_wrlock (_nl_state_lock);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 old_domain = (char *) _nl_current_default_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 /* If domain name is the null string set to default domain "messages". */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 if (domainname[0] == '\0'
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 || strcmp (domainname, _nl_default_default_domain) == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 _nl_current_default_domain = _nl_default_default_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 new_domain = (char *) _nl_current_default_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 else if (strcmp (domainname, old_domain) == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 /* This can happen and people will use it to signal that some
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 environment variable changed. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 new_domain = old_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 /* If the following malloc fails `_nl_current_default_domain'
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 will be NULL. This value will be returned and so signals we
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 are out of core. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 #if defined _LIBC || defined HAVE_STRDUP
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 new_domain = strdup (domainname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 size_t len = strlen (domainname) + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 new_domain = (char *) malloc (len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 if (new_domain != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 memcpy (new_domain, domainname, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 if (new_domain != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 _nl_current_default_domain = new_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 /* We use this possibility to signal a change of the loaded catalogs
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 since this is most likely the case and there is no other easy we
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 to do it. Do it only when the call was successful. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 if (new_domain != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 ++_nl_msg_cat_cntr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 if (old_domain != new_domain && old_domain != _nl_default_default_domain)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 free (old_domain);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 __libc_rwlock_unlock (_nl_state_lock);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 return new_domain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 /* Alias for function name in GNU C Library. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 weak_alias (__textdomain, textdomain);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 #endif