]> granicus.if.org Git - php/commitdiff
(PHP nl_langinfo) Added function when provided by OS
authorWez Furlong <wez@php.net>
Wed, 4 Jul 2001 10:10:30 +0000 (10:10 +0000)
committerWez Furlong <wez@php.net>
Wed, 4 Jul 2001 10:10:30 +0000 (10:10 +0000)
(PHP htmlentities, htmlspecialchars) Uses nl_langinfo to determine charset
@- Added nl_langinfo() (when OS provides it) that returns locale
   information. (Wez Furlong)
# There are a lot of constants used by nl_langinfo; should we do something
# along the lines of what we do for syslog?

configure.in
ext/standard/basic_functions.c
ext/standard/html.c
ext/standard/php_string.h
ext/standard/string.c

index c6dc97d41bc5625b2bcafa38c36185ec4512dd2d..b7ae5f6af9d9b549e98ea44cf6fe2698ac2b1401 100644 (file)
@@ -290,6 +290,7 @@ crypt.h \
 fcntl.h \
 grp.h \
 ieeefp.h \
+langinfo.h \
 limits.h \
 locale.h \
 netinet/in.h \
@@ -388,6 +389,7 @@ memcpy \
 memmove \
 mkstemp \
 mmap \
+nl_langinfo \
 putenv \
 random \
 rand_r \
index 131d949e9a76a7a9ac80a6b69d1a08f3c773b8b2..7f15e80852300659bf96c89b247ac67d425bc3fb 100644 (file)
@@ -193,6 +193,11 @@ function_entry basic_functions[] = {
        PHP_FE(implode,                                                                 NULL)
        PHP_FE(setlocale,                                                               NULL)
        PHP_FE(localeconv,                                                              NULL)
+#if HAVE_NL_LANGINFO
+       PHP_FE(nl_langinfo,                                                             NULL)
+#else
+       PHP_FALIAS(nl_langinfo, warn_not_available,             NULL)
+#endif
        PHP_FE(soundex,                                                                 NULL)
        PHP_FE(levenshtein,                                                             NULL)
        PHP_FE(chr,                                                                             NULL)
@@ -759,7 +764,9 @@ PHP_MINIT_FUNCTION(basic)
 #if defined(HAVE_LOCALECONV) && defined(ZTS)
        PHP_MINIT(localeconv)(INIT_FUNC_ARGS_PASSTHRU);
 #endif
-
+#if defined(HAVE_NL_LANGINFO)
+       PHP_MINIT(nl_langinfo)(INIT_FUNC_ARGS_PASSTHRU);
+#endif
 #if HAVE_CRYPT
        PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU);
 #endif
index 5e9bc5011746ad17c1d6478224dfe74fefef5a67..5d1b01fd2752afd47ab5e5ab673a7924b28c582b 100644 (file)
@@ -14,6 +14,7 @@
    +----------------------------------------------------------------------+
    | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca>                       |
    |          Jaakko Hyvätti <jaakko.hyvatti@iki.fi>                      |
+   |          Wez Furlong <wez@thebrainroom.com>                          |
    +----------------------------------------------------------------------+
 */
 
@@ -26,6 +27,9 @@
 #if HAVE_LOCALE_H
 #include <locale.h>
 #endif
+#if HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
 
 /* This must be fixed to handle the input string according to LC_CTYPE.
    Defaults to ISO-8859-1 for now. */
@@ -218,41 +222,50 @@ static enum entity_charset determine_charset(char * charset_hint)
        enum entity_charset charset = cs_8859_1;
        int len;
 
-#if HAVE_LOCALE_H
+       /* Guarantee default behaviour */
        if (charset_hint == NULL)
