summaryrefslogtreecommitdiffstats
path: root/libpaper-useglibcfallback.patch
blob: 8a80f781d8aaeb34a5909c7da00b73847f2f77a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff -up libpaper-1.1.24/lib/paper.c.useglibcfallback libpaper-1.1.24/lib/paper.c
--- libpaper-1.1.24/lib/paper.c.useglibcfallback	2010-04-24 08:12:11.000000000 -0400
+++ libpaper-1.1.24/lib/paper.c	2010-04-24 12:04:59.549538425 -0400
@@ -20,6 +20,9 @@
 
 #include <unistd.h>
 
+#include <locale.h>
+#include <langinfo.h>
+
 #include "paper.h"
 
 struct paper {
@@ -108,6 +111,27 @@ in PAPERCONFVAR, fall-back to the old be
 }
 
 const char* defaultpapername(void) {
+#if defined(LC_PAPER) && defined(_GNU_SOURCE)
+
+#define NL_PAPER_GET(x)         \
+  ((union { char *string; unsigned int word; })nl_langinfo(x)).word
+
+#define PT_TO_MM(v) (unsigned int)((v * 2.54 * 10 / 72) + 0.5)
+
+    const struct paper* pp;
+
+    unsigned int w = NL_PAPER_GET(_NL_PAPER_WIDTH);
+    unsigned int h = NL_PAPER_GET(_NL_PAPER_HEIGHT);
+
+    for (pp = paperfirst(); pp; pp = papernext(pp)) {
+	if (
+             PT_TO_MM(pp->pswidth) == w &&
+             PT_TO_MM(pp->psheight) == h
+           ) {
+	    return pp->name;
+	}
+    }
+#endif
     return PAPERSIZE;
 }
 
diff -up libpaper-1.1.24/man/paperconf.1.in.useglibcfallback libpaper-1.1.24/man/paperconf.1.in
--- libpaper-1.1.24/man/paperconf.1.in.useglibcfallback	2004-01-19 23:35:04.000000000 -0500
+++ libpaper-1.1.24/man/paperconf.1.in	2010-04-24 12:03:56.866532268 -0400
@@ -48,10 +48,12 @@ looking in order at the
 .B @PAPERSIZEVAR@
 environment variable, at the contents of the file specified by the
 .B @PAPERCONFVAR@
-environment variable, at the contects of
+environment variable, at the contents of the file
 .B @PAPERCONF@
-or by using
-.B letter
+, consulting the values controlled by the
+.B LC_PAPER
+locale setting, or by using
+.B @PAPERSIZE@
 as a fall-back value if none of the other alternatives are successful.
 By default, width and height of the paper are printed in PostScript points.
 .SH OPTIONS
diff -up libpaper-1.1.24/src/paperconf.c.useglibcfallback libpaper-1.1.24/src/paperconf.c
--- libpaper-1.1.24/src/paperconf.c.useglibcfallback	2007-09-26 02:13:38.000000000 -0400
+++ libpaper-1.1.24/src/paperconf.c	2010-04-24 12:03:56.867538135 -0400
@@ -13,6 +13,7 @@
 #include <errno.h>
 
 #include <paper.h>
+#include <locale.h>
 
 
 /* needed for GNU/Hurd */
@@ -99,6 +100,8 @@ int main(int argc, char** argv)
 
     const char* progname;
 
+    setlocale(LC_ALL, "");
+
     progname = strrchr(*argv, '/');
     if (progname) {
 	++progname;