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