Ignore:
Timestamp:
Nov 8, 2006, 1:11:07 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Deprecate buffer management. We're back to standard void* memory areas.
File:
1 moved

Legend:

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

    r1301 r1302  
    1313
    1414/*
    15  *  This file contains buffer handling functions.
     15 *  This file contains legacy functions that we keep around until all
     16 *  applications are ported.
    1617 */
    1718
     
    2021
    2122#if !defined(__KERNEL__)
     23#   if defined(HAVE_ERRNO_H)
     24#       include <errno.h>
     25#   endif
    2226#   include <stdio.h>
    2327#   include <stdlib.h>
     
    2832#include "cucul_internals.h"
    2933
    30 /** \brief Load a memory area into a buffer.
    31  *
    32  *  Create a \e libcucul buffer that points to the given memory area. The
    33  *  data is not duplicated and any changes made to the original memory area
    34  *  will appear in the buffer.
    35  *
    36  *  Keep in mind that buffers are not strings. When loading a C string, the
    37  *  terminating '\\0' must not be part of the buffer, hence \e size should
    38  *  be computed with strlen(). Conversely, the '\\0' is not appended to
    39  *  exported buffers even when they could be parsed as strings.
    40  *
    41  *  \param data The memory area to load.
    42  *  \param size The size of the memory area.
    43  *  \return A \e libcucul buffer pointing to the memory area, or NULL
    44  *          if an error occurred.
     34/*
     35 * Functions from color.c
    4536 */
     37
     38int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
     39{
     40    return cucul_set_color_ansi(cv, fg, bg);
     41}
     42
     43int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
     44{
     45    return cucul_set_color_argb(cv, fg, bg);
     46}
     47
     48/*
     49 * Functions from import.c
     50 */
     51
     52cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
     53{
     54    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
     55    int ret = cucul_import(cv, (unsigned char const *)buf->data,
     56                           buf->size, format);
     57    if(ret < 0)
     58    {
     59        cucul_free_canvas(cv);
     60        return NULL;
     61    }
     62
     63    return cv;
     64}
     65
     66/*
     67 * Functions from export.c
     68 */
     69
     70cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
     71{
     72    cucul_buffer_t *ex;
     73
     74    ex = malloc(sizeof(cucul_buffer_t));
     75    if(!ex)
     76    {
     77#if defined(HAVE_ERRNO_H)
     78        errno = ENOMEM;
     79#endif
     80        return NULL;
     81    }
     82
     83    ex->data = cucul_export(cv, format, &ex->size);
     84    if(!ex->data)
     85    {
     86        free(ex);
     87        return NULL;
     88    }
     89
     90    ex->user_data = 0;
     91
     92    return ex;
     93}
     94
     95/*
     96 * Functions from buffer.c
     97 */
     98
    4699cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
    47100{
     
    59112}
    60113
    61 /** \brief Load a file into a buffer.
    62  *
    63  *  Load a file into memory and returns a \e libcucul buffer for use with
    64  *  other functions.
    65  *
    66  *  \param file The filename
    67  *  \return A \e libcucul buffer containing the file's contents, or NULL
    68  *          if an error occurred.
    69  */
    70114#if !defined(__KERNEL__)
    71115cucul_buffer_t *cucul_load_file(char const *file)
     
    106150}
    107151#endif
    108 /** \brief Get the buffer size.
    109  *
    110  *  Return the length (in bytes) of the memory area stored in the given
    111  *  \e libcucul buffer.
    112  *
    113  *  This function never fails.
    114  *
    115  *  \param buf A \e libcucul buffer
    116  *  \return The buffer data length.
    117  */
     152
    118153unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
    119154{
     
    121156}
    122157
    123 /** \brief Get the buffer data.
    124  *
    125  *  Get a pointer to the memory area stored in the given
    126  *  \e libcucul buffer.
    127  *
    128  *  This function never fails.
    129  *
    130  *  \param buf A \e libcucul buffer
    131  *  \return A pointer to the buffer memory area.
    132  */
    133158void * cucul_get_buffer_data(cucul_buffer_t *buf)
    134159{
     
    136161}
    137162
    138 /** \brief Free a buffer.
    139  *
    140  *  Free the structures associated with the given \e libcucul buffer.
    141  *
    142  *  This function never fails.
    143  *
    144  *  \param buf A \e libcucul buffer
    145  *  \return This function always returns 0.
    146  */
    147163int cucul_free_buffer(cucul_buffer_t *buf)
    148164{
Note: See TracChangeset for help on using the changeset viewer.