Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Add :localtime and :gmtime which use value as f...



details:   https://anonhg.NetBSD.org/src/rev/638e5beec3c5
branches:  trunk
changeset: 764061:638e5beec3c5
user:      sjg <sjg%NetBSD.org@localhost>
date:      Mon Apr 11 01:44:15 2011 +0000

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

diffstat:

 usr.bin/make/make.1 |  14 ++++++++++++--
 usr.bin/make/var.c  |  48 +++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 55 insertions(+), 7 deletions(-)

diffs (135 lines):

diff -r cebc76fd0a39 -r 638e5beec3c5 usr.bin/make/make.1
--- a/usr.bin/make/make.1       Mon Apr 11 01:40:13 2011 +0000
+++ b/usr.bin/make/make.1       Mon Apr 11 01:44:15 2011 +0000
@@ -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 ,
diff -r cebc76fd0a39 -r 638e5beec3c5 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Apr 11 01:40:13 2011 +0000
+++ b/usr.bin/make/var.c        Mon Apr 11 01:44:15 2011 +0000
@@ -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 */



Home | Main Index | Thread Index | Old Index