Back to index

tetex-bin  3.0
explodename.c
Go to the documentation of this file.
00001 /* Copyright (C) 1995-1998, 2000-2001, 2003 Free Software Foundation, Inc.
00002    Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
00003 
00004    This program is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU Library General Public License as published
00006    by 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 GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public
00015    License along with this program; if not, write to the Free Software
00016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00017    USA.  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022 
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <sys/types.h>
00026 
00027 #include "loadinfo.h"
00028 
00029 /* On some strange systems still no definition of NULL is found.  Sigh!  */
00030 #ifndef NULL
00031 # if defined __STDC__ && __STDC__
00032 #  define NULL ((void *) 0)
00033 # else
00034 #  define NULL 0
00035 # endif
00036 #endif
00037 
00038 /* @@ end of prolog @@ */
00039 
00040 char *
00041 _nl_find_language (const char *name)
00042 {
00043   while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
00044         && name[0] != '+' && name[0] != ',')
00045     ++name;
00046 
00047   return (char *) name;
00048 }
00049 
00050 
00051 int
00052 _nl_explode_name (char *name,
00053                 const char **language, const char **modifier,
00054                 const char **territory, const char **codeset,
00055                 const char **normalized_codeset, const char **special,
00056                 const char **sponsor, const char **revision)
00057 {
00058   enum { undecided, xpg, cen } syntax;
00059   char *cp;
00060   int mask;
00061 
00062   *modifier = NULL;
00063   *territory = NULL;
00064   *codeset = NULL;
00065   *normalized_codeset = NULL;
00066   *special = NULL;
00067   *sponsor = NULL;
00068   *revision = NULL;
00069 
00070   /* Now we determine the single parts of the locale name.  First
00071      look for the language.  Termination symbols are `_' and `@' if
00072      we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
00073   mask = 0;
00074   syntax = undecided;
00075   *language = cp = name;
00076   cp = _nl_find_language (*language);
00077 
00078   if (*language == cp)
00079     /* This does not make sense: language has to be specified.  Use
00080        this entry as it is without exploding.  Perhaps it is an alias.  */
00081     cp = strchr (*language, '\0');
00082   else if (cp[0] == '_')
00083     {
00084       /* Next is the territory.  */
00085       cp[0] = '\0';
00086       *territory = ++cp;
00087 
00088       while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
00089             && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
00090        ++cp;
00091 
00092       mask |= TERRITORY;
00093 
00094       if (cp[0] == '.')
00095        {
00096          /* Next is the codeset.  */
00097          syntax = xpg;
00098          cp[0] = '\0';
00099          *codeset = ++cp;
00100 
00101          while (cp[0] != '\0' && cp[0] != '@')
00102            ++cp;
00103 
00104          mask |= XPG_CODESET;
00105 
00106          if (*codeset != cp && (*codeset)[0] != '\0')
00107            {
00108              *normalized_codeset = _nl_normalize_codeset (*codeset,
00109                                                     cp - *codeset);
00110              if (strcmp (*codeset, *normalized_codeset) == 0)
00111               free ((char *) *normalized_codeset);
00112              else
00113               mask |= XPG_NORM_CODESET;
00114            }
00115        }
00116     }
00117 
00118   if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
00119     {
00120       /* Next is the modifier.  */
00121       syntax = cp[0] == '@' ? xpg : cen;
00122       cp[0] = '\0';
00123       *modifier = ++cp;
00124 
00125       while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
00126             && cp[0] != ',' && cp[0] != '_')
00127        ++cp;
00128 
00129       mask |= XPG_MODIFIER | CEN_AUDIENCE;
00130     }
00131 
00132   if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
00133     {
00134       syntax = cen;
00135 
00136       if (cp[0] == '+')
00137        {
00138          /* Next is special application (CEN syntax).  */
00139          cp[0] = '\0';
00140          *special = ++cp;
00141 
00142          while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
00143            ++cp;
00144 
00145          mask |= CEN_SPECIAL;
00146        }
00147 
00148       if (cp[0] == ',')
00149        {
00150          /* Next is sponsor (CEN syntax).  */
00151          cp[0] = '\0';
00152          *sponsor = ++cp;
00153 
00154          while (cp[0] != '\0' && cp[0] != '_')
00155            ++cp;
00156 
00157          mask |= CEN_SPONSOR;
00158        }
00159 
00160       if (cp[0] == '_')
00161        {
00162          /* Next is revision (CEN syntax).  */
00163          cp[0] = '\0';
00164          *revision = ++cp;
00165 
00166          mask |= CEN_REVISION;
00167        }
00168     }
00169 
00170   /* For CEN syntax values it might be important to have the
00171      separator character in the file name, not for XPG syntax.  */
00172   if (syntax == xpg)
00173     {
00174       if (*territory != NULL && (*territory)[0] == '\0')
00175        mask &= ~TERRITORY;
00176 
00177       if (*codeset != NULL && (*codeset)[0] == '\0')
00178        mask &= ~XPG_CODESET;
00179 
00180       if (*modifier != NULL && (*modifier)[0] == '\0')
00181        mask &= ~XPG_MODIFIER;
00182     }
00183 
00184   return mask;
00185 }