locale.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /* Copyright (C) 2002 Manuel Novoa III
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Library General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public
  14. * License along with this library; if not, write to the Free
  15. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. /* TODO:
  18. * Implement the shared mmap code so non-mmu platforms can use this.
  19. * Add some basic collate functionality similar to what the previous
  20. * locale support had (8-bit codesets only).
  21. */
  22. #define _GNU_SOURCE
  23. #include <locale.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <stddef.h>
  27. #include <limits.h>
  28. #include <stdint.h>
  29. #include <assert.h>
  30. #ifndef __LOCALE_C_ONLY
  31. #define CUR_LOCALE_SPEC (__global_locale.cur_locale)
  32. #undef CODESET_LIST
  33. #define CODESET_LIST (__locale_mmap->codeset_list)
  34. /* TODO: Optional... See below. */
  35. #define __LOCALE_STRICTER_SETLOCALE
  36. #endif /* __LOCALE_C_ONLY */
  37. /**********************************************************************/
  38. #ifdef L_setlocale
  39. #ifdef __LOCALE_C_ONLY
  40. link_warning(setlocale,"the 'setlocale' function supports only C|POSIX locales")
  41. static const char C_string[] = "C";
  42. char *setlocale(int category, register const char *locale)
  43. {
  44. return ( (((unsigned int)(category)) <= LC_ALL)
  45. && ( (!locale) /* Request for locale category string. */
  46. || (!*locale) /* Implementation-defined default is C. */
  47. || ((*locale == 'C') && !locale[1])
  48. || (!strcmp(locale, "POSIX"))) )
  49. ? (char *) C_string /* Always in C/POSIX locale. */
  50. : NULL;
  51. }
  52. #else /* ---------------------------------------------- __LOCALE_C_ONLY */
  53. #if !defined(NUM_LOCALES) || (NUM_LOCALES <= 1)
  54. #error locales enabled, but not data other than for C locale!
  55. #endif
  56. static unsigned char setlocale_buf[LOCALE_STRING_SIZE];
  57. #define LOCALE_NAMES (__locale_mmap->locale_names5)
  58. #define LOCALES (__locale_mmap->locales)
  59. #define LOCALE_AT_MODIFIERS (__locale_mmap->locale_at_modifiers)
  60. #define CATEGORY_NAMES (__locale_mmap->lc_names)
  61. static const char posix[] = "POSIX";
  62. static int find_locale(int category, const char *p, unsigned char *new_locale)
  63. {
  64. int i;
  65. const unsigned char *s;
  66. uint16_t n;
  67. unsigned char lang_cult, codeset;
  68. #if defined(LOCALE_AT_MODIFIERS_LENGTH) && 1
  69. /* Support standard locale handling for @-modifiers. */
  70. char buf[18]; /* TODO: 7+{max codeset name length} */
  71. const char *q;
  72. if ((q = strchr(p,'@')) != NULL) {
  73. if ((((size_t)((q-p)-5)) > (sizeof(buf) - 5)) || (p[2] != '_')) {
  74. return 0;
  75. }
  76. /* locale name at least 5 chars long and 3rd char is '_' */
  77. s = LOCALE_AT_MODIFIERS;
  78. do {
  79. if (!strcmp(s+2, q+1)) {
  80. break;
  81. }
  82. s += 2 + *s; /* TODO - fix this throughout */
  83. } while (*s);
  84. if (!*s) {
  85. return 0;
  86. }
  87. memcpy(buf, p, q-p);
  88. buf[q-p] = 0;
  89. buf[2] = s[1];
  90. p = buf;
  91. }
  92. #endif
  93. lang_cult = codeset = 0; /* Assume C and default codeset. */
  94. if (((*p == 'C') && !p[1]) || !strcmp(p, posix)) {
  95. goto FIND_LOCALE;
  96. }
  97. if (p[5] == '.') { /* Codeset specified in locale name? */
  98. /* TODO: maybe CODESET_LIST + *s ??? */
  99. /* 7bit is 1, UTF-8 is 2, 8-bit is >= 3 */
  100. codeset = 2;
  101. if (strcmp("UTF-8",p+6) != 0) {/* TODO - fix! */
  102. s = CODESET_LIST;
  103. do {
  104. ++codeset; /* Increment codeset first. */
  105. if (!strcmp(CODESET_LIST+*s, p+6)) {
  106. goto FIND_LANG_CULT;
  107. }
  108. } while (*++s);
  109. return 0; /* No matching codeset! */
  110. }
  111. }
  112. FIND_LANG_CULT: /* Find language_culture number. */
  113. s = LOCALE_NAMES;
  114. do { /* TODO -- do a binary search? */
  115. /* TODO -- fix gen_mmap!*/
  116. ++lang_cult; /* Increment first since C/POSIX is 0. */
  117. if (!strncmp(s,p,5)) { /* Found a matching locale name; */
  118. goto FIND_LOCALE;
  119. }
  120. s += 5;
  121. } while (lang_cult < NUM_LOCALE_NAMES);
  122. return 0; /* No matching language_culture! */
  123. FIND_LOCALE: /* Find locale row matching name and codeset */
  124. s = LOCALES;
  125. n = 1;
  126. do { /* TODO -- do a binary search? */
  127. if ((lang_cult == *s) && ((codeset == s[1]) || (codeset == s[2]))) {
  128. i = ((category == LC_ALL) ? 0 : category);
  129. s = new_locale + 2*i;
  130. do {
  131. /* Encode current locale row number. */
  132. *((unsigned char *) ++s) = (n >> 8) | 0x80;
  133. *((unsigned char *) ++s) = n & 0xff;
  134. } while (++i < category);
  135. return i; /* Return non-zero */
  136. }
  137. s += WIDTH_LOCALES;
  138. ++n;
  139. } while (n <= NUM_LOCALES); /* We started at 1!!! */
  140. return 0; /* Unsupported locale. */
  141. }
  142. char *setlocale(int category, const char *locale)
  143. {
  144. const unsigned char *p;
  145. unsigned char *s;
  146. int i;
  147. unsigned lc_mask;
  148. unsigned char new_locale[LOCALE_STRING_SIZE];
  149. if (((unsigned int)(category)) > LC_ALL) {
  150. /* TODO - set errno? SUSv3 doesn't say too. */
  151. return NULL; /* Illegal/unsupported category. */
  152. }
  153. lc_mask = 1 << category;
  154. if (category == LC_ALL) {
  155. --lc_mask;
  156. }
  157. if (!locale) { /* Request for locale category string... */
  158. DONE:
  159. strcpy(setlocale_buf, CUR_LOCALE_SPEC);
  160. #ifdef __LOCALE_STRICTER_SETLOCALE
  161. /* The standard says you can only use the string returned to restore
  162. * the category (categories) requested. This could be optional.
  163. * See below as well. */
  164. s = setlocale_buf + 1;
  165. lc_mask |= (1 << LC_ALL);
  166. do {
  167. if (!(lc_mask & 1)) {
  168. /* Encode non-selected locale flag. */
  169. s[1] = *s = 0xff;
  170. }
  171. s += 2;
  172. } while ((lc_mask >>= 1) > 1);
  173. #endif /* __LOCALE_STRICTER_SETLOCALE */
  174. return (char *) setlocale_buf;
  175. }
  176. strcpy(new_locale, CUR_LOCALE_SPEC); /* Start with current. */
  177. if (!*locale) { /* locale == "", so check environment. */
  178. i = ((category == LC_ALL) ? 0 : category);
  179. do {
  180. /* Note: SUSv3 doesn't define a fallback mechanism here. So,
  181. * if LC_ALL is invalid, we do _not_ continue trying the other
  182. * environment vars. */
  183. if (!(p = getenv("LC_ALL"))) {
  184. if (!(p = getenv(CATEGORY_NAMES + CATEGORY_NAMES[i]))) {
  185. if (!(p = getenv("LANG"))) {
  186. p = posix;
  187. }
  188. }
  189. }
  190. /* The user set something... is it valid? */
  191. /* Note: Since we don't support user-supplied locales and
  192. * alternate paths, we don't need to worry about special
  193. * handling for suid/sgid apps. */
  194. if (!find_locale(i, p, new_locale)) {
  195. return NULL;
  196. }
  197. } while (++i < category);
  198. } else if (*locale == '#') { /* Previsouly returned value. */
  199. assert(strlen(locale) == LOCALE_STRING_SIZE - 1);
  200. i = ((category == LC_ALL) ? 0 : category);
  201. p = locale + 2*i;
  202. s = new_locale + 2*i;
  203. do {
  204. #ifdef __LOCALE_STRICTER_SETLOCALE
  205. /* Only set categories that were selected in the previous
  206. * return value. Could be optional. See above as well.
  207. * NOTE: This still isn't quite right for non-LC_ALL
  208. * as it only checks the category selected to set. */
  209. if ((*p == 0xff) && (p[1] == 0xff)) {
  210. return NULL;
  211. }
  212. #endif /* __LOCALE_STRICTER_SETLOCALE */
  213. /* Note: Validate settings below. */
  214. *++s = *++p;
  215. *++s = *++p;
  216. } while (++i < category);
  217. } else if (!find_locale(category, locale, new_locale)) {
  218. return NULL;
  219. }
  220. /* TODO: Ok, everything checks out, so install the new locale. */
  221. _locale_set(new_locale);
  222. /* Everything ok, so make a copy in setlocale_buf and return. */
  223. goto DONE;
  224. }
  225. #endif /* __LOCALE_C_ONLY */
  226. #endif
  227. /**********************************************************************/
  228. #ifdef L_localeconv
  229. /* Note: We assume here that the compiler does the sane thing regarding
  230. * placement of the fields in the struct. If necessary, we could ensure
  231. * this usings an array of offsets but at some size cost. */
  232. #ifdef __LOCALE_C_ONLY
  233. link_warning(localeconv,"the 'localeconv' function is hardwired for C/POSIX locale only")
  234. static struct lconv the_lconv;
  235. static const char decpt[] = ".";
  236. struct lconv *localeconv(void)
  237. {
  238. register char *p = (char *)(&the_lconv);
  239. *((char **)p) = (char *) decpt;
  240. do {
  241. p += sizeof(char **);
  242. *((char **)p) = (char *) (decpt+1);
  243. } while (p < (char *) &the_lconv.negative_sign);
  244. p = (&the_lconv.int_frac_digits);
  245. do {
  246. *p = CHAR_MAX;
  247. ++p;
  248. } while (p <= &the_lconv.int_n_sign_posn);
  249. return &the_lconv;
  250. }
  251. #else /* __LOCALE_C_ONLY */
  252. static struct lconv the_lconv;
  253. struct lconv *localeconv(void)
  254. {
  255. register char *p = (char *) &the_lconv;
  256. register char **q = (char **) &__global_locale.decimal_point;
  257. do {
  258. *((char **)p) = *q;
  259. p += sizeof(char **);
  260. ++q;
  261. } while (p < &the_lconv.int_frac_digits);
  262. do {
  263. *p = **q;
  264. ++p;
  265. ++q;
  266. } while (p <= &the_lconv.int_n_sign_posn);
  267. return &the_lconv;
  268. }
  269. #endif /* __LOCALE_C_ONLY */
  270. #endif
  271. /**********************************************************************/
  272. #ifdef L__locale_init
  273. #ifndef __LOCALE_C_ONLY
  274. #define C_LOCALE_SELECTOR "\x23\x80\x01\x80\x01\x80\x01\x80\x01\x80\x01\x80\x01"
  275. #define LOCALE_INIT_FAILED "locale init failed!\n"
  276. #define CUR_LOCALE_SPEC (__global_locale.cur_locale)
  277. __locale_t __global_locale;
  278. void _locale_init(void)
  279. {
  280. /* TODO: mmap the locale file */
  281. /* TODO - ??? */
  282. memset(CUR_LOCALE_SPEC, 0, LOCALE_STRING_SIZE);
  283. CUR_LOCALE_SPEC[0] = '#';
  284. memcpy(__global_locale.category_item_count,
  285. __locale_mmap->lc_common_item_offsets_LEN,
  286. LC_ALL);
  287. __global_locale.category_offsets[0] = offsetof(__locale_t, codeset);
  288. __global_locale.category_offsets[1] = offsetof(__locale_t, decimal_point);
  289. __global_locale.category_offsets[2] = offsetof(__locale_t, int_curr_symbol);
  290. __global_locale.category_offsets[3] = offsetof(__locale_t, abday_1);
  291. /* __global_locale.category_offsets[4] = offsetof(__locale_t, collate???); */
  292. __global_locale.category_offsets[5] = offsetof(__locale_t, yesexpr);
  293. #ifdef __CTYPE_HAS_8_BIT_LOCALES
  294. __global_locale.tbl8ctype
  295. = (const unsigned char *) &__locale_mmap->tbl8ctype;
  296. __global_locale.tbl8uplow
  297. = (const unsigned char *) &__locale_mmap->tbl8uplow;
  298. #ifdef __WCHAR_ENABLED
  299. __global_locale.tbl8c2wc
  300. = (const uint16_t *) &__locale_mmap->tbl8c2wc;
  301. __global_locale.tbl8wc2c
  302. = (const unsigned char *) &__locale_mmap->tbl8wc2c;
  303. /* translit */
  304. #endif /* __WCHAR_ENABLED */
  305. #endif /* __CTYPE_HAS_8_BIT_LOCALES */
  306. #ifdef __WCHAR_ENABLED
  307. __global_locale.tblwctype
  308. = (const unsigned char *) &__locale_mmap->tblwctype;
  309. __global_locale.tblwuplow
  310. = (const unsigned char *) &__locale_mmap->tblwuplow;
  311. __global_locale.tblwuplow_diff
  312. = (const uint16_t *) &__locale_mmap->tblwuplow_diff;
  313. __global_locale.tblwcomb
  314. = (const unsigned char *) &__locale_mmap->tblwcomb;
  315. /* width?? */
  316. #endif /* __WCHAR_ENABLED */
  317. _locale_set(C_LOCALE_SELECTOR);
  318. }
  319. static const char ascii[] = "ASCII";
  320. static const char utf8[] = "UTF-8";
  321. void _locale_set(const unsigned char *p)
  322. {
  323. const char **x;
  324. unsigned char *s = CUR_LOCALE_SPEC + 1;
  325. const size_t *stp;
  326. const unsigned char *r;
  327. const uint16_t *io;
  328. const uint16_t *ii;
  329. const unsigned char *d;
  330. int row; /* locale row */
  331. int crow; /* category row */
  332. int len;
  333. int c;
  334. int i = 0;
  335. ++p;
  336. do {
  337. if ((*p != *s) || (p[1] != s[1])) {
  338. row = (((int)(*p & 0x7f)) << 8) + p[1] - 1;
  339. #ifndef NDEBUG
  340. assert(row < NUM_LOCALES);
  341. #endif
  342. *s = *p;
  343. s[1] = p[1];
  344. if (i == LC_CTYPE) {
  345. c = __locale_mmap->locales[ WIDTH_LOCALES * row + 2 ]; /* codeset */
  346. if (c <= 2) {
  347. if (c == 2) {
  348. __global_locale.codeset = utf8;
  349. __global_locale.encoding = __ctype_encoding_utf8;
  350. /* TODO - fix for bcc */
  351. __global_locale.mb_cur_max = 6;
  352. } else {
  353. assert(c==1);
  354. __global_locale.codeset = ascii;
  355. __global_locale.encoding = __ctype_encoding_7_bit;
  356. __global_locale.mb_cur_max = 1;
  357. }
  358. } else {
  359. const codeset_8_bit_t *c8b;
  360. r = CODESET_LIST;
  361. __global_locale.codeset = r + r[c -= 3];
  362. __global_locale.encoding = __ctype_encoding_8_bit;
  363. #ifdef __UCLIBC_MJN3_ONLY__
  364. #warning REMINDER: update 8 bit mb_cur_max when trasnlit implemented!
  365. #endif
  366. /* TODO - update when translit implemented! */
  367. __global_locale.mb_cur_max = 1;
  368. c8b = __locale_mmap->codeset_8_bit + c;
  369. #ifdef __CTYPE_HAS_8_BIT_LOCALES
  370. __global_locale.idx8ctype = c8b->idx8ctype;
  371. __global_locale.idx8uplow = c8b->idx8uplow;
  372. #ifdef __WCHAR_ENABLED
  373. __global_locale.idx8c2wc = c8b->idx8c2wc;
  374. __global_locale.idx8wc2c = c8b->idx8wc2c;
  375. /* translit */
  376. #endif /* __WCHAR_ENABLED */
  377. #endif /* __CTYPE_HAS_8_BIT_LOCALES */
  378. }
  379. } else if ((len = __locale_mmap->lc_common_item_offsets_LEN[i]) != 0) {
  380. crow = __locale_mmap->locales[ WIDTH_LOCALES * row + 3 + i ]
  381. * len;
  382. x = (const char **)(((char *) &__global_locale)
  383. + __global_locale.category_offsets[i]);
  384. stp = __locale_mmap->lc_common_tbl_offsets + 4*i;
  385. r = (const unsigned char *)( ((char *)__locale_mmap) + *stp );
  386. io = (const uint16_t *)( ((char *)__locale_mmap) + *++stp );
  387. ii = (const uint16_t *)( ((char *)__locale_mmap) + *++stp );
  388. d = (const unsigned char *)( ((char *)__locale_mmap) + *++stp );
  389. for (c=0 ; c < len ; c++) {
  390. *(x + c) = d + ii[ r[crow + c] + io[c] ];
  391. }
  392. }
  393. }
  394. ++i;
  395. p += 2;
  396. s += 2;
  397. } while (i < LC_ALL);
  398. }
  399. #endif /* __LOCALE_C_ONLY */
  400. #endif
  401. /**********************************************************************/
  402. #ifdef L_nl_langinfo
  403. #include <langinfo.h>
  404. #include <nl_types.h>
  405. #ifdef __LOCALE_C_ONLY
  406. /* We need to index 300 bytes of data, so you might initially think we
  407. * need to store the offsets in shorts. But since the offset of the
  408. * 64th item is 231, we'll store "offset - 64" for all items >= 64
  409. * and always calculate the data offset as "offset[i] + (i & 64)".
  410. * This allows us to pack the data offsets in an unsigned char while
  411. * also avoiding an "if".
  412. *
  413. * Note: Category order is assumed to be:
  414. * ctype, numeric, monetary, time, collate, messages, all
  415. */
  416. #define C_LC_ALL 6
  417. /* Combine the data to avoid size penalty for seperate char arrays when
  418. * compiler aligns objects. The original code is left in as documentation. */
  419. #define cat_start nl_data
  420. #define C_locale_data (nl_data + C_LC_ALL + 1 + 78)
  421. static const unsigned char nl_data[C_LC_ALL + 1 + 78 + 300] = {
  422. /* static const unsigned char cat_start[C_LC_ALL + 1] = { */
  423. '\x00', '\x01', '\x04', '\x1a', '\x4c', '\x4c', '\x4e',
  424. /* }; */
  425. /* static const unsigned char item_offset[78] = { */
  426. '\x00', '\x06', '\x07', '\x07', '\x07', '\x07', '\x07', '\x07',
  427. '\x07', '\x07', '\x07', '\x08', '\x08', '\x08', '\x08', '\x08',
  428. '\x08', '\x08', '\x08', '\x08', '\x08', '\x08', '\x08', '\x08',
  429. '\x08', '\x0a', '\x0c', '\x10', '\x14', '\x18', '\x1c', '\x20',
  430. '\x24', '\x28', '\x2f', '\x36', '\x3e', '\x48', '\x51', '\x58',
  431. '\x61', '\x65', '\x69', '\x6d', '\x71', '\x75', '\x79', '\x7d',
  432. '\x81', '\x85', '\x89', '\x8d', '\x91', '\x99', '\xa2', '\xa8',
  433. '\xae', '\xb2', '\xb7', '\xbc', '\xc3', '\xcd', '\xd5', '\xde',
  434. '\xa7', '\xaa', '\xad', '\xc2', '\xcb', '\xd4', '\xdf', '\xdf',
  435. '\xdf', '\xdf', '\xdf', '\xdf', '\xe0', '\xe6',
  436. /* }; */
  437. /* static const unsigned char C_locale_data[300] = { */
  438. 'A', 'S', 'C', 'I', 'I', '\x00', '.', '\x00',
  439. '\x7f', '\x00', '-', '\x00', 'S', 'u', 'n', '\x00',
  440. 'M', 'o', 'n', '\x00', 'T', 'u', 'e', '\x00',
  441. 'W', 'e', 'd', '\x00', 'T', 'h', 'u', '\x00',
  442. 'F', 'r', 'i', '\x00', 'S', 'a', 't', '\x00',
  443. 'S', 'u', 'n', 'd', 'a', 'y', '\x00', 'M',
  444. 'o', 'n', 'd', 'a', 'y', '\x00', 'T', 'u',
  445. 'e', 's', 'd', 'a', 'y', '\x00', 'W', 'e',
  446. 'd', 'n', 'e', 's', 'd', 'a', 'y', '\x00',
  447. 'T', 'h', 'u', 'r', 's', 'd', 'a', 'y',
  448. '\x00', 'F', 'r', 'i', 'd', 'a', 'y', '\x00',
  449. 'S', 'a', 't', 'u', 'r', 'd', 'a', 'y',
  450. '\x00', 'J', 'a', 'n', '\x00', 'F', 'e', 'b',
  451. '\x00', 'M', 'a', 'r', '\x00', 'A', 'p', 'r',
  452. '\x00', 'M', 'a', 'y', '\x00', 'J', 'u', 'n',
  453. '\x00', 'J', 'u', 'l', '\x00', 'A', 'u', 'g',
  454. '\x00', 'S', 'e', 'p', '\x00', 'O', 'c', 't',
  455. '\x00', 'N', 'o', 'v', '\x00', 'D', 'e', 'c',
  456. '\x00', 'J', 'a', 'n', 'u', 'a', 'r', 'y',
  457. '\x00', 'F', 'e', 'b', 'r', 'u', 'a', 'r',
  458. 'y', '\x00', 'M', 'a', 'r', 'c', 'h', '\x00',
  459. 'A', 'p', 'r', 'i', 'l', '\x00', 'M', 'a',
  460. 'y', '\x00', 'J', 'u', 'n', 'e', '\x00', 'J',
  461. 'u', 'l', 'y', '\x00', 'A', 'u', 'g', 'u',
  462. 's', 't', '\x00', 'S', 'e', 'p', 't', 'e',
  463. 'm', 'b', 'e', 'r', '\x00', 'O', 'c', 't',
  464. 'o', 'b', 'e', 'r', '\x00', 'N', 'o', 'v',
  465. 'e', 'm', 'b', 'e', 'r', '\x00', 'D', 'e',
  466. 'c', 'e', 'm', 'b', 'e', 'r', '\x00', 'A',
  467. 'M', '\x00', 'P', 'M', '\x00', '%', 'a', ' ',
  468. '%', 'b', ' ', '%', 'e', ' ', '%', 'H',
  469. ':', '%', 'M', ':', '%', 'S', ' ', '%',
  470. 'Y', '\x00', '%', 'm', '/', '%', 'd', '/',
  471. '%', 'y', '\x00', '%', 'H', ':', '%', 'M',
  472. ':', '%', 'S', '\x00', '%', 'I', ':', '%',
  473. 'M', ':', '%', 'S', ' ', '%', 'p', '\x00',
  474. '^', '[', 'y', 'Y', ']', '\x00', '^', '[',
  475. 'n', 'N', ']', '\x00',
  476. };
  477. char *nl_langinfo(nl_item item)
  478. {
  479. unsigned int c;
  480. unsigned int i;
  481. if ((c = _NL_ITEM_CATEGORY(item)) < C_LC_ALL) {
  482. if ((i = cat_start[c] + _NL_ITEM_INDEX(item)) < cat_start[c+1]) {
  483. /* return (char *) C_locale_data + item_offset[i] + (i & 64); */
  484. return (char *) C_locale_data + nl_data[C_LC_ALL+1+i] + (i & 64);
  485. }
  486. }
  487. return (char *) cat_start; /* Conveniently, this is the empty string. */
  488. }
  489. #else /* __LOCALE_C_ONLY */
  490. static const char empty[] = "";
  491. char *nl_langinfo(nl_item item)
  492. {
  493. unsigned int c = _NL_ITEM_CATEGORY(item);
  494. unsigned int i = _NL_ITEM_INDEX(item);
  495. if ((c < LC_ALL) && (i < __global_locale.category_item_count[c])) {
  496. return ((char **)(((char *) &__global_locale)
  497. + __global_locale.category_offsets[c]))[i];
  498. }
  499. return (char *) empty;
  500. }
  501. #endif /* __LOCALE_C_ONLY */
  502. #endif
  503. /**********************************************************************/