/xbmc/visualizations/Goom/goom2k4-0/gtk-gui-devel/intl/bindtextdom.c

http://github.com/xbmc/xbmc · C · 203 lines · 142 code · 26 blank · 35 comment · 48 complexity · 0d0f701f3de2b7d66164cd9dfc174378 MD5 · raw file

  1. /* Implementation of the bindtextdomain(3) function
  2. Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. #ifdef HAVE_CONFIG_H
  15. # include <config.h>
  16. #endif
  17. #if defined STDC_HEADERS || defined _LIBC
  18. # include <stdlib.h>
  19. #else
  20. # ifdef HAVE_MALLOC_H
  21. # include <malloc.h>
  22. # else
  23. void free ();
  24. # endif
  25. #endif
  26. #if defined HAVE_STRING_H || defined _LIBC
  27. # include <string.h>
  28. #else
  29. # include <strings.h>
  30. # ifndef memcpy
  31. # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
  32. # endif
  33. #endif
  34. #ifdef _LIBC
  35. # include <libintl.h>
  36. #else
  37. # include "libgettext.h"
  38. #endif
  39. #include "gettext.h"
  40. #include "gettextP.h"
  41. /* @@ end of prolog @@ */
  42. /* Contains the default location of the message catalogs. */
  43. extern const char _nl_default_dirname[];
  44. /* List with bindings of specific domains. */
  45. extern struct binding *_nl_domain_bindings;
  46. /* Names for the libintl functions are a problem. They must not clash
  47. with existing names and they should follow ANSI C. But this source
  48. code is also used in GNU C Library where the names have a __
  49. prefix. So we have to make a difference here. */
  50. #ifdef _LIBC
  51. # define BINDTEXTDOMAIN __bindtextdomain
  52. # ifndef strdup
  53. # define strdup(str) __strdup (str)
  54. # endif
  55. #else
  56. # define BINDTEXTDOMAIN bindtextdomain__
  57. #endif
  58. /* Specify that the DOMAINNAME message catalog will be found
  59. in DIRNAME rather than in the system locale data base. */
  60. char *
  61. BINDTEXTDOMAIN (domainname, dirname)
  62. const char *domainname;
  63. const char *dirname;
  64. {
  65. struct binding *binding;
  66. /* Some sanity checks. */
  67. if (domainname == NULL || domainname[0] == '\0')
  68. return NULL;
  69. for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next)
  70. {
  71. int compare = strcmp (domainname, binding->domainname);
  72. if (compare == 0)
  73. /* We found it! */
  74. break;
  75. if (compare < 0)
  76. {
  77. /* It is not in the list. */
  78. binding = NULL;
  79. break;
  80. }
  81. }
  82. if (dirname == NULL)
  83. /* The current binding has be to returned. */
  84. return binding == NULL ? (char *) _nl_default_dirname : binding->dirname;
  85. if (binding != NULL)
  86. {
  87. /* The domain is already bound. If the new value and the old
  88. one are equal we simply do nothing. Otherwise replace the
  89. old binding. */
  90. if (strcmp (dirname, binding->dirname) != 0)
  91. {
  92. char *new_dirname;
  93. if (strcmp (dirname, _nl_default_dirname) == 0)
  94. new_dirname = (char *) _nl_default_dirname;
  95. else
  96. {
  97. #if defined _LIBC || defined HAVE_STRDUP
  98. new_dirname = strdup (dirname);
  99. if (new_dirname == NULL)
  100. return NULL;
  101. #else
  102. size_t len = strlen (dirname) + 1;
  103. new_dirname = (char *) malloc (len);
  104. if (new_dirname == NULL)
  105. return NULL;
  106. memcpy (new_dirname, dirname, len);
  107. #endif
  108. }
  109. if (binding->dirname != _nl_default_dirname)
  110. free (binding->dirname);
  111. binding->dirname = new_dirname;
  112. }
  113. }
  114. else
  115. {
  116. /* We have to create a new binding. */
  117. #if !defined _LIBC && !defined HAVE_STRDUP
  118. size_t len;
  119. #endif
  120. struct binding *new_binding =
  121. (struct binding *) malloc (sizeof (*new_binding));
  122. if (new_binding == NULL)
  123. return NULL;
  124. #if defined _LIBC || defined HAVE_STRDUP
  125. new_binding->domainname = strdup (domainname);
  126. if (new_binding->domainname == NULL)
  127. return NULL;
  128. #else
  129. len = strlen (domainname) + 1;
  130. new_binding->domainname = (char *) malloc (len);
  131. if (new_binding->domainname == NULL)
  132. return NULL;
  133. memcpy (new_binding->domainname, domainname, len);
  134. #endif
  135. if (strcmp (dirname, _nl_default_dirname) == 0)
  136. new_binding->dirname = (char *) _nl_default_dirname;
  137. else
  138. {
  139. #if defined _LIBC || defined HAVE_STRDUP
  140. new_binding->dirname = strdup (dirname);
  141. if (new_binding->dirname == NULL)
  142. return NULL;
  143. #else
  144. len = strlen (dirname) + 1;
  145. new_binding->dirname = (char *) malloc (len);
  146. if (new_binding->dirname == NULL)
  147. return NULL;
  148. memcpy (new_binding->dirname, dirname, len);
  149. #endif
  150. }
  151. /* Now enqueue it. */
  152. if (_nl_domain_bindings == NULL
  153. || strcmp (domainname, _nl_domain_bindings->domainname) < 0)
  154. {
  155. new_binding->next = _nl_domain_bindings;
  156. _nl_domain_bindings = new_binding;
  157. }
  158. else
  159. {
  160. binding = _nl_domain_bindings;
  161. while (binding->next != NULL
  162. && strcmp (domainname, binding->next->domainname) > 0)
  163. binding = binding->next;
  164. new_binding->next = binding->next;
  165. binding->next = new_binding;
  166. }
  167. binding = new_binding;
  168. }
  169. return binding->dirname;
  170. }
  171. #ifdef _LIBC
  172. /* Alias for function name in GNU C Library. */
  173. weak_alias (__bindtextdomain, bindtextdomain);
  174. #endif