* Implemented figlet's -t (adapt to terminal's width).

This commit is contained in:
Sam Hocevar 2006-09-27 07:18:20 +00:00 committed by sam
parent 15a742ce5c
commit c025bc4f2b
2 changed files with 35 additions and 4 deletions

View file

@ -25,7 +25,8 @@ if test "$build" != "$host" -a "${PKG_CONFIG_LIBDIR}" = ""; then
export PKG_CONFIG_LIBDIR=/dev/null export PKG_CONFIG_LIBDIR=/dev/null
fi fi
AC_CHECK_HEADERS(getopt.h) AC_CHECK_HEADERS(getopt.h sys/ioctl.h)
AC_CHECK_FUNCS(getopt_long, AC_CHECK_FUNCS(getopt_long,
[AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the `getopt_long' function.)], [AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the `getopt_long' function.)],
[AC_CHECK_LIB(gnugetopt, getopt_long, [AC_CHECK_LIB(gnugetopt, getopt_long,
@ -33,6 +34,18 @@ AC_CHECK_FUNCS(getopt_long,
GETOPT_LIBS="${GETOPT_LIBS} -lgnugetopt"])]) GETOPT_LIBS="${GETOPT_LIBS} -lgnugetopt"])])
AC_SUBST(GETOPT_LIBS) AC_SUBST(GETOPT_LIBS)
AC_CACHE_CHECK([for TIOCGWINSZ],
[ac_cv_have_tiocgwinsz],
[AC_TRY_COMPILE(
[#include <sys/ioctl.h>],
[struct winsize ws;
ioctl(1, TIOCGWINSZ, &ws);],
ac_cv_have_tiocgwinsz=yes,
ac_cv_have_tiocgwinsz=no)])
if test "${ac_cv_have_tiocgwinsz}" = "yes"; then
AC_DEFINE(HAVE_TIOCGWINSZ, 1, [Define if you have TIOCGWINSZ])
fi
CUCUL="no" CUCUL="no"
PKG_CHECK_MODULES(cucul, cucul >= 0.99.beta5, PKG_CHECK_MODULES(cucul, cucul >= 0.99.beta5,
[CUCUL="yes"], [CUCUL="yes"],

View file

@ -23,6 +23,9 @@
#if defined(HAVE_GETOPT_H) #if defined(HAVE_GETOPT_H)
# include <getopt.h> # include <getopt.h>
#endif #endif
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ)
# include <sys/ioctl.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -67,6 +70,7 @@ int main(int argc, char *argv[])
{ "font", 1, NULL, 'f' }, { "font", 1, NULL, 'f' },
{ "directory", 1, NULL, 'd' }, { "directory", 1, NULL, 'd' },
{ "width", 1, NULL, 'w' }, { "width", 1, NULL, 'w' },
{ "termwidth", 0, NULL, 't' },
{ "gay", 0, NULL, 'g' }, { "gay", 0, NULL, 'g' },
{ "metal", 0, NULL, 'm' }, { "metal", 0, NULL, 'm' },
{ "irc", 0, NULL, 'i' }, { "irc", 0, NULL, 'i' },
@ -76,11 +80,11 @@ int main(int argc, char *argv[])
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
int c = getopt_long(argc, argv, "d:f:I:w:ghimv", int c = getopt_long(argc, argv, "d:f:I:w:ghimtv",
long_options, &option_index); 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, "d:f:I:w:ghimv"); int c = getopt(argc, argv, "d:f:I:w:ghimtv");
# endif # endif
if(c == -1) if(c == -1)
break; break;
@ -111,6 +115,18 @@ int main(int argc, char *argv[])
case 'w': /* --width */ case 'w': /* --width */
term_width = atoi(optarg); term_width = atoi(optarg);
break; break;
case 't': /* --termwidth */
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ)
struct winsize ws;
if((ioctl(1, TIOCGWINSZ, &ws) != -1 ||
ioctl(2, TIOCGWINSZ, &ws) != -1 ||
ioctl(0, TIOCGWINSZ, &ws) != -1) && ws.ws_col != 0)
term_width = ws.ws_col;
#endif
break;
}
case 'i': /* --irc */ case 'i': /* --irc */
export = "irc"; export = "irc";
break; break;
@ -221,13 +237,14 @@ static void version(void)
#if defined(HAVE_GETOPT_H) #if defined(HAVE_GETOPT_H)
static void usage(void) static void usage(void)
{ {
printf("Usage: toilet [ -ghimv ] [ -d fontdirectory ]\n"); printf("Usage: toilet [ -ghimtv ] [ -d fontdirectory ]\n");
printf(" [ -f fontfile ] [ -w outputwidth ]\n"); printf(" [ -f fontfile ] [ -w outputwidth ]\n");
printf(" [ -I infocode ] [ message ]\n"); printf(" [ -I infocode ] [ message ]\n");
# ifdef HAVE_GETOPT_LONG # ifdef HAVE_GETOPT_LONG
printf(" -f, --font <fontfile> select the font\n"); printf(" -f, --font <fontfile> select the font\n");
printf(" -d, --directory <dir> specify font directory\n"); printf(" -d, --directory <dir> specify font directory\n");
printf(" -w, --width <width> set output width\n"); printf(" -w, --width <width> set output width\n");
printf(" -t, --termwidth adapt to terminal's width\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");
@ -238,6 +255,7 @@ static void usage(void)
printf(" -f <fontfile> select the font\n"); printf(" -f <fontfile> select the font\n");
printf(" -d <dir> specify font directory\n"); printf(" -d <dir> specify font directory\n");
printf(" -w <width> set output width\n"); printf(" -w <width> set output width\n");
printf(" -t adapt to terminal's width\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");