From 8b8fa19b7aace99532d1238b1c89c754580fb671 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 18 Oct 2008 21:24:58 +0000 Subject: [PATCH] Port cacamoo to the unified libcaca 0.99.beta15 API. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/cacamoo/trunk@2979 92316355-f0b4-4df1-b90c-862c8a59935f --- configure.ac | 4 ++-- src/Makefile.am | 4 ++-- src/cacamoo.h | 8 ++++---- src/main.c | 39 +++++++++++++-------------------------- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/configure.ac b/configure.ac index 5455e4a..0c6742a 100644 --- a/configure.ac +++ b/configure.ac @@ -35,10 +35,10 @@ AC_CHECK_FUNCS(getopt_long, AC_SUBST(GETOPT_LIBS) CACA="no" -PKG_CHECK_MODULES(CUCUL, cucul, +PKG_CHECK_MODULES(CACA, caca >= 0.99.beta15, [CACA="yes"], [AC_MSG_RESULT(no) - AC_MSG_ERROR([you need libcucul version 0.99 or later])]) + AC_MSG_ERROR([you need libcaca version 0.99.beta15 or later])]) # Optimizations CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer" diff --git a/src/Makefile.am b/src/Makefile.am index bc44629..1d2b14a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,6 +2,6 @@ bin_PROGRAMS = cacamoo cacamoo_SOURCES = main.c cacamoo.h -cacamoo_CFLAGS = @CUCUL_CFLAGS@ -cacamoo_LDADD = @CUCUL_LIBS@ +cacamoo_CFLAGS = @CACA_CFLAGS@ +cacamoo_LDADD = @CACA_LIBS@ diff --git a/src/cacamoo.h b/src/cacamoo.h index 72b0935..3d0ed86 100644 --- a/src/cacamoo.h +++ b/src/cacamoo.h @@ -12,8 +12,8 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -#ifndef _CACASAY_H_ -#define _CACASAY_H_ +#ifndef _CACAMOO_H_ +#define _CACAMOO_H_ #include #include @@ -23,7 +23,7 @@ #include -#include +#include static void version(void); char *construct_balloon(char *buffer, unsigned int termwidth); @@ -38,4 +38,4 @@ void list_files(const char *directory); static void usage(void); #endif -#endif /* _CACASAY_H_ */ +#endif /* _CACAMOO_H_ */ diff --git a/src/main.c b/src/main.c index a084730..31e3e9e 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,7 @@ #endif #include "cacamoo.h" -#include +#include char const *cacamoo_export = "utf8"; char const *cacamoo_file = "default"; @@ -72,10 +72,8 @@ int main (int argc, char **argv) unsigned int new_width = 0; char *initial = NULL; unsigned int no_wrap = 0; - cucul_buffer_t* input_buffer; - cucul_buffer_t* output_buffer; - cucul_canvas_t* canvas; - int buf_size; + caca_canvas_t* canvas; + size_t buf_size; char *buf_data; if ((strstr(argv[0], "cacathink")) != NULL) { @@ -250,43 +248,32 @@ int main (int argc, char **argv) return -1; } - /* Import our buffer as an ansi (color) one */ - input_buffer = cucul_load_memory(buffer, buffer_size-1); - if(input_buffer == NULL) - { - printf("Can't load file in libcucul !\n"); - return -1; - } - canvas = cucul_import_canvas (input_buffer, unicode?"utf8":"ansi"); - if(canvas == NULL) + canvas = caca_create_canvas(0, 0); + if(caca_import_memory(canvas, buffer, buffer_size - 1, + unicode ? "utf8" : "ansi") < 0) { - printf("Can't load file in libcucul !\n"); + printf("Can't load file in libcaca !\n"); return -1; } + /* Export given canvas to format we want */ - output_buffer = cucul_export_canvas(canvas, "utf8"); - if(output_buffer == NULL) + buf_data = caca_export_memory(canvas, "utf8", &buf_size); + if(buf_data == NULL) { printf("Can't export file to text !\n"); return -1; } - buf_size = cucul_get_buffer_size(output_buffer); - buf_data = cucul_get_buffer_data(output_buffer); - - for(i = 0; i < buf_size; i++) - printf("%c", buf_data[i]); + fwrite(buf_data, buf_size, 1, stdout); if(string) free(string); if(buffer) free(buffer); - cucul_free_buffer(input_buffer); - cucul_free_buffer(output_buffer); - cucul_free_canvas(canvas); - + free(buf_data); + caca_free_canvas(canvas); return 0; }