Changeset 244 for cpp


Ignore:
Timestamp:
05/31/14 21:31:01 (10 years ago)
Author:
Maciej Komosinski
Message:

Printing multi-line messages splits the message into separate lines and adds "..." prefix

Location:
cpp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/framsg.cpp

    r197 r244  
    99
    1010const char* MSG_LEVEL[]={"DEBUG","INFO","WARN","ERROR","CRITICAL"};
     11
     12void FramMessage(const char *o, const char *m, const char *txt, int w)
     13{
     14        int line = 0; //all lines except the first one get the "..." prefix
     15        const char* nextsep;
     16        do
     17        {
     18                nextsep = strchr(txt, '\n');
     19                if (nextsep == NULL) //last chunk, until the end
     20                        nextsep = strchr(txt, '\0');
     21                if ((nextsep > txt) && (nextsep[-1] == '\r'))
     22                        nextsep--;
     23                if (line == 0)
     24                {
     25                        if (*nextsep == 0) //there was only one line! no need to modify it in any way.
     26                                _FramMessageSingleLine(o, m, txt, w);
     27                        else //first line from multi-line
     28                                _FramMessageSingleLine(o, m, string(txt, nextsep - txt).c_str(), w);
     29                }
     30                else //consecutive lines from multi-line
     31                        _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
     32                line++;
     33                if ((nextsep[0] == '\r') && (nextsep[1] == '\n'))
     34                        txt = nextsep + 2;
     35                else if (*nextsep)
     36                        txt = nextsep + 1;
     37        } while (*nextsep);
     38}
     39
    1140
    1241void FMprintf_va(const char *o,const char *m,int w,const char *bl,va_list va)
  • cpp/common/framsg.h

    r197 r244  
    1313void FMprintf_va(const char *o,const char *m,int w,const char *bl,va_list va); //a different name than FMprintf - otherwise the compiler could confuse the "string" parameter with va_list and could call the wrong function
    1414void printFM(const char *bl,...); //a shorthand for printf (a different name again to avoid the risk of confusion with the two functions above. This would be unlikely but possible when the argument types would match)
    15 void FramMessage(const char *o,const char *m,const char *bl,int w);
     15void FramMessage(const char *o,const char *m,const char *txt,int w);
     16
     17void _FramMessageSingleLine(const char *o,const char *m,const char *txt,int w); //don't call this directly - it is used internally
    1618
    1719#define FMLV_DEBUG -1
  • cpp/common/nonstd.h

    r227 r244  
    5757#endif
    5858
    59 #ifdef MACOS
     59#if defined MACOS || defined __ANDROID__
    6060 #define stricmp(a,b) strcasecmp(a,b)
    6161#endif
  • cpp/frams/errmgr/errmanager.cpp

    r197 r244  
    66#include <common/stl-util.h>
    77
    8 void FramMessage(const char *o,const char *m,const char *bl,int w)
     8void _FramMessageSingleLine(const char *o, const char *m, const char *txt, int w)
    99{
    10 tlsGetRef(errmgr_instance).send(o,m,bl,w);
     10tlsGetRef(errmgr_instance).send(o,m,txt,w);
    1111}
    1212
  • cpp/frams/errmgr/stdouterr.cpp

    r197 r244  
    1010#endif
    1111
    12 void StdoutErrorHandler::handle(const char *o,const char *m,const char *bl,int w)
     12void StdoutErrorHandler::handle(const char *o, const char *m, const char *bl, int w)
    1313{
    14 if (w<-1) w=-1; else if (w>3) w=3;
     14        if (w < -1) w = -1; else if (w>3) w = 3;
    1515#ifdef SHP
    16 AppLog("[%s] %s::%s - %s\n",MSG_LEVEL[w+1],o,m,bl);
     16        AppLog("[%s] %s::%s - %s\n",MSG_LEVEL[w+1],o,m,bl);
    1717#else
    18 if (file)
    19         file->printf("[%s] %s::%s - %s\n",MSG_LEVEL[w+1],o,m,bl);
    20 else
    21         printf("[%s] %s::%s - %s\n",MSG_LEVEL[w+1],o,m,bl);
     18        if (file)
     19                file->printf("[%s] %s::%s - %s\n", MSG_LEVEL[w + 1], o, m, bl);
     20        else
     21                printf("[%s] %s::%s - %s\n", MSG_LEVEL[w + 1], o, m, bl);
    2222#endif
    2323}
Note: See TracChangeset for help on using the changeset viewer.