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

Last change on this file since 1390 was 1390, checked in by Sam Hocevar, 13 years ago
  • Implemented cucul_get_frame_name() and cucul_set_frame_name().
  • Renamed cucul_*_canvas_frame() to cucul_*_frame() because we bloody well know that a frame belongs to a canvas.
  • Property svn:keywords set to Id
File size: 3.8 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 1390 2006-11-13 23:16:35Z 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#   include <stdio.h>
24#   include <stdlib.h>
25#   include <string.h>
26#endif
27
28#include "cucul.h"
29#include "cucul_internals.h"
30
31/*
32 * Functions from canvas.c
33 */
34
35int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
36{
37    return cucul_put_char(cv, x, y, ch);
38}
39
40unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y)
41{
42    return cucul_get_char(cv, x, y);
43}
44
45int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
46{
47    return cucul_put_str(cv, x, y, s);
48}
49
50/*
51 * Functions from color.c
52 */
53
54int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
55{
56    return cucul_set_color_ansi(cv, fg, bg);
57}
58
59int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
60{
61    return cucul_set_color_argb(cv, fg, bg);
62}
63
64/*
65 * Functions from import.c
66 */
67
68cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
69{
70    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
71    int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
72                                  buf->size, format);
73    if(ret < 0)
74    {
75        cucul_free_canvas(cv);
76        return NULL;
77    }
78
79    return cv;
80}
81
82/*
83 * Functions from export.c
84 */
85
86cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
87{
88    cucul_buffer_t *ex;
89
90    ex = malloc(sizeof(cucul_buffer_t));
91    if(!ex)
92    {
93        seterrno(ENOMEM);
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 frame.c
111 */
112
113unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
114{
115    return cucul_get_frame_count(cv);
116}
117
118int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
119{
120    return cucul_set_frame(cv, id);
121}
122
123int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
124{
125    return cucul_create_frame(cv, id);
126}
127
128int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
129{
130    return cucul_free_frame(cv, id);
131}
132
133/*
134 * Functions from buffer.c
135 */
136
137cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
138{
139    cucul_buffer_t *buf;
140
141    buf = malloc(sizeof(cucul_buffer_t));
142    if(!buf)
143        return NULL;
144
145    buf->data = data;
146    buf->size = size;
147    buf->user_data = 1;
148
149    return buf;
150}
151
152#if !defined(__KERNEL__)
153cucul_buffer_t *cucul_load_file(char const *file)
154{
155    cucul_buffer_t *buf;
156    FILE *fp;
157    long int size;
158
159    fp = fopen(file, "rb");
160    if(!fp)
161        return NULL;
162
163    buf = malloc(sizeof(cucul_buffer_t));
164    if(!buf)
165    {
166        fclose(fp);
167        return NULL;
168    }
169
170    fseek(fp, 0, SEEK_END);
171    size = ftell(fp);
172
173    buf->data = malloc(size);
174    if(!buf->data)
175    {
176        free(buf);
177        fclose(fp);
178        return NULL;
179    }
180    buf->size = size;
181    buf->user_data = 0;
182
183    fseek(fp, 0, SEEK_SET);
184    fread(buf->data, buf->size, 1, fp);
185    fclose(fp);
186
187    return buf;
188}
189#endif
190
191unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
192{
193    return buf->size;
194}
195
196void * cucul_get_buffer_data(cucul_buffer_t *buf)
197{
198    return buf->data;
199}
200
201int cucul_free_buffer(cucul_buffer_t *buf)
202{
203    if(!buf->user_data)
204        free(buf->data);
205
206    free(buf);
207
208    return 0;
209}
210
Note: See TracBrowser for help on using the repository browser.