ソースを参照

* Convert all programs and tests to the new import/export API.

tags/v0.99.beta14
Sam Hocevar sam 18年前
コミット
9621f21c5a
8個のファイルの変更50行の追加96行の削除
  1. +2
    -11
      src/cacadraw.c
  2. +3
    -14
      src/cacaplay.c
  3. +13
    -22
      src/cacaserver.c
  4. +5
    -5
      src/img2irc.c
  5. +7
    -15
      test/export.c
  6. +5
    -5
      test/font2tga.c
  7. +3
    -12
      test/import.c
  8. +12
    -12
      test/text.c

+ 2
- 11
src/cacadraw.c ファイルの表示

@@ -55,22 +55,13 @@ int main(int argc, char **argv)

if(!image)
{
cucul_buffer_t *b = cucul_load_file(argv[file]);
if(!b)
{
fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
return 1;
}

image = cucul_import_canvas(b, "ansi");
if(!image)
image = cucul_create_canvas(0, 0);
if(cucul_import_file(image, argv[file], "ansi") < 0)
{
fprintf(stderr, "%s: invalid file `%s'.\n", argv[0], argv[1]);
return 1;
}

cucul_free_buffer(b);

ih = cucul_get_canvas_height(image);
iw = cucul_get_canvas_width(image);
x = y = 0;


+ 3
- 14
src/cacaplay.c ファイルの表示

@@ -25,7 +25,6 @@
int main(int argc, char **argv)
{
caca_event_t ev;
cucul_buffer_t *b;
cucul_canvas_t *cv;
caca_display_t *dp;

@@ -35,23 +34,13 @@ int main(int argc, char **argv)
return 1;
}

b = cucul_load_file(argv[1]);
if(!b)
cv = cucul_create_canvas(0, 0);
if(cucul_import_file(cv, argv[1], "caca") < 0)
{
fprintf(stderr, "%s: could not open %s.\n", argv[0], argv[1]);
fprintf(stderr, "%s: could not import file %s.\n", argv[0], argv[1]);
return 1;
}

cv = cucul_import_canvas(b, "caca");
if(!cv)
{
fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
cucul_free_buffer(b);
return 1;
}

cucul_free_buffer(b);

dp = caca_create_display(cv);

caca_refresh_display(dp);


+ 13
- 22
src/cacaserver.c ファイルの表示

@@ -105,9 +105,8 @@ struct server
char prefix[sizeof(INIT_PREFIX)];

cucul_canvas_t *canvas;
cucul_buffer_t *buffer;
void *buffer;
unsigned long int buflen;
void *bufdata;

int client_count;
struct client *clients;
@@ -184,7 +183,7 @@ int main(void)
return -1;
}

server->canvas = NULL;
server->canvas = cucul_create_canvas(0, 0);
server->buffer = NULL;

/* Ignore SIGPIPE */
@@ -196,7 +195,6 @@ int main(void)
/* Main loop */
for(;;)
{
cucul_buffer_t *b;
uint8_t *buf = server->input;
uint32_t control_size, data_size;
unsigned int size;
@@ -224,29 +222,20 @@ int main(void)
buf = server->input = realloc(server->input, size);
read(0, buf + 12, size - 12);

/* Free the previous canvas, if any */
if(server->canvas)
cucul_free_canvas(server->canvas);

b = cucul_load_memory(buf, size);
server->canvas = cucul_import_canvas(b, "caca");
cucul_free_buffer(b);

if(!server->canvas)
if(cucul_import_memory(server->canvas, buf, size, "caca") < 0)
continue; /* Load error */

/* Free the previous export buffer, if any */
if(server->buffer)
{
cucul_free_buffer(server->buffer);
free(server->buffer);
server->buffer = NULL;
}

/* Get ANSI representation of the image and skip the end-of buffer
* linefeed ("\r\n", 2 byte) */
server->buffer = cucul_export_canvas(server->canvas, "utf8cr");
server->bufdata = cucul_get_buffer_data(server->buffer);
server->buflen = cucul_get_buffer_size(server->buffer);
server->buffer = cucul_export_memory(server->canvas, "utf8cr",
&server->buflen);
server->buflen -= 2;

for(i = 0; i < server->client_count; i++)
@@ -275,7 +264,9 @@ int main(void)
}

if(server->buffer)
cucul_free_buffer(server->buffer);
free(server->buffer);

cucul_free_canvas(server->canvas);

/* Restore SIGPIPE handler */
signal(SIGPIPE, server->sigpipe_handler);
@@ -452,7 +443,7 @@ static int send_data(struct server *server, struct client *c)

memcpy(c->outbuf + c->stop, ANSI_PREFIX, strlen(ANSI_PREFIX));
c->stop += strlen(ANSI_PREFIX);
memcpy(c->outbuf + c->stop, server->bufdata, server->buflen);
memcpy(c->outbuf + c->stop, server->buffer, server->buflen);
c->stop += server->buflen;

return 0;
@@ -487,14 +478,14 @@ static int send_data(struct server *server, struct client *c)

memcpy(c->outbuf, ANSI_PREFIX, strlen(ANSI_PREFIX) - ret);
c->stop = strlen(ANSI_PREFIX) - ret;
memcpy(c->outbuf + c->stop, server->bufdata, server->buflen);
memcpy(c->outbuf + c->stop, server->buffer, server->buflen);
c->stop += server->buflen;

