summaryrefslogtreecommitdiff
path: root/appl/cmd/timestamp.b
diff options
context:
space:
mode:
Diffstat (limited to 'appl/cmd/timestamp.b')
-rw-r--r--appl/cmd/timestamp.b42
1 files changed, 42 insertions, 0 deletions
diff --git a/appl/cmd/timestamp.b b/appl/cmd/timestamp.b
new file mode 100644
index 00000000..8f8554f8
--- /dev/null
+++ b/appl/cmd/timestamp.b
@@ -0,0 +1,42 @@
+implement Timestamp;
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+include "bufio.m";
+ bufio: Bufio;
+ Iobuf: import bufio;
+
+Timestamp: module {
+ init: fn(nil: ref Draw->Context, argv: list of string);
+};
+
+timefd: ref Sys->FD;
+starttime: big;
+
+init(nil: ref Draw->Context, argv: list of string)
+{
+ sys = load Sys Sys->PATH;
+ bufio = load Bufio Bufio->PATH;
+
+ note: string;
+ if(len argv > 1)
+ note = hd tl argv + " ";
+
+ timefd = sys->open("/dev/time", Sys->OREAD);
+ starttime = now();
+
+ sys->print("%.10bd %sstart %bd\n", now(), note, starttime);
+
+ iob := bufio->fopen(sys->fildes(0), Sys->OREAD);
+ while((s := iob.gets('\n')) != nil)
+ sys->print("%.10bd %s%s", now(), note, s);
+}
+
+now(): big
+{
+ buf := array[24] of byte;
+ n := sys->pread(timefd, buf, len buf, big 0);
+ if(n <= 0)
+ return big 0;
+ return big string buf[0:n] / big 1000 - starttime;
+}