home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gettext-0.10.24-bin.lha / share / gettext / intl / textdomain.c < prev    next >
C/C++ Source or Header  |  1996-10-12  |  3KB  |  98 lines

  1. /* textdomain.c -- implementation of the textdomain(3) function
  2.    Copyright (C) 1995 Software Foundation, Inc.
  3.  
  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)
  7. any later version.
  8.  
  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.
  13.  
  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
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  17.  
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21.  
  22. #if defined STDC_HEADERS || defined _LIBC
  23. # include <stdlib.h>
  24. #endif
  25.  
  26. #if defined STDC_HEADERS || defined HAVE_STRING_H || defined _LIBC
  27. # include <string.h>
  28. #else
  29. # include <strings.h>
  30. #endif
  31.  
  32. #ifdef _LIBC
  33. # include <libintl.h>
  34. #else
  35. # include "libgettext.h"
  36. #endif
  37.  
  38. /* @@ end of prolog @@ */
  39.  
  40. /* Name of the default text domain.  */
  41. extern const char _nl_default_default_domain[];
  42.  
  43. /* Default text domain in which entries for gettext(3) are to be found.  */
  44. extern const char *_nl_current_default_domain;
  45.  
  46.  
  47. /* Names for the libintl functions are a problem.  They must not clash
  48.    with existing names and they should follow ANSI C.  But this source
  49.    code is also used in GNU C Library where the names have a __
  50.    prefix.  So we have to make a difference here.  */
  51. #ifdef _LIBC
  52. # define TEXTDOMAIN __textdomain
  53. #else
  54. # define TEXTDOMAIN textdomain__
  55. #endif
  56.  
  57. /* Set the current default message catalog to DOMAINNAME.
  58.    If DOMAINNAME is null, return the current default.
  59.    If DOMAINNAME is "", reset to the default of "messages".  */
  60. char *
  61. TEXTDOMAIN (domainname)
  62.      const char *domainname;
  63. {
  64.   char *old;
  65.  
  66.   /* A NULL pointer requests the current setting.  */
  67.   if (domainname == NULL)
  68.     return (char *) _nl_current_default_domain;
  69.  
  70.   old = (char *) _nl_current_default_domain;
  71.  
  72.   /* If domain name is the null string set to default domain "messages".  */
  73.   if (domainname[0] == '\0'
  74.       || strcmp (domainname, _nl_default_default_domain) == 0)
  75.     _nl_current_default_domain = _nl_default_default_domain;
  76.   else
  77.     {
  78.       /* If the following malloc fails `_nl_current_default_domain'
  79.      will be NULL.  This value will be returned and so signals we
  80.      are out of core.  */
  81.       size_t len = strlen (domainname) + 1;
  82.       char *cp = (char *) malloc (len);
  83.       if (cp != NULL)
  84.     memcpy (cp, domainname, len);
  85.       _nl_current_default_domain = cp;
  86.     }
  87.  
  88.   if (old != _nl_default_default_domain)
  89.     free (old);
  90.  
  91.   return (char *) _nl_current_default_domain;
  92. }
  93.  
  94. #ifdef _LIBC
  95. /* Alias for function name in GNU C Library.  */
  96. weak_alias (__textdomain, textdomain);
  97. #endif
  98.