Back to index

plt-scheme  4.2.1
textdomain.c
Go to the documentation of this file.
00001 /* textdomain.c -- implementation of the textdomain(3) function
00002    Copyright (C) 1995 Software Foundation, Inc.
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2, or (at your option)
00007 any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00017 
00018 #ifdef HAVE_CONFIG_H
00019 # include <config.h>
00020 #endif
00021 
00022 #if defined STDC_HEADERS || defined _LIBC
00023 # include <stdlib.h>
00024 #endif
00025 
00026 #if defined STDC_HEADERS || defined HAVE_STRING_H || defined _LIBC
00027 # include <string.h>
00028 #else
00029 # include <strings.h>
00030 #endif
00031 
00032 #ifdef _LIBC
00033 # include <libintl.h>
00034 #else
00035 # include "libgettext.h"
00036 #endif
00037 
00038 /* @@ end of prolog @@ */
00039 
00040 /* Name of the default text domain.  */
00041 extern const char _nl_default_default_domain[];
00042 
00043 /* Default text domain in which entries for gettext(3) are to be found.  */
00044 extern const char *_nl_current_default_domain;
00045 
00046 
00047 /* Names for the libintl functions are a problem.  They must not clash
00048    with existing names and they should follow ANSI C.  But this source
00049    code is also used in GNU C Library where the names have a __
00050    prefix.  So we have to make a difference here.  */
00051 #ifdef _LIBC
00052 # define TEXTDOMAIN __textdomain
00053 #else
00054 # define TEXTDOMAIN textdomain__
00055 #endif
00056 
00057 /* Set the current default message catalog to DOMAINNAME.
00058    If DOMAINNAME is null, return the current default.
00059    If DOMAINNAME is "", reset to the default of "messages".  */
00060 char *
00061 TEXTDOMAIN (domainname)
00062      const char *domainname;
00063 {
00064   char *old;
00065 
00066   /* A NULL pointer requests the current setting.  */
00067   if (domainname == NULL)
00068     return (char *) _nl_current_default_domain;
00069 
00070   old = (char *) _nl_current_default_domain;
00071 
00072   /* If domain name is the null string set to default domain "messages".  */
00073   if (domainname[0] == '\0'
00074       || strcmp (domainname, _nl_default_default_domain) == 0)
00075     _nl_current_default_domain = _nl_default_default_domain;
00076   else
00077     {
00078       /* If the following malloc fails `_nl_current_default_domain'
00079         will be NULL.  This value will be returned and so signals we
00080         are out of core.  */
00081       size_t len = strlen (domainname) + 1;
00082       char *cp = (char *) malloc (len);
00083       if (cp != NULL)
00084        memcpy (cp, domainname, len);
00085       _nl_current_default_domain = cp;
00086     }
00087 
00088   if (old != _nl_default_default_domain)
00089     free (old);
00090 
00091   return (char *) _nl_current_default_domain;
00092 }
00093 
00094 #ifdef _LIBC
00095 /* Alias for function name in GNU C Library.  */
00096 weak_alias (__textdomain, textdomain);
00097 #endif