/*
* Original from sqweek@gmail.com, sqweek.dnsdojo.org, sqweek on freenode
* 2009-01-25
* Local changes by anthony
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
void
usage(void)
{
fprint(2, "usage: %s [ -i ] [ -f format ]\n", argv0);
exits("usage");
}
void
main(int argc, char **argv)
{
Biobuf in;
char *line, *format, *stamp;
vlong prev, now, delta;
int iflag;
iflag = 0;
format = 0;
ARGBEGIN{
case 'i':
iflag = 1;
break;
case 'f':
format = EARGF(usage());
break;
default:
usage();
}ARGEND;
prev = nsec();
stamp = smprint("");
Binit(&in, 0, OREAD);
while(line = Brdline(&in, '\n')){
now = nsec();
delta = now - prev;
line[Blinelen(&in)-1] = '\0';
if(format != 0){
int pid;
pid=fork();
if(pid == 0){
//print("%s", format);
execl("/bin/datefmt", "datefmt", smprint("%s", format), nil);
exits("execl failed");
}
else
wait();
}
else
stamp=smprint("[+%lld.%09lld] ", delta/(vlong)(1000*1000*1000),
delta%(vlong)(1000*1000*1000));
print("%s%s\n", stamp, line);
if(iflag)
prev = now;
}
exits(0);
}
|