instead.pull/1/head
| @@ -24,19 +24,7 @@ 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 sys/ioctl.h) | |||||
| ac_cv_have_getopt_long="no" | |||||
| AC_CHECK_FUNCS(getopt_long, | |||||
| [ac_cv_have_getopt_long="yes"], | |||||
| [AC_CHECK_LIB(gnugetopt, getopt_long, | |||||
| [ac_cv_have_getopt_long="yes" | |||||
| GETOPT_LIBS="${GETOPT_LIBS} -lgnugetopt"])]) | |||||
| if test "$ac_cv_have_getopt_long" != "no"; then | |||||
| AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the ‘getopt_long’ function.) | |||||
| fi | |||||
| AM_CONDITIONAL(NEED_GETOPT_LONG, test "$ac_cv_have_getopt_long" = "no") | |||||
| AC_SUBST(GETOPT_LIBS) | |||||
| AC_CHECK_HEADERS(sys/ioctl.h) | |||||
| AC_CACHE_CHECK([for TIOCGWINSZ], | AC_CACHE_CHECK([for TIOCGWINSZ], | ||||
| [ac_cv_have_tiocgwinsz], | [ac_cv_have_tiocgwinsz], | ||||
| @@ -51,10 +39,10 @@ if test "${ac_cv_have_tiocgwinsz}" = "yes"; then | |||||
| fi | fi | ||||
| CUCUL="no" | CUCUL="no" | ||||
| PKG_CHECK_MODULES(CACA, caca >= 0.99.beta17, | |||||
| PKG_CHECK_MODULES(CACA, caca >= 0.99.beta18, | |||||
| [CUCUL="yes"], | [CUCUL="yes"], | ||||
| [AC_MSG_RESULT(no) | [AC_MSG_RESULT(no) | ||||
| AC_MSG_ERROR([you need libcaca version 0.99.beta17 or later])]) | |||||
| AC_MSG_ERROR([you need libcaca version 0.99.beta18 or later])]) | |||||
| AC_MSG_CHECKING([for release date]) | AC_MSG_CHECKING([for release date]) | ||||
| tmp="${stamp%-*}" | tmp="${stamp%-*}" | ||||
| @@ -5,16 +5,11 @@ toilet_SOURCES = main.c toilet.h \ | |||||
| render.c render.h \ | render.c render.h \ | ||||
| filter.c filter.h \ | filter.c filter.h \ | ||||
| export.c export.h \ | export.c export.h \ | ||||
| term.c figlet.c \ | |||||
| $(GETOPT) | |||||
| term.c figlet.c | |||||
| toilet_CPPFLAGS = -DFONTDIR=\"$(datadir)/figlet\" | toilet_CPPFLAGS = -DFONTDIR=\"$(datadir)/figlet\" | ||||
| toilet_CFLAGS = @CACA_CFLAGS@ | toilet_CFLAGS = @CACA_CFLAGS@ | ||||
| toilet_LDADD = @CACA_LIBS@ @GETOPT_LIBS@ | |||||
| if NEED_GETOPT_LONG | |||||
| GETOPT = mygetopt.c mygetopt.h | |||||
| endif | |||||
| toilet_LDADD = @CACA_LIBS@ | |||||
| echo-sources: ; echo $(SOURCES) | echo-sources: ; echo $(SOURCES) | ||||
| @@ -19,11 +19,6 @@ | |||||
| #if defined HAVE_INTTYPES_H | #if defined HAVE_INTTYPES_H | ||||
| # include <inttypes.h> | # include <inttypes.h> | ||||
| #endif | #endif | ||||
| #if !defined HAVE_GETOPT_LONG | |||||
| # include "mygetopt.h" | |||||
| #elif defined HAVE_GETOPT_H | |||||
| # include <getopt.h> | |||||
| #endif | |||||
| #if defined HAVE_SYS_IOCTL_H && defined HAVE_TIOCGWINSZ | #if defined HAVE_SYS_IOCTL_H && defined HAVE_TIOCGWINSZ | ||||
| # include <sys/ioctl.h> | # include <sys/ioctl.h> | ||||
| #endif | #endif | ||||
| @@ -37,13 +32,6 @@ | |||||
| #include "filter.h" | #include "filter.h" | ||||
| #include "export.h" | #include "export.h" | ||||
| #if defined HAVE_GETOPT_LONG | |||||
| # define mygetopt getopt_long | |||||
| # define myoptind optind | |||||
| # define myoptarg optarg | |||||
| # define myoption option | |||||
| #endif | |||||
| static void version(void); | static void version(void); | ||||
| static void usage(void); | static void usage(void); | ||||
| @@ -69,7 +57,7 @@ int main(int argc, char *argv[]) | |||||
| { | { | ||||
| #define MOREINFO "Try `%s --help' for more information.\n" | #define MOREINFO "Try `%s --help' for more information.\n" | ||||
| int option_index = 0; | int option_index = 0; | ||||
| static struct myoption long_options[] = | |||||
| static struct caca_option long_options[] = | |||||
| { | { | ||||
| /* Long option, needs arg, flag, short option */ | /* Long option, needs arg, flag, short option */ | ||||
| { "font", 1, NULL, 'f' }, | { "font", 1, NULL, 'f' }, | ||||
| @@ -88,8 +76,8 @@ int main(int argc, char *argv[]) | |||||
| { NULL, 0, NULL, 0 } | { NULL, 0, NULL, 0 } | ||||
| }; | }; | ||||
| int c = mygetopt(argc, argv, "f:d:w:tsSkWoF:E:hI:v", | |||||
| long_options, &option_index); | |||||
| int c = caca_getopt(argc, argv, "f:d:w:tsSkWoF:E:hI:v", | |||||
| long_options, &option_index); | |||||
| if(c == -1) | if(c == -1) | ||||
| break; | break; | ||||
| @@ -99,21 +87,21 @@ int main(int argc, char *argv[]) | |||||
| usage(); | usage(); | ||||
| return 0; | return 0; | ||||
| case 'I': /* --infocode */ | case 'I': /* --infocode */ | ||||
| infocode = atoi(myoptarg); | |||||
| infocode = atoi(caca_optarg); | |||||
| break; | break; | ||||
| case 'v': /* --version */ | case 'v': /* --version */ | ||||
| version(); | version(); | ||||
| return 0; | return 0; | ||||
| case 'f': /* --font */ | case 'f': /* --font */ | ||||
| cx->font = myoptarg; | |||||
| cx->font = caca_optarg; | |||||
| break; | break; | ||||
| case 'd': /* --directory */ | case 'd': /* --directory */ | ||||
| cx->dir = myoptarg; | |||||
| cx->dir = caca_optarg; | |||||
| break; | break; | ||||
| case 'F': /* --filter */ | case 'F': /* --filter */ | ||||
| if(!strcmp(myoptarg, "list")) | |||||
| if(!strcmp(caca_optarg, "list")) | |||||
| return filter_list(); | return filter_list(); | ||||
| if(filter_add(cx, myoptarg) < 0) | |||||
| if(filter_add(cx, caca_optarg) < 0) | |||||
| return -1; | return -1; | ||||
| break; | break; | ||||
| case 130: /* --gay */ | case 130: /* --gay */ | ||||
| @@ -123,7 +111,7 @@ int main(int argc, char *argv[]) | |||||
| filter_add(cx, "metal"); | filter_add(cx, "metal"); | ||||
| break; | break; | ||||
| case 'w': /* --width */ | case 'w': /* --width */ | ||||
| cx->term_width = atoi(myoptarg); | |||||
| cx->term_width = atoi(caca_optarg); | |||||
| break; | break; | ||||
| case 't': /* --termwidth */ | case 't': /* --termwidth */ | ||||
| { | { | ||||
| @@ -153,9 +141,9 @@ int main(int argc, char *argv[]) | |||||
| cx->hmode = H_OVERLAP; | cx->hmode = H_OVERLAP; | ||||
| break; | break; | ||||
| case 'E': /* --export */ | case 'E': /* --export */ | ||||
| if(!strcmp(myoptarg, "list")) | |||||
| if(!strcmp(caca_optarg, "list")) | |||||
| return export_list(); | return export_list(); | ||||
| if(export_set(cx, myoptarg) < 0) | |||||
| if(export_set(cx, caca_optarg) < 0) | |||||
| return -1; | return -1; | ||||
| break; | break; | ||||
| case 140: /* --irc */ | case 140: /* --irc */ | ||||
| @@ -200,10 +188,10 @@ int main(int argc, char *argv[]) | |||||
| if(render_init(cx) < 0) | if(render_init(cx) < 0) | ||||
| return -1; | return -1; | ||||
| if(myoptind >= argc) | |||||
| if(caca_optind >= argc) | |||||
| render_stdin(cx); | render_stdin(cx); | ||||
| else | else | ||||
| render_list(cx, argc - myoptind, argv + myoptind); | |||||
| render_list(cx, argc - caca_optind, argv + caca_optind); | |||||
| render_end(cx); | render_end(cx); | ||||
| filter_end(cx); | filter_end(cx); | ||||
| @@ -1,120 +0,0 @@ | |||||
| /* | |||||
| * TOIlet The Other Implementation’s letters | |||||
| * Copyright (c) 2002-2010 Sam Hocevar <sam@hocevar.net> | |||||
| * All Rights Reserved | |||||
| * | |||||
| * This program is free software. It comes without any warranty, to | |||||
| * the extent permitted by applicable law. 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. | |||||
| */ | |||||
| /* | |||||
| * mygetopt.c: getopt_long reimplementation | |||||
| */ | |||||
| #include "config.h" | |||||
| #if defined HAVE_STDINT_H | |||||
| # include <stdint.h> | |||||
| #elif defined HAVE_INTTYPES_H | |||||
| # include <inttypes.h> | |||||
| #endif | |||||
| #include <stdio.h> | |||||
| #include <string.h> | |||||
| #include "mygetopt.h" | |||||
| int myoptind = 1; | |||||
| char *myoptarg = NULL; | |||||
| /* XXX: this getopt_long implementation should not be trusted for other | |||||
| * applications without any serious peer reviewing. It “just works” with | |||||
| * zzuf but may fail miserably in other programs. */ | |||||
| int mygetopt(int argc, char * const _argv[], const char *optstring, | |||||
| const struct myoption *longopts, int *longindex) | |||||
| { | |||||
| char **argv = (char **)(uintptr_t)_argv; | |||||
| char *flag; | |||||
| int i; | |||||
| if(myoptind >= argc) | |||||
| return -1; | |||||
| flag = argv[myoptind]; | |||||
| if(flag[0] == '-' && flag[1] != '-') | |||||
| { | |||||
| char *tmp; | |||||
| int ret = flag[1]; | |||||
| if(ret == '\0') | |||||
| return -1; | |||||
| tmp = strchr(optstring, ret); | |||||
| if(!tmp || ret == ':') | |||||
| return '?'; | |||||
| myoptind++; | |||||
| if(tmp[1] == ':') | |||||
| { | |||||
| if(flag[2] != '\0') | |||||
| myoptarg = flag + 2; | |||||
| else | |||||
| myoptarg = argv[myoptind++]; | |||||
| return ret; | |||||
| } | |||||
| if(flag[2] != '\0') | |||||
| { | |||||
| flag[1] = '-'; | |||||
| myoptind--; | |||||
| argv[myoptind]++; | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| if(flag[0] == '-' && flag[1] == '-') | |||||
| { | |||||
| if(flag[2] == '\0') | |||||
| return -1; | |||||
| for(i = 0; longopts[i].name; i++) | |||||
| { | |||||
| size_t l = strlen(longopts[i].name); | |||||
| if(strncmp(flag + 2, longopts[i].name, l)) | |||||
| continue; | |||||
| switch(flag[2 + l]) | |||||
| { | |||||
| case '=': | |||||
| if(!longopts[i].has_arg) | |||||
| goto bad_opt; | |||||
| if(longindex) | |||||
| *longindex = i; | |||||
| myoptind++; | |||||
| myoptarg = flag + 2 + l + 1; | |||||
| return longopts[i].val; | |||||
| case '\0': | |||||
| if(longindex) | |||||
| *longindex = i; | |||||
| myoptind++; | |||||
| if(longopts[i].has_arg) | |||||
| myoptarg = argv[myoptind++]; | |||||
| return longopts[i].val; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| bad_opt: | |||||
| fprintf(stderr, "%s: unrecognized option `%s'\n", argv[0], flag); | |||||
| return '?'; | |||||
| } | |||||
| return -1; | |||||
| } | |||||
| @@ -1,29 +0,0 @@ | |||||
| /* | |||||
| * TOIlet The Other Implementation’s letters | |||||
| * Copyright (c) 2002-2010 Sam Hocevar <sam@hocevar.net> | |||||
| * All Rights Reserved | |||||
| * | |||||
| * This program is free software. It comes without any warranty, to | |||||
| * the extent permitted by applicable law. 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. | |||||
| */ | |||||
| /* | |||||
| * mygetopt.h: getopt_long reimplementation | |||||
| */ | |||||
| struct myoption | |||||
| { | |||||
| const char *name; | |||||
| int has_arg; | |||||
| int *flag; | |||||
| int val; | |||||
| }; | |||||
| extern int myoptind; | |||||
| extern char *myoptarg; | |||||
| int mygetopt(int, char * const[], const char *, const struct myoption *, int *); | |||||