This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Teach perl about more locale categories
authorKarl Williamson <khw@cpan.org>
Wed, 26 Jul 2017 14:59:33 +0000 (08:59 -0600)
committerKarl Williamson <khw@cpan.org>
Wed, 31 Jan 2018 05:28:41 +0000 (22:28 -0700)
glibc has various other categories than the ones perl handles, for
example LC_PAPER.  This commit adds knowledge of these to perl, so that
one can set them, interrogate them, and have libraries work on them,
even though perl itself does not.

This is in preparation for future commits, where it becomes more
important than currently for perl to know about all the locale
categories on the system.

I looked through various other systems to try to find other categories,
but did not see any.  If a system does have such a category, it is
pretty easy to tell perl about it, and recompile.  Use the changes in
this commit as a template, and send an email to perlbug@perl.org, so
that the next Perl release will have it.

ext/POSIX/Makefile.PL
ext/POSIX/lib/POSIX.pm
ext/POSIX/t/export.t
locale.c
perl.h

index 1ed4d32..5d5c009 100644 (file)
@@ -50,7 +50,8 @@ my @names =
       ESOCKTNOSUPPORT ESPIPE ESRCH ESTALE ETIME ETIMEDOUT ETOOMANYREFS ETXTBSY
       EUSERS EWOULDBLOCK EXDEV FILENAME_MAX F_OK HUPCL ICANON ICRNL IEXTEN
       IGNBRK IGNCR IGNPAR INLCR INPCK INT_MAX INT_MIN ISIG ISTRIP IXOFF IXON
-      LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME
+      LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION LC_MEASUREMENT
+      LC_MESSAGES LC_MONETARY LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME
       LINK_MAX LONG_MAX LONG_MIN L_ctermid L_cuserid MAX_CANON
       MAX_INPUT MB_LEN_MAX MSG_CTRUNC MSG_DONTROUTE MSG_EOR MSG_OOB MSG_PEEK
       MSG_TRUNC MSG_WAITALL NAME_MAX NCCS NGROUPS_MAX NOFLSH OPEN_MAX OPOST
index 1270fc9..8f61f6e 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 
 our ($AUTOLOAD, %SIGRT);
 
-our $VERSION = '1.81';
+our $VERSION = '1.82';
 
 require XSLoader;
 
