Subversion Repositories tpanel

Rev

Rev 14 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 21
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2020 by Andreas Theofilu <andreas@theosys.at>
2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
3
 *
3
 *
4
 * This program is free software; you can redistribute it and/or modify
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
7
 * (at your option) any later version.
Line 294... Line 294...
294
void TError::logHex(char* str, size_t size)
294
void TError::logHex(char* str, size_t size)
295
{
295
{
296
    if (!str || !size)
296
    if (!str || !size)
297
        return;
297
        return;
298
 
298
 
-
 
299
    message_mutex.lock();
299
    Current();
300
    Current();
300
    // Save the old format settings in case they were manipulated
301
    // Save the old format settings in case they were manipulated
301
    std::ios oldstate(nullptr);
302
    std::ios oldstate(nullptr);
302
    oldstate.copyfmt(std::cout);
303
    oldstate.copyfmt(std::cout);
303
    // Print out the message
304
    // Print out the message
304
    int lc = 0;
-
 
305
    std::ostream *stream = mCurrent->getStream();
305
    std::ostream *stream = mCurrent->getStream();
-
 
306
    *stream << strToHex(str, size, 16, true, 12) << std::endl;
-
 
307
    stream->copyfmt(oldstate);     // Restore old format (reset)
-
 
308
    message_mutex.unlock();
-
 
309
}
-
 
310
 
-
 
311
string TError::toHex(int num, int width)
-
 
312
{
-
 
313
    string ret;
-
 
314
    std::stringstream stream;
-
 
315
    stream << std::setfill ('0') << std::setw(width) << std::hex << num;
-
 
316
    ret = stream.str();
-
 
317
    return ret;
-
 
318
}
-
 
319
 
-
 
320
string TError::strToHex(const char *str, size_t size, int width, bool format, int indent)
-
 
321
{
-
 
322
    DECL_TRACER("TError::strToHex(const char *str, size_t size, int width, bool format, int indent)");
-
 
323
 
-
 
324
    int len = 0, pos = 0, old = 0;
-
 
325
    int w = (format) ? 1 : width;
-
 
326
    string out, left, right;
-
 
327
    string ind;
-
 
328
 
-
 
329
    if (indent > 0)
-
 
330
    {
-
 
331
        for (int j = 0; j < indent; j++)
-
 
332
            ind.append(" ");
-
 
333
    }
306
 
334
 
307
    for (size_t i = 0; i < size; i++)
335
    for (size_t i = 0; i < size; i++)
308
    {
336
    {
309
        int bt = (int) * (str + i) & 0x0000ff;
337
        if (len >= w)
-
 
338
        {
310
        *stream << std::setw(2) << std::setfill('0') << std::hex << bt << " ";
339
            left.append(" ");
-
 
340
            len = 0;
311
        lc++;
341
        }
312
 
342
 
313
        if (lc >= 8)
343
        if (format && i > 0 && (pos % width) == 0)
314
        {
344
        {
-
 
345
            out += ind + toHex(old, 4) + ": " + left + " | " + right + "\n";
-
 
346
            left.clear();
315
            *stream << std::endl << std::flush;
347
            right.clear();
316
            lc = 0;
348
            old = pos;
317
        }
349
        }
-
 
350
 
-
 
351
        int c = *(str+i) & 0x000000ff;
-
 
352
        left.append(toHex(c, 2));
-
 
353
 
-
 
354
        if (format)
-
 
355
        {
-
 
356
            if (std::isprint(c))
-
 
357
                right.push_back(c);
-
 
358
            else
-
 
359
                right.push_back('.');
-
 
360
        }
-
 
361
 
-
 
362
        len++;
-
 
363
        pos++;
318
    }
364
    }
319
 
365
 
-
 
366
    if (!format)
-
 
367
        return left;
-
 
368
    else if (pos > 0)
-
 
369
    {
-
 
370
        if ((pos % width) != 0)
-
 
371
        {
320
    stream->copyfmt(oldstate);     // Restore old format (reset)
372
            for (int i = 0; i < (width - (pos % width)); i++)
-
 
373
                left.append("   ");
-
 
374
        }
-
 
375
 
-
 
376
        out += ind + toHex(old, 4)+": "+left + "  | " + right;
-
 
377
    }
-
 
378
 
-
 
379
    return out;
321
}
380
}
322
 
381
 
323
void TError::setErrorMsg(const std::string& msg)
382
void TError::setErrorMsg(const std::string& msg)
324
{
383
{
325
    if (msg.empty())
384
    if (msg.empty())