pdcurses/debug.c

Fri, 24 Jul 2015 04:24:38 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Fri, 24 Jul 2015 04:24:38 +0300
changeset 100
d301ead29d7c
parent 97
2d43f05b284c
permissions
-rw-r--r--

Apply Leonard's patch for fixing the colors:

The colors were broken again.
* isprint for some reason returned true when the given byte is higher than 255.
The char cast of the byte was then printed which resulted in odd characters
popping up. Black appeared as ^@ which is NULL in caret notation.
* After that, the colors were all messed up because the RLINE enum didn't take
in account the color swapping.
So instead of messing up the enum order/number I went for a new "range-like"
method.
* After fixing all of that, I noticed the Interface::render_colorline had a
broken loop since the VS2010 commits.
This made the lines not print entierely and messed up the colors etc.

/* Public Domain Curses */

#include <curspriv.h>

RCSID("$Id: debug.c,v 1.7 2008/07/13 16:08:18 wmcbrine Exp $")

/*man-start**************************************************************

  Name:                                                         debug

  Synopsis:
        void traceon(void);
        void traceoff(void);
        void PDC_debug(const char *, ...);

  Description:
        traceon() and traceoff() toggle the recording of debugging 
        information to the file "trace". Although not standard, similar 
        functions are in some other curses implementations.

        PDC_debug() is the function that writes to the file, based on 
        whether traceon() has been called. It's used from the PDC_LOG() 
        macro.

  Portability                                X/Open    BSD    SYS V
        traceon                                 -       -       -
        traceoff                                -       -       -
        PDC_debug                               -       -       -

**man-end****************************************************************/

#include <string.h>
#include <sys/types.h>
#include <time.h>

bool pdc_trace_on = FALSE;

void PDC_debug(const char *fmt, ...)
{
    va_list args;
    FILE *dbfp;
    char hms[9];
    time_t now;

    if (!pdc_trace_on)
        return; 

    /* open debug log file append */

    dbfp = fopen("trace", "a");
    if (!dbfp)
    {
        fprintf(stderr,
            "PDC_debug(): Unable to open debug log file\n");
        return;
    }

    time(&now);
    strftime(hms, 9, "%H:%M:%S", localtime(&now));
    fprintf(dbfp, "At: %8.8ld - %s ", (long) clock(), hms);

    va_start(args, fmt);
    vfprintf(dbfp, fmt, args);
    va_end(args);

    fclose(dbfp);
}

void traceon(void)
{
    PDC_LOG(("traceon() - called\n"));

    pdc_trace_on = TRUE;
}

void traceoff(void)
{
    PDC_LOG(("traceoff() - called\n"));

    pdc_trace_on = FALSE;
}

mercurial