Changeset 4683


Ignore:
Timestamp:
10/08/10 00:52:54 (3 years ago)
Author:
sam
Message:

Get rid of the getopt reimplementation and depend on libcaca instead.

Location:
zzuf/trunk
Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/configure.ac

    r4676 r4683  
    1212AC_PROG_LIBTOOL 
    1313 
     14dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right 
     15dnl now otherwise it might be set in an obscure if statement. Same thing for 
     16dnl PKG_PROG_PKG_CONFIG which needs to be called first. 
     17AC_EGREP_CPP(yes, foo) 
     18PKG_PROG_PKG_CONFIG() 
     19 
     20dnl Don't let pkg-config fuck our cross-compilation environment 
     21m4_pattern_allow([^PKG_CONFIG_LIBDIR$]) 
     22if test "$build" != "$host" -a "${PKG_CONFIG_LIBDIR}" = ""; then 
     23  export PKG_CONFIG_LIBDIR=/dev/null 
     24fi 
     25 
    1426AC_C_INLINE 
    1527AC_C_FUNC 
     
    2335AC_MSG_RESULT($SONAME) 
    2436AC_DEFINE_UNQUOTED(SONAME, "$SONAME", [Define to the libzzuf full name]) 
     37 
     38PKG_CHECK_MODULES(CACA, caca >= 0.99.beta18, 
     39 [:], 
     40 [AC_MSG_RESULT(no) 
     41  AC_MSG_ERROR([you need libcaca version 0.99.beta18 or later])]) 
    2542 
    2643# Optimizations 
     
    4663AC_SUBST(DLL_LDFLAGS) 
    4764 
    48 AC_CHECK_HEADERS(windows.h winsock2.h io.h process.h unistd.h inttypes.h stdint.h getopt.h libc.h malloc.h dlfcn.h regex.h sys/cdefs.h sys/socket.h netinet/in.h arpa/inet.h sys/uio.h aio.h sys/mman.h sys/wait.h sys/resource.h sys/time.h endian.h mach/task.h) 
     65AC_CHECK_HEADERS(windows.h winsock2.h io.h process.h unistd.h inttypes.h stdint.h libc.h malloc.h dlfcn.h regex.h sys/cdefs.h sys/socket.h netinet/in.h arpa/inet.h sys/uio.h aio.h sys/mman.h sys/wait.h sys/resource.h sys/time.h endian.h mach/task.h) 
    4966 
    5067AC_CHECK_FUNCS(setenv waitpid setrlimit gettimeofday fork kill pipe _pipe) 
     
    162179AC_DEFINE_UNQUOTED(ATTRIBUTE_PRINTF(x,y), $ac_v_attribute_printf, [Define to the __printf__ attribute if present]) 
    163180 
    164 ac_cv_have_getopt_long="no" 
    165 AC_CHECK_FUNCS(getopt_long, 
    166  [ac_cv_have_getopt_long="yes"], 
    167  [AC_CHECK_LIB(gnugetopt, getopt_long, 
    168    [ac_cv_have_getopt_long="yes" 
    169     GETOPT_LIBS="${GETOPT_LIBS} -lgnugetopt"])]) 
    170 if test "$ac_cv_have_getopt_long" != "no"; then 
    171   AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the `getopt_long' function.) 
    172 fi 
    173 AM_CONDITIONAL(NEED_GETOPT_LONG, test "$ac_cv_have_getopt_long" = "no") 
    174 AC_SUBST(GETOPT_LIBS) 
    175  
    176181AC_CHECK_LIB(m, log, [MATH_LIBS="-lm"]) 
    177182AC_SUBST(MATH_LIBS) 
  • zzuf/trunk/msvc/config.h

    r4676 r4683  
    5050/* #undef HAVE_GETDELIM */ 
    5151/* #undef HAVE_GETLINE */ 
    52 /* #undef HAVE_GETOPT_H */ 
    53 /* #undef HAVE_GETOPT_LONG */ 
    5452#define HAVE_GETPAGESIZE 1 
    5553/* #undef HAVE_GETTIMEOFDAY */ 
  • zzuf/trunk/msvc/zzat.vcxproj

    r4675 r4683  
    9494  </ItemDefinitionGroup> 
    9595  <ItemGroup> 
    96     <ClCompile Include="..\src\mygetopt.c" /> 
    9796    <ClCompile Include="..\src\zzat.c"> 
    9897      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)%(FileName)1.obj</ObjectFileName> 
     
    101100  </ItemGroup> 
    102101  <ItemGroup> 
    103     <ClInclude Include="..\src\mygetopt.h" /> 
    104102    <ClInclude Include="config.h" /> 
    105103  </ItemGroup> 
  • zzuf/trunk/msvc/zzuf.vcxproj

    r4675 r4683  
    101101    <ClInclude Include="..\src\md5.h" /> 
    102102    <ClInclude Include="..\src\myfork.h" /> 
    103     <ClInclude Include="..\src\mygetopt.h" /> 
    104103    <ClInclude Include="..\src\opts.h" /> 
    105104    <ClInclude Include="..\src\timer.h" /> 
     
    113112    <ClCompile Include="..\src\md5.c" /> 
    114113    <ClCompile Include="..\src\myfork.c" /> 
    115     <ClCompile Include="..\src\mygetopt.c" /> 
    116114    <ClCompile Include="..\src\opts.c" /> 
    117115    <ClCompile Include="..\src\timer.c" /> 
  • zzuf/trunk/src/Makefile.am

    r4657 r4683  
    2424    common/fuzz.c common/fuzz.h 
    2525 
    26 if NEED_GETOPT_LONG 
    27 GETOPT = mygetopt.c mygetopt.h 
    28 endif 
    29  
    30 zzuf_SOURCES = $(ZZUF) $(COMMON) $(GETOPT) 
     26zzuf_SOURCES = $(ZZUF) $(COMMON) 
    3127zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\" -I$(srcdir)/common 
    32 zzuf_LDFLAGS = $(MATH_LIBS) $(WINSOCK2_LIBS) 
     28zzuf_LDFLAGS = $(CACA_LIBS) $(MATH_LIBS) $(WINSOCK2_LIBS) 
    3329zzuf_DEPENDENCIES = libzzuf.la 
    3430 
    35 zzat_SOURCES = $(ZZAT) $(GETOPT) 
     31zzat_SOURCES = $(ZZAT) 
     32zzat_LDFLAGS = $(CACA_LIBS) 
    3633 
    3734libzzuf_la_SOURCES = $(LIBZZUF) $(COMMON) 
    3835libzzuf_la_CFLAGS = -DLIBZZUF -I$(srcdir)/libzzuf -I$(srcdir)/common 
    3936libzzuf_la_LDFLAGS = -avoid-version -no-undefined $(DLL_LDFLAGS) 
    40 libzzuf_la_LIBADD = $(GETOPT_LIBS) $(DL_LIBS) $(MATH_LIBS) $(WINSOCK2_LIBS) 
     37libzzuf_la_LIBADD = $(DL_LIBS) $(MATH_LIBS) $(WINSOCK2_LIBS) 
    4138 
    4239echo-sources: ; echo $(SOURCES) 
  • zzuf/trunk/src/zzat.c

    r4654 r4683  
    5151#include <string.h> 
    5252 
    53 #if !defined HAVE_GETOPT_LONG 
    54 #   include "mygetopt.h" 
    55 #elif defined HAVE_GETOPT_H 
    56 #   include <getopt.h> 
    57 #endif 
    58  
    59 #if defined HAVE_GETOPT_LONG 
    60 #   define mygetopt getopt_long 
    61 #   define myoptind optind 
    62 #   define myoptarg optarg 
    63 #   define myoption option 
    64 #endif 
     53#include <caca.h> 
    6554 
    6655static int run(char const *sequence, char const *file); 
     
    10089#define MOREINFO "Try `%s --help' for more information.\n" 
    10190        int option_index = 0; 
    102         static struct myoption long_options[] = 
     91        static struct caca_option long_options[] = 
    10392        { 
    10493            { "show-all",         0, NULL, 'A' }, 
     
    117106            { NULL,               0, NULL,  0  } 
    118107        }; 
    119         int c = mygetopt(argc, argv, OPTSTR, long_options, &option_index); 
     108        int c = caca_getopt(argc, argv, OPTSTR, long_options, &option_index); 
    120109 
    121110        if (c == -1) 
     
    143132            break; 
    144133        case 'r': /* --repeat */ 
    145             repeat = atoi(myoptarg); 
     134            repeat = atoi(caca_optarg); 
    146135            break; 
    147136        case 's': /* --squeeze-blank */ 
     
    158147            break; 
    159148        case 'x': /* --execute */ 
    160             if (myoptarg[0] == '=') 
    161                 myoptarg++; 
    162             sequence = myoptarg; 
     149            if (caca_optarg[0] == '=') 
     150                caca_optarg++; 
     151            sequence = caca_optarg; 
    163152            break; 
    164153        case 'l': /* --list */ 
     
    178167    } 
    179168 
    180     if (myoptind >= argc) 
     169    if (caca_optind >= argc) 
    181170    { 
    182171        fprintf(stderr, "E: zzat: too few arguments\n"); 
     
    185174 
    186175    while (repeat-- > 0) 
    187         for (i = myoptind; i < argc; i++) 
     176        for (i = caca_optind; i < argc; i++) 
    188177        { 
    189178            int ret = run(sequence, argv[i]); 
  • zzuf/trunk/src/zzuf.c

    r4669 r4683  
    2424#   include <inttypes.h> 
    2525#endif 
    26 #if !defined HAVE_GETOPT_LONG 
    27 #   include "mygetopt.h" 
    28 #elif defined HAVE_GETOPT_H 
    29 #   include <getopt.h> 
    30 #endif 
    3126#include <stdio.h> 
    3227#include <stdlib.h> 
     
    5550#   include <sys/resource.h> /* for RLIMIT_AS */ 
    5651#endif 
     52 
     53#include <caca.h> 
    5754 
    5855#include "common.h" 
     
    6562#include "timer.h" 
    6663 
    67 #if defined HAVE_GETOPT_LONG 
    68 #   define mygetopt getopt_long 
    69 #   define myoptind optind 
    70 #   define myoptarg optarg 
    71 #   define myoption option 
    72 #endif 
    73  
    7464#if !defined SIGKILL 
    7565#   define SIGKILL 9 
     
    157147#define MOREINFO "Try `%s --help' for more information.\n" 
    158148        int option_index = 0; 
    159         static struct myoption long_options[] = 
     149        static struct caca_option long_options[] = 
    160150        { 
    161151            /* Long option, needs arg, flag, short option */ 
     
    200190            { NULL,           0, NULL,  0  } 
    201191        }; 
    202         int c = mygetopt(argc, argv, OPTSTR, long_options, &option_index); 
     192        int c = caca_getopt(argc, argv, OPTSTR, long_options, &option_index); 
    203193 
    204194        if(c == -1) 
     
    208198        { 
    209199        case 'a': /* --allow */ 
    210             opts->allow = myoptarg; 
     200            opts->allow = caca_optarg; 
    211201            break; 
    212202        case 'A': /* --autoinc */ 
     
    214204            break; 
    215205        case 'b': /* --bytes */ 
    216             opts->bytes = myoptarg; 
     206            opts->bytes = caca_optarg; 
    217207            break; 
    218208        case 'B': /* --max-bytes */ 
    219             if(myoptarg[0] == '=') 
    220                 myoptarg++; 
    221             opts->maxbytes = atoi(myoptarg); 
     209            if(caca_optarg[0] == '=') 
     210                caca_optarg++; 
     211            opts->maxbytes = atoi(caca_optarg); 
    222212            break; 
    223213#if defined HAVE_REGEX_H 
     
    227217#endif 
    228218        case 'C': /* --max-crashes */ 
    229             if(myoptarg[0] == '=') 
    230                 myoptarg++; 
    231             opts->maxcrashes = atoi(myoptarg); 
     219            if(caca_optarg[0] == '=') 
     220                caca_optarg++; 
     221            opts->maxcrashes = atoi(caca_optarg); 
    232222            if(opts->maxcrashes <= 0) 
    233223                opts->maxcrashes = 0; 
     
    237227            break; 
    238228        case 'D': /* --delay */ 
    239             if(myoptarg[0] == '=') 
    240                 myoptarg++; 
    241             opts->delay = (int64_t)(atof(myoptarg) * 1000000.0); 
     229            if(caca_optarg[0] == '=') 
     230                caca_optarg++; 
     231            opts->delay = (int64_t)(atof(caca_optarg) * 1000000.0); 
    242232            break; 
    243233#if defined HAVE_REGEX_H 
    244234        case 'E': /* --exclude */ 
    245             exclude = merge_regex(exclude, myoptarg); 
     235            exclude = merge_regex(exclude, caca_optarg); 
    246236            if(!exclude) 
    247237            { 
    248238                fprintf(stderr, "%s: invalid regex -- `%s'\n", 
    249                         argv[0], myoptarg); 
     239                        argv[0], caca_optarg); 
    250240                _zz_opts_fini(opts); 
    251241                return EXIT_FAILURE; 
     
    254244#endif 
    255245        case 'f': /* --fuzzing */ 
    256             opts->fuzzing = myoptarg; 
     246            opts->fuzzing = caca_optarg; 
    257247            break; 
    258248        case 'F': 
     
    265255#if defined HAVE_REGEX_H 
    266256        case 'I': /* --include */ 
    267             include = merge_regex(include, myoptarg); 
     257            include = merge_regex(include, caca_optarg); 
    268258            if(!include) 
    269259            { 
    270260                fprintf(stderr, "%s: invalid regex -- `%s'\n", 
    271                         argv[0], myoptarg); 
     261                        argv[0], caca_optarg); 
    272262                _zz_opts_fini(opts); 
    273263                return EXIT_FAILURE; 
     
    276266#endif 
    277267        case 'j': /* --jobs */ 
    278             if(myoptarg[0] == '=') 
    279                 myoptarg++; 
    280             opts->maxchild = atoi(myoptarg) > 1 ? atoi(myoptarg) : 1; 
     268            if(caca_optarg[0] == '=') 
     269                caca_optarg++; 
     270            opts->maxchild = atoi(caca_optarg) > 1 ? atoi(caca_optarg) : 1; 
    281271            break; 
    282272        case 'l': /* --list */ 
    283             opts->list = myoptarg; 
     273            opts->list = caca_optarg; 
    284274            break; 
    285275        case 'm': /* --md5 */ 
     
    288278#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_MEM 
    289279        case 'M': /* --max-memory */ 
    290             if(myoptarg[0] == '=') 
    291                 myoptarg++; 
    292             opts->maxmem = atoi(myoptarg); 
     280            if(caca_optarg[0] == '=') 
     281                caca_optarg++; 
     282            opts->maxmem = atoi(caca_optarg); 
    293283            break; 
    294284#endif 
     
    298288            break; 
    299289        case 'O': /* --opmode */ 
    300             if(myoptarg[0] == '=') 
    301                 myoptarg++; 
    302             if (!strcmp(myoptarg, "preload")) 
     290            if(caca_optarg[0] == '=') 
     291                caca_optarg++; 
     292            if (!strcmp(caca_optarg, "preload")) 
    303293                opts->opmode = OPMODE_PRELOAD; 
    304             else if (!strcmp(myoptarg, "copy")) 
     294            else if (!strcmp(caca_optarg, "copy")) 
    305295                opts->opmode = OPMODE_COPY; 
    306296            else 
    307297            { 
    308298                fprintf(stderr, "%s: invalid operating mode -- `%s'\n", 
    309                         argv[0], myoptarg); 
     299                        argv[0], caca_optarg); 
    310300                _zz_opts_fini(opts); 
    311301                return EXIT_FAILURE; 
     
    313303            break; 
    314304        case 'p': /* --ports */ 
    315             opts->ports = myoptarg; 
     305            opts->ports = caca_optarg; 
    316306            break; 
    317307        case 'P': /* --protect */ 
    318             opts->protect = myoptarg; 
     308            opts->protect = caca_optarg; 
    319309            break; 
    320310        case 'q': /* --quiet */ 
     
    322312            break; 
    323313        case 'r': /* --ratio */ 
    324             if(myoptarg[0] == '=') 
    325                 myoptarg++; 
    326             tmp = strchr(myoptarg, ':'); 
    327             opts->minratio = atof(myoptarg); 
     314            if(caca_optarg[0] == '=') 
     315                caca_optarg++; 
     316            tmp = strchr(caca_optarg, ':'); 
     317            opts->minratio = atof(caca_optarg); 
    328318            opts->maxratio = tmp ? atof(tmp + 1) : opts->minratio; 
    329319            break; 
    330320        case 'R': /* --refuse */ 
    331             opts->refuse = myoptarg; 
     321            opts->refuse = caca_optarg; 
    332322            break; 
    333323        case 's': /* --seed */ 
    334             if(myoptarg[0] == '=') 
    335                 myoptarg++; 
    336             tmp = strchr(myoptarg, ':'); 
    337             opts->seed = atol(myoptarg); 
     324            if(caca_optarg[0] == '=') 
     325                caca_optarg++; 
     326            tmp = strchr(caca_optarg, ':'); 
     327            opts->seed = atol(caca_optarg); 
    338328            opts->endseed = tmp ? tmp[1] ? (uint32_t)atol(tmp + 1) 
    339329                                         : (uint32_t)-1L 
     
    344334            break; 
    345335        case 't': /* --max-time */ 
    346             if(myoptarg[0] == '=') 
    347                 myoptarg++; 
    348             opts->maxtime = (int64_t)atoi(myoptarg) * 1000000; 
     336            if(caca_optarg[0] == '=') 
     337                caca_optarg++; 
     338            opts->maxtime = (int64_t)atoi(caca_optarg) * 1000000; 
    349339            break; 
    350340#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_CPU 
    351341        case 'T': /* --max-cputime */ 
    352             if(myoptarg[0] == '=') 
    353                 myoptarg++; 
    354             opts->maxcpu = (int)(atof(myoptarg) + 0.5); 
     342            if(caca_optarg[0] == '=') 
     343                caca_optarg++; 
     344            opts->maxcpu = (int)(atof(caca_optarg) + 0.5); 
    355345            break; 
    356346#endif 
    357347        case 'U': /* --max-usertime */ 
    358             if(myoptarg[0] == '=') 
    359                 myoptarg++; 
    360             opts->maxusertime = (int64_t)(atof(myoptarg) * 1000000.0); 
     348            if(caca_optarg[0] == '=') 
     349                caca_optarg++; 
     350            opts->maxusertime = (int64_t)(atof(caca_optarg) * 1000000.0); 
    361351            break; 
    362352        case 'x': /* --check-exit */ 
     
    420410     * Mode 1: asked to read from the standard input 
    421411     */ 
    422     if(myoptind >= argc) 
     412    if(caca_optind >= argc) 
    423413    { 
    424414        if(opts->verbose) 
     
    449439            int dashdash = 0; 
    450440 
    451             for(i = myoptind + 1; i < argc; i++) 
     441            for(i = caca_optind + 1; i < argc; i++) 
    452442            { 
    453443                if(dashdash) 
     
    504494        for(i = 0; i < opts->maxchild; i++) 
    505495        { 
    506             int len = argc - myoptind; 
     496            int len = argc - caca_optind; 
    507497            opts->child[i].newargv = malloc((len + 1) * sizeof(char *)); 
    508             memcpy(opts->child[i].newargv, argv + myoptind, 
     498            memcpy(opts->child[i].newargv, argv + caca_optind, 
    509499                   len * sizeof(char *)); 
    510500            opts->child[i].newargv[len] = (char *)NULL; 
     
    705695            tmpdir = "/tmp"; 
    706696 
    707         for (j = myoptind + 1; j < opts->oldargc; j++) 
     697        for (j = caca_optind + 1; j < opts->oldargc; j++) 
    708698        { 
    709699            fpin = fopen(opts->oldargv[j], "r"); 
     
    723713            } 
    724714 
    725             opts->child[i].newargv[j - myoptind] = strdup(tmpname); 
     715            opts->child[i].newargv[j - caca_optind] = strdup(tmpname); 
    726716 
    727717            _zz_register(k); 
     
    898888        if (opts->opmode == OPMODE_COPY) 
    899889        { 
    900             for (j = myoptind + 1; j < opts->oldargc; j++) 
     890            for (j = caca_optind + 1; j < opts->oldargc; j++) 
    901891            { 
    902                 if (opts->child[i].newargv[j - myoptind] != opts->oldargv[j]) 
     892                if (opts->child[i].newargv[j - caca_optind] != opts->oldargv[j]) 
    903893                { 
    904                     unlink(opts->child[i].newargv[j - myoptind]); 
    905                     free(opts->child[i].newargv[j - myoptind]); 
    906                     opts->child[i].newargv[j - myoptind] = opts->oldargv[j]; 
     894                    unlink(opts->child[i].newargv[j - caca_optind]); 
     895                    free(opts->child[i].newargv[j - caca_optind]); 
     896                    opts->child[i].newargv[j - caca_optind] = opts->oldargv[j]; 
    907897                } 
    908898            } 
Note: See TracChangeset for help on using the changeset viewer.