Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Allow providing a utc value to :{gm, local}time



details:   https://anonhg.NetBSD.org/src/rev/4ec9004d71d5
branches:  trunk
changeset: 350640:4ec9004d71d5
user:      sjg <sjg%NetBSD.org@localhost>
date:      Sat Jan 14 22:58:04 2017 +0000

description:
Allow providing a utc value to :{gm,local}time

Reviewed by: christos

diffstat:

 usr.bin/make/make.1                 |  18 +++++++++----
 usr.bin/make/unit-tests/varmisc.exp |   2 +
 usr.bin/make/unit-tests/varmisc.mk  |  13 +++++++++-
 usr.bin/make/var.c                  |  45 +++++++++++++++++++++++-------------
 4 files changed, 54 insertions(+), 24 deletions(-)

diffs (206 lines):

diff -r 374ed8df4dc4 -r 4ec9004d71d5 usr.bin/make/make.1
--- a/usr.bin/make/make.1       Sat Jan 14 22:24:43 2017 +0000
+++ b/usr.bin/make/make.1       Sat Jan 14 22:58:04 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: make.1,v 1.263 2016/08/26 23:37:54 dholland Exp $
+.\"    $NetBSD: make.1,v 1.264 2017/01/14 22:58:04 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 August 26, 2016
+.Dd January 14, 2017
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -1204,18 +1204,24 @@
 .Nm .
 .It Cm \&:R
 Replaces each word in the variable with everything but its suffix.
-.It Cm \&:gmtime
+.It Cm \&:gmtime[=utc]
 The value is a format string for
 .Xr strftime 3 ,
-using the current
+using
 .Xr gmtime 3 .
+If a
+.Va utc
+value is not provided or is 0, the current time is used.
 .It Cm \&:hash
 Compute a 32-bit hash of the value and encode it as hex digits.
-.It Cm \&:localtime
+.It Cm \&:localtime[=utc]
 The value is a format string for
 .Xr strftime 3 ,
-using the current
+using
 .Xr localtime 3 .
+If a
+.Va utc
+value is not provided or is 0, the current time is used.
 .It Cm \&:tA
 Attempt to convert variable to an absolute path using
 .Xr realpath 3 ,
diff -r 374ed8df4dc4 -r 4ec9004d71d5 usr.bin/make/unit-tests/varmisc.exp
--- a/usr.bin/make/unit-tests/varmisc.exp       Sat Jan 14 22:24:43 2017 +0000
+++ b/usr.bin/make/unit-tests/varmisc.exp       Sat Jan 14 22:58:04 2017 +0000
@@ -17,4 +17,6 @@
 FALSE
 do not evaluate or expand :? if discarding
 is set
+year=2016 month=04 day=01
+date=20160401
 exit status 0
diff -r 374ed8df4dc4 -r 4ec9004d71d5 usr.bin/make/unit-tests/varmisc.mk
--- a/usr.bin/make/unit-tests/varmisc.mk        Sat Jan 14 22:24:43 2017 +0000
+++ b/usr.bin/make/unit-tests/varmisc.mk        Sat Jan 14 22:58:04 2017 +0000
@@ -1,8 +1,9 @@
-# $Id: varmisc.mk,v 1.5 2015/10/12 17:09:29 sjg Exp $
+# $Id: varmisc.mk,v 1.6 2017/01/14 22:58:04 sjg Exp $
 #
 # Miscellaneous variable tests.
 
-all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none
+all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
+       strftime
 
 unmatched_var_paren:
        @echo ${foo::=foo-text}
@@ -40,3 +41,11 @@
 NQ_none:
        @echo do not evaluate or expand :? if discarding
        @echo ${VSET:U${1:L:?${True}:${False}}}
