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

Last change on this file since 1366 was 1366, checked in by Sam Hocevar, 13 years ago
  • Re-added cucul_getchar() to the legacy functions. Debian's current version of toilet needs it.
  • Property svn:keywords set to Id
File size: 3.4 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 1366 2006-11-12 17:45:14Z 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 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.