From a74644d1d00cf1229c11cc7c1956867c4eb4cb7f Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 2 Mar 2017 21:50:34 +0100 Subject: Factor out vprintf from ScreenBuffer::(mv)printf --- screenbuffer.cpp | 25 +++++++++++-------------- screenbuffer.h | 1 + 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); -- cgit v1.2.3-70-g09d2