X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=inline;f=src%2Futil.c;h=b4b96b7bbff47c78bd5f77e1200ab9a15669fcee;hb=44494b046145941d3bed279e0046cb0ef9279669;hp=7be18596a4cc1dabb2b2aa1a05551a0b8a3acdb4;hpb=6478a82a947e3662c31b95682661f2de9952944d;p=oftp diff --git a/src/util.c b/src/util.c index 7be1859..b4b96b7 100644 --- a/src/util.c +++ b/src/util.c @@ -2,6 +2,7 @@ #include #include #include "util.h" +#include "tui.h" void *malloc_nf_impl(size_t sz, const char *file, int line) { @@ -52,3 +53,62 @@ int match_prefix(const char *str, const char *prefix) } return *prefix ? 0 : 1; } + +static FILE *logfile; + +static void closelog(void) +{ + fclose(logfile); +} + +static void logmsg(const char *tag, const char *fmt, va_list ap) +{ + if(!logfile) { + if(!(logfile = fopen("oftp.log", "w"))) { + return; + } + setvbuf(logfile, 0, _IOLBF, 0); + atexit(closelog); + } + fprintf(logfile, "%s: ", tag); + vfprintf(logfile, fmt, ap); +} + +void errmsg(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + tui_vmsgbox(TUI_ERROR, "error", fmt, ap); + va_end(ap); + + va_start(ap, fmt); + logmsg("error", fmt, ap); + va_end(ap); +} + +void warnmsg(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + tui_status(TUI_WARN, fmt, ap); + va_end(ap); + + va_start(ap, fmt); + logmsg("warning", fmt, ap); + va_end(ap); +} + +void infomsg(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + tui_status(TUI_INFO, fmt, ap); + va_end(ap); + + va_start(ap, fmt); + logmsg("info", fmt, ap); + va_end(ap); +}