Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

explodename.c

00001 /* Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc.
00002    Contributed by Ulrich Drepper <[email protected]>, 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 (name)
00042      const char *name;
00043 {
00044   while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
00045          && name[0] != '+' && name[0] != ',')
00046     ++name;
00047 
00048   return (char *) name;
00049 }
00050 
00051 
00052 int
00053 _nl_explode_name (name, language, modifier, territory, codeset,
00054                   normalized_codeset, special, sponsor, revision)
00055      char *name;
00056      const char **language;
00057      const char **modifier;
00058      const char **territory;
00059      const char **codeset;
00060      const char **normalized_codeset;
00061      const char **special;
00062      const char **sponsor;
00063      const char **revision;
00064 {
00065   enum { undecided, xpg, cen } syntax;
00066   char *cp;
00067   int mask;
00068 
00069   *modifier = NULL;
00070   *territory = NULL;
00071   *codeset = NULL;
00072   *normalized_codeset = NULL;
00073   *special = NULL;
00074   *sponsor = NULL;
00075   *revision = NULL;
00076 
00077   /* Now we determine the single parts of the locale name.  First
00078      look for the language.  Termination symbols are `_' and `@' if
00079      we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
00080   mask = 0;
00081   syntax = undecided;
00082   *language = cp = name;
00083   cp = _nl_find_language (*language);
00084 
00085   if (*language == cp)
00086     /* This does not make sense: language has to be specified.  Use
00087        this entry as it is without exploding.  Perhaps it is an alias.  */
00088     cp = strchr (*language, '\0');
00089   else if (cp[0] == '_')
00090     {
00091       /* Next is the territory.  */
00092       cp[0] = '\0';
00093       *territory = ++cp;
00094 
00095       while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
00096              && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
00097         ++cp;
00098 
00099       mask |= TERRITORY;
00100 
00101       if (cp[0] == '.')
00102         {
00103           /* Next is the codeset.  */
00104           syntax = xpg;
00105           cp[0] = '\0';
00106           *codeset = ++cp;
00107 
00108           while (cp[0] != '\0' && cp[0] != '@')
00109             ++cp;
00110 
00111           mask |= XPG_CODESET;
00112 
00113           if (*codeset != cp && (*codeset)[0] != '\0')
00114             {
00115               *normalized_codeset = _nl_normalize_codeset (*codeset,
00116                                                            cp - *codeset);
00117               if (strcmp (*codeset, *normalized_codeset) == 0)
00118                 free ((char *) *normalized_codeset);
00119               else
00120                 mask |= XPG_NORM_CODESET;
00121             }
00122         }
00123     }
00124 
00125   if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
00126     {
00127       /* Next is the modifier.  */
00128       syntax = cp[0] == '@' ? xpg : cen;
00129       cp[0] = '\0';
00130       *modifier = ++cp;
00131 
00132       while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
00133              && cp[0] != ',' && cp[0] != '_')
00134         ++cp;
00135 
00136       mask |= XPG_MODIFIER | CEN_AUDIENCE;
00137     }
00138 
00139   if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
00140     {
00141       syntax = cen;
00142 
00143       if (cp[0] == '+')
00144         {
00145           /* Next is special application (CEN syntax).  */
00146           cp[0] = '\0';
00147           *special = ++cp;
00148 
00149           while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
00150             ++cp;
00151 
00152           mask |= CEN_SPECIAL;
00153         }
00154 
00155       if (cp[0] == ',')
00156         {
00157           /* Next is sponsor (CEN syntax).  */
00158           cp[0] = '\0';
00159           *sponsor = ++cp;
00160 
00161           while (cp[0] != '\0' && cp[0] != '_')
00162             ++cp;
00163 
00164           mask |= CEN_SPONSOR;
00165         }
00166 
00167       if (cp[0] == '_')
00168         {
00169           /* Next is revision (CEN syntax).  */
00170           cp[0] = '\0';
00171           *revision = ++cp;
00172 
00173           mask |= CEN_REVISION;
00174         }
00175     }
00176 
00177   /* For CEN syntax values it might be important to have the
00178      separator character in the file name, not for XPG syntax.  */
00179   if (syntax == xpg)
00180     {
00181       if (*territory != NULL && (*territory)[0] == '\0')
00182         mask &= ~TERRITORY;
00183 
00184       if (*codeset != NULL && (*codeset)[0] == '\0')
00185         mask &= ~XPG_CODESET;
00186 
00187       if (*modifier != NULL && (*modifier)[0] == '\0')
00188         mask &= ~XPG_MODIFIER;
00189     }
00190 
00191   return mask;
00192 }

Generated on Tue Dec 20 10:14:20 2005 for vlc-0.8.4a by  doxygen 1.4.2