Ignore:
Timestamp:
Apr 26, 2006, 1:54:26 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Implemented cucul_load_file() and cucul_load_memory() to load respectively a file and a memory area into a libcucul buffer.
  • Changed the cucul_import_canvas() prototype so that it uses libcucul buffers instead of simple memory areas.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/import.c

    r895 r896  
    4444 *  \li \c "caca": import native libcaca files.
    4545 *
    46  *  \param data The memory area to be loaded into a canvas.
     46 *  \param buffer A \e libcucul buffer containing the data to be loaded
     47 *         into a canvas.
    4748 *  \param size The length of the memory area.
    4849 *  \param format A string describing the input format.
    4950 *  \return A libcucul canvas, or NULL in case of error.
    5051 */
    51 cucul_canvas_t * cucul_import_canvas(void const *data, unsigned int size,
    52                                      char const *format)
    53 {
    54     char const *buf = (char const*) data;
    55 
    56     if(size==0 || data==NULL)
     52cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *b, char const *format)
     53{
     54    char const *buf = (char const*)b->data;
     55
     56    if(b->size == 0 || b->data == NULL)
    5757        return NULL;
    5858
    5959    if(!strcasecmp("caca", format))
    60         return import_caca(data, size);
     60        return import_caca(b->data, b->size);
    6161    if(!strcasecmp("text", format))
    62         return import_text(data, size);
     62        return import_text(b->data, b->size);
    6363    if(!strcasecmp("ansi", format))
    64         return import_ansi(data, size);
     64        return import_ansi(b->data, b->size);
    6565
    6666    /* Autodetection */
     
    6969        unsigned int i=0;
    7070        /* if 4 first letters are CACA */
    71         if(size >= 4 &&
     71        if(b->size >= 4 &&
    7272            buf[0] == 'C' && buf[1] == 'A' && buf[2] == 'C' && buf[3] != 'A')
    73             return import_caca(data, size);
     73            return import_caca(b->data, b->size);
    7474
    7575        /* If we find ESC[ argv, we guess it's an ANSI file */
    76         while(i<size-1)
     76        while(i < b->size - 1)
    7777        {
    7878            if((buf[i] == 0x1b) && (buf[i+1] == '['))
    79                 return import_ansi(data, size);
     79                return import_ansi(b->data, b->size);
    8080            i++;
    8181        }
    8282
    8383        /* Otherwise, import it as text */
    84         return import_text(data, size);
     84        return import_text(b->data, b->size);
    8585    }
    8686    return NULL;
Note: See TracChangeset for help on using the changeset viewer.