From 4096dd5257226cfdd43cd24ade33ba1d02784c0f Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 19:54:59 +0000 Subject: Apply patch libpaper-useglibcfallback.patch patch_name: libpaper-useglibcfallback.patch present_in_specfile: true --- diff --git a/lib/paper.c b/lib/paper.c index d510c85..0039bb0 100644 --- a/lib/paper.c +++ b/lib/paper.c @@ -20,6 +20,9 @@ #include +#include +#include + #include "paper.h" struct paper { @@ -108,6 +111,27 @@ in PAPERCONFVAR, fall-back to the old behaviour. } 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 --git a/man/paperconf.1.in b/man/paperconf.1.in index 6be58eb..a33faa8 100644 --- a/man/paperconf.1.in +++ b/man/paperconf.1.in @@ -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 contents 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 --git a/src/paperconf.c b/src/paperconf.c index d0fa34f..a52ef34 100644 --- a/src/paperconf.c +++ b/src/paperconf.c @@ -13,6 +13,7 @@ #include #include +#include /* 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;