Esempio n. 1
0
/*
 * stc_msg_format
 *
 * Message formatting, with variable-length arg list.
 */
int
stc_msg_format (statcode_t statcode, char *buf, size_t bufsiz, ...)
{
    va_list ap;
    int result;

    va_start(ap, bufsiz);
    result = stc_msg_vformat(statcode, buf, bufsiz, ap);
    va_end(ap);
    return result;

} /* stc_msg_format */
Esempio n. 2
0
/*
 * log_vsignal
 *
 * Core logging function.  Formats the diagnostic message and text
 * position (if possible), emits the message on stderr, and handles
 * the next step - incrementing the appropriate diagnostic counter
 * and possibly aborting.
 */
void
log_vsignal (logctx_t ctx, textpos_t pos, statcode_t code, va_list ap)
{
    char logbuf[256];
    int len;
    unsigned int sev = stc_severity(code);

    if (sev == STC_K_FATAL) {
        ctx->logtoterm = 1;
    }

    if (ctx->listprintfn != 0 || ctx->logtoterm) {
        int fileno = textpos_fileno(pos);
        unsigned int lineno = textpos_lineno(pos);
        unsigned int colno  = textpos_colnum(pos);
        if (ctx->linefetchfn != 0) {
            strdesc_t *curline = (*ctx->linefetchfn)(ctx->lfctx, fileno, lineno);
            if (curline != 0) {
                doprintsrc(ctx, curline->ptr, curline->len);
                if (curline->len < sizeof(logbuf) && colno < curline->len) {
                    memset(logbuf, '.', colno);
                    logbuf[colno] = '|';
                    doprint(ctx, logbuf, colno+1, !ctx->logsrctolst);
                }
            }
        }
        len = stc_msg_vformat(code, logbuf, sizeof(logbuf)-1, ap);
        doprint(ctx, logbuf, len, 0);
        if (pos != 0 && ctx->fetchfn != 0) {
            strdesc_t *fname = ctx->fetchfn(ctx->ffctx, fileno);
            if (fname != 0)  {
                len = snprintf(logbuf, sizeof(logbuf)-1, "-  at %-*.*s:%u:%u",
                               fname->len, fname->len, fname->ptr, lineno, colno+1);
                if (len > 0) doprint(ctx, logbuf, len, 0);
            }
        }
    }
    switch (sev) {
        case STC_K_ERROR:
            ctx->errcount += 1;
            if (ctx->errcount < ctx->maxerrs) break;
            // Force this error message to the terminal
            ctx->logtoterm = 1;
            len = snprintf(logbuf, sizeof(logbuf)-1, "%%BLISS-F-TOOMANYERRS, "
                           "maximum number of errors exceeded, aborting");
            if (len > 0) doprint(ctx, logbuf, len, 0);
            // FALLTHROUGH
        case STC_K_FATAL:
            fflush(stderr);
            longjmp(ctx->retenv, 1);
            break;
        case STC_K_WARN:
            ctx->warncount += 1;
            break;
        case STC_K_INFO:
            ctx->infocount += 1;
            break;
        default:
            break;
    }

} /* log_vsignal */