From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- appl/cmd/timestamp.b | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 appl/cmd/timestamp.b (limited to 'appl/cmd/timestamp.b') 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; +} -- cgit v1.2.3