[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rpm-cvs
Subject:    [CVS] RPM: popt/ CHANGES Makefile.am libpopt.vers tdict.c
From:       "Jeff Johnson" <jbj () rpm5 ! org>
Date:       2009-07-26 19:14:09
Message-ID: 20090726191409.6D30A4C1C () rpm5 ! org
[Download RAW message or body]

  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: popt                             Date:   26-Jul-2009 21:14:09
  Branch: HEAD                             Handle: 2009072619140900

  Added files:
    popt                    tdict.c
  Modified files:
    popt                    CHANGES Makefile.am libpopt.vers

  Log:
    - add tdict.c to exercise popt bit sets against /usr/dict/words.

  Summary:
    Revision    Changes     Path
    1.116       +1  -0      popt/CHANGES
    1.52        +4  -1      popt/Makefile.am
    1.10        +1  -0      popt/libpopt.vers
    1.1         +125 -0     popt/tdict.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: popt/CHANGES
  ============================================================================
  $ cvs diff -u -r1.115 -r1.116 CHANGES
  --- popt/CHANGES	26 Jul 2009 17:09:27 -0000	1.115
  +++ popt/CHANGES	26 Jul 2009 19:14:09 -0000	1.116
  @@ -1,4 +1,5 @@
   1.15 -> 1.16:
  +    - add tdict.c to exercise popt bit sets against /usr/dict/words.
       - add poptBitsArgs() method to generate args bit set.
       - add methods for bit set union and intersection.
       - permit comma separated attribute lists, handle negated attributes.
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.51 -r1.52 Makefile.am
  --- popt/Makefile.am	25 Jul 2009 05:47:13 -0000	1.51
  +++ popt/Makefile.am	26 Jul 2009 19:14:09 -0000	1.52
  @@ -16,7 +16,7 @@
   
   noinst_HEADERS = poptint.h system.h
   
  -noinst_PROGRAMS = test1 test2 test3
  +noinst_PROGRAMS = test1 test2 test3 tdict
   test1_SOURCES = test1.c
   test1_LDFLAGS = 
   test1_LDADD = $(usrlib_LTLIBRARIES)
  @@ -26,6 +26,9 @@
   test3_SOURCES = test3.c
   test3_LDFLAGS = 
   test3_LDADD = $(usrlib_LTLIBRARIES)
  +tdict_SOURCES = tdict.c
  +tdict_LDFLAGS = 
  +tdict_LDADD = $(usrlib_LTLIBRARIES)
   
   noinst_SCRIPTS = testit.sh
   
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/libpopt.vers
  ============================================================================
  $ cvs diff -u -r1.9 -r1.10 libpopt.vers
  --- popt/libpopt.vers	26 Jul 2009 17:09:27 -0000	1.9
  +++ popt/libpopt.vers	26 Jul 2009 19:14:09 -0000	1.10
  @@ -42,6 +42,7 @@
       poptReadDefaultConfig;
       poptResetContext;
       poptSaneFile;
  +    poptSaveBits;
       poptSaveInt;
       poptSaveLong;
       poptSaveLongLong;
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/tdict.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1 tdict.c
  --- /dev/null	2009-07-26 21:11:00 +0200
  +++ tdict.c	2009-07-26 21:14:09 +0200
  @@ -0,0 +1,125 @@
  +#include "system.h"
  +#include <stdio.h>
  +#include "popt.h"
  +
  +static int _debug = 0;
  +static int _verbose = 1;
  +static const char * dictfn = "/usr/share/dict/words";
  +static poptBits dictbits = NULL;
  +static struct {
  +    unsigned total;
  +    unsigned hits;
  +    unsigned misses;
  +} e;
  +
  +static int loadDict(const char * fn, poptBits * ap)
  +{
  +    char b[BUFSIZ];
  +    size_t nb = sizeof(b);
  +    FILE * fp = fopen(fn, "r");
  +    char * t, *te;
  +    int nlines = -1;
  +
  +    if (fp == NULL || ferror(fp)) goto exit;
  +
  +    nlines = 0;
  +    while ((t = fgets(b, nb, fp)) != NULL) {
  +	while (*t && isspace(*t)) t++;
  +	if (*t == '#') continue;
  +	te = t + strlen(t);
  +	while (te-- > t && isspace(*te)) *te = '\0';
  +	if (*t == '\0') continue;
  +	if (ap) {
  +if (_debug)
  +fprintf(stderr, "==> poptSaveBits(%p, \"%s\")\n", *ap, t);
  +	    (void) poptSaveBits(ap, 0, t);
  +	}
  +	nlines++;
  +    }
  +exit:
  +    if (fp) (void) fclose(fp);
  +    return nlines;
  +}
  +
  +static struct poptOption options[] = {
  +  { "debug", 'd', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE, &_debug, 1,
  +        "Set debugging.", NULL },
  +  { "verbose", 'v', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE, &_verbose, 1,
  +        "Set verbosity.", NULL },
  +
  +  POPT_AUTOALIAS
  +  POPT_AUTOHELP
  +  POPT_TABLEEND
  +};
  +
  +int main(int argc, const char ** argv)
  +{
  +    poptContext optCon = NULL;
  +    const char ** av = NULL;
  +    poptBits avbits = NULL;
  +    int ec = 2;		/* assume failure */
  +    int rc;
  +
  +#if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
  +    mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
  +#endif
  +
  +    /* XXX Scale the Bloom filters in popt. */
  +    if ((rc = loadDict(dictfn, NULL)) <= 0)
  +	goto exit;
  +    _poptBitsK = 2;
  +    _poptBitsM = 0;
  +    _poptBitsN = _poptBitsK * rc;
  +
  +    optCon = poptGetContext("tdict", argc, argv, options, 0);
  +
  +    /* Read all the options (if any). */
  +    while ((rc = poptGetNextOpt(optCon)) > 0) {
  +        char * optArg = poptGetOptArg(optCon);
  +	if (optArg) free(optArg);
  +        switch (rc) {
  +        default:	goto exit;	break;
  +        }
  +    }
  +    if (rc < -1) {
  +        fprintf(stderr, "tdict: %s: %s\n",
  +                poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
  +                poptStrerror(rc));
  +	goto exit;
  +    }
  +
  +    if ((rc = loadDict(dictfn, &dictbits)) <= 0)
  +	goto exit;
  +
  +    av = poptGetArgs(optCon);
  +    if ((rc = poptBitsArgs(optCon, &avbits)) != 0)
  +	goto exit;
  +    if (av && avbits)
  +    while (*av) {
  +	rc = poptBitsChk(dictbits, *av);
  +	if (rc < 0) goto exit;
  +	e.total++;
  +	if (rc > 0) {
  +	    if (_verbose)
  +		fprintf(stdout, "%s:\tYES\n", *av);
  +	    e.hits++;
  +	} else {
  +	    if (_verbose)
  +		fprintf(stdout, "%s:\tNO\n", *av);
  +	    e.misses++;
  +	}
  +	av++;
  +    }
  +
  +    ec = 0;
  +
  +exit:
  +    fprintf(stdout, "===== poptBits N:%u M:%u K:%u (%uKb) total(%u) = hits(%u) + misses(%u)\n",
  +	_poptBitsN, _poptBitsM, _poptBitsK, (((_poptBitsM/8)+1)+1023)/1024, e.total, e.hits, e.misses);
  +    if (avbits) free(avbits);
  +    optCon = poptFreeContext(optCon);
  +#if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
  +    muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
  +#endif
  +    return ec;
  +}
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic