aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2006-09-24 12:37:06 +0000
committerEli Zaretskii2006-09-24 12:37:06 +0000
commitd613418bc52df7a77c0a02a77aaa1be00e413ff9 (patch)
tree7140161fba2076523694945fd98b0950921b6d0d /src
parentfeb75452042980533320bf22ebb95bb3b58c994f (diff)
downloademacs-d613418bc52df7a77c0a02a77aaa1be00e413ff9.tar.gz
emacs-d613418bc52df7a77c0a02a77aaa1be00e413ff9.zip
(nl_langinfo): New function.
Diffstat (limited to 'src')
-rw-r--r--src/w32proc.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/w32proc.c b/src/w32proc.c
index d874d183b17..29491931015 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -49,6 +49,11 @@ Boston, MA 02110-1301, USA.
49extern BOOL WINAPI IsValidLocale(LCID, DWORD); 49extern BOOL WINAPI IsValidLocale(LCID, DWORD);
50#endif 50#endif
51 51
52#ifdef HAVE_LANGINFO_CODESET
53#include <nl_types.h>
54#include <langinfo.h>
55#endif
56
52#include "lisp.h" 57#include "lisp.h"
53#include "w32.h" 58#include "w32.h"
54#include "w32heap.h" 59#include "w32heap.h"
@@ -1817,6 +1822,69 @@ If successful, the return value is t, otherwise nil. */)
1817 return result; 1822 return result;
1818} 1823}
1819 1824
1825#ifdef HAVE_LANGINFO_CODESET
1826/* Emulation of nl_langinfo. Used in fns.c:Flocale_info. */
1827char *nl_langinfo (nl_item item)
1828{
1829 /* Conversion of Posix item numbers to their Windows equivalents. */
1830 static const LCTYPE w32item[] = {
1831 LOCALE_IDEFAULTANSICODEPAGE,
1832 LOCALE_SDAYNAME1, LOCALE_SDAYNAME2, LOCALE_SDAYNAME3,
1833 LOCALE_SDAYNAME4, LOCALE_SDAYNAME5, LOCALE_SDAYNAME6, LOCALE_SDAYNAME7,
1834 LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3,
1835 LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6,
1836 LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
1837 LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12
1838 };
1839
1840 static char *nl_langinfo_buf = NULL;
1841 static int nl_langinfo_len = 0;
1842
1843 if (nl_langinfo_len <= 0)
1844 nl_langinfo_buf = xmalloc (nl_langinfo_len = 1);
1845
1846 if (item < 0 || item >= _NL_NUM)
1847 nl_langinfo_buf[0] = 0;
1848 else
1849 {
1850 LCID cloc = GetThreadLocale ();
1851 int need_len = GetLocaleInfo (cloc, w32item[item] | LOCALE_USE_CP_ACP,
1852 NULL, 0);
1853
1854 if (need_len <= 0)
1855 nl_langinfo_buf[0] = 0;
1856 else
1857 {
1858 if (item == CODESET)
1859 {
1860 need_len += 2; /* for the "cp" prefix */
1861 if (need_len < 8) /* for the case we call GetACP */
1862 need_len = 8;
1863 }
1864 if (nl_langinfo_len <= need_len)
1865 nl_langinfo_buf = xrealloc (nl_langinfo_buf,
1866 nl_langinfo_len = need_len);
1867 if (!GetLocaleInfo (cloc, w32item[item] | LOCALE_USE_CP_ACP,
1868 nl_langinfo_buf, nl_langinfo_len))
1869 nl_langinfo_buf[0] = 0;
1870 else if (item == CODESET)
1871 {
1872 if (strcmp (nl_langinfo_buf, "0") == 0 /* CP_ACP */
1873 || strcmp (nl_langinfo_buf, "1") == 0) /* CP_OEMCP */
1874 sprintf (nl_langinfo_buf, "cp%u", GetACP ());
1875 else
1876 {
1877 memmove (nl_langinfo_buf + 2, nl_langinfo_buf,
1878 strlen (nl_langinfo_buf) + 1);
1879 nl_langinfo_buf[0] = 'c';
1880 nl_langinfo_buf[1] = 'p';
1881 }
1882 }
1883 }
1884 }
1885 return nl_langinfo_buf;
1886}
1887#endif /* HAVE_LANGINFO_CODESET */
1820 1888
1821DEFUN ("w32-get-locale-info", Fw32_get_locale_info, 1889DEFUN ("w32-get-locale-info", Fw32_get_locale_info,
1822 Sw32_get_locale_info, 1, 2, 0, 1890 Sw32_get_locale_info, 1, 2, 0,