#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <time.h>
#include "shmlog.h"
#include "vrt.h"
/*--------------------------------------------------------------------*/
+char *
+VRT_r_strftime(struct sess *sp, const char *format, double timestamp)
+{
+ char *s;
+ unsigned length;
+ size_t r;
+ struct tm tm;
+ time_t time;
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+
+ time = timestamp;
+ AN(length = WS_Reserve(sp->http->ws, 0));
+ AN(gmtime_r(&time, &tm));
+ r = strftime(sp->http->ws->f, length, format, &tm);
+ s = sp->http->ws->f;
+ WS_Release(sp->http->ws, r + 1);
+ return s;
+}
+
double
VRT_r_now(const struct sess *sp)
{
/*--------------------------------------------------------------------*/
+void
+parse_format_time(struct tokenlist *tl)
+{
+ vcc_NextToken(tl);
+
+ Expect(tl, '(');
+ vcc_NextToken(tl);
+ Fb(tl, 1, "VRT_strftime(sp, ");
+
+ if (!vcc_StringVal(tl)) {
+ ERRCHK(tl);
+ vcc_ExpectedStringval(tl);
+ return;
+ }
+ Fb(tl, 0, ", ");
+
+ Expect(tl, ',');
+ vcc_NextToken(tl);
+
+ vcc_RTimeVal(tl);
+ Fb(tl, 0, ");");
+ Expect(tl, ')');
+ vcc_NextToken(tl);
+}
+
+/*--------------------------------------------------------------------*/
+
static void
illegal_assignment(const struct tokenlist *tl, const char *type)
{
return (T_ELSE);
}
return (0);
+ case 'f':
+ if (p[1] == 'o' && p[2] == 'r' && p[3] == 'm' &&
+ p[4] == 'a' && p[5] == 't' && p[6] == '_' &&
+ p[7] == 't' && p[8] == 'i' && p[9] == 'm' &&
+ p[10] == 'e' && !isvar(p[11])) {
+ *q = p + 11;
+ return (T_FORMAT_TIME);
+ }
+ return (0);
case 'i':
if (p[1] == 'n' && p[2] == 'c' && p[3] == 'l' &&
p[4] == 'u' && p[5] == 'd' && p[6] == 'e'
[T_ELSEIF] = "elseif",
[T_ELSIF] = "elsif",
[T_EQ] = "==",
+ [T_FORMAT_TIME] = "format_time",
[T_GEQ] = ">=",
[T_IF] = "if",
[T_INC] = "++",
if else elseif elsif
}
+# Functions
+#
+set functions {
+ format_time
+}
+
# Non-word tokens
#
set magic {
}
foreach k $keywords { mk_token $k $k 1 }
+foreach k $functions { mk_token $k $k 1 }
foreach k $magic { mk_token [lindex $k 1] [lindex $k 0] 0 }
foreach k $extras {
set t [string toupper $k]
{
struct var *vp;
+ fprintf(stderr, "foo\n");
if (tl->t->tok == CSTR) {
EncToken(tl->fb, tl->t);
vcc_NextToken(tl);
vcc_NextToken(tl);
return (1);
}
+ if (tl->t->tok == ID && vcc_IdIs(tl->t, "format_string")) {
+ parse_format_time(tl);
+ return (1);
+ }
if (tl->t->tok == VAR) {
vp = vcc_FindVar(tl, tl->t, vcc_vars);
if (tl->err)
#define T_ELSE 130
#define T_ELSEIF 131
#define T_ELSIF 132
-#define T_INC 133
-#define T_DEC 134
-#define T_CAND 135
-#define T_COR 136
-#define T_LEQ 137
-#define T_EQ 138
-#define T_NEQ 139
-#define T_GEQ 140
-#define T_SHR 141
-#define T_SHL 142
-#define T_INCR 143
-#define T_DECR 144
-#define T_MUL 145
-#define T_DIV 146
-#define ID 147
-#define VAR 148
-#define CNUM 149
-#define CSTR 150
-#define EOI 151
-#define CSRC 152
+#define T_FORMAT_TIME 133
+#define T_INC 134
+#define T_DEC 135
+#define T_CAND 136
+#define T_COR 137
+#define T_LEQ 138
+#define T_EQ 139
+#define T_NEQ 140
+#define T_GEQ 141
+#define T_SHR 142
+#define T_SHL 143
+#define T_INCR 144
+#define T_DECR 145
+#define T_MUL 146
+#define T_DIV 147
+#define ID 148
+#define VAR 149
+#define CNUM 150
+#define CSTR 151
+#define EOI 152
+#define CSRC 153