localeconv.c (f2d0f4274bcb0e51ada2510f5f14190665f9ce80) | localeconv.c (831e8f614c17f44fcf64bfafd036188c485a662a) |
---|---|
1/* 2 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> 3 * Copyright (c) 1991, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 27 unchanged lines hidden (view full) --- 36#if 0 37static char sccsid[] = "@(#)localeconv.c 8.1 (Berkeley) 6/4/93"; 38#endif 39static char rcsid[] = 40 "$FreeBSD$"; 41#endif /* LIBC_SCCS and not lint */ 42 43#include <locale.h> | 1/* 2 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> 3 * Copyright (c) 1991, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 27 unchanged lines hidden (view full) --- 36#if 0 37static char sccsid[] = "@(#)localeconv.c 8.1 (Berkeley) 6/4/93"; 38#endif 39static char rcsid[] = 40 "$FreeBSD$"; 41#endif /* LIBC_SCCS and not lint */ 42 43#include <locale.h> |
44#include <stdlib.h> 45#include <limits.h> | |
46#include "lmonetary.h" 47#include "lnumeric.h" 48 49/* 50 * The localeconv() function constructs a struct lconv from the current 51 * monetary and numeric locales. 52 * 53 * Because localeconv() may be called many times (especially by library 54 * routines like printf() & strtod()), the approprate members of the 55 * lconv structure are computed only when the monetary or numeric 56 * locale has been changed. 57 */ 58int __mlocale_changed = 1; 59int __nlocale_changed = 1; 60 | 44#include "lmonetary.h" 45#include "lnumeric.h" 46 47/* 48 * The localeconv() function constructs a struct lconv from the current 49 * monetary and numeric locales. 50 * 51 * Because localeconv() may be called many times (especially by library 52 * routines like printf() & strtod()), the approprate members of the 53 * lconv structure are computed only when the monetary or numeric 54 * locale has been changed. 55 */ 56int __mlocale_changed = 1; 57int __nlocale_changed = 1; 58 |
61static char 62cnv(char *str) { 63 int i = strtol(str, NULL, 10); 64 if (i == -1) 65 i = CHAR_MAX; 66 return (char)i; 67} 68 | |
69/* 70 * Return the current locale conversion. 71 */ 72struct lconv * 73localeconv() 74{ 75 static struct lconv ret; 76 77 if (__mlocale_changed) { 78 /* LC_MONETARY part */ 79 struct lc_monetary_T * mptr; 80 81#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME) | 59/* 60 * Return the current locale conversion. 61 */ 62struct lconv * 63localeconv() 64{ 65 static struct lconv ret; 66 67 if (__mlocale_changed) { 68 /* LC_MONETARY part */ 69 struct lc_monetary_T * mptr; 70 71#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME) |
82#define M_ASSIGN_CHAR(NAME) (ret.NAME = cnv((char*)mptr->NAME)) | 72#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0]) |
83 84 mptr = __get_current_monetary_locale(); 85 M_ASSIGN_STR(int_curr_symbol); 86 M_ASSIGN_STR(currency_symbol); 87 M_ASSIGN_STR(mon_decimal_point); 88 M_ASSIGN_STR(mon_thousands_sep); 89 M_ASSIGN_STR(mon_grouping); 90 M_ASSIGN_STR(positive_sign); --- 27 unchanged lines hidden --- | 73 74 mptr = __get_current_monetary_locale(); 75 M_ASSIGN_STR(int_curr_symbol); 76 M_ASSIGN_STR(currency_symbol); 77 M_ASSIGN_STR(mon_decimal_point); 78 M_ASSIGN_STR(mon_thousands_sep); 79 M_ASSIGN_STR(mon_grouping); 80 M_ASSIGN_STR(positive_sign); --- 27 unchanged lines hidden --- |