-       {
-               /* try to figure out the charset from the locale */
-               char * localename;
-               char * dot, * at;
-
-               /* lang[_territory][.codeset][@modifier] */
-               localename = setlocale(LC_CTYPE, NULL);
-
-               dot = strchr(localename, '.');
-               if (dot)        {
-                       dot++;
-                       /* locale specifies a codeset */
-                       at = strchr(dot, '@');
-                       if (at)
-                               len = at - dot;
-                       else
-                               len = strlen(dot);
-                       charset_hint = dot;
+               return cs_8859_1;
+
+       if (strlen(charset_hint) == 0)  {
+               /* try to detect the charset for the locale */
+#if HAVE_NL_LANGINFO
+               charset_hint = nl_langinfo(CODESET);
+#endif
+#if HAVE_LOCALE_H
+               if (charset_hint == NULL)
+               {
+                       /* try to figure out the charset from the locale */
+                       char * localename;
+                       char * dot, * at;
+
+                       /* lang[_territory][.codeset][@modifier] */
+                       localename = setlocale(LC_CTYPE, NULL);
+
+                       dot = strchr(localename, '.');
+                       if (dot)        {
+                               dot++;
+                               /* locale specifies a codeset */
+                               at = strchr(dot, '@');
+                               if (at)
+                                       len = at - dot;
+                               else
+                                       len = strlen(dot);
+                               charset_hint = dot;
+                       }
+                       else    {
+                               /* no explicit name; see if the name itself
+                                * is the charset */
+                               charset_hint = localename;
+                               len = strlen(charset_hint);
+                       }
                }
-               else    {
-                       /* no explicit name; see if the name itself
-                        * is the charset */
-                       charset_hint = localename;
+               else
                        len = strlen(charset_hint);
-               }
-       }
-       else
-               len = strlen(charset_hint);
 #else
-       if (charset_hint)
-               len = strlen(charset_hint);
+               if (charset_hint)
+                       len = strlen(charset_hint);
 #endif
-
+       }
        if (charset_hint)       {
                /* now walk the charset map and look for the codeset */
                for (i = 0; charset_map[i].codeset; i++)        {
@@ -262,7 +275,6 @@ static enum entity_charset determine_charset(char * charset_hint)
                        }
                }
        }
-       
        return charset;
 }
 /* }}} */
index a223043f9f111f0342523ad88cbdd5587d62e1ea..7e0ea30dcb13252d0acc203e2039a47a84631658 100644 (file)
@@ -66,6 +66,7 @@ PHP_FUNCTION(ord);
 PHP_FUNCTION(nl2br);
 PHP_FUNCTION(setlocale);
 PHP_FUNCTION(localeconv);
+PHP_FUNCTION(nl_langinfo);
 PHP_FUNCTION(stristr);
 PHP_FUNCTION(chunk_split);
 PHP_FUNCTION(parse_str);
@@ -88,6 +89,9 @@ PHP_FUNCTION(strcoll);
 PHP_MINIT_FUNCTION(localeconv);
 PHP_MSHUTDOWN_FUNCTION(localeconv);
 #endif
+#if HAVE_NL_LANGINFO
+PHP_MINIT_FUNCTION(nl_langinfo);
+#endif
 
 #define strnatcmp(a, b) \
        strnatcmp_ex(a, strlen(a), b, strlen(b), 0)
index 74ea02863abc1272fc620fafc73b03f7d12363f9..61fb9db4aa1ca979c9e337e60b10e2471b28cd7f 100644 (file)
@@ -30,6 +30,9 @@
 #ifdef HAVE_LOCALE_H
 # include <locale.h>
 #endif
+#ifdef HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
 #include "scanf.h"
 #include "zend_API.h"
 #include "zend_execute.h"
@@ -225,6 +228,122 @@ PHP_FUNCTION(strcspn)
 }
 /* }}} */
 