@@ -306,7 +306,8 @@ my %default_export_tags = ( # cf. exports policy below
                _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
 
     locale_h =>        [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES
-                   LC_MONETARY LC_NUMERIC LC_TIME NULL
+                   LC_MONETARY LC_NUMERIC LC_TIME LC_IDENTIFICATION
+                    LC_MEASUREMENT LC_PAPER LC_TELEPHONE LC_ADDRESS NULL
                    localeconv setlocale)],
 
     math_h =>   [qw(FP_ILOGB0 FP_ILOGBNAN FP_INFINITE FP_NAN FP_NORMAL
index 6637fa6..50648c8 100644 (file)
@@ -45,8 +45,10 @@ my %expect = (
             FLT_ROUNDS F_DUPFD F_GETFD F_GETFL F_GETLK F_OK F_RDLCK
             F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK HUGE_VAL
             HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR INLCR INPCK
-            INT_MAX INT_MIN ISIG ISTRIP IXOFF IXON LC_ALL LC_COLLATE
-            LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LDBL_DIG
+            INT_MAX INT_MIN ISIG ISTRIP IXOFF IXON
+            LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION
+            LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NUMERIC LC_PAPER
+            LC_TELEPHONE LC_TIME LDBL_DIG
             LDBL_EPSILON LDBL_MANT_DIG LDBL_MAX LDBL_MAX_10_EXP
             LDBL_MAX_EXP LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP LINK_MAX
             LONG_MAX LONG_MIN L_ctermid L_cuserid MAX_CANON
index 7182fe8..dd7d1d3 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -141,6 +141,21 @@ const int categories[] = {
 #    ifdef USE_LOCALE_MONETARY
                              LC_MONETARY,
 #    endif
+#    ifdef USE_LOCALE_ADDRESS
+                             LC_ADDRESS,
+#    endif
+#    ifdef USE_LOCALE_IDENTIFICATION
+                             LC_IDENTIFICATION,
+#    endif
+#    ifdef USE_LOCALE_MEASUREMENT
+                             LC_MEASUREMENT,
+#    endif
+#    ifdef USE_LOCALE_PAPER
+                             LC_PAPER,
+#    endif
+#    ifdef USE_LOCALE_TELEPHONE
+                             LC_TELEPHONE,
+#    endif
 #    ifdef LC_ALL
                              LC_ALL,
 #    endif
@@ -171,6 +186,21 @@ const char * category_names[] = {
 #    ifdef USE_LOCALE_MONETARY
                                  "LC_MONETARY",
 #    endif
+#    ifdef USE_LOCALE_ADDRESS
+                                 "LC_ADDRESS",
+#    endif
+#    ifdef USE_LOCALE_IDENTIFICATION
+                                 "LC_IDENTIFICATION",
+#    endif
+#    ifdef USE_LOCALE_MEASUREMENT
+                                 "LC_MEASUREMENT",
+#    endif
+#    ifdef USE_LOCALE_PAPER
+                                 "LC_PAPER",
+#    endif
+#    ifdef USE_LOCALE_TELEPHONE
+                                 "LC_TELEPHONE",
+#    endif
 #    ifdef LC_ALL
                                  "LC_ALL",
 #    endif
@@ -280,8 +310,38 @@ S_category_name(const int category)
 #  else
 #    define _DUMMY_MONETARY             _DUMMY_MESSAGES
 #  endif
+#  ifdef USE_LOCALE_ADDRESS
+#    define LC_ADDRESS_INDEX            _DUMMY_MONETARY + 1
+#    define _DUMMY_ADDRESS              LC_ADDRESS_INDEX
+#  else
+#    define _DUMMY_ADDRESS              _DUMMY_MONETARY
+#  endif
+#  ifdef USE_LOCALE_IDENTIFICATION
+#    define LC_IDENTIFICATION_INDEX     _DUMMY_ADDRESS + 1
+#    define _DUMMY_IDENTIFICATION       LC_IDENTIFICATION_INDEX
+#  else
+#    define _DUMMY_IDENTIFICATION       _DUMMY_ADDRESS
+#  endif
+#  ifdef USE_LOCALE_MEASUREMENT
+#    define LC_MEASUREMENT_INDEX        _DUMMY_IDENTIFICATION + 1
+#    define _DUMMY_MEASUREMENT          LC_MEASUREMENT_INDEX
+#  else
+#    define _DUMMY_MEASUREMENT          _DUMMY_IDENTIFICATION
+#  endif
+#  ifdef USE_LOCALE_PAPER
+#    define LC_PAPER_INDEX              _DUMMY_MEASUREMENT + 1
+#    define _DUMMY_PAPER                LC_PAPER_INDEX
+#  else
+#    define _DUMMY_PAPER                _DUMMY_MEASUREMENT
+#  endif
+#  ifdef USE_LOCALE_TELEPHONE
+#    define LC_TELEPHONE_INDEX          _DUMMY_PAPER + 1
+#    define _DUMMY_TELEPHONE            LC_TELEPHONE_INDEX
+#  else
+#    define _DUMMY_TELEPHONE            _DUMMY_PAPER
+#  endif
 #  ifdef LC_ALL
-#    define LC_ALL_INDEX                _DUMMY_MONETARY + 1
+#    define LC_ALL_INDEX                _DUMMY_TELEPHONE + 1
 #  endif
 #endif /* ifdef USE_LOCALE */
 
@@ -1892,6 +1952,26 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
     assert(categories[LC_MONETARY_INDEX] == LC_MONETARY);
     assert(strEQ(category_names[LC_MONETARY_INDEX], "LC_MONETARY"));
 #    endif
+#    ifdef USE_LOCALE_ADDRESS
+    assert(categories[LC_ADDRESS_INDEX] == LC_ADDRESS);
+    assert(strEQ(category_names[LC_ADDRESS_INDEX], "LC_ADDRESS"));
+#    endif
+#    ifdef USE_LOCALE_IDENTIFICATION
+    assert(categories[LC_IDENTIFICATION_INDEX] == LC_IDENTIFICATION);
+    assert(strEQ(category_names[LC_IDENTIFICATION_INDEX], "LC_IDENTIFICATION"));
+#    endif
+#    ifdef USE_LOCALE_MEASUREMENT
+    assert(categories[LC_MEASUREMENT_INDEX] == LC_MEASUREMENT);
+    assert(strEQ(category_names[LC_MEASUREMENT_INDEX], "LC_MEASUREMENT"));
+#    endif
+#    ifdef USE_LOCALE_PAPER
+    assert(categories[LC_PAPER_INDEX] == LC_PAPER);
+    assert(strEQ(category_names[LC_PAPER_INDEX], "LC_PAPER"));
+#    endif
+#    ifdef USE_LOCALE_TELEPHONE
+    assert(categories[LC_TELEPHONE_INDEX] == LC_TELEPHONE);
+    assert(strEQ(category_names[LC_TELEPHONE_INDEX], "LC_TELEPHONE"));
+#    endif
 #    ifdef LC_ALL
     assert(categories[LC_ALL_INDEX] == LC_ALL);
     assert(strEQ(category_names[LC_ALL_INDEX], "LC_ALL"));
@@ -2050,8 +2130,6 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
                     }
                 }
 
-                PerlIO_printf(Perl_error_log, "and possibly others\n");
-
 #  endif /* LC_ALL */
 
                 PerlIO_printf(Perl_error_log,
diff --git a/perl.h b/perl.h
index 097a970..d1d6ea5 100644 (file)
--- a/perl.h
+++ b/perl.h
 #   if !defined(NO_LOCALE_TIME) && defined(LC_TIME)
 #      define USE_LOCALE_TIME
 #   endif
+#   if !defined(NO_LOCALE_ADDRESS) && defined(LC_ADDRESS)
+#      define USE_LOCALE_ADDRESS
+#   endif
+#   if !defined(NO_LOCALE_IDENTIFICATION) && defined(LC_IDENTIFICATION)
+#      define USE_LOCALE_IDENTIFICATION
+#   endif
+#   if !defined(NO_LOCALE_MEASUREMENT) && defined(LC_MEASUREMENT)
+#      define USE_LOCALE_MEASUREMENT
+#   endif
+#   if !defined(NO_LOCALE_PAPER) && defined(LC_PAPER)
+#      define USE_LOCALE_PAPER
+#   endif
+#   if !defined(NO_LOCALE_TELEPHONE) && defined(LC_TELEPHONE)
+#      define USE_LOCALE_TELEPHONE
+#   endif
 #endif /* !NO_LOCALE && HAS_SETLOCALE */
 
 #include <setjmp.h>