Ignore:
Timestamp:
Sep 27, 2008, 3:12:46 PM (12 years ago)
Author:
Sam Hocevar
Message:

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

File:
1 copied

Legend:

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

    r2819 r2821  
    11/*
    2  *  libcucul      Canvas for ultrafast compositing of Unicode letters
     2 *  libcaca       Colour ASCII-Art library
    33 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
     
    3636#endif
    3737
    38 #include "cucul.h"
    39 #include "cucul_internals.h"
     38#include "caca.h"
     39#include "caca_internals.h"
    4040
    4141/** \brief Set cursor position.
     
    4747 *  This function never fails.
    4848 *
    49  *  \param cv A handle to the libcucul canvas.
     49 *  \param cv A handle to the libcaca canvas.
    5050 *  \param x X cursor coordinate.
    5151 *  \param y Y cursor coordinate.
    5252 *  \return This function always returns 0.
    5353 */
    54 int cucul_gotoxy(cucul_canvas_t *cv, int x, int y)
     54int caca_gotoxy(caca_canvas_t *cv, int x, int y)
    5555{
    5656    cv->frames[cv->frame].x = x;
     
    6666 *  This function never fails.
    6767 *
    68  *  \param cv A handle to the libcucul canvas.
     68 *  \param cv A handle to the libcaca canvas.
    6969 *  \return The cursor's X coordinate.
    7070 */
    71 int cucul_get_cursor_x(cucul_canvas_t const *cv)
     71int caca_get_cursor_x(caca_canvas_t const *cv)
    7272{
    7373    return cv->frames[cv->frame].x;
     
    8080 *  This function never fails.
    8181 *
    82  *  \param cv A handle to the libcucul canvas.
     82 *  \param cv A handle to the libcaca canvas.
    8383 *  \return The cursor's Y coordinate.
    8484 */
    85 int cucul_get_cursor_y(cucul_canvas_t const *cv)
     85int caca_get_cursor_y(caca_canvas_t const *cv)
    8686{
    8787    return cv->frames[cv->frame].y;
     
    100100 *  The behaviour when printing non-printable characters or invalid UTF-32
    101101 *  characters is undefined. To print a sequence of bytes forming an UTF-8
    102  *  character instead of an UTF-32 character, use the cucul_put_str() function.
    103  *
    104  *  This function never fails.
    105  *
    106  *  \param cv A handle to the libcucul canvas.
     102 *  character instead of an UTF-32 character, use the caca_put_str() function.
     103 *
     104 *  This function never fails.
     105 *
     106 *  \param cv A handle to the libcaca canvas.
    107107 *  \param x X coordinate.
    108108 *  \param y Y coordinate.
     
    110110 *  \return This function always returns 0.
    111111 */
    112 int cucul_put_char(cucul_canvas_t *cv, int x, int y, uint32_t ch)
     112int caca_put_char(caca_canvas_t *cv, int x, int y, uint32_t ch)
    113113{
    114114    uint32_t *curchar, *curattr, attr;
     
    118118        return 0;
    119119
    120     if(ch == CUCUL_MAGIC_FULLWIDTH)
     120    if(ch == CACA_MAGIC_FULLWIDTH)
    121121        return 0;
    122122
    123     fullwidth = cucul_utf32_is_fullwidth(ch);
     123    fullwidth = caca_utf32_is_fullwidth(ch);
    124124
    125125    if(x == -1 && fullwidth)
     
    138138    /* When overwriting the right part of a fullwidth character,
    139139     * replace its left part with a space. */
    140     if(x && curchar[0] == CUCUL_MAGIC_FULLWIDTH)
     140    if(x && curchar[0] == CACA_MAGIC_FULLWIDTH)
    141141        curchar[-1] = ' ';
    142142
     
    149149            /* When overwriting the left part of a fullwidth character,
    150150             * replace its right part with a space. */
    151             if(x + 2 < (int)cv->width && curchar[2] == CUCUL_MAGIC_FULLWIDTH)
     151            if(x + 2 < (int)cv->width && curchar[2] == CACA_MAGIC_FULLWIDTH)
    152152                curchar[2] = ' ';
    153153
    154             curchar[1] = CUCUL_MAGIC_FULLWIDTH;
     154            curchar[1] = CACA_MAGIC_FULLWIDTH;
    155155            curattr[1] = attr;
    156156        }
     
    160160        /* When overwriting the left part of a fullwidth character,
    161161         * replace its right part with a space. */
    162         if(x + 1 != (int)cv->width && curchar[1] == CUCUL_MAGIC_FULLWIDTH)
     162        if(x + 1 != (int)cv->width && curchar[1] == CACA_MAGIC_FULLWIDTH)
    163163            curchar[1] = ' ';
    164164    }
     
    180180 *  is returned.
    181181 *
    182  *  A special exception is when CUCUL_MAGIC_FULLWIDTH is returned. This
     182 *  A special exception is when CACA_MAGIC_FULLWIDTH is returned. This
    183183 *  value is guaranteed not to be a valid Unicode character, and indicates
    184184 *  that the character at the left of the requested one is a fullwidth
     
    187187 *  This function never fails.
    188188 *
    189  *  \param cv A handle to the libcucul canvas.
     189 *  \param cv A handle to the libcaca canvas.
    190190 *  \param x X coordinate.
    191191 *  \param y Y coordinate.
    192192 *  \return This function always returns 0.
    193193 */
    194 uint32_t cucul_get_char(cucul_canvas_t const *cv, int x, int y)
     194uint32_t caca_get_char(caca_canvas_t const *cv, int x, int y)
    195195{
    196196    if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height)
     
    207207 *  be cropped accordingly if it is too long.
    208208 *
    209  *  See cucul_put_char() for more information on how fullwidth characters
     209 *  See caca_put_char() for more information on how fullwidth characters
    210210 *  are handled when overwriting each other or at the canvas' boundaries.
    211211 *
    212212 *  This function never fails.
    213213 *
    214  *  \param cv A handle to the libcucul canvas.
     214 *  \param cv A handle to the libcaca canvas.
    215215 *  \param x X coordinate.
    216216 *  \param y Y coordinate.
     
    218218 *  \return This function always returns 0.
    219219 */
    220 int cucul_put_str(cucul_canvas_t *cv, int x, int y, char const *s)
     220int caca_put_str(caca_canvas_t *cv, int x, int y, char const *s)
    221221{
    222222    size_t rd;
     
    227227    while(*s && x < -1)
    228228    {
    229         x += cucul_utf32_is_fullwidth(cucul_utf8_to_utf32(s, &rd)) ? 2 : 1;
     229        x += caca_utf32_is_fullwidth(caca_utf8_to_utf32(s, &rd)) ? 2 : 1;
    230230        s += rd;
    231231    }
     
    233233    while(*s && x < (int)cv->width)
    234234    {
    235         uint32_t ch = cucul_utf8_to_utf32(s, &rd);
    236         cucul_put_char(cv, x, y, ch);
    237         x += cucul_utf32_is_fullwidth(ch) ? 2 : 1;
     235        uint32_t ch = caca_utf8_to_utf32(s, &rd);
     236        caca_put_char(cv, x, y, ch);
     237        x += caca_utf32_is_fullwidth(ch) ? 2 : 1;
    238238        s += rd;
    239239    }
     
    252252 *  This function never fails.
    253253 *
    254  *  \param cv A handle to the libcucul canvas.
     254 *  \param cv A handle to the libcaca canvas.
    255255 *  \param x X coordinate.
    256256 *  \param y Y coordinate.
     
    259259 *  \return This function always returns 0.
    260260 */
    261 int cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...)
     261int caca_printf(caca_canvas_t *cv, int x, int y, char const *format, ...)
    262262{
    263263    char tmp[BUFSIZ];
     
    280280    va_end(args);
    281281
    282     cucul_put_str(cv, x, y, buf);
     282    caca_put_str(cv, x, y, buf);
    283283
    284284    if(buf != tmp)
     
    297297 *  \return This function always returns 0.
    298298 */
    299 int cucul_clear_canvas(cucul_canvas_t *cv)
     299int caca_clear_canvas(caca_canvas_t *cv)
    300300{
    301301    uint32_t attr = cv->curattr;
     
    318318 *  This function never fails.
    319319 *
    320  *  \param cv A handle to the libcucul canvas.
     320 *  \param cv A handle to the libcaca canvas.
    321321 *  \param x X handle coordinate.
    322322 *  \param y Y handle coordinate.
    323323 *  \return This function always returns 0.
    324324 */
    325 int cucul_set_canvas_handle(cucul_canvas_t *cv, int x, int y)
     325int caca_set_canvas_handle(caca_canvas_t *cv, int x, int y)
    326326{
    327327    cv->frames[cv->frame].handlex = x;
     
    337337 *  This function never fails.
    338338 *
    339  *  \param cv A handle to the libcucul canvas.
     339 *  \param cv A handle to the libcaca canvas.
    340340 *  \return The canvas' handle's X coordinate.
    341341 */
    342 int cucul_get_canvas_handle_x(cucul_canvas_t const *cv)
     342int caca_get_canvas_handle_x(caca_canvas_t const *cv)
    343343{
    344344    return cv->frames[cv->frame].handlex;
     
    351351 *  This function never fails.
    352352 *
    353  *  \param cv A handle to the libcucul canvas.
     353 *  \param cv A handle to the libcaca canvas.
    354354 *  \return The canvas' handle's Y coordinate.
    355355 */
    356 int cucul_get_canvas_handle_y(cucul_canvas_t const *cv)
     356int caca_get_canvas_handle_y(caca_canvas_t const *cv)
    357357{
    358358    return cv->frames[cv->frame].handley;
     
    375375 *  \return 0 in case of success, -1 if an error occurred.
    376376 */
    377 int cucul_blit(cucul_canvas_t *dst, int x, int y,
    378                cucul_canvas_t const *src, cucul_canvas_t const *mask)
     377int caca_blit(caca_canvas_t *dst, int x, int y,
     378               caca_canvas_t const *src, caca_canvas_t const *mask)
    379379{
    380380    int i, j, starti, startj, endi, endj;
     
    405405
    406406        /* FIXME: we are ignoring the mask here */
    407         if((starti + x) && dst->chars[dstix] == CUCUL_MAGIC_FULLWIDTH)
     407        if((starti + x) && dst->chars[dstix] == CACA_MAGIC_FULLWIDTH)
    408408            dst->chars[dstix - 1] = ' ';
    409409
    410410        if(endi + x < dst->width
    411                 && dst->chars[dstix + stride] == CUCUL_MAGIC_FULLWIDTH)
     411                && dst->chars[dstix + stride] == CACA_MAGIC_FULLWIDTH)
    412412            dst->chars[dstix + stride] = ' ';
    413413
     
    430430
    431431        /* Fix split fullwidth chars */
    432         if(src->chars[srcix] == CUCUL_MAGIC_FULLWIDTH)
     432        if(src->chars[srcix] == CACA_MAGIC_FULLWIDTH)
    433433            dst->chars[dstix] = ' ';
    434434
    435         if(endi < src->width && src->chars[endi] == CUCUL_MAGIC_FULLWIDTH)
     435        if(endi < src->width && src->chars[endi] == CACA_MAGIC_FULLWIDTH)
    436436            dst->chars[dstix + stride - 1] = ' ';
    437437    }
     
    459459 *  \return 0 in case of success, -1 if an error occurred.
    460460 */
    461 int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y, int w, int h)
    462 {
    463     cucul_canvas_t *new;
     461int caca_set_canvas_boundaries(caca_canvas_t *cv, int x, int y, int w, int h)
     462{
     463    caca_canvas_t *new;
    464464    int f, saved_f, framecount;
    465465
     
    476476    }
    477477
    478     new = cucul_create_canvas(w, h);
    479 
    480     framecount = cucul_get_frame_count(cv);
     478    new = caca_create_canvas(w, h);
     479
     480    framecount = caca_get_frame_count(cv);
    481481    saved_f = cv->frame;
    482482
     
    484484    {
    485485        if(f)
    486             cucul_create_frame(new, framecount);
    487 
    488         cucul_set_frame(cv, f);
    489         cucul_set_frame(new, f);
    490         cucul_blit(new, -x, -y, cv, NULL);
     486            caca_create_frame(new, framecount);
     487
     488        caca_set_frame(cv, f);
     489        caca_set_frame(new, f);
     490        caca_blit(new, -x, -y, cv, NULL);
    491491        free(cv->frames[f].chars);
    492492        free(cv->frames[f].attrs);
     
    497497    free(new);
    498498
    499     cucul_set_frame(cv, saved_f);
    500     _cucul_load_frame_info(cv);
    501    
    502     return 0;
    503 }
    504 
     499    caca_set_frame(cv, saved_f);
     500    _caca_load_frame_info(cv);
     501
     502    return 0;
     503}
     504
Note: See TracChangeset for help on using the changeset viewer.