Module Name:    src
Committed By:   sjg
Date:           Mon Apr 11 01:44:15 UTC 2011

Modified Files:
        src/usr.bin/make: make.1 var.c

Log Message:
Add :localtime and :gmtime which use value as format string for strftime.


To generate a diff of this commit:
cvs rdiff -u -r1.186 -r1.187 src/usr.bin/make/make.1
cvs rdiff -u -r1.163 -r1.164 src/usr.bin/make/var.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.186 src/usr.bin/make/make.1:1.187
--- src/usr.bin/make/make.1:1.186	Thu Apr  7 01:40:01 2011
+++ src/usr.bin/make/make.1	Mon Apr 11 01:44:15 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.186 2011/04/07 01:40:01 joerg Exp $
+.\"	$NetBSD: make.1,v 1.187 2011/04/11 01:44:15 sjg Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd April 2, 2011
+.Dd April 10, 2011
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -1042,8 +1042,18 @@
 .Nm .
 .It Cm \&:R
 Replaces each word in the variable with everything but its suffix.
+.It Cm \&:gmtime
+The value is a format string for 
+.Xr strftime 3 ,
+using the current 
+.Xr gmtime 3 .
 .It Cm \&:hash
 Compute a 32bit hash of the value and encode it as hex digits.
+.It Cm \&:localtime
+The value is a format string for 
+.Xr strftime 3 ,
+using the current 
+.Xr localtime 3 .
 .It Cm \&:tA
 Attempt to convert variable to an absolute path using
 .Xr realpath 3 ,

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.163 src/usr.bin/make/var.c:1.164
--- src/usr.bin/make/var.c:1.163	Thu Apr  7 01:40:01 2011
+++ src/usr.bin/make/var.c	Mon Apr 11 01:44:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.163 2011/04/07 01:40:01 joerg Exp $	*/
+/*	$NetBSD: var.c,v 1.164 2011/04/11 01:44:15 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.163 2011/04/07 01:40:01 joerg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.164 2011/04/11 01:44:15 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.163 2011/04/07 01:40:01 joerg Exp $");
+__RCSID("$NetBSD: var.c,v 1.164 2011/04/11 01:44:15 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2366,6 +2366,21 @@
    return Buf_Destroy(&buf, FALSE);
 }
 
+static char *
+VarStrftime(const char *fmt, int zulu)
+{
+    char buf[BUFSIZ];
+    time_t utc;
+
+    time(&utc);
+    if (!*fmt)
+	fmt = "%c";
+    strftime(buf, sizeof(buf), fmt, zulu ? gmtime(&utc) : localtime(&utc));
+    
+    buf[sizeof(buf) - 1] = '\0';
+    return bmake_strdup(buf);
+}
+
 /*
  * Now we need to apply any modifiers the user wants applied.
  * These are:
@@ -2451,6 +2466,10 @@
  *			variable.
  */
 
+/* we now have some modifiers with long names */
+#define STRMOD_MATCH(s, want, n) \
+    (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':'))
+
 static char *
 ApplyModifiers(char *nstr, const char *tstr,
 	       int startc, int endc,
@@ -2896,10 +2915,19 @@
 		}
 
 	    }
+	case 'g':
+	    cp = tstr + 1;	/* make sure it is set */
+	    if (STRMOD_MATCH(tstr, "gmtime", 6)) {
+		newStr = VarStrftime(nstr, 1);
+		cp = tstr + 6;
+		termc = *cp;
+	    } else {
+		goto bad_modifier;
+	    }
+	    break;
 	case 'h':
 	    cp = tstr + 1;	/* make sure it is set */
-	    if (strncmp(tstr, "hash", 4) == 0 &&
-		(tstr[4] == endc || tstr[4] == ':')) {
+	    if (STRMOD_MATCH(tstr, "hash", 4)) {
 		newStr = VarHash(nstr);
 		cp = tstr + 4;
 		termc = *cp;
@@ -2907,6 +2935,16 @@
 		goto bad_modifier;
 	    }
 	    break;
+	case 'l':
+	    cp = tstr + 1;	/* make sure it is set */
+	    if (STRMOD_MATCH(tstr, "localtime", 9)) {
+		newStr = VarStrftime(nstr, 0);
+		cp = tstr + 9;
+		termc = *cp;
+	    } else {
+		goto bad_modifier;
+	    }
+	    break;
 	case 't':
 	    {
 		cp = tstr + 1;	/* make sure it is set */

Reply via email to