about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-11-29 18:52:03 -0500
committerJune McEnroe <june@causal.agency>2018-11-29 18:52:03 -0500
commit908b834c1a6346b8bde7168e42d1b9786e4f658f (patch)
tree9942f43260e8e64077a7a02231938362ae0d2056
parentAdd basic log replay (diff)
downloadcatgirl-908b834c1a6346b8bde7168e42d1b9786e4f658f.tar.gz
catgirl-908b834c1a6346b8bde7168e42d1b9786e4f658f.zip
Strip timestamps from log replay
Also fix string length. %.*s does not behave as one might expect when
writing wchar_t.
-rw-r--r--log.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/log.c b/log.c
index 9cd6557..150b629 100644
--- a/log.c
+++ b/log.c
@@ -91,6 +91,8 @@ static FILE *logFile(struct Tag tag, const struct tm *time) {
 	return log->file;
 }
 
+enum { StampSize = sizeof("YYYY-MM-DDThh:mm:ss+hhmm") };
+
 void logFmt(struct Tag tag, const time_t *ts, const char *format, ...) {
 	if (logRoot < 0) return;
 
@@ -105,8 +107,8 @@ void logFmt(struct Tag tag, const time_t *ts, const char *format, ...) {
 
 	FILE *file = logFile(tag, time);
 
-	char stamp[sizeof("YYYY-MM-DDThh:mm:ss+hhmm")];
-	strftime(stamp, sizeof(stamp), "%FT%T%z", time);
+	char stamp[StampSize];
+	strftime(stamp, StampSize, "%FT%T%z", time);
 	fprintf(file, "[%s] ", stamp);
 	if (ferror(file)) err(EX_IOERR, "%s", tag.name);
 
@@ -133,7 +135,9 @@ void logReplay(struct Tag tag) {
 	size_t len;
 	char *line;
 	while (NULL != (line = fgetln(file, &len))) {
-		uiFmt(tag, UICold, "\3%d%.*s", IRCGray, (int)(len - 1), line);
+		line[len - 1] = '\0';
+		if (len > 2 + StampSize) line = &line[2 + StampSize];
+		uiFmt(tag, UICold, "\3%d%s", IRCGray, line);
 	}
 	if (ferror(file)) err(EX_IOERR, "%s", tag.name);
 }
2022-02-20Clean up unimplemented editing mode stuffJune McEnroe 2022-02-20Save input buffer contentsJune McEnroe 2022-02-20Share a cut buffer between all edit buffersJune McEnroe 2022-02-20Assert return values in edit testsJune McEnroe 2022-02-20Move mbs out of struct Edit, use a global bufferJune McEnroe 2022-02-20Clear edit buffer before running commandJune McEnroe 2022-02-20Show indicator in status when window has pending inputJune McEnroe 2022-02-20Use separate edit buffers for each IDJune McEnroe 2022-02-20Make sure new cap is actually larger than new lengthJune McEnroe 2022-02-20Remove unused mbs.len field from struct EditJune McEnroe 2022-02-19Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe 2022-02-18Implement new line editing "library"June McEnroe 2022-02-18Simplify cursor positioning in inputJune McEnroe 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe