
#include "debugrep.h"

#include "swis.h"
#include "kernel.h"

#include <stdarg.h>
#include <stdio.h>

#define DEBUG_MAX_LINE_LENGTH 256

int debug_printf(char *cntrl_string, ...)
{
        char            s[DEBUG_MAX_LINE_LENGTH];
        int             ret;
        va_list         ap;
        int             swinum;

        /* Reporter (a debug tool) provides Report_Text0;
           If it isn't loaded, the look-up fails and we silently do nothing. */
        if (_swix(OS_SWINumberFromString, _IN(1) | _OUT(0), "Report_Text0", &swinum) != NULL)
                return 0;

        int pre = sprintf(s, DEBUG_PREFIX);

        va_start(ap, cntrl_string);
        ret = vsnprintf(s+pre, DEBUG_MAX_LINE_LENGTH-pre, cntrl_string, ap);
        s[DEBUG_MAX_LINE_LENGTH - 1] = '\0';

        _swix(swinum, _IN(0), s);

        return ret;
}
