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

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