+
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
+
+DEFUN ("locale-info", Flocale_info, Slocale_info, 1, 1, 0,
+ doc: /* Access locale data ITEM for the current C locale, if available.
+ITEM should be one of the following:
+
+`codeset', returning the character set as a string (locale item CODESET);
+
+`days', returning a 7-element vector of day names (locale items DAY_n);
+
+`months', returning a 12-element vector of month names (locale items MON_n);
+
+`paper', returning a list (WIDTH HEIGHT) for the default paper size,
+ both measured in milimeters (locale items PAPER_WIDTH, PAPER_HEIGHT).
+
+If the system can't provide such information through a call to
+`nl_langinfo', or if ITEM isn't from the list above, return nil.
+
+See also Info node `(libc)Locales'.
+
+The data read from the system are decoded using `locale-coding-system'. */)
+ (item)
+ Lisp_Object item;
+{
+ char *str = NULL;
+#ifdef HAVE_LANGINFO_CODESET
+ Lisp_Object val;
+ if (EQ (item, Qcodeset))
+ {
+ str = nl_langinfo (CODESET);
+ return build_string (str);
+ }
+#ifdef DAY_1
+ else if (EQ (item, Qdays)) /* e.g. for calendar-day-name-array */
+ {
+ Lisp_Object v = Fmake_vector (make_number (7), Qnil);
+ int days[7] = {DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7};
+ int i;
+ synchronize_system_time_locale ();
+ for (i = 0; i < 7; i++)
+ {
+ str = nl_langinfo (days[i]);
+ val = make_unibyte_string (str, strlen (str));
+ /* Fixme: Is this coding system necessarily right, even if
+ it is consistent with CODESET? If not, what to do? */
+ Faset (v, make_number (i),
+ code_convert_string_norecord (val, Vlocale_coding_system,
+ 0));
+ }
+ return v;
+ }
+#endif /* DAY_1 */
+#ifdef MON_1
+ else if (EQ (item, Qmonths)) /* e.g. for calendar-month-name-array */
+ {
+ struct Lisp_Vector *p = allocate_vector (12);
+ int months[12] = {MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7,
+ MON_8, MON_9, MON_10, MON_11, MON_12};
+ int i;
+ synchronize_system_time_locale ();
+ for (i = 0; i < 12; i++)
+ {
+ str = nl_langinfo (months[i]);
+ val = make_unibyte_string (str, strlen (str));
+ p->contents[i] =
+ code_convert_string_norecord (val, Vlocale_coding_system, 0);
+ }
+ XSETVECTOR (val, p);
+ return val;
+ }
+#endif /* MON_1 */
+/* LC_PAPER stuff isn't defined as accessible in glibc as of 2.3.1,
+ but is in the locale files. This could be used by ps-print. */
+#ifdef PAPER_WIDTH
+ else if (EQ (item, Qpaper))
+ {
+ return list2 (make_number (nl_langinfo (PAPER_WIDTH)),
+ make_number (nl_langinfo (PAPER_HEIGHT)));
+ }
+#endif /* PAPER_WIDTH */
+#endif /* HAVE_LANGINFO_CODESET*/
+ return Qnil;
+}