aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-02 21:50:34 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-02 21:50:34 +0100
commita74644d1d00cf1229c11cc7c1956867c4eb4cb7f (patch)
tree8b03d56ba8e4394b818c4e6419b562e0973b0310
parentc2bea7ec74b8f957e56a14a55aa7aa07e7dd3118 (diff)
Factor out vprintf from ScreenBuffer::(mv)printf
-rw-r--r--screenbuffer.cpp25
-rw-r--r--screenbuffer.h1
2 files changed, 12 insertions, 14 deletions
diff --git a/screenbuffer.cpp b/screenbuffer.cpp
index a382e82..d224181 100644
--- a/screenbuffer.cpp
+++ b/screenbuffer.cpp
@@ -74,35 +74,32 @@ void ScreenBuffer::printstr(const char *buf){
}
}
-__attribute__((format (printf, 2, 3)))
-int ScreenBuffer::printf(const char *format,...){
- va_list ap;
- va_start(ap,format);
+int ScreenBuffer::printf_varargs(const char *format,va_list ap){
char *buf;
int ret=vasprintf(&buf,format,ap);
- va_end(ap);
assert(buf);
-
printstr(buf);
-
free(buf);
return ret;
}
+__attribute__((format (printf, 2, 3)))
+int ScreenBuffer::printf(const char *format,...){
+ va_list ap;
+ va_start(ap,format);
+ int ret=printf_varargs(format,ap);
+ va_end(ap);
+ return ret;
+}
+
__attribute__((format (printf, 4, 5)))
int ScreenBuffer::mvprintf(int x,int y,const char *format,...){
moveto(x,y);
va_list ap;
va_start(ap,format);
- char *buf;
- int ret=vasprintf(&buf,format,ap);
+ int ret=printf_varargs(format,ap);
va_end(ap);
- assert(buf);
-
- printstr(buf);
-
- free(buf);
return ret;
}
diff --git a/screenbuffer.h b/screenbuffer.h
index 49cc5c5..6e3d429 100644
--- a/screenbuffer.h
+++ b/screenbuffer.h
@@ -9,6 +9,7 @@ class ScreenBuffer{
int curx=0,cury=0;
void printstr(const char *buf);
+ int printf_varargs(const char *format,va_list ap);
public:
ScreenBuffer(int W,int H);