diff options
Diffstat (limited to 'library.cpp')
-rw-r--r-- | library.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/library.cpp b/library.cpp index 29e50db..cee789e 100644 --- a/library.cpp +++ b/library.cpp @@ -1,4 +1,7 @@ +#define _GNU_SOURCE //vasprintf #include <iostream> +#include <cstdarg> +#include <cassert> #include "global.h" #include "library.h" #include "main.h" @@ -6,10 +9,45 @@ using namespace std; +static void draw_text(int x,int y,const char *s,size_t len){ + fl_draw(s,len,x,y); +} + void draw_text(int x,int y,const char *s){ - fl_draw(s,x,y); + draw_text(x,y,s,strlen(s)); +} + +__attribute__((format (printf, 3, 4))) +void draw_textf(int x,int y,const char *format,...){ + va_list ap; + va_start(ap,format); + char *buf; + int len=vasprintf(&buf,format,ap); + va_end(ap); + assert(len>=0); + draw_text(x,y,buf,len); + free(buf); +} + + +static void log(const char *buf,size_t len){ + cerr<<"[LOG] "; + cerr.write(buf,len); + cerr<<endl; } void log(const char *s){ - cerr<<"[LOG] "<<s<<endl; + log(s,strlen(s)); +} + +__attribute__((format (printf, 1, 2))) +void logf(const char *format,...){ + va_list ap; + va_start(ap,format); + char *buf; + int len=vasprintf(&buf,format,ap); + va_end(ap); + assert(len>=0); + log(buf,len); + free(buf); } |