diff --git a/.gitignore b/.gitignore index f61f893..967599a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ .auto .libs .deps +.dirstamp Makefile Makefile.in aclocal.m4 @@ -31,6 +32,8 @@ test/zzone test/bug-div0 test/bug-memory test/bug-overflow +test/*.log +test/*.trs doc/zzat.1 doc/zzuf.1 doc/libzzuf.3 diff --git a/configure.ac b/configure.ac index a5d50c0..e37d740 100644 --- a/configure.ac +++ b/configure.ac @@ -35,11 +35,6 @@ esac AC_MSG_RESULT($SONAME) AC_DEFINE_UNQUOTED(SONAME, "$SONAME", [Define to the libzzuf full name]) -PKG_CHECK_MODULES(CACA, caca >= 0.99.beta18, - [:], - [AC_MSG_RESULT(no) - AC_MSG_ERROR([you need libcaca version 0.99.beta18 or later])]) - # Optimizations AC_TRY_CFLAGS(-g -O2, CFLAGS="${CFLAGS} -g -O2") # Code qui fait des warnings == code de porc == deux baffes dans ta gueule diff --git a/msvc/zzat.vcxproj b/msvc/zzat.vcxproj index 3a91a77..cbe2cf3 100644 --- a/msvc/zzat.vcxproj +++ b/msvc/zzat.vcxproj @@ -85,7 +85,7 @@ Disabled - ..\msvc;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true EnableFastChecks @@ -97,7 +97,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Debug\Win32\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) $(OutDir)zzat.exe true $(OutDir)zzat.pdb @@ -108,7 +108,7 @@ Disabled - ..\msvc;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug @@ -119,7 +119,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Debug\x64\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) $(OutDir)zzat.exe true $(OutDir)zzat.pdb @@ -128,7 +128,7 @@ - ..\msvc;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded @@ -138,7 +138,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Release\Win32\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) $(OutDir)zzat.exe true Console @@ -149,7 +149,7 @@ - ..\msvc;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded @@ -159,7 +159,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Release\x64\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) $(OutDir)zzat.exe true Console @@ -181,4 +181,4 @@ - \ No newline at end of file + diff --git a/msvc/zzuf.vcxproj b/msvc/zzuf.vcxproj index 97f4def..3e31a9f 100644 --- a/msvc/zzuf.vcxproj +++ b/msvc/zzuf.vcxproj @@ -85,7 +85,7 @@ Disabled - ..\msvc;..\src\common;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true EnableFastChecks @@ -97,7 +97,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Debug\Win32\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) $(OutDir)zzuf.exe true $(OutDir)zzuf.pdb @@ -108,7 +108,7 @@ Disabled - ..\msvc;..\src\common;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug @@ -119,7 +119,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Debug\x64\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;AdditionalDependencies) $(OutDir)zzuf.exe true $(OutDir)zzuf.pdb @@ -128,7 +128,7 @@ - ..\msvc;..\src\common;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded @@ -138,7 +138,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Release\Win32\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) $(OutDir)zzuf.exe true Console @@ -149,7 +149,7 @@ - ..\msvc;..\src\common;..\..\libcaca\caca;..\..\libcaca\caca\win32;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded @@ -159,7 +159,7 @@ CompileAsC - ws2_32.lib;..\..\libcaca\win32\Release\x64\libcaca.lib;%(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) $(OutDir)zzuf.exe true Console @@ -200,4 +200,4 @@ - \ No newline at end of file + diff --git a/src/Makefile.am b/src/Makefile.am index 1ba5e8c..15d065c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,10 +3,12 @@ bin_PROGRAMS = zzuf zzat pkglib_LTLIBRARIES = libzzuf.la ZZUF = \ - zzuf.c opts.c opts.h md5.c md5.h timer.c timer.h myfork.c myfork.h + zzuf.c opts.c opts.h md5.c md5.h timer.c timer.h myfork.c myfork.h \ + caca_getopt.c caca_getopt.h ZZAT = \ - zzat.c + zzat.c \ + caca_getopt.c caca_getopt.h LIBZZUF = \ libzzuf/libzzuf.c libzzuf/libzzuf.h \ @@ -25,11 +27,11 @@ COMMON = \ zzuf_SOURCES = $(ZZUF) $(COMMON) zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\" -I$(srcdir)/common -zzuf_LDFLAGS = $(CACA_LIBS) $(MATH_LIBS) $(WINSOCK2_LIBS) +zzuf_LDFLAGS = $(MATH_LIBS) $(WINSOCK2_LIBS) zzuf_DEPENDENCIES = libzzuf.la zzat_SOURCES = $(ZZAT) -zzat_LDFLAGS = $(CACA_LIBS) +zzat_LDFLAGS = libzzuf_la_SOURCES = $(LIBZZUF) $(COMMON) libzzuf_la_CFLAGS = -DLIBZZUF -I$(srcdir)/libzzuf -I$(srcdir)/common diff --git a/src/caca_getopt.c b/src/caca_getopt.c new file mode 100644 index 0000000..7056c03 --- /dev/null +++ b/src/caca_getopt.c @@ -0,0 +1,131 @@ +/* + * libcaca Colour ASCII-Art library + * Copyright (c) 2002-2014 Sam Hocevar + * 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://www.wtfpl.net/ for more details. + */ + +/* + * getopt.c: getopt_long reimplementation + */ + +#include "config.h" + +#include +#include +#if defined HAVE_GETOPT_H && defined HAVE_GETOPT_LONG +# include +#endif +#include + +#include "caca_getopt.h" + +int caca_optind = 1; +char *caca_optarg = NULL; + +int caca_getopt(int argc, char * const _argv[], char const *optstring, + struct caca_option const *longopts, int *longindex) +{ +#if defined HAVE_GETOPT_LONG + int ret; + optind = caca_optind; + optarg = caca_optarg; + ret = getopt_long(argc, _argv, optstring, + (struct option const *)longopts, longindex); + caca_optind = optind; + caca_optarg = optarg; + return ret; + +#else + /* XXX: this getopt_long implementation should not be trusted for other + * applications without any serious peer reviewing. It “just works” with + * zzuf and a few libcaca programs but may fail miserably in other + * programs. */ + char **argv = (char **)(uintptr_t)_argv; + char *flag; + int i; + + if(caca_optind >= argc) + return -1; + + flag = argv[caca_optind]; + + if(flag[0] == '-' && flag[1] != '-') + { + char *tmp; + int ret = flag[1]; + + if(ret == '\0') + return -1; + + tmp = strchr(optstring, ret); + if(!tmp || ret == ':') + return '?'; + + caca_optind++; + if(tmp[1] == ':') + { + if(flag[2] != '\0') + caca_optarg = flag + 2; + else + caca_optarg = argv[caca_optind++]; + return ret; + } + + if(flag[2] != '\0') + { + flag[1] = '-'; + caca_optind--; + argv[caca_optind]++; + } + + 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; + caca_optind++; + caca_optarg = flag + 2 + l + 1; + return longopts[i].val; + case '\0': + if(longindex) + *longindex = i; + caca_optind++; + if(longopts[i].has_arg) + caca_optarg = argv[caca_optind++]; + return longopts[i].val; + default: + break; + } + } + bad_opt: + fprintf(stderr, "%s: unrecognized option `%s'\n", argv[0], flag); + return '?'; + } + + return -1; +#endif +} + diff --git a/src/caca_getopt.h b/src/caca_getopt.h new file mode 100644 index 0000000..f3708d7 --- /dev/null +++ b/src/caca_getopt.h @@ -0,0 +1,40 @@ +/* + * libcaca Colour ASCII-Art library + * Copyright (c) 2002-2014 Sam Hocevar + * 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://www.wtfpl.net/ for more details. + */ + +/* + * getopt.h: getopt_long reimplementation + */ + +/** \brief Option parsing. + * + * This structure contains commandline parsing information for systems + * where getopt_long() is unavailable. + */ +struct caca_option +{ + char const *name; + int has_arg; + int *flag; + int val; +}; + +/** \defgroup caca_process libcaca process management + * + * These functions help with various process handling tasks such as + * option parsing, DLL injection. + * + * @{ */ +extern int caca_optind; +extern char *caca_optarg; +extern int caca_getopt(int, char * const[], char const *, + struct caca_option const *, int *); + diff --git a/src/zzuf.c b/src/zzuf.c index 44da8ad..cd12684 100644 --- a/src/zzuf.c +++ b/src/zzuf.c @@ -54,8 +54,6 @@ # include /* for RLIMIT_AS */ #endif -#include - #include "common.h" #include "opts.h" #include "random.h" @@ -64,6 +62,7 @@ #include "myfork.h" #include "md5.h" #include "timer.h" +#include "caca_getopt.h" #if !defined SIGKILL # define SIGKILL 9