#include "fmt.h"
#include "open.h"
+/* appends (not crash-proof) a line to "Log". The format is: */
+/* "timestamp event address[ comment]\n". address is free of ' ' */
+/* Unprintable chars are changed to '?'. Comment may have spaces */
+
static substdio ss;
static char buf[1];
static char num[FMT_ULONG];
static stralloc line = {0};
+static stralloc fn = {0};
-void log(event,addr)
+void log(dir,event,addr,comment)
+char *dir;
char *event;
char *addr;
+char *comment;
{
char ch;
int fd;
if ((ch < 33) || (ch > 126)) ch = '?';
if (!stralloc_append(&line,&ch)) return;
}
+ if (comment && *comment) {
+ if (!stralloc_cats(&line," ")) return;
+ while (ch = *comment++) {
+ if (ch == '\t')
+ ch = ' ';
+ else
+ if ((ch < 32) || (ch > 126)) ch = '?';
+ if (!stralloc_append(&line,&ch)) return;
+ }
+ }
if (!stralloc_cats(&line,"\n")) return;
- fd = open_append("Log");
+ if (!stralloc_copys(&fn,dir)) return;
+ if (!stralloc_cats(&fn,"/Log")) return;
+ if (!stralloc_0(&fn)) return;
+ fd = open_append(fn.s);
if (fd == -1) return;
substdio_fdbuf(&ss,write,fd,buf,sizeof(buf));
substdio_putflush(&ss,line.s,line.len);