Selaa lähdekoodia

* 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
master
jylam 18 vuotta sitten
vanhempi
commit
c59a5589dd
2 muutettua tiedostoa jossa 64 lisäystä ja 5 poistoa
  1. +6
    -1
      src/cacamoo.h
  2. +58
    -4
      src/main.c

+ 6
- 1
src/cacamoo.h Näytä tiedosto

@@ -17,8 +17,12 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cucul.h>
/* Portability ? */
#include <sys/types.h>
#include <dirent.h>


#include <cucul.h>

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);


+ 58
- 4
src/main.c Näytä tiedosto

@@ -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;


Ladataan…
Peruuta
Tallenna