From c59a5589dd12ab4b09bb13d25206164dfb9a74aa Mon Sep 17 00:00:00 2001 From: jylam Date: Fri, 27 Oct 2006 19:30:36 +0000 Subject: [PATCH] * Added --list-files option, unicode option (not working yet) git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/cacamoo/trunk@1246 92316355-f0b4-4df1-b90c-862c8a59935f --- src/cacamoo.h | 7 +++++- src/main.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/cacamoo.h b/src/cacamoo.h index cbab7bc..547585e 100644 --- a/src/cacamoo.h +++ b/src/cacamoo.h @@ -17,8 +17,12 @@ #include #include #include -#include +/* Portability ? */ +#include +#include + +#include static void version(void); char *construct_balloon(char *buffer, unsigned int termwidth); @@ -27,6 +31,7 @@ char *make_caca_from_file(unsigned int *size); char *replace(char *string, char *oldpiece, const char *newpiece); char *remove_slashes(char *str); char *remove_comments(char *str); +void list_files(const char *directory); #if defined(HAVE_GETOPT_H) static void usage(void); diff --git a/src/main.c b/src/main.c index 7faad85..a5bc078 100644 --- a/src/main.c +++ b/src/main.c @@ -59,6 +59,9 @@ unsigned int term_width = 40-1; /* Default for cowsay */ /* Think ? */ unsigned char think = 0; +/* Unicode */ +unsigned char unicode = 0; + int main (int argc, char **argv) { @@ -102,18 +105,20 @@ int main (int argc, char **argv) { "youth", 1, NULL, 'y' }, { "wired", 1, NULL, 'w' }, { "think", 1, NULL, 'O' }, + { "unicode", 1, NULL, 'u' }, { "version", 0, NULL, 'v' }, + { "list-files", 0, NULL, 'l' }, { "help", 0, NULL, 'h' }, { NULL, 0, NULL, 0 } }; - int c = getopt_long(argc, argv, "D:f:W:e:T:hvObtdgpsywn", + int c = getopt_long(argc, argv, "D:f:W:e:T:hvObtdgpsylwnu", long_options, &option_index); # else # define MOREINFO "Try `%s -h' for more information.\n" - int c = getopt(argc, argv, "D:f:W:hvObtdgpsywn"); + int c = getopt(argc, argv, "D:f:W:hvObtdgpsylwnu"); # endif if(c == -1) break; @@ -169,7 +174,15 @@ int main (int argc, char **argv) term_width = strtol(optarg, NULL, 10); if(term_width && (term_width != 1)) term_width--; break; - case 'n': /* --width */ + case 'l': /* --list-files */ + list_files("."); + list_files(cacamoo_dir); + return 0; + break; + case 'u': /* --unicode */ + unicode = 1; + break; + case 'n': /* --no-wrap */ no_wrap = 1; break; case '?': @@ -239,9 +252,24 @@ int main (int argc, char **argv) /* Import our buffer as an ansi (color) one */ input_buffer = cucul_load_memory(buffer, buffer_size); - canvas = cucul_import_canvas (input_buffer, "ansi"); + 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) + { + printf("Can't load file in libcucul !\n"); + return -1; + } /* Export given canvas to format we want */ output_buffer = cucul_export_canvas(canvas, "irc"); + if(output_buffer == 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); @@ -258,6 +286,32 @@ int main (int argc, char **argv) } +void list_files(const char *directory) +{ + struct dirent * dp; + int count = 0; + DIR *dir = opendir(directory); + + + for (dp = readdir(dir); dp != NULL; dp = readdir(dir)) + { + if(!strncmp(&dp->d_name[strlen(dp->d_name)-4], ".cow", 4)) + { + char name[256]; + memcpy(name, dp->d_name, strlen(dp->d_name)-4); + name[strlen(dp->d_name)-4] = 0; + printf("%s ", name); + count++; + if(!(count%6)) + printf("\n"); + } + } + closedir(dir); + if(count) + printf("\n"); + return; +} + char * make_caca_from_file(unsigned int *size) { FILE *fp = NULL;