source: libcaca/trunk/cucul/legacy.c @ 1347

Last change on this file since 1347 was 1347, checked in by Sam Hocevar, 14 years ago
  • Rename cucul_put*() into cucul_put_*(). Updated all code to reflect that.
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/*
2 *  libcucul      Canvas for ultrafast compositing of Unicode letters
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: legacy.c 1347 2006-11-11 16:29:39Z sam $
7 *
8 *  This library is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14/*
15 *  This file contains legacy functions that we keep around until all
16 *  applications are ported.
17 */
18
19#include "config.h"
20#include "common.h"
21
22#if !defined(__KERNEL__)
23#   if defined(HAVE_ERRNO_H)
24#       include <errno.h>
25#   endif
26#   include <stdio.h>
27#   include <stdlib.h>
28#   include <string.h>
29#endif
30
31#include "cucul.h"
32#include "cucul_internals.h"
33
34/*
35 * Functions from canvas.c
36 */
37
38int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
39{
40    return cucul_put_char(cv, x, y, ch);
41}
42
43int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
44{
45    return cucul_put_str(cv, x, y, s);
46}
47
48/*
49 * Functions from color.c
50 */
51
52int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
53{
54    return cucul_set_color_ansi(cv, fg, bg);
55}
56
57int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
58{
59    return cucul_set_color_argb(cv, fg, bg);
60}
61
62/*
63 * Functions from import.c
64 */
65
66cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
67{
68    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
69    int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
70                                  buf->size, format);
71    if(ret < 0)
72    {
73        cucul_free_canvas(cv);
74        return NULL;
75    }
76
77    return cv;
78}
79
80/*
81 * Functions from export.c
82 */
83
84cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
85{
86    cucul_buffer_t *ex;
87
88    ex = malloc(sizeof(cucul_buffer_t));
89    if(!ex)
90    {
91#if defined(HAVE_ERRNO_H)
92        errno = ENOMEM;
93#endif
94        return NULL;
95    }
96
97    ex->data = cucul_export_memory(cv, format, &ex->size);
98    if(!ex->data)
99    {
100        free(ex);
101        return NULL;
102    }
103
104    ex->user_data = 0;
105
106    return ex;
107}
108
109/*
110 * Functions from buffer.c
111 */
112
113cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
114{
115    cucul_buffer_t *buf;
116
117    buf = malloc(sizeof(cucul_buffer_t));
118    if(!buf)
119        return NULL;
120
121    buf->data = data;
122    buf->size = size;
123    buf->user_data = 1;
124
125    return buf;
126}
127
128#if !defined(__KERNEL__)
129cucul_buffer_t *cucul_load_file(char const *file)
130{
131    cucul_buffer_t *buf;
132    FILE *fp;
133    long int size;
134
135    fp = fopen(file, "rb");
136    if(!fp)
137        return NULL;
138
139    buf = malloc(sizeof(cucul_buffer_t));
140    if(!buf)
141    {
142        fclose(fp);
143        return NULL;
144    }
145
146    fseek(fp, 0, SEEK_END);
147    size = ftell(fp);
148
149    buf->data = malloc(size);
150    if(!buf->data)
151    {
152        free(buf);
153        fclose(fp);
154        return NULL;
155    }
156    buf->size = size;
157    buf->user_data = 0;
158
159    fseek(fp, 0, SEEK_SET);
160    fread(buf->data, buf->size, 1, fp);
161    fclose(fp);
162
163    return buf;
164}
165#endif
166
167unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
168{
169    return buf->size;
170}
171
172void * cucul_get_buffer_data(cucul_buffer_t *buf)
173{
174    return buf->data;
175}
176
177int cucul_free_buffer(cucul_buffer_t *buf)
178{
179    if(!buf->user_data)
180        free(buf->data);
181
182    free(buf);
183
184    return 0;
185}
186
Note: See TracBrowser for help on using the repository browser.