Changeset 2988 for toilet


Ignore:
Timestamp:
Oct 18, 2008, 11:36:17 PM (15 years ago)
Author:
Sam Hocevar
Message:

Port toilet to the unified libcaca 0.99.beta15 API.

Location:
toilet/trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/configure.ac

    r2537 r2988  
    5252
    5353CUCUL="no"
    54 PKG_CHECK_MODULES(CUCUL, cucul >= 0.99.beta14,
     54PKG_CHECK_MODULES(CACA, caca >= 0.99.beta15,
    5555 [CUCUL="yes"],
    5656 [AC_MSG_RESULT(no)
    57   AC_MSG_ERROR([you need libcucul version 0.99.beta14 or later])])
     57  AC_MSG_ERROR([you need libcaca version 0.99.beta15 or later])])
    5858
    5959AC_MSG_CHECKING([for release date])
  • toilet/trunk/doc/toilet.1.in

    r1403 r2988  
    123123such as XTerm or rxvt.
    124124.I <format>
    125 is the name of the export format as recognised by libcucul. The special
     125is the name of the export format as recognised by libcaca. The special
    126126argument
    127127.I list
  • toilet/trunk/src/Makefile.am

    r2420 r2988  
    88        term.c figlet.c
    99toilet_CPPFLAGS = -DFONTDIR=\"$(datadir)/figlet\"
    10 toilet_CFLAGS = @CUCUL_CFLAGS@
    11 toilet_LDADD = @CUCUL_LIBS@ @GETOPT_LIBS@ @ZLIB_LIBS@
     10toilet_CFLAGS = @CACA_CFLAGS@
     11toilet_LDADD = @CACA_LIBS@ @GETOPT_LIBS@ @ZLIB_LIBS@
    1212
  • toilet/trunk/src/export.c

    r1461 r2988  
    2525#include <stdio.h>
    2626#include <stdlib.h>
    27 #include <cucul.h>
     27#include <caca.h>
    2828
    2929#include "toilet.h"
     
    3636    printf("Available export formats:\n");
    3737
    38     exports = cucul_get_export_list();
     38    exports = caca_get_export_list();
    3939    for(p = exports; *p; p += 2)
    4040        printf("\"%s\": %s\n", *p, *(p + 1));
     
    4949    cx->export = format;
    5050
    51     exports = cucul_get_export_list();
     51    exports = caca_get_export_list();
    5252    for(p = exports; *p; p += 2)
    5353        if(!strcmp(*p, format))
  • toilet/trunk/src/figlet.c

    r2420 r2988  
    2525#include <stdlib.h>
    2626#include <string.h>
    27 #include <cucul.h>
     27#include <caca.h>
    2828
    2929#include "toilet.h"
     
    4242
    4343    snprintf(path, 2047, "%s/%s", cx->dir, cx->font);
    44     if(cucul_canvas_set_figfont(cx->cv, path))
     44    if(caca_canvas_set_figfont(cx->cv, path))
    4545        return -1;
    4646
     
    5454static int feed_figlet(context_t *cx, uint32_t ch, uint32_t attr)
    5555{
    56     return cucul_put_figchar(cx->cv, ch);
     56    return caca_put_figchar(cx->cv, ch);
    5757}
    5858
    5959static int flush_figlet(context_t *cx)
    6060{
    61     int ret = cucul_flush_figlet(cx->cv);
     61    int ret = caca_flush_figlet(cx->cv);
    6262    cx->torender = cx->cv;
    63     cx->cv = cucul_create_canvas(0, 0);
     63    cx->cv = caca_create_canvas(0, 0);
    6464    return ret;
    6565}
     
    6767static int end_figlet(context_t *cx)
    6868{
    69     return cucul_canvas_set_figfont(cx->cv, NULL);
     69    return caca_canvas_set_figfont(cx->cv, NULL);
    7070}
    7171
  • toilet/trunk/src/filter.c

    r1831 r2988  
    2525#include <stdio.h>
    2626#include <stdlib.h>
    27 #include <cucul.h>
     27#include <caca.h>
    2828
    2929#include "toilet.h"
     
    130130    unsigned int xmin, xmax, ymin, ymax;
    131131
    132     xmin = w = cucul_get_canvas_width(cx->torender);
     132    xmin = w = caca_get_canvas_width(cx->torender);
    133133    xmax = 0;
    134     ymin = h = cucul_get_canvas_height(cx->torender);
     134    ymin = h = caca_get_canvas_height(cx->torender);
    135135    ymax = 0;
    136136
     
    138138        for(x = 0; x < w; x++)
    139139    {
    140         unsigned long int ch = cucul_get_char(cx->torender, x, y);
     140        unsigned long int ch = caca_get_char(cx->torender, x, y);
    141141        if(ch != (unsigned char)' ')
    142142        {
     
    155155        return;
    156156
    157     cucul_set_canvas_boundaries(cx->torender, xmin, ymin,
     157    caca_set_canvas_boundaries(cx->torender, xmin, ymin,
    158158                                xmax - xmin + 1, ymax - ymin + 1);
    159159}
     
    163163    static unsigned char const palette[] =
    164164    {
    165         CUCUL_LIGHTBLUE, CUCUL_BLUE, CUCUL_LIGHTGRAY, CUCUL_DARKGRAY,
     165        CACA_LIGHTBLUE, CACA_BLUE, CACA_LIGHTGRAY, CACA_DARKGRAY,
    166166    };
    167167
    168168    unsigned int x, y, w, h;
    169169
    170     w = cucul_get_canvas_width(cx->torender);
    171     h = cucul_get_canvas_height(cx->torender);
     170    w = caca_get_canvas_width(cx->torender);
     171    h = caca_get_canvas_height(cx->torender);
    172172
    173173    for(y = 0; y < h; y++)
    174174        for(x = 0; x < w; x++)
    175175    {
    176         unsigned long int ch = cucul_get_char(cx->torender, x, y);
     176        unsigned long int ch = caca_get_char(cx->torender, x, y);
    177177        int i;
    178178
     
    181181
    182182        i = ((cx->lines + y + x / 8) / 2) % 4;
    183         cucul_set_color_ansi(cx->torender, palette[i], CUCUL_TRANSPARENT);
    184         cucul_put_char(cx->torender, x, y, ch);
     183        caca_set_color_ansi(cx->torender, palette[i], CACA_TRANSPARENT);
     184        caca_put_char(cx->torender, x, y, ch);
    185185    }
    186186}
     
    190190    static unsigned char const rainbow[] =
    191191    {
    192         CUCUL_LIGHTMAGENTA, CUCUL_LIGHTRED, CUCUL_YELLOW,
    193         CUCUL_LIGHTGREEN, CUCUL_LIGHTCYAN, CUCUL_LIGHTBLUE,
     192        CACA_LIGHTMAGENTA, CACA_LIGHTRED, CACA_YELLOW,
     193        CACA_LIGHTGREEN, CACA_LIGHTCYAN, CACA_LIGHTBLUE,
    194194    };
    195195    unsigned int x, y, w, h;
    196196
    197     w = cucul_get_canvas_width(cx->torender);
    198     h = cucul_get_canvas_height(cx->torender);
     197    w = caca_get_canvas_width(cx->torender);
     198    h = caca_get_canvas_height(cx->torender);
    199199
    200200    for(y = 0; y < h; y++)
    201201        for(x = 0; x < w; x++)
    202202    {
    203         unsigned long int ch = cucul_get_char(cx->torender, x, y);
     203        unsigned long int ch = caca_get_char(cx->torender, x, y);
    204204        if(ch != (unsigned char)' ')
    205205        {
    206             cucul_set_color_ansi(cx->torender,
     206            caca_set_color_ansi(cx->torender,
    207207                                 rainbow[(x / 2 + y + cx->lines) % 6],
    208                                  CUCUL_TRANSPARENT);
    209             cucul_put_char(cx->torender, x, y, ch);
     208                                 CACA_TRANSPARENT);
     209            caca_put_char(cx->torender, x, y, ch);
    210210        }
    211211    }
     
    214214static void filter_flip(context_t *cx)
    215215{
    216     cucul_flip(cx->torender);
     216    caca_flip(cx->torender);
    217217}
    218218
    219219static void filter_flop(context_t *cx)
    220220{
    221     cucul_flop(cx->torender);
     221    caca_flop(cx->torender);
    222222}
    223223
    224224static void filter_180(context_t *cx)
    225225{
    226     cucul_rotate_180(cx->torender);
     226    caca_rotate_180(cx->torender);
    227227}
    228228
    229229static void filter_left(context_t *cx)
    230230{
    231     cucul_rotate_left(cx->torender);
     231    caca_rotate_left(cx->torender);
    232232}
    233233
    234234static void filter_right(context_t *cx)
    235235{
    236     cucul_rotate_right(cx->torender);
    237 }
    238 
     236    caca_rotate_right(cx->torender);
     237}
     238
  • toilet/trunk/src/main.c

    r1461 r2988  
    3131#include <stdlib.h>
    3232#include <string.h>
    33 #include <cucul.h>
     33#include <caca.h>
    3434
    3535#include "toilet.h"
  • toilet/trunk/src/render.c

    r2419 r2988  
    2525#include <string.h>
    2626#include <stdio.h>
    27 #include <cucul.h>
     27#include <caca.h>
    2828
    2929#include "toilet.h"
     
    3838    cx->w = cx->h = 0;
    3939    cx->lines = 0;
    40     cx->cv = cucul_create_canvas(0, 0);
     40    cx->cv = caca_create_canvas(0, 0);
    4141
    4242    if(!strcasecmp(cx->font, "term"))
     
    4848int render_stdin(context_t *cx)
    4949{
    50     cucul_canvas_t *cv;
     50    caca_canvas_t *cv;
    5151    char *line;
    5252    int i, len;
     
    5555    len = 1024;
    5656    line = malloc(len);
    57     cv = cucul_create_canvas(0, 0);
     57    cv = caca_create_canvas(0, 0);
    5858
    5959    /* Read from stdin */
     
    6363            break;
    6464
    65         cucul_set_canvas_size(cv, 0, 0);
    66         cucul_import_memory(cv, line, strlen(line), "utf8");
    67         for(i = 0; i < cucul_get_canvas_width(cv); i++)
     65        caca_set_canvas_size(cv, 0, 0);
     66        caca_import_memory(cv, line, strlen(line), "utf8");
     67        for(i = 0; i < caca_get_canvas_width(cv); i++)
    6868        {
    69             uint32_t ch = cucul_get_char(cv, i, 0);
    70             uint32_t at = cucul_get_attr(cv, i, 0);
     69            uint32_t ch = caca_get_char(cv, i, 0);
     70            uint32_t at = caca_get_attr(cv, i, 0);
    7171            cx->feed(cx, ch, at);
    72             if(cucul_utf32_is_fullwidth(ch)) i++;
     72            if(caca_utf32_is_fullwidth(ch)) i++;
    7373        }
    7474
     
    8383int render_list(context_t *cx, int argc, char *argv[])
    8484{
    85     cucul_canvas_t *cv;
     85    caca_canvas_t *cv;
    8686    int i, j, len;
    8787    char *parser = NULL;
    8888
    89     cv = cucul_create_canvas(0, 0);
     89    cv = caca_create_canvas(0, 0);
    9090
    9191    for(j = 0; j < argc; )
     
    106106            len = strlen(parser);
    107107
    108         cucul_set_canvas_size(cv, 0, 0);
    109         cucul_import_memory(cv, parser, len, "utf8");
    110         for(i = 0; i < cucul_get_canvas_width(cv); i++)
     108        caca_set_canvas_size(cv, 0, 0);
     109        caca_import_memory(cv, parser, len, "utf8");
     110        for(i = 0; i < caca_get_canvas_width(cv); i++)
    111111        {
    112             uint32_t ch = cucul_get_char(cv, i, 0);
    113             uint32_t at = cucul_get_attr(cv, i, 0);
     112            uint32_t ch = caca_get_char(cv, i, 0);
     113            uint32_t at = caca_get_attr(cv, i, 0);
    114114            cx->feed(cx, ch, at);
    115             if(cucul_utf32_is_fullwidth(ch)) i++;
     115            if(caca_utf32_is_fullwidth(ch)) i++;
    116116        }
    117117
     
    130130    render_flush(cx);
    131131
    132     cucul_free_canvas(cv);
     132    caca_free_canvas(cv);
    133133
    134134    return 0;
     
    138138{
    139139    cx->end(cx);
    140     cucul_free_canvas(cx->cv);
     140    caca_free_canvas(cx->cv);
    141141
    142142    return 0;
     
    157157
    158158    /* Output line */
    159     buffer = cucul_export_memory(cx->torender, cx->export, &len);
     159    buffer = caca_export_memory(cx->torender, cx->export, &len);
    160160    if(!buffer)
    161161        return -1;
    162162    fwrite(buffer, len, 1, stdout);
    163163    free(buffer);
    164     cucul_free_canvas(cx->torender);
     164    caca_free_canvas(cx->torender);
    165165
    166166    return 0;
  • toilet/trunk/src/term.c

    r1461 r2988  
    2323#endif
    2424#include <stdlib.h>
    25 #include <cucul.h>
     25#include <caca.h>
    2626
    2727#include "toilet.h"
     
    8181    }
    8282
    83     cucul_set_attr(cx->cv, attr);
    84     cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);
     83    caca_set_attr(cx->cv, attr);
     84    caca_set_canvas_size(cx->cv, cx->ew, cx->eh);
    8585
    86     cucul_put_char(cx->cv, cx->x, cx->y, ch);
     86    caca_put_char(cx->cv, cx->x, cx->y, ch);
    8787    cx->x++;
    8888
     
    9393{
    9494    cx->torender = cx->cv;
    95     cucul_set_canvas_size(cx->torender, cx->w, cx->h);
     95    caca_set_canvas_size(cx->torender, cx->w, cx->h);
    9696
    9797    cx->ew = 16;
     
    9999    cx->x = cx->y = 0;
    100100    cx->w = cx->h = 0;
    101     cx->cv = cucul_create_canvas(cx->ew, cx->eh);
     101    cx->cv = caca_create_canvas(cx->ew, cx->eh);
    102102
    103103    return 0;
  • toilet/trunk/src/toilet.h

    r1461 r2988  
    2525    unsigned int term_width;
    2626
    27     cucul_canvas_t *cv;
    28     cucul_canvas_t *torender;
     27    caca_canvas_t *cv;
     28    caca_canvas_t *torender;
    2929    unsigned int w, h, ew, eh, x, y, lines;
    3030
     
    4242    unsigned int print_direction, full_layout, codetag_count;
    4343    unsigned int glyphs;
    44     cucul_canvas_t *fontcv, *charcv;
     44    caca_canvas_t *fontcv, *charcv;
    4545    int *left, *right; /* Unused yet */
    4646    unsigned int *lookup;
  • toilet/trunk/tools/Makefile.am

    r1468 r2988  
    44
    55caca2tlf_SOURCES = caca2tlf.c
    6 caca2tlf_CFLAGS = @CUCUL_CFLAGS@
    7 caca2tlf_LDADD = @CUCUL_LIBS@
     6caca2tlf_CFLAGS = @CACA_CFLAGS@
     7caca2tlf_LDADD = @CACA_LIBS@
    88
  • toilet/trunk/tools/caca2tlf.c

    r2415 r2988  
    2525#include <string.h>
    2626#include <stdlib.h>
    27 #include <cucul.h>
     27#include <caca.h>
    2828
    2929enum mode { GRAY, HALFBLOCKS, QUARTERBLOCKS } mode;
     
    3232static void add_char(unsigned long int);
    3333
    34 cucul_font_t *f;
    35 cucul_canvas_t *out, *onechar;
     34caca_font_t *f;
     35caca_canvas_t *out, *onechar;
    3636uint32_t const *blocks;
    3737uint8_t * image;
     
    6969    }
    7070
    71     f = cucul_load_font(fontname, 0);
     71    f = caca_load_font(fontname, 0);
    7272
    7373    if(!f)
     
    7878    }
    7979
    80     w = cucul_get_font_width(f);
    81     h = cucul_get_font_height(f);
     80    w = caca_get_font_width(f);
     81    h = caca_get_font_height(f);
    8282    iw = w * 2 + 1;
    8383    ih = h + 1;
     
    101101    }
    102102
    103     blocks = cucul_get_font_blocks(f);
    104     onechar = cucul_create_canvas(0, 0);
    105     cucul_set_color_ansi(onechar, CUCUL_WHITE, CUCUL_BLACK);
     103    blocks = caca_get_font_blocks(f);
     104    onechar = caca_create_canvas(0, 0);
     105    caca_set_color_ansi(onechar, CACA_WHITE, CACA_BLACK);
    106106    image = malloc(4 * iw * ih);
    107107
    108     out = cucul_create_canvas(0, 0);
     108    out = caca_create_canvas(0, 0);
    109109    printf("tlf2a$ %u %u %u -1 4 0 0 0\n", gh, gh - 1, fgw + 2);
    110110
     
    141141                continue;
    142142
    143             len = cucul_utf32_to_utf8(buf, ch);
     143            len = caca_utf32_to_utf8(buf, ch);
    144144            buf[len] = '\0';
    145145            printf("0x%.04lX %s\n", ch, buf);
     
    148148    }
    149149
    150     cucul_free_canvas(out);
    151     cucul_free_canvas(onechar);
     150    caca_free_canvas(out);
     151    caca_free_canvas(onechar);
    152152    free(image);
    153     cucul_free_font(f);
     153    caca_free_font(f);
    154154
    155155    return 0;
     
    163163    fprintf(stderr, "Available fonts:\n");
    164164
    165     fonts = cucul_get_font_list();
     165    fonts = caca_get_font_list();
    166166    for(i = 0; fonts[i]; i++)
    167167        fprintf(stderr, "  \"%s\"\n", fonts[i]);
     
    173173    unsigned long int len;
    174174    unsigned int x, y, myw, mygw;
    175     int full = cucul_utf32_is_fullwidth(ch);
    176 
    177     cucul_set_canvas_size(onechar, full ? 2 : 1, 1);
    178     cucul_put_char(onechar, 0, 0, ch);
    179     cucul_render_canvas(onechar, f, image, iw, ih, 4 * iw);
     175    int full = caca_utf32_is_fullwidth(ch);
     176
     177    caca_set_canvas_size(onechar, full ? 2 : 1, 1);
     178    caca_put_char(onechar, 0, 0, ch);
     179    caca_render_canvas(onechar, f, image, iw, ih, 4 * iw);
    180180
    181181    myw = full ? 2 * w : w;
    182182    mygw = full ? fgw : gw;
    183183
    184     cucul_set_canvas_size(out, (full ? fgw : gw) + 2, gh);
     184    caca_set_canvas_size(out, (full ? fgw : gw) + 2, gh);
    185185
    186186    switch(mode)
     
    193193
    194194            if(c >= 0xa0)
    195                 cucul_put_str(out, x, y, "█");
     195                caca_put_str(out, x, y, "█");
    196196            else if(c >= 0x80)
    197                 cucul_put_str(out, x, y, "▓");
     197                caca_put_str(out, x, y, "▓");
    198198            else if(c >= 0x40)
    199                 cucul_put_str(out, x, y, "▒");
     199                caca_put_str(out, x, y, "▒");
    200200            else if(c >= 0x20)
    201                 cucul_put_str(out, x, y, "░");
     201                caca_put_str(out, x, y, "░");
    202202            else
    203                 cucul_put_char(out, x, y, ' ');
     203                caca_put_char(out, x, y, ' ');
    204204        }
    205205        break;
     
    213213            uint8_t p2 = image[4 * (x + (y * 2 + 1) * iw) + 2];
    214214
    215             cucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);
     215            caca_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80)]);
    216216        }
    217217        break;
     
    231231            uint8_t p4 = image[4 * (x * 2 + 1 + (y * 2 + 1) * iw) + 2];
    232232
    233             cucul_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +
     233            caca_put_str(out, x, y, str[(p1 > 0x80) + 2 * (p2 > 0x80) +
    234234                                         4 * (p3 > 0x80) + 8 * (p4 > 0x80)]);
    235235        }
     
    239239    if(ch == ' ' || ch == 0xa0)
    240240    {
    241         cucul_draw_line(out, mygw - 1, 0, mygw - 1, gh - 1, '$');
    242         cucul_draw_line(out, mygw / 2, 0, mygw / 2, gh - 1, '$');
    243     }
    244 
    245     cucul_draw_line(out, mygw, 0, mygw, gh - 1, '@');
    246     cucul_put_char(out, mygw + 1, gh - 1, '@');
    247 
    248     buf = cucul_export_memory(out, "utf8", &len);
     241        caca_draw_line(out, mygw - 1, 0, mygw - 1, gh - 1, '$');
     242        caca_draw_line(out, mygw / 2, 0, mygw / 2, gh - 1, '$');
     243    }
     244
     245    caca_draw_line(out, mygw, 0, mygw, gh - 1, '@');
     246    caca_put_char(out, mygw + 1, gh - 1, '@');
     247
     248    buf = caca_export_memory(out, "utf8", &len);
    249249    fwrite(buf, len, 1, stdout);
    250250    free(buf);
Note: See TracChangeset for help on using the changeset viewer.