setlocale.c (11660) | setlocale.c (11695) |
---|---|
1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Paul Borman at Krystal Technologies. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 29 unchanged lines hidden (view full) --- 38static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; 39#endif /* LIBC_SCCS and not lint */ 40 41#include <limits.h> 42#include <locale.h> 43#include <rune.h> 44#include <stdlib.h> 45#include <string.h> | 1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Paul Borman at Krystal Technologies. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 29 unchanged lines hidden (view full) --- 38static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; 39#endif /* LIBC_SCCS and not lint */ 40 41#include <limits.h> 42#include <locale.h> 43#include <rune.h> 44#include <stdlib.h> 45#include <string.h> |
46#include "common_setlocale.h" 47#include "common_rune.h" | 46#include "collate.h" |
48 | 47 |
48/* 49 * Category names for getenv() 50 */ 51static char *categories[_LC_LAST] = { 52 "LC_ALL", 53 "LC_COLLATE", 54 "LC_CTYPE", 55 "LC_MONETARY", 56 "LC_NUMERIC", 57 "LC_TIME", 58}; 59 60/* 61 * Current locales for each category 62 */ 63static char current_categories[_LC_LAST][32] = { 64 "C", 65 "C", 66 "C", 67 "C", 68 "C", 69 "C", 70}; 71 72/* 73 * The locales we are going to try and load 74 */ 75static char new_categories[_LC_LAST][32]; 76 77static char current_locale_string[_LC_LAST * 33]; |
|
49char *_PathLocale; 50 | 78char *_PathLocale; 79 |
80static char *currentlocale __P((void)); |
|
51static char *loadlocale __P((int)); 52 | 81static char *loadlocale __P((int)); 82 |
83extern int __time_load_locale __P((const char *)); /* strftime.c */ 84 85#ifdef XPG4 86extern int _xpg4_setrunelocale __P((char *)); 87#endif 88 |
|
53char * 54setlocale(category, locale) 55 int category; 56 const char *locale; 57{ 58 int found, i, len; 59 char *env, *r; 60 | 89char * 90setlocale(category, locale) 91 int category; 92 const char *locale; 93{ 94 int found, i, len; 95 char *env, *r; 96 |
61 if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE"))) 62 PathLocale = _PATH_LOCALE; | 97 if (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))) 98 _PathLocale = _PATH_LOCALE; |
63 64 if (category < 0 || category >= _LC_LAST) 65 return (NULL); 66 67 if (!locale) 68 return (category ? 69 current_categories[category] : currentlocale()); 70 --- 63 unchanged lines hidden (view full) --- 134 for (i = 1; i < _LC_LAST; ++i) 135 if (loadlocale(i) != NULL) 136 found = 1; 137 if (found) 138 return (currentlocale()); 139 return (NULL); 140} 141 | 99 100 if (category < 0 || category >= _LC_LAST) 101 return (NULL); 102 103 if (!locale) 104 return (category ? 105 current_categories[category] : currentlocale()); 106 --- 63 unchanged lines hidden (view full) --- 170 for (i = 1; i < _LC_LAST; ++i) 171 if (loadlocale(i) != NULL) 172 found = 1; 173 if (found) 174 return (currentlocale()); 175 return (NULL); 176} 177 |
178#ifndef XPG4 179/* To be compatible with old binaries */ 180void 181_startup_setlocale(category, locale) 182 int category; 183 const char *locale; 184{ 185 (void) setlocale(category, locale); 186} 187#endif 188 |
|
142static char * | 189static char * |
190currentlocale() 191{ 192 int i, len; 193 194 (void)strcpy(current_locale_string, current_categories[1]); 195 196 for (i = 2; i < _LC_LAST; ++i) 197 if (strcmp(current_categories[1], current_categories[i])) { 198 len = strlen(current_categories[1]) + 1 + 199 strlen(current_categories[2]) + 1 + 200 strlen(current_categories[3]) + 1 + 201 strlen(current_categories[4]) + 1 + 202 strlen(current_categories[5]) + 1; 203 if (len > sizeof(current_locale_string)) 204 return NULL; 205 (void) strcpy(current_locale_string, current_categories[1]); 206 (void) strcat(current_locale_string, "/"); 207 (void) strcat(current_locale_string, current_categories[2]); 208 (void) strcat(current_locale_string, "/"); 209 (void) strcat(current_locale_string, current_categories[3]); 210 (void) strcat(current_locale_string, "/"); 211 (void) strcat(current_locale_string, current_categories[4]); 212 (void) strcat(current_locale_string, "/"); 213 (void) strcat(current_locale_string, current_categories[5]); 214 break; 215 } 216 return (current_locale_string); 217} 218 219static char * |
|
143loadlocale(category) 144 int category; 145{ 146#if 0 147 char name[PATH_MAX]; 148#endif 149 if (strcmp(new_categories[category], 150 current_categories[category]) == 0) 151 return (current_categories[category]); 152 153 if (category == LC_CTYPE) { | 220loadlocale(category) 221 int category; 222{ 223#if 0 224 char name[PATH_MAX]; 225#endif 226 if (strcmp(new_categories[category], 227 current_categories[category]) == 0) 228 return (current_categories[category]); 229 230 if (category == LC_CTYPE) { |
231#ifdef XPG4 232 if (_xpg4_setrunelocale(new_categories[LC_CTYPE])) 233#else |
|
154 if (setrunelocale(new_categories[LC_CTYPE])) | 234 if (setrunelocale(new_categories[LC_CTYPE])) |
235#endif |
|
155 return (NULL); 156 (void)strcpy(current_categories[LC_CTYPE], 157 new_categories[LC_CTYPE]); 158 return (current_categories[LC_CTYPE]); 159 } 160 161 if (category == LC_COLLATE) { 162 if (__collate_load_tables(new_categories[LC_COLLATE]) < 0) --- 23 unchanged lines hidden (view full) --- 186 new_categories[category]); 187 return (current_categories[category]); 188 } 189#if 0 190 /* 191 * Some day we will actually look at this file. 192 */ 193 (void)snprintf(name, sizeof(name), "%s/%s/%s", | 236 return (NULL); 237 (void)strcpy(current_categories[LC_CTYPE], 238 new_categories[LC_CTYPE]); 239 return (current_categories[LC_CTYPE]); 240 } 241 242 if (category == LC_COLLATE) { 243 if (__collate_load_tables(new_categories[LC_COLLATE]) < 0) --- 23 unchanged lines hidden (view full) --- 267 new_categories[category]); 268 return (current_categories[category]); 269 } 270#if 0 271 /* 272 * Some day we will actually look at this file. 273 */ 274 (void)snprintf(name, sizeof(name), "%s/%s/%s", |
194 PathLocale, new_categories[category], categories[category]); | 275 _PathLocale, new_categories[category], categories[category]); |
195#endif 196 switch (category) { 197 case LC_MONETARY: 198 case LC_NUMERIC: 199 return (NULL); 200 } 201 /* Just in case...*/ 202 return (NULL); 203} | 276#endif 277 switch (category) { 278 case LC_MONETARY: 279 case LC_NUMERIC: 280 return (NULL); 281 } 282 /* Just in case...*/ 283 return (NULL); 284} |