Back to index

plt-scheme  4.2.1
finddomain.c
Go to the documentation of this file.
00001 /* finddomain.c -- handle list of needed message catalogs
00002    Copyright (C) 1995, 1996 Free Software Foundation, Inc.
00003    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2, or (at your option)
00008 any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022 
00023 #include <ctype.h>
00024 #include <errno.h>
00025 #include <stdio.h>
00026 #include <sys/types.h>
00027 
00028 #if defined STDC_HEADERS || defined _LIBC
00029 # include <stdlib.h>
00030 #else
00031 # ifdef HAVE_MALLOC_H
00032 #  include <malloc.h>
00033 # else
00034 void free ();
00035 # endif
00036 #endif
00037 
00038 #if defined HAVE_STRING_H || defined _LIBC
00039 # include <string.h>
00040 #else
00041 # include <strings.h>
00042 #endif
00043 #if !HAVE_STRCHR && !defined _LIBC
00044 # ifndef strchr
00045 #  define strchr index
00046 # endif
00047 #endif
00048 
00049 #if defined HAVE_UNISTD_H || defined _LIBC
00050 # include <unistd.h>
00051 #endif
00052 
00053 #include "gettext.h"
00054 #include "gettextP.h"
00055 #ifdef _LIBC
00056 # include <libintl.h>
00057 #else
00058 # include "libgettext.h"
00059 #endif
00060 
00061 /* @@ end of prolog @@ */
00062 
00063 #ifdef _LIBC
00064 /* Rename the non ANSI C functions.  This is required by the standard
00065    because some ANSI C functions will require linking with this object
00066    file and the name space must not be polluted.  */
00067 # define stpcpy(dest, src) __stpcpy(dest, src)
00068 #else
00069 # ifndef HAVE_STPCPY
00070 static char *stpcpy PARAMS ((char *dest, const char *src));
00071 # endif
00072 #endif
00073 
00074 /* List of already loaded domains.  */
00075 static struct loaded_l10nfile *_nl_loaded_domains;
00076 
00077 
00078 /* Return a data structure describing the message catalog described by
00079    the DOMAINNAME and CATEGORY parameters with respect to the currently
00080    established bindings.  */
00081 struct loaded_l10nfile *
00082 _nl_find_domain (dirname, locale, domainname)
00083      const char *dirname;
00084      char *locale;
00085      const char *domainname;
00086 {
00087   struct loaded_l10nfile *retval;
00088   const char *language;
00089   const char *modifier;
00090   const char *territory;
00091   const char *codeset;
00092   const char *normalized_codeset;
00093   const char *special;
00094   const char *sponsor;
00095   const char *revision;
00096   const char *alias_value;
00097   int mask;
00098 
00099   /* LOCALE can consist of up to four recognized parts for the XPG syntax:
00100 
00101               language[_territory[.codeset]][@modifier]
00102 
00103      and six parts for the CEN syntax:
00104 
00105        language[_territory][+audience][+special][,sponsor][_revision]
00106 
00107      Beside the first all of them are allowed to be missing.  If the
00108      full specified locale is not found, the less specific one are
00109      looked for.  The various part will be stripped of according to
00110      the following order:
00111               (1) revision
00112               (2) sponsor
00113               (3) special
00114               (4) codeset
00115               (5) normalized codeset
00116               (6) territory
00117               (7) audience/modifier
00118    */
00119 
00120   /* If we have already tested for this locale entry there has to
00121      be one data set in the list of loaded domains.  */
00122   retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
00123                             strlen (dirname) + 1, 0, locale, NULL, NULL,
00124                             NULL, NULL, NULL, NULL, NULL, domainname, 0);
00125   if (retval != NULL)
00126     {
00127       /* We know something about this locale.  */
00128       int cnt;
00129 
00130       if (retval->decided == 0)
00131        _nl_load_domain (retval);
00132 
00133       if (retval->data != NULL)
00134        return retval;
00135 
00136       for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
00137        {
00138          if (retval->successor[cnt]->decided == 0)
00139            _nl_load_domain (retval->successor[cnt]);
00140 
00141          if (retval->successor[cnt]->data != NULL)
00142            break;
00143        }
00144       return cnt >= 0 ? retval : NULL;
00145       /* NOTREACHED */
00146     }
00147 
00148   /* See whether the locale value is an alias.  If yes its value
00149      *overwrites* the alias name.  No test for the original value is
00150      done.  */
00151   alias_value = _nl_expand_alias (locale);
00152   if (alias_value != NULL)
00153     {
00154       size_t len = strlen (alias_value) + 1;
00155       locale = (char *) malloc (len);
00156       if (locale == NULL)
00157        return NULL;
00158 
00159       memcpy (locale, alias_value, len);
00160     }
00161 
00162   /* Now we determine the single parts of the locale name.  First
00163      look for the language.  Termination symbols are `_' and `@' if
00164      we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
00165   mask = _nl_explode_name (locale, &language, &modifier, &territory,
00166                         &codeset, &normalized_codeset, &special,
00167                         &sponsor, &revision);
00168 
00169   /* Create all possible locale entries which might be interested in
00170      generalzation.  */
00171   retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
00172                             strlen (dirname) + 1, mask, language, territory,
00173                             codeset, normalized_codeset, modifier, special,
00174                             sponsor, revision, domainname, 1);
00175   if (retval == NULL)
00176     /* This means we are out of core.  */
00177     return NULL;
00178 
00179   if (retval->decided == 0)
00180     _nl_load_domain (retval);
00181   if (retval->data == NULL)
00182     {
00183       int cnt;
00184       for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
00185        {
00186          if (retval->successor[cnt]->decided == 0)
00187            _nl_load_domain (retval->successor[cnt]);
00188          if (retval->successor[cnt]->data != NULL)
00189            break;
00190        }
00191     }
00192 
00193   /* The room for an alias was dynamically allocated.  Free it now.  */
00194   if (alias_value != NULL)
00195     free (locale);
00196 
00197   return retval;
00198 }
00199 
00200 /* @@ begin of epilog @@ */
00201 
00202 /* We don't want libintl.a to depend on any other library.  So we
00203    avoid the non-standard function stpcpy.  In GNU C Library this
00204    function is available, though.  Also allow the symbol HAVE_STPCPY
00205    to be defined.  */
00206 #if !_LIBC && !HAVE_STPCPY
00207 static char *
00208 stpcpy (dest, src)
00209      char *dest;
00210      const char *src;
00211 {
00212   while ((*dest++ = *src++) != '\0')
00213     /* Do nothing. */ ;
00214   return dest - 1;
00215 }
00216 #endif