return 0;
}

/* Send actual data */
ret = nonblock_write(c->fd, server->bufdata, server->buflen);
ret = nonblock_write(c->fd, server->buffer, server->buflen);
if(ret == -1)
{
if(errno == EAGAIN)
@@ -517,7 +508,7 @@ static int send_data(struct server *server, struct client *c)
return 0;
}

memcpy(c->outbuf, server->bufdata, server->buflen - ret);
memcpy(c->outbuf, server->buffer, server->buflen - ret);
c->stop = server->buflen - ret;

return 0;


+ 5
- 5
src/img2irc.c ファイルの表示

@@ -27,7 +27,8 @@ int main(int argc, char **argv)
{
/* libcucul context */
cucul_canvas_t *cv;
cucul_buffer_t *export;
void *export;
unsigned long int len;
struct image *i;
int cols = 56, lines;

@@ -62,10 +63,9 @@ int main(int argc, char **argv)

unload_image(i);

export = cucul_export_canvas(cv, "irc");
fwrite(cucul_get_buffer_data(export),
cucul_get_buffer_size(export), 1, stdout);
cucul_free_buffer(export);
export = cucul_export_memory(cv, "irc", &len);
fwrite(export, len, 1, stdout);
free(export);

cucul_free_canvas(cv);



+ 7
- 15
test/export.c ファイルの表示

@@ -34,9 +34,10 @@ int main(int argc, char *argv[])
{
cucul_canvas_t *cv;
cucul_dither_t *dither;
cucul_buffer_t *buffer;
void *buffer;
char *file, *format;
char const * const * exports, * const * p;
unsigned long int len;
int x, y;

exports = cucul_get_export_list();
@@ -77,20 +78,12 @@ int main(int argc, char *argv[])

if(file)
{
cucul_buffer_t *tmp;
tmp = cucul_load_file(file);
if(!tmp)
{
fprintf(stderr, "%s: could not load `%s'\n", argv[0], file);
exit(-1);
}
cv = cucul_import_canvas(tmp, "");
if(!cv)
cv = cucul_create_canvas(0, 0);
if(cucul_import_file(cv, file, "") < 0)
{
fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
exit(-1);
}
cucul_free_buffer(tmp);
}
else
{
@@ -146,10 +139,9 @@ int main(int argc, char *argv[])
}
}

buffer = cucul_export_canvas(cv, format);
fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer);
buffer = cucul_export_memory(cv, format, &len);
fwrite(buffer, len, 1, stdout);
free(buffer);

cucul_free_canvas(cv);



+ 5
- 5
test/font2tga.c ファイルの表示

@@ -32,7 +32,8 @@ int main(int argc, char *argv[])
cucul_font_t *f;
char const * const * fonts;
cucul_canvas_t *cv;
cucul_buffer_t *buffer;
void *buffer;
unsigned long int len;
unsigned int i, j, x, y, glyphs;

fonts = cucul_get_font_list();
@@ -65,10 +66,9 @@ int main(int argc, char *argv[])

cucul_free_font(f);

buffer = cucul_export_canvas(cv, "tga");
fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer);
buffer = cucul_export_memory(cv, "tga", &len);
fwrite(buffer, len, 1, stdout);
free(buffer);

/* Free everything */
cucul_free_canvas(cv);


+ 3
- 12
test/import.c ファイルの表示

@@ -30,7 +30,6 @@
int main(int argc, char *argv[])
{
cucul_canvas_t *cv;
cucul_buffer_t *b;
caca_display_t *dp;

if(argc < 2)
@@ -40,22 +39,14 @@ int main(int argc, char *argv[])
return 1;
}

b = cucul_load_file(argv[1]);
if(!b)
cv = cucul_create_canvas(0, 0);
if(cucul_import_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0)
{
fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
cucul_free_canvas(cv);
return 1;
}

cv = cucul_import_canvas(b, argc >= 3 ? argv[2] : "");
if(!cv)
{
fprintf(stderr, "%s: could not import `%s'.\n", argv[0], argv[1]);
return 1;
}

cucul_free_buffer(b);

dp = caca_create_display(cv);

caca_refresh_display(dp);


+ 12
- 12
test/text.c ファイルの表示

@@ -19,6 +19,7 @@
# endif
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
#endif
#include "cucul.h"

@@ -33,23 +34,22 @@
int main(int argc, char *argv[])
{
cucul_canvas_t *cv;
cucul_buffer_t *buffer;
void *buffer;
unsigned long int len;

buffer = cucul_load_memory(STRING, strlen(STRING));
cv = cucul_import_canvas(buffer, "text");
cucul_free_buffer(buffer);
cv = cucul_create_canvas(0, 0);

buffer = cucul_export_canvas(cv, "utf8");
fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer);
cucul_import_memory(cv, STRING, strlen(STRING), "text");

buffer = cucul_export_memory(cv, "utf8", &len);
fwrite(buffer, len, 1, stdout);
free(buffer);

cucul_rotate(cv);

buffer = cucul_export_canvas(cv, "utf8");
fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer);
buffer = cucul_export_memory(cv, "utf8", &len);
fwrite(buffer, len, 1, stdout);
free(buffer);

cucul_free_canvas(cv);



読み込み中…
キャンセル
保存