+#if HAVE_NL_LANGINFO
+PHP_MINIT_FUNCTION(nl_langinfo)
+{
+#define REGISTER_NL_LANGINFO_CONSTANT(x)       REGISTER_LONG_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT)
+       REGISTER_NL_LANGINFO_CONSTANT(ABDAY_1);
+       REGISTER_NL_LANGINFO_CONSTANT(ABDAY_2);
+       REGISTER_NL_LANGINFO_CONSTANT(ABDAY_3);
+       REGISTER_NL_LANGINFO_CONSTANT(ABDAY_4);
+       REGISTER_NL_LANGINFO_CONSTANT(ABDAY_5);
+       REGISTER_NL_LANGINFO_CONSTANT(ABDAY_6);
+       REGISTER_NL_LANGINFO_CONSTANT(ABDAY_7);
+       REGISTER_NL_LANGINFO_CONSTANT(DAY_1);
+       REGISTER_NL_LANGINFO_CONSTANT(DAY_2);
+       REGISTER_NL_LANGINFO_CONSTANT(DAY_3);
+       REGISTER_NL_LANGINFO_CONSTANT(DAY_4);
+       REGISTER_NL_LANGINFO_CONSTANT(DAY_5);
+       REGISTER_NL_LANGINFO_CONSTANT(DAY_6);
+       REGISTER_NL_LANGINFO_CONSTANT(DAY_7);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_1);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_2);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_3);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_4);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_5);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_6);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_7);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_8);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_9);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_10);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_11);
+       REGISTER_NL_LANGINFO_CONSTANT(ABMON_12);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_1);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_2);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_3);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_4);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_5);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_6);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_7);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_8);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_9);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_10);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_11);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_12);
+       REGISTER_NL_LANGINFO_CONSTANT(AM_STR);
+       REGISTER_NL_LANGINFO_CONSTANT(PM_STR);
+       REGISTER_NL_LANGINFO_CONSTANT(D_T_FMT);
+       REGISTER_NL_LANGINFO_CONSTANT(D_FMT);
+       REGISTER_NL_LANGINFO_CONSTANT(T_FMT);
+       REGISTER_NL_LANGINFO_CONSTANT(T_FMT_AMPM);
+       REGISTER_NL_LANGINFO_CONSTANT(ERA);
+       REGISTER_NL_LANGINFO_CONSTANT(ERA_YEAR);
+       REGISTER_NL_LANGINFO_CONSTANT(ERA_D_T_FMT);
+       REGISTER_NL_LANGINFO_CONSTANT(ERA_D_FMT);
+       REGISTER_NL_LANGINFO_CONSTANT(ERA_T_FMT);
+       REGISTER_NL_LANGINFO_CONSTANT(ALT_DIGITS);
+       REGISTER_NL_LANGINFO_CONSTANT(INT_CURR_SYMBOL);
+#ifdef CURRENCY_SYMBOL
+       REGISTER_NL_LANGINFO_CONSTANT(CURRENCY_SYMBOL);
+#endif
+#ifdef CRNCYSTR
+       REGISTER_NL_LANGINFO_CONSTANT(CRNCYSTR);
+#endif
+       REGISTER_NL_LANGINFO_CONSTANT(MON_DECIMAL_POINT);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_THOUSANDS_SEP);
+       REGISTER_NL_LANGINFO_CONSTANT(MON_GROUPING);
+       REGISTER_NL_LANGINFO_CONSTANT(POSITIVE_SIGN);
+       REGISTER_NL_LANGINFO_CONSTANT(NEGATIVE_SIGN);
+       REGISTER_NL_LANGINFO_CONSTANT(INT_FRAC_DIGITS);
+       REGISTER_NL_LANGINFO_CONSTANT(FRAC_DIGITS);
+       REGISTER_NL_LANGINFO_CONSTANT(P_CS_PRECEDES);
+       REGISTER_NL_LANGINFO_CONSTANT(P_SEP_BY_SPACE);
+       REGISTER_NL_LANGINFO_CONSTANT(N_CS_PRECEDES);
+       REGISTER_NL_LANGINFO_CONSTANT(N_SEP_BY_SPACE);
+       REGISTER_NL_LANGINFO_CONSTANT(P_SIGN_POSN);
+       REGISTER_NL_LANGINFO_CONSTANT(N_SIGN_POSN);
+#ifdef DECIMAL_POINT
+       REGISTER_NL_LANGINFO_CONSTANT(DECIMAL_POINT);
+#endif
+#ifdef RADIXCHAR
+       REGISTER_NL_LANGINFO_CONSTANT(RADIXCHAR);
+#endif
+#ifdef THOUSANDS_SEP
+       REGISTER_NL_LANGINFO_CONSTANT(THOUSANDS_SEP);
+#endif
+#ifdef THOUSEP
+       REGISTER_NL_LANGINFO_CONSTANT(THOUSEP);
+#endif
+       REGISTER_NL_LANGINFO_CONSTANT(GROUPING);
+       REGISTER_NL_LANGINFO_CONSTANT(YESEXPR);
+       REGISTER_NL_LANGINFO_CONSTANT(NOEXPR);
+       REGISTER_NL_LANGINFO_CONSTANT(YESSTR);
+       REGISTER_NL_LANGINFO_CONSTANT(NOSTR);
+#ifdef CODESET
+       REGISTER_NL_LANGINFO_CONSTANT(CODESET);
+#endif
+#undef REGISTER_NL_LANGINFO_CONSTANT
+       return SUCCESS;
+}
+PHP_FUNCTION(nl_langinfo)
+{
+       zval ** item;
+       char * value;
+       
+       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &item) == FAILURE)        {
+               WRONG_PARAM_COUNT;
+       }
+       convert_to_long_ex(item);
+       value = nl_langinfo(Z_LVAL_PP(item));
+       if (value == NULL)      {
+               RETURN_FALSE;
+       }
+       else    {
+               RETURN_STRING(value, 1);
+       }
+}
+#endif
+
 #ifdef HAVE_STRCOLL
 /* {{{ proto int strcoll(string str1, string str2)
    Compare two strings using the current locale */