Blame SOURCES/libpaper-useglibcfallback.patch

5b8658
diff -up libpaper-1.1.24+nmu3/lib/paper.c.useglibcfallback libpaper-1.1.24+nmu3/lib/paper.c
5b8658
--- libpaper-1.1.24+nmu3/lib/paper.c.useglibcfallback	2010-04-24 08:12:11.000000000 -0400
5b8658
+++ libpaper-1.1.24+nmu3/lib/paper.c	2014-04-22 15:58:33.120039001 -0400
5b8658
@@ -20,6 +20,9 @@
5b8658
 
5b8658
 #include <unistd.h>
5b8658
 
5b8658
+#include <locale.h>
5b8658
+#include <langinfo.h>
5b8658
+
5b8658
 #include "paper.h"
5b8658
 
5b8658
 struct paper {
5b8658
@@ -108,6 +111,27 @@ in PAPERCONFVAR, fall-back to the old be
5b8658
 }
5b8658
 
5b8658
 const char* defaultpapername(void) {
5b8658
+#if defined(LC_PAPER) && defined(_GNU_SOURCE)
5b8658
+
5b8658
+#define NL_PAPER_GET(x)         \
5b8658
+  ((union { char *string; unsigned int word; })nl_langinfo(x)).word
5b8658
+
5b8658
+#define PT_TO_MM(v) (unsigned int)((v * 2.54 * 10 / 72) + 0.5)
5b8658
+
5b8658
+    const struct paper* pp;
5b8658
+
5b8658
+    unsigned int w = NL_PAPER_GET(_NL_PAPER_WIDTH);
5b8658
+    unsigned int h = NL_PAPER_GET(_NL_PAPER_HEIGHT);
5b8658
+
5b8658
+    for (pp = paperfirst(); pp; pp = papernext(pp)) {
5b8658
+	if (
5b8658
+             PT_TO_MM(pp->pswidth) == w &&
5b8658
+             PT_TO_MM(pp->psheight) == h
5b8658
+           ) {
5b8658
+	    return pp->name;
5b8658
+	}
5b8658
+    }
5b8658
+#endif
5b8658
     return PAPERSIZE;
5b8658
 }
5b8658
 
5b8658
diff -up libpaper-1.1.24+nmu3/man/paperconf.1.in.useglibcfallback libpaper-1.1.24+nmu3/man/paperconf.1.in
5b8658
--- libpaper-1.1.24+nmu3/man/paperconf.1.in.useglibcfallback	2014-04-22 15:58:33.121038995 -0400
5b8658
+++ libpaper-1.1.24+nmu3/man/paperconf.1.in	2014-04-22 16:00:15.973428376 -0400
5b8658
@@ -48,10 +48,12 @@ looking in order at the
5b8658
 .B @PAPERSIZEVAR@
5b8658
 environment variable, at the contents of the file specified by the
5b8658
 .B @PAPERCONFVAR@
5b8658
-environment variable, at the contents of
5b8658
+environment variable, at the contents of the file
5b8658
 .B @PAPERCONF@
5b8658
-or by using
5b8658
-.B letter
5b8658
+, consulting the values controlled by the
5b8658
+.B LC_PAPER
5b8658
+locale setting, or by using
5b8658
+.B @PAPERSIZE@
5b8658
 as a fall-back value if none of the other alternatives are successful.
5b8658
 By default, width and height of the paper are printed in PostScript points.
5b8658
 .SH OPTIONS
5b8658
diff -up libpaper-1.1.24+nmu3/src/paperconf.c.useglibcfallback libpaper-1.1.24+nmu3/src/paperconf.c
5b8658
--- libpaper-1.1.24+nmu3/src/paperconf.c.useglibcfallback	2012-05-03 15:05:12.000000000 -0400
5b8658
+++ libpaper-1.1.24+nmu3/src/paperconf.c	2014-04-22 15:58:33.121038995 -0400
5b8658
@@ -13,6 +13,7 @@
5b8658
 #include <errno.h>
5b8658
 
5b8658
 #include <paper.h>
5b8658
+#include <locale.h>
5b8658
 
5b8658
 
5b8658
 /* needed for GNU/Hurd */
5b8658
@@ -99,6 +100,8 @@ int main(int argc, char** argv)
5b8658
 
5b8658
     const char* progname;
5b8658
 
5b8658
+    setlocale(LC_ALL, "");
5b8658
+
5b8658
     progname = strrchr(*argv, '/');
5b8658
     if (progname) {
5b8658
 	++progname;