* Created skeleton for future FIGlet font handling. Nothing here yet.

This commit is contained in:
Sam Hocevar 2006-09-23 22:53:17 +00:00 committed by sam
parent 05204d2b7a
commit 7c14f93b9d
4 changed files with 88 additions and 16 deletions

View file

@ -1,7 +1,10 @@
bin_PROGRAMS = toilet bin_PROGRAMS = toilet
toilet_SOURCES = main.c render.c render.h filters.c filter.h toilet_SOURCES = main.c \
render.c render.h \
filters.c filter.h \
figlet.c figlet.h
toilet_CFLAGS = `pkg-config --cflags cucul` toilet_CFLAGS = `pkg-config --cflags cucul`
toilet_LDFLAGS = `pkg-config --libs cucul` @GETOPT_LIBS@ toilet_LDFLAGS = `pkg-config --libs cucul` @GETOPT_LIBS@

34
src/figlet.c Normal file
View file

@ -0,0 +1,34 @@
/*
* TOIlet The Other Implementations letters
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
#include "config.h"
#if defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#endif
#include <cucul.h>
#include "figlet.h"
cucul_canvas_t *render_figlet(uint32_t const *string, unsigned int length,
char const *fontname)
{
cucul_canvas_t *cv;
cv = cucul_create_canvas(3, 1);
cucul_putstr(cv, 0, 0, "LOL");
return cv;
}

16
src/figlet.h Normal file
View file

@ -0,0 +1,16 @@
/*
* TOIlet The Other Implementations letters
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
extern cucul_canvas_t *render_figlet(uint32_t const *, unsigned int,
char const *);

View file

@ -25,6 +25,7 @@
#include <cucul.h> #include <cucul.h>
#include "render.h" #include "render.h"
#include "figlet.h"
#include "filters.h" #include "filters.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -38,6 +39,7 @@ int main(int argc, char *argv[])
int i; int i;
char const *export = "utf8"; char const *export = "utf8";
char const *font = "mono9";
unsigned flag_gay = 0; unsigned flag_gay = 0;
unsigned flag_metal = 0; unsigned flag_metal = 0;
@ -50,18 +52,19 @@ int main(int argc, char *argv[])
static struct option long_options[] = static struct option long_options[] =
{ {
/* Long option, needs arg, flag, short option */ /* Long option, needs arg, flag, short option */
{ "metal", 0, NULL, 'm' }, { "font", 1, NULL, 'f' },
{ "gay", 0, NULL, 'g' }, { "gay", 0, NULL, 'g' },
{ "metal", 0, NULL, 'm' },
{ "irc", 0, NULL, 'i' }, { "irc", 0, NULL, 'i' },
{ "help", 0, NULL, 'h' }, { "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' }, { "version", 0, NULL, 'v' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
int c = getopt_long(argc, argv, "gmihv", long_options, &option_index); int c = getopt_long(argc, argv, "f:gmihv", long_options, &option_index);
# else # else
# define MOREINFO "Try `%s -h' for more information.\n" # define MOREINFO "Try `%s -h' for more information.\n"
int c = getopt(argc, argv, "gmihv"); int c = getopt(argc, argv, "f:gmihv");
# endif # endif
if(c == -1) if(c == -1)
break; break;
@ -69,14 +72,18 @@ int main(int argc, char *argv[])
switch(c) switch(c)
{ {
case 'h': /* --help */ case 'h': /* --help */
printf("Usage: %s [ -gmihv ] [ message ]\n", argv[0]); printf("Usage: %s [ -f:gmihv ] [ message ]\n", argv[0]);
# ifdef HAVE_GETOPT_LONG # ifdef HAVE_GETOPT_LONG
printf(" -f, --font <fontfile>\n");
printf(" select the font\n");
printf(" -g, --gay add a rainbow effect to the text\n"); printf(" -g, --gay add a rainbow effect to the text\n");
printf(" -m, --metal add a metal effect to the text\n"); printf(" -m, --metal add a metal effect to the text\n");
printf(" -i, --irc output IRC colour codes\n"); printf(" -i, --irc output IRC colour codes\n");
printf(" -h, --help display this help and exit\n"); printf(" -h, --help display this help and exit\n");
printf(" -v, --version output version information and exit\n"); printf(" -v, --version output version information and exit\n");
# else # else
printf(" -f <fontfile>\n");
printf(" select the font\n");
printf(" -g add a rainbow effect to the text\n"); printf(" -g add a rainbow effect to the text\n");
printf(" -m add a metal effect to the text\n"); printf(" -m add a metal effect to the text\n");
printf(" -i output IRC colour codes\n"); printf(" -i output IRC colour codes\n");
@ -84,20 +91,23 @@ int main(int argc, char *argv[])
printf(" -v output version information and exit\n"); printf(" -v output version information and exit\n");
# endif # endif
return 0; return 0;
case 'm': /* --metal */
flag_metal = 1;
break;
case 'g': /* --gay */
flag_gay = 1;
break;
case 'i': /* --irc */
export = "irc";
break;
case 'v': /* --version */ case 'v': /* --version */
printf("TOIlet Copyright 2006 Sam Hocevar %s\n", VERSION); printf("TOIlet Copyright 2006 Sam Hocevar %s\n", VERSION);
printf("Internet: <sam@zoy.org> Version: 0, date: 21 Sep 2006\n"); printf("Internet: <sam@zoy.org> Version: 0, date: 21 Sep 2006\n");
printf("\n"); printf("\n");
return 0; return 0;
case 'f': /* --font */
font = optarg;
break;
case 'g': /* --gay */
flag_gay = 1;
break;
case 'm': /* --metal */
flag_metal = 1;
break;
case 'i': /* --irc */
export = "irc";
break;
case '?': case '?':
printf(MOREINFO, argv[0]); printf(MOREINFO, argv[0]);
return 1; return 1;
@ -144,9 +154,18 @@ int main(int argc, char *argv[])
length += real_len; length += real_len;
} }
/* Do gay stuff with our string (léopard) */ /* Render string to canvas */
cv = render_big(string, length); if(!strcasecmp(font, "mono9"))
cv = render_big(string, length);
else if(!strcasecmp(font, "term"))
cv = render_tiny(string, length);
else
cv = render_figlet(string, length, font);
/* Crop output */
filter_autocrop(cv); filter_autocrop(cv);
/* Do gay stuff with our string (léopard) */
if(flag_metal) if(flag_metal)
filter_metal(cv); filter_metal(cv);
if(flag_gay) if(flag_gay)