[PATCH] agetty: use nl_langinfo() for days and months

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Davidlohr Bueso <dave@xxxxxxx>
agetty: use nl_langinfo() for days and months

When available, do not use hardcoded English names.

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 login-utils/agetty.c |   55 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/login-utils/agetty.c b/login-utils/agetty.c
index 9d463ce..6f54074 100644
--- a/login-utils/agetty.c
+++ b/login-utils/agetty.c
@@ -10,7 +10,9 @@
 
    1999-05-05 Thorsten Kranzkowski <dl8bcu@xxxxxxx>
    - enable hardware flow control before displaying /etc/issue
-   
+
+   2010-11-14 Davidlohr Bueso <dave@xxxxxxx>
+   - use nl_langinfo(3) for days & months, when available
 */
 
 #include <stdio.h>
@@ -36,6 +38,10 @@
 #include "nls.h"
 #include "pathnames.h"
 
+#ifdef HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
+
 #ifdef __linux__
 #include <sys/param.h>
 #define USE_SYSLOG
@@ -819,12 +825,40 @@ auto_baud(tp)
     (void) tcsetattr(0, TCSANOW, tp);
 }
 
+enum { WEEKDAY, MONTH};
+char *
+get_date(flag, num)
+     int flag;
+     int num;
+{
+#ifdef HAVE_LANGINFO_H
+	if (flag == WEEKDAY)
+		return nl_langinfo(ABDAY_1+num);
+	else if (flag == MONTH)
+		return nl_langinfo(ABMON_1+num);
+	else return NULL;
+#else
+	char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
+			    "Fri", "Sat" };
+	char *month[] = { "Jan", "Feb", "Mar", "Apr", "May",
+			  "Jun", "Jul", "Aug", "Sep", "Oct",
+			  "Nov", "Dec" };
+
+	if (flag == WEEKDAY) 
+		return weekday[num];
+	else if (flag == MONTH) 
+		return month[num];
+	else return NULL;
+#endif
+}
+
 /* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
 void
 do_prompt(op, tp)
      struct options *op;
      struct termios *tp;
 {
+	
 #ifdef	ISSUE
     FILE    *fd;
     int     oflag;
@@ -909,13 +943,7 @@ do_prompt(op, tp)
 
 		  case 'd':
 		  case 't':
-		    {
-		      /* TODO: use nl_langinfo() */
-		      char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
-					  "Fri", "Sat" };
-		      char *month[] = { "Jan", "Feb", "Mar", "Apr", "May",
-					"Jun", "Jul", "Aug", "Sep", "Oct",
-					"Nov", "Dec" };
+		    {		      
 		      time_t now;
 		      struct tm *tm;
 
@@ -923,11 +951,12 @@ do_prompt(op, tp)
 		      tm = localtime(&now);
 
 		      if (c == 'd')
-			(void) printf ("%s %s %d  %d",
-				weekday[tm->tm_wday], month[tm->tm_mon],
-				tm->tm_mday, 
-				tm->tm_year < 70 ? tm->tm_year + 2000 :
-				tm->tm_year + 1900);
+			      printf("%s %s %d %d",
+				     get_date(WEEKDAY, tm->tm_wday),
+				     get_date(MONTH, tm->tm_mon),
+				     tm->tm_mday,
+				     tm->tm_year < 70 ? tm->tm_year + 2000 :
+				     tm->tm_year + 1900);		  
 		      else
 			(void) printf ("%02d:%02d:%02d",
 				tm->tm_hour, tm->tm_min, tm->tm_sec);
-- 
1.7.1



--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux