Include <langinfo.h> if it exists.
authorJim Meyering <jim@meyering.net>
Mon, 3 Apr 2000 07:38:41 +0000 (07:38 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 3 Apr 2000 07:38:41 +0000 (07:38 +0000)
(DATE_FMT_LANGINFO): New macro.
(show_date): Use it to get the locale-specific default format for
"date" if it exists.

src/date.c

index ef8563a..555bf7e 100644 (file)
@@ -21,6 +21,9 @@
 #include <stdio.h>
 #include <getopt.h>
 #include <sys/types.h>
+#if HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
 
 #include "system.h"
 #include "argmatch.h"
@@ -106,6 +109,12 @@ static struct option const long_options[] =
 #define MAYBE_SET_TZ_UTC0 \
   do { if (universal_time) set_tz (TZ_UTC0); } while (0)
 
+#ifdef _DATE_FMT
+# define DATE_FMT_LANGINFO() nl_langinfo (_DATE_FMT)
+#else
+# define DATE_FMT_LANGINFO() ""
+#endif
+
 void
 usage (int status)
 {
@@ -490,13 +499,17 @@ show_date (const char *format, time_t when)
         in the RFC format to %Z; this gives, however, an invalid
         RFC time format outside the continental United States and GMT. */
 
-      format = (rfc_format
-               ? (universal_time
-                  ? "%a, %_d %b %Y %H:%M:%S GMT"
-                  : "%a, %_d %b %Y %H:%M:%S %z")
-               : (iso_8601_format
-                  ? iso_format_string[iso_8601_format][universal_time]
-                  : "%a %b %e %H:%M:%S %Z %Y"));
+      if (rfc_format)
+       format = (universal_time
+                 ? "%a, %_d %b %Y %H:%M:%S GMT"
+                 : "%a, %_d %b %Y %H:%M:%S %z");
+      else if (iso_8601_format)
+       format = iso_format_string[iso_8601_format][universal_time];
+      else
+       {
+         char *date_fmt = DATE_FMT_LANGINFO ();
+         format = *date_fmt ? date_fmt : "%a %b %e %H:%M:%S %Z %Y";
+       }
     }
   else if (*format == '\0')
     {