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

Last change on this file since 1362 was 1362, checked in by Sam Hocevar, 14 years ago
  • Got rid of HAVE_ERRNO_H ifdefs by defining seterrno()/geterrno() functions.
  • More debugging information in the import/export and font functions.
  • 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 1362 2006-11-12 15:26:13Z 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
40int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
41{
42    return cucul_put_str(cv, x, y, s);
43}
44
45/*
46 * Functions from color.c
47 */
48
49int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
50{
51    return cucul_set_color_ansi(cv, fg, bg);
52}
53
54int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
55{
56    return cucul_set_color_argb(cv, fg, bg);
57}
58
59/*
60 * Functions from import.c
61 */
62
63cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
64{
65    cucul_canvas_t *cv = cucul_create_canvas(0, 0);
66    int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
67                                  buf->size, format);
68    if(ret < 0)
69    {
70        cucul_free_canvas(cv);
71        return NULL;
72    }
73
74    return cv;
75}
76
77/*
78 * Functions from export.c
79 */
80
81cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
82{
83    cucul_buffer_t *ex;
84
85    ex = malloc(sizeof(cucul_buffer_t));
86    if(!ex)
87    {
88        seterrno(ENOMEM);
89        return NULL;
90    }
91
92    ex->data = cucul_export_memory(cv, format, &ex->size);
93    if(!ex->data)
94    {
95        free(ex);
96        return NULL;
97    }
98
99    ex->user_data = 0;
100
101    return ex;
102}
103
104/*
105 * Functions from buffer.c
106 */
107
108cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
109{
110    cucul_buffer_t *buf;
111
112    buf = malloc(sizeof(cucul_buffer_t));
113    if(!buf)
114        return NULL;
115
116    buf->data = data;
117    buf->size = size;
118    buf->user_data = 1;
119
120    return buf;
121}
122
123#if !defined(__KERNEL__)
124cucul_buffer_t *cucul_load_file(char const *file)
125{
126    cucul_buffer_t *buf;
127    FILE *fp;
128    long int size;
129
130    fp = fopen(file, "rb");
131    if(!fp)
132        return NULL;
133
134    buf = malloc(sizeof(cucul_buffer_t));
135    if(!buf)
136    {
137        fclose(fp);
138        return NULL;
139    }
140
141    fseek(fp, 0, SEEK_END);
142    size = ftell(fp);
143
144    buf->data = malloc(size);
145    if(!buf->data)
146    {
147        free(buf);
148        fclose(fp);
149        return NULL;
150    }
151    buf->size = size;
152    buf->user_data = 0;
153
154    fseek(fp, 0, SEEK_SET);
155    fread(buf->data, buf->size, 1, fp);
156    fclose(fp);
157
158    return buf;
159}
160#endif
161
162unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
163{
164    return buf->size;
165}
166
167void * cucul_get_buffer_data(cucul_buffer_t *buf)
168{
169    return buf->data;
170}
171
172int cucul_free_buffer(cucul_buffer_t *buf)
173{
174    if(!buf->user_data)
175        free(buf->data);
176
177    free(buf);
178
179    return 0;
180}
181
Note: See TracBrowser for help on using the repository browser.