Ignore:
Timestamp:
Mar 14, 2006, 11:05:34 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Replaced all cucul_get_* exporters with a generic cucul_export() function.
  • Got rid of static buffers; we now use cucul_free() to free exported buffers.
  • Fixed light background in the ANSI exporter by adding escape sequences for most terminal emulators.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver_network.c

    r605 r609  
    8686    char prefix[sizeof(INIT_PREFIX)];
    8787
    88     char *buffer;
    89     int size;
     88    struct cucul_buffer *ex;
    9089
    9190    int client_count;
     
    170169    }
    171170
    172     kk->drv.p->buffer = NULL;
    173     kk->drv.p->size = 0;
     171    kk->drv.p->ex = NULL;
    174172
    175173    /* Ignore SIGPIPE */
     
    192190    }
    193191
     192    if(kk->drv.p->ex)
     193        cucul_free(kk->drv.p->ex);
     194
    194195    /* Restore SIGPIPE handler */
    195196    signal(SIGPIPE, kk->drv.p->sigpipe_handler);
     
    220221    int i;
    221222
     223    /* Free the previous export buffer, if any */
     224    if(kk->drv.p->ex)
     225    {
     226        cucul_free(kk->drv.p->ex);
     227        kk->drv.p->ex = NULL;
     228    }
     229
    222230    /* Get ANSI representation of the image and skip the end-of buffer
    223231     * linefeed ("\r\n\0", 3 bytes) */
    224     kk->drv.p->buffer = cucul_get_ansi(kk->qq, 0, &kk->drv.p->size);
    225     kk->drv.p->size -= 3;
     232    kk->drv.p->ex = cucul_export(kk->qq, CUCUL_FORMAT_ANSI);
     233    kk->drv.p->ex->size -= 3;
    226234
    227235    for(i = 0; i < kk->drv.p->client_count; i++)
     
    371379
    372380    /* No error, there's just nothing to send yet */
    373     if(!kk->drv.p->buffer)
     381    if(!kk->drv.p->ex)
    374382        return 0;
    375383
     
    396404            c->start += ret;
    397405
    398             if(c->stop - c->start + strlen(ANSI_PREFIX) + kk->drv.p->size
     406            if(c->stop - c->start + strlen(ANSI_PREFIX) + kk->drv.p->ex->size
    399407                > OUTBUFFER)
    400408            {
     
    407415
    408416            /* Need to move? */
    409             if(c->stop + strlen(ANSI_PREFIX) + kk->drv.p->size > OUTBUFFER)
     417            if(c->stop + strlen(ANSI_PREFIX) + kk->drv.p->ex->size > OUTBUFFER)
    410418            {
    411419                memmove(c->outbuf, c->outbuf + c->start, c->stop - c->start);
     
    416424            memcpy(c->outbuf + c->stop, ANSI_PREFIX, strlen(ANSI_PREFIX));
    417425            c->stop += strlen(ANSI_PREFIX);
    418             memcpy(c->outbuf + c->stop, kk->drv.p->buffer, kk->drv.p->size);
    419             c->stop += kk->drv.p->size;
     426            memcpy(c->outbuf + c->stop, kk->drv.p->ex->buffer, kk->drv.p->ex->size);
     427            c->stop += kk->drv.p->ex->size;
    420428
    421429            return 0;
     
    437445    if(ret < (ssize_t)strlen(ANSI_PREFIX))
    438446    {
    439         if(strlen(ANSI_PREFIX) + kk->drv.p->size > OUTBUFFER)
     447        if(strlen(ANSI_PREFIX) + kk->drv.p->ex->size > OUTBUFFER)
    440448        {
    441449            /* Overflow! Empty buffer and start again */
     
    448456        memcpy(c->outbuf, ANSI_PREFIX, strlen(ANSI_PREFIX) - ret);
    449457        c->stop = strlen(ANSI_PREFIX) - ret;
    450         memcpy(c->outbuf + c->stop, kk->drv.p->buffer, kk->drv.p->size);
    451         c->stop += kk->drv.p->size;
     458        memcpy(c->outbuf + c->stop, kk->drv.p->ex->buffer, kk->drv.p->ex->size);
     459        c->stop += kk->drv.p->ex->size;
    452460
    453461        return 0;
     
    455463
    456464    /* Send actual data */
    457     ret = nonblock_write(c->fd, kk->drv.p->buffer, kk->drv.p->size);
     465    ret = nonblock_write(c->fd, kk->drv.p->ex->buffer, kk->drv.p->ex->size);
    458466    if(ret == -1)
    459467    {
     
    464472    }
    465473
    466     if(ret < kk->drv.p->size)
    467     {
    468         if(kk->drv.p->size > OUTBUFFER)
     474    if(ret < (int)kk->drv.p->ex->size)
     475    {
     476        if(kk->drv.p->ex->size > OUTBUFFER)
    469477        {
    470478            /* Overflow! Empty buffer and start again */
     
    475483        }
    476484
    477         memcpy(c->outbuf, kk->drv.p->buffer, kk->drv.p->size - ret);
    478         c->stop = kk->drv.p->size - ret;
     485        memcpy(c->outbuf, kk->drv.p->ex->buffer, kk->drv.p->ex->size - ret);
     486        c->stop = kk->drv.p->ex->size - ret;
    479487
    480488        return 0;
Note: See TracChangeset for help on using the changeset viewer.