// This file is a part of Framsticks SDK. http://www.framsticks.com/ // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. #include "framsg.h" #include #include "stl-util.h" #include "Convert.h" const char* MSG_LEVEL[]={"DEBUG","INFO","WARN","ERROR","CRITICAL"}; void FramMessage(const char *o, const char *m, const char *txt, int w) { int line = 0; //all lines except the first one get the "..." prefix const char* nextsep; do { nextsep = strchr(txt, '\n'); if (nextsep == NULL) //last chunk, until the end nextsep = strchr(txt, '\0'); if ((nextsep > txt) && (nextsep[-1] == '\r')) nextsep--; if (line == 0) { if (*nextsep == 0) //there was only one line! no need to modify it in any way. _FramMessageSingleLine(o, m, txt, w); else //first line from multi-line _FramMessageSingleLine(o, m, string(txt, nextsep - txt).c_str(), w); } else //consecutive lines from multi-line _FramMessageSingleLine(o, m, ("..." + string(txt, nextsep - txt)).c_str(), w); //could also add line numbers like ...(3)... but let's keep the prefix short and simple line++; if ((nextsep[0] == '\r') && (nextsep[1] == '\n')) txt = nextsep + 2; else if (*nextsep) txt = nextsep + 1; } while (*nextsep); } void FMprintf_va(const char *o,const char *m,int w,const char *bl,va_list va) { string buf=ssprintf_va(bl,va); FramMessage(o,m,buf.c_str(),w); } void FMprintf(const char *o,const char *m,int w,const char *bl, ...) { va_list argptr; va_start(argptr,bl); FMprintf_va(o,m,w,bl,argptr); va_end(argptr); } void printFM(const char *bl,...) { va_list argptr; va_start(argptr,bl); FMprintf_va("Message","printf",FMLV_INFO,bl,argptr); va_end(argptr); }