ref: 5c479143296d316505df08fbe35218f19cc0876d
parent: ec160f1296fa62bf0e739cd2d670854261bfafd2
author: Ali Gholami Rudi <ali@rudi.ir>
date: Mon May 27 14:53:16 EDT 2013
reg: date registers
--- a/reg.c
+++ b/reg.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include "xroff.h"
#define NREGS (1 << 16)
@@ -81,6 +82,9 @@
case REG('.', '$'):
sprintf(numbuf, "%d", in_nargs());
break;
+ case REG('y', 'r'):
+ sprintf(numbuf, "%02d", nregs[id]);
+ break;
default:
sprintf(numbuf, "%d", *nreg(id));
}
@@ -179,9 +183,20 @@
}
}
+static void init_time(void)
+{
+ time_t t = time(NULL);
+ struct tm *tm = localtime(&t);
+ nregs[REG('d', 'w')] = tm->tm_wday + 1;
+ nregs[REG('d', 'y')] = tm->tm_mday;
+ nregs[REG('m', 'o')] = tm->tm_mon + 1;
+ nregs[REG('y', 'r')] = tm->tm_year % 100;
+}
+
void env_init(void)
{
int i;
+ init_time();
for (i = 0; i < LEN(eregs); i++)
eregs_idx[eregs[i]] = i + 1;
env_set(0);