+
+April1= 1459494000
+
+# slightly contorted syntax to use utc via variable
+strftime:
+       @echo ${year=%Y month=%m day=%d:L:gmtime=1459494000}
+       @echo date=${%Y%m%d:L:${gmtime=${April1}:L}}
+
diff -r 374ed8df4dc4 -r 4ec9004d71d5 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Jan 14 22:24:43 2017 +0000
+++ b/usr.bin/make/var.c        Sat Jan 14 22:58:04 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.208 2016/06/03 01:21:59 sjg Exp $    */
+/*     $NetBSD: var.c,v 1.209 2017/01/14 22:58:04 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.208 2016/06/03 01:21:59 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.209 2017/01/14 22:58:04 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.208 2016/06/03 01:21:59 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.209 2017/01/14 22:58:04 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2381,12 +2381,12 @@
 }
 
 static char *
-VarStrftime(const char *fmt, int zulu)
+VarStrftime(const char *fmt, int zulu, time_t utc)
 {
     char buf[BUFSIZ];
-    time_t utc;
-
-    time(&utc);
+
+    if (!utc)
+       time(&utc);
     if (!*fmt)
        fmt = "%c";
     strftime(buf, sizeof(buf), fmt, zulu ? gmtime(&utc) : localtime(&utc));
@@ -2483,6 +2483,8 @@
 /* we now have some modifiers with long names */
 #define STRMOD_MATCH(s, want, n) \
     (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':'))
+#define STRMOD_MATCHX(s, want, n) \
+    (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':' || s[n] == '='))
 
 static char *
 ApplyModifiers(char *nstr, const char *tstr,
@@ -2494,12 +2496,14 @@
     const char     *cp;        /* Secondary pointer into str (place marker
                                 * for tstr) */
     char          *newStr;     /* New value to return */
+    char          *ep;
     char           termc;      /* Character which terminated scan */
     int             cnt;       /* Used to count brace pairs when variable in
                                 * in parens or braces */
     char       delim;
     int                modifier;       /* that we are processing */
     Var_Parse_State parsestate; /* Flags passed to helper functions */
+    time_t     utc;            /* for VarStrftime */
 
     delim = '\0';
     parsestate.oneBigWord = FALSE;
@@ -2896,8 +2900,6 @@
                     * integer for :[N], or two integers
                     * separated by ".." for :[start..end].
                     */
-                   char *ep;
-
                    VarSelectWords_t seldata = { 0, 0 };
 
                    seldata.start = strtol(estr, &ep, 0);
@@ -2956,9 +2958,15 @@
            }
        case 'g':
            cp = tstr + 1;      /* make sure it is set */
-           if (STRMOD_MATCH(tstr, "gmtime", 6)) {
-               newStr = VarStrftime(nstr, 1);
-               cp = tstr + 6;
+           if (STRMOD_MATCHX(tstr, "gmtime", 6)) {
+               if (tstr[6] == '=') {
+                   utc = strtoul(&tstr[7], &ep, 10);
+                   cp = ep;
+               } else {
+                   utc = 0;
+                   cp = tstr + 6;
+               }
+               newStr = VarStrftime(nstr, 1, utc);
                termc = *cp;
            } else {
                goto default_case;
@@ -2976,9 +2984,15 @@
            break;
        case 'l':
            cp = tstr + 1;      /* make sure it is set */
-           if (STRMOD_MATCH(tstr, "localtime", 9)) {
-               newStr = VarStrftime(nstr, 0);
-               cp = tstr + 9;
+           if (STRMOD_MATCHX(tstr, "localtime", 9)) {
+               if (tstr[9] == '=') {
+                   utc = strtoul(&tstr[10], &ep, 10);
+                   cp = ep;
+               } else {
+                   utc = 0;
+                   cp = tstr + 9;
+               }
+               newStr = VarStrftime(nstr, 0, utc);
                termc = *cp;
            } else {
                goto default_case;
@@ -3027,7 +3041,6 @@
                                goto get_numeric;
                            default:
                                if (isdigit((unsigned char)tstr[3])) {
-                                   char *ep;
 
                                get_numeric:
                                    parsestate.varSpace =



Home | Main Index | Thread Index | Old Index