tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: make: time stamps
On Sat, 9 Apr 2011 07:36:21 +0000, David Holland writes:
>Once again: how about using words as the modifier names?
>
>(thus, :localtime and :gmtime)
This does :fmt-localtime and :fmt-gmtime
Reasonable?
Index: var.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/var.c,v
retrieving revision 1.163
diff -u -p -r1.163 var.c
--- var.c 7 Apr 2011 01:40:01 -0000 1.163
+++ var.c 10 Apr 2011 01:16:32 -0000
@@ -2366,6 +2366,21 @@ VarChangeCase(char *str, int upper)
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 @@ VarChangeCase(char *str, int upper)
* 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,23 @@ ApplyModifiers(char *nstr, const char *t
}
}
+ case 'f':
+ cp = tstr + 1; /* make sure it is set */
+ if (STRMOD_MATCH(tstr, "fmt-localtime", 13)) {
+ newStr = VarStrftime(nstr, 0);
+ cp = tstr + 13;
+ termc = *cp;
+ } else if (STRMOD_MATCH(tstr, "fmt-gmtime", 10)) {
+ newStr = VarStrftime(nstr, 1);
+ cp = tstr + 10;
+ 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;
Home |
Main Index |
Thread Index |
Old Index