localepaper.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * localepaper: print the dimensions in mm of the current locale's
  3. * paper size, if possible.
  4. *
  5. * Based on a patch by Caolan McNamara:
  6. * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=481213
  7. *
  8. * Copyright (C) Reuben Thomas <rrt@sc3d.org>, 2013.
  9. *
  10. * Copying and distribution of this file, with or without modification,
  11. * are permitted in any medium without royalty provided the copyright
  12. * notice and this notice are preserved.
  13. */
  14. #include <config.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <locale.h>
  18. #if defined LC_PAPER && defined _GNU_SOURCE
  19. #include <langinfo.h>
  20. #endif
  21. #include "progname.h"
  22. int main(int argc, char *argv[])
  23. {
  24. set_program_name(argv[0]);
  25. argc = argc; /* Avoid a compiler warning. */
  26. #if defined LC_PAPER && defined _GNU_SOURCE
  27. setlocale(LC_ALL, "");
  28. #define NL_PAPER_GET(x) \
  29. ((union { char *string; unsigned word; })nl_langinfo(x)).word
  30. printf("%d %d\n", NL_PAPER_GET(_NL_PAPER_WIDTH), NL_PAPER_GET(_NL_PAPER_HEIGHT));
  31. return EXIT_SUCCESS;
  32. #else
  33. printf("%s: locale paper size information is not supported on this system", program_name);
  34. return EXIT_FAILURE;
  35. #endif
  36. }