Back to index

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