/*-*-C-*-
 *
 * Debugging
 */

#include "resed.h"

#if DEBUG

#include <stdarg.h>

#define HostFS_HostVdu 0x40100
#define HostFS_TubeVdu 0x40101

static FILE *f = NULL;


void debug_file (char *filename)
{
    if (f)
        fclose (f);
    if (filename)
        f = fopen (filename, "w");
}


int dprintf (char *format, ...)
{
    int ret = 0;
    va_list list;
    Bool doit = TRUE;
    va_start (list, format);
    if (!f)
        doit = swi (HostFS_HostVdu, END) == NULL;
    if (doit)
        ret = vfprintf(f ? f : stdout, format, list);
    if (!f)
        swi (HostFS_TubeVdu, END);
    va_end(list);
    return ret;
}

#endif
