| 1 | /* Compatibility code for gettext-using-catgets interface.
|
|---|
| 2 | Copyright (C) 1995, 1997 Free 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 Foundation,
|
|---|
| 16 | 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 | #include <stdio.h>
|
|---|
| 23 |
|
|---|
| 24 | #ifdef STDC_HEADERS
|
|---|
| 25 | # include <stdlib.h>
|
|---|
| 26 | # include <string.h>
|
|---|
| 27 | #else
|
|---|
| 28 | char *getenv ();
|
|---|
| 29 | # ifdef HAVE_MALLOC_H
|
|---|
| 30 | # include <malloc.h>
|
|---|
| 31 | # endif
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | #ifdef HAVE_NL_TYPES_H
|
|---|
| 35 | # include <nl_types.h>
|
|---|
| 36 | #endif
|
|---|
| 37 |
|
|---|
| 38 | #include "libgettext.h"
|
|---|
| 39 |
|
|---|
| 40 | /* @@ end of prolog @@ */
|
|---|
| 41 |
|
|---|
| 42 | /* XPG3 defines the result of `setlocale (category, NULL)' as:
|
|---|
| 43 | ``Directs `setlocale()' to query `category' and return the current
|
|---|
| 44 | setting of `local'.''
|
|---|
| 45 | However it does not specify the exact format. And even worse: POSIX
|
|---|
| 46 | defines this not at all. So we can use this feature only on selected
|
|---|
| 47 | system (e.g. those using GNU C Library). */
|
|---|
| 48 | #ifdef _LIBC
|
|---|
| 49 | # define HAVE_LOCALE_NULL
|
|---|
| 50 | #endif
|
|---|
| 51 |
|
|---|
| 52 | /* The catalog descriptor. */
|
|---|
| 53 | static nl_catd catalog = (nl_catd) -1;
|
|---|
| 54 |
|
|---|
| 55 | /* Name of the default catalog. */
|
|---|
| 56 | static const char default_catalog_name[] = "messages";
|
|---|
| 57 |
|
|---|
| 58 | /* Name of currently used catalog. */
|
|---|
| 59 | static const char *catalog_name = default_catalog_name;
|
|---|
| 60 |
|
|---|
| 61 | /* Get ID for given string. If not found return -1. */
|
|---|
| 62 | static int msg_to_cat_id PARAMS ((const char *msg));
|
|---|
| 63 |
|
|---|
| 64 | /* Substitution for systems lacking this function in their C library. */
|
|---|
| 65 | #if !_LIBC && !HAVE_STPCPY
|
|---|
| 66 | static char *stpcpy PARAMS ((char *dest, const char *src));
|
|---|
| 67 | #endif
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | /* Set currently used domain/catalog. */
|
|---|
| 71 | char *
|
|---|
| 72 | textdomain (domainname)
|
|---|
| 73 | const char *domainname;
|
|---|
| 74 | {
|
|---|
| 75 | nl_catd new_catalog;
|
|---|
| 76 | char *new_name;
|
|---|
| 77 | size_t new_name_len;
|
|---|
| 78 | char *lang;
|
|---|
| 79 |
|
|---|
| 80 | #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES \
|
|---|
| 81 | && defined HAVE_LOCALE_NULL
|
|---|
| 82 | lang = setlocale (LC_MESSAGES, NULL);
|
|---|
| 83 | #else
|
|---|
| 84 | lang = getenv ("LC_ALL");
|
|---|
| 85 | if (lang == NULL || lang[0] == '\0')
|
|---|
| 86 | {
|
|---|
| 87 | lang = getenv ("LC_MESSAGES");
|
|---|
| 88 | if (lang == NULL || lang[0] == '\0')
|
|---|
| 89 | lang = getenv ("LANG");
|
|---|
| 90 | }
|
|---|
| 91 | #endif
|
|---|
| 92 | if (lang == NULL || lang[0] == '\0')
|
|---|
| 93 | lang = "C";
|
|---|
| 94 |
|
|---|
| 95 | /* See whether name of currently used domain is asked. */
|
|---|
| 96 | if (domainname == NULL)
|
|---|
| 97 | return (char *) catalog_name;
|
|---|
| 98 |
|
|---|
| 99 | if (domainname[0] == '\0')
|
|---|
|
|---|