summaryrefslogtreecommitdiff
path: root/src/w32proc.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2019-02-04 18:05:59 +0200
committerEli Zaretskii <eliz@gnu.org>2019-02-04 18:05:59 +0200
commitf37000aeb2b987c0fb14b6770fef69eaf274167a (patch)
treeaf50afbb4fd52389a11ae8259d2f18ccd081ce61 /src/w32proc.c
parentd5f629d193ffe88c464379f02dd2adaadc9dfdf0 (diff)
downloademacs-f37000aeb2b987c0fb14b6770fef69eaf274167a.tar.gz
Support (locale-info 'paper) on MS-Windows
* src/w32proc.c (LOCALE_IPAPERSIZE): Define if undefined. (nl_langinfo): Support _NL_PAPER_WIDTH and _NL_PAPER_HEIGHT like glibc does. * src/fns.c (Flocale_info): Update the doc string. * nt/inc/langinfo.h: Add _NL_PAPER_WIDTH and _NL_PAPER_HEIGHT to the enumeration. (_NL_PAPER_WIDTH, _NL_PAPER_HEIGHT): Define namesake macros. * nt/mingw-cfg.site (emacs_cv_langinfo__nl_paper_width): Set to 'yes'. * doc/lispref/nonascii.texi (Locales): Update the documentation of 'locale-info' for the argument of 'paper'. * etc/NEWS: Update the locale-info entry.
Diffstat (limited to 'src/w32proc.c')
-rw-r--r--src/w32proc.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/w32proc.c b/src/w32proc.c
index 05e6c46b336..ab0bf0fff08 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -3248,6 +3248,12 @@ such programs cannot be invoked by Emacs anyway. */)
}
#ifdef HAVE_LANGINFO_CODESET
+
+/* If we are compiling for compatibility with older 32-bit Windows
+ versions, this might not be defined by the Windows headers. */
+#ifndef LOCALE_IPAPERSIZE
+# define LOCALE_IPAPERSIZE 0x100A
+#endif
/* Emulation of nl_langinfo. Used in fns.c:Flocale_info. */
char *
nl_langinfo (nl_item item)
@@ -3260,7 +3266,8 @@ nl_langinfo (nl_item item)
LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3,
LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6,
LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
- LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12
+ LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12,
+ LOCALE_IPAPERSIZE, LOCALE_IPAPERSIZE
};
static char *nl_langinfo_buf = NULL;
@@ -3269,6 +3276,8 @@ nl_langinfo (nl_item item)
if (nl_langinfo_len <= 0)
nl_langinfo_buf = xmalloc (nl_langinfo_len = 1);
+ char *retval = nl_langinfo_buf;
+
if (item < 0 || item >= _NL_NUM)
nl_langinfo_buf[0] = 0;
else
@@ -3290,6 +3299,8 @@ nl_langinfo (nl_item item)
if (nl_langinfo_len <= need_len)
nl_langinfo_buf = xrealloc (nl_langinfo_buf,
nl_langinfo_len = need_len);
+ retval = nl_langinfo_buf;
+
if (!GetLocaleInfo (cloc, w32item[item] | LOCALE_USE_CP_ACP,
nl_langinfo_buf, nl_langinfo_len))
nl_langinfo_buf[0] = 0;
@@ -3306,9 +3317,32 @@ nl_langinfo (nl_item item)
nl_langinfo_buf[1] = 'p';
}
}
+ else if (item == _NL_PAPER_WIDTH || item == _NL_PAPER_HEIGHT)
+ {
+ static const int paper_size[][2] =
+ {
+ { -1, -1 },
+ { 216, 279 },
+ { -1, -1 },
+ { -1, -1 },
+ { -1, -1 },
+ { 216, 356 },
+ { -1, -1 },
+ { -1, -1 },
+ { 297, 420 },
+ { 210, 297 }
+ };
+ int idx = atoi (nl_langinfo_buf);
+ if (0 <= idx && idx < ARRAYELTS (paper_size))
+ retval = (char *)(intptr_t) (item == _NL_PAPER_WIDTH
+ ? paper_size[idx][0]
+ : paper_size[idx][1]);
+ else
+ retval = (char *)(intptr_t) -1;
+ }
}
}
- return nl_langinfo_buf;
+ return retval;
}
#endif /* HAVE_LANGINFO_CODESET */