Ejemplo n.º 1
0
/*
 *   Log an error using va_list arguments
 */
void CTcMain::S_v_log_error(CTcTokFileDesc *linedesc, long linenum,
                            int *err_counter, int *warn_counter,
                            int *first_error, int *first_warning,
                            unsigned long options,
                            const int *suppress_list, size_t suppress_cnt,
                            tc_severity_t severity, int err, va_list args)
{
    const char *msg;
    char msgbuf[2048];

    /* show the prefix */
    msg = log_msg_internal_1(linedesc, linenum, err_counter, warn_counter,
                             first_error, first_warning, options,
                             suppress_list, suppress_cnt, severity, err);

    /* if the message is suppressed, we're done */
    if (msg == 0)
        return;

    /* format the message using the va_list argument */
    t3vsprintf(msgbuf, sizeof(msgbuf), msg, args);

    /* display it */
    format_message(msgbuf, options);

    /* show the suffix */
    log_msg_internal_2(options, severity);
}
Ejemplo n.º 2
0
/*
 *   allocating vsprintf implementation 
 */
char *t3vsprintf_alloc(const char *fmt, va_list args)
{
    /* measure the required space - add in a byte for null termination */
    size_t len = t3vsprintf(0, 0, fmt, args) + 1;

    /* allocate space */
    char *buf = (char *)t3malloc(len);
    if (buf == 0)
        return 0;

    /* do the actual formatting */
    t3vsprintf(buf, len, fmt, args);

    /* return the allocated buffer */
    return buf;
}
Ejemplo n.º 3
0
/*
 *   buffer-checked sprintf implementation
 */
void t3sprintf(char *buf, size_t buflen, const char *fmt, ...)
{
    va_list args;

    /* package the arguments as a va_list and invoke our va_list version */
    va_start(args, fmt);
    t3vsprintf(buf, buflen, fmt, args);
    va_end(args);
}
Ejemplo n.º 4
0
/*
 *   buffer-checked sprintf implementation
 */
size_t t3sprintf(char *buf, size_t buflen, const char *fmt, ...)
{
    /* package the arguments as a va_list and invoke our va_list version */
    va_list args;
    va_start(args, fmt);
    size_t len = t3vsprintf(buf, buflen, fmt, args);
    va_end(args);

    /* return the length */
    return len;
}
Ejemplo n.º 5
0
/* 
 *   log an error in a source line 
 */
void CTcLibParser::src_err_msg(const char *msg, ...)
{
    char buf[1024];
    va_list args;

    /* format the caller's message and its arguments */
    va_start(args, msg);
    t3vsprintf(buf, sizeof(buf), msg, args);
    va_end(args);

    /* display the message with the source name and line number */
    err_msg("%s (%lu): %s", lib_name_, linenum_, buf);
}
Ejemplo n.º 6
0
    /* append text to a buffer, with sprintf-style formatting */
    void vappendf(const char *fmt, va_list argp)
    {
        /* calculate the amount of space we need */
        int plen = t3vsprintf(0, 0, fmt, argp);

        /* if that worked, format the data */
        if (plen >= 0)
        {
            /* reserve the required space */
            reserve(plen);

            /* format the text */
            int plen = t3vsprintf(buf + wrtidx, len - wrtidx, fmt, argp);

            /* if that worked, advance the buffer pointers */
            if (plen >= 0)
                wrtidx += plen;

            /* null-terminate at the new length in any case */
            buf[wrtidx] = '\0';
        }
    }
Ejemplo n.º 7
0
/*
 *   display a message - internal interface; this routine formats the
 *   message and converts it to the console character set for display 
 */
void CTcHostIfcStdio::v_printf(const char *msg, va_list args)
{
    char buf[1024];
    
    /* format the message to our internal buffer */
    t3vsprintf(buf, sizeof(buf), msg, args);

    /* translate to the local character set if we have a mapper */
    if (G_tcmain->get_console_mapper() != 0)
    {
        char xlat_buf[1024];
        utf8_ptr p;
        size_t len;

        /* translate it */
        p.set(buf);
        len = G_tcmain->get_console_mapper()
              ->map_utf8z_esc(xlat_buf, sizeof(xlat_buf), p,
                              &CCharmapToLocal::source_esc_cb);

        /* if there's room, null-terminate the buffer */
        if (len < sizeof(xlat_buf))
            xlat_buf[len] = '\0';
        
        /* display it on the standard output */
        printf("%s", xlat_buf);
    }
    else
    {
        /* there's no character mapper - display the untranslated buffer */
        printf("%s", buf);
    }

    /* 
     *   Flush the standard output immediately.  If our output is being
     *   redirected to a pipe that another program is reading, this will
     *   ensure that the other program will see our output as soon as we
     *   produce it, which might be important in some cases.  In any case,
     *   we don't generally produce so much console output that this should
     *   significantly affect performance.  
     */
    fflush(stdout);
}