Преглед на файлове

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

pull/1/head
Sam Hocevar sam преди 18 години
родител
ревизия
c025bc4f2b
променени са 2 файла, в които са добавени 35 реда и са изтрити 4 реда
  1. +14
    -1
      configure.ac
  2. +21
    -3
      src/main.c

+ 14
- 1
configure.ac Целия файл

@@ -25,7 +25,8 @@ if test "$build" != "$host" -a "${PKG_CONFIG_LIBDIR}" = ""; then
export PKG_CONFIG_LIBDIR=/dev/null
fi

AC_CHECK_HEADERS(getopt.h)
AC_CHECK_HEADERS(getopt.h sys/ioctl.h)

AC_CHECK_FUNCS(getopt_long,
[AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the `getopt_long' function.)],
[AC_CHECK_LIB(gnugetopt, getopt_long,
@@ -33,6 +34,18 @@ AC_CHECK_FUNCS(getopt_long,
GETOPT_LIBS="${GETOPT_LIBS} -lgnugetopt"])])
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"
PKG_CHECK_MODULES(cucul, cucul >= 0.99.beta5,
[CUCUL="yes"],


+ 21
- 3
src/main.c Целия файл

@@ -23,6 +23,9 @@
#if defined(HAVE_GETOPT_H)
# include <getopt.h>
#endif
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ)
# include <sys/ioctl.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -67,6 +70,7 @@ int main(int argc, char *argv[])
{ "font", 1, NULL, 'f' },
{ "directory", 1, NULL, 'd' },
{ "width", 1, NULL, 'w' },
{ "termwidth", 0, NULL, 't' },
{ "gay", 0, NULL, 'g' },
{ "metal", 0, NULL, 'm' },
{ "irc", 0, NULL, 'i' },
@@ -76,11 +80,11 @@ int main(int argc, char *argv[])
{ 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);
# else
# 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
if(c == -1)
break;
@@ -111,6 +115,18 @@ int main(int argc, char *argv[])
case 'w': /* --width */
term_width = atoi(optarg);
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 */
export = "irc";
break;
@@ -221,13 +237,14 @@ static void version(void)
#if defined(HAVE_GETOPT_H)
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(" [ -I infocode ] [ message ]\n");
# ifdef HAVE_GETOPT_LONG
printf(" -f, --font <fontfile> select the font\n");
printf(" -d, --directory <dir> specify font directory\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(" -m, --metal add a metal effect to the text\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(" -d <dir> specify font directory\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(" -m add a metal effect to the text\n");
printf(" -i output IRC colour codes\n");


Зареждане…
Отказ
Запис