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

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  [email protected]
  Module: popt                             Date:   26-Jul-2009 18:25:23
  Branch: HEAD                             Handle: 2009072616252300

  Modified files:
    popt                    CHANGES libpopt.vers popt.c popt.h test1.c
                            testit.sh

  Log:
    - add methods for bit set union and intersection.
    - permit comma separated attribute lists, handle negated attributes.
    - better test for POPT_ARG_BITSET.

  Summary:
    Revision    Changes     Path
    1.114       +3  -0      popt/CHANGES
    1.8         +9  -0      popt/libpopt.vers
    1.134       +85 -15     popt/popt.c
    1.75        +6  -2      popt/popt.h
    1.43        +17 -5      popt/test1.c
    1.31        +1  -1      popt/testit.sh
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: popt/CHANGES
  ============================================================================
  $ cvs diff -u -r1.113 -r1.114 CHANGES
  --- popt/CHANGES      25 Jul 2009 22:24:29 -0000      1.113
  +++ popt/CHANGES      26 Jul 2009 16:25:23 -0000      1.114
  @@ -1,4 +1,7 @@
   1.15 -> 1.16:
  +    - add methods for bit set union and intersection.
  +    - permit comma separated attribute lists, handle negated attributes.
  +    - better test for POPT_ARG_BITSET.
       - add POPT_ARG_BITSET handling.
       - add POPT_ARG_SHORT handling.
       - handle all callback traversals within a C switch (for extendability 
ease).
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/libpopt.vers
  ============================================================================
  $ cvs diff -u -r1.7 -r1.8 libpopt.vers
  --- popt/libpopt.vers 25 Jul 2009 18:52:36 -0000      1.7
  +++ popt/libpopt.vers 26 Jul 2009 16:25:23 -0000      1.8
  @@ -9,6 +9,15 @@
       poptAddItem;
       poptAliasOptions;
       poptBadOption;
  +    _poptBitsN;
  +    _poptBitsM;
  +    _poptBitsK;
  +    poptBitsAdd;
  +    poptBitsChk;
  +    poptBitsClr;
  +    poptBitsDel;
  +    poptBitsIntersect;
  +    poptBitsUnion;
       poptConfigFileToString;
       poptDupArgv;
       poptFinit;
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/popt.c
  ============================================================================
  $ cvs diff -u -r1.133 -r1.134 popt.c
  --- popt/popt.c       25 Jul 2009 22:24:29 -0000      1.133
  +++ popt/popt.c       26 Jul 2009 16:25:23 -0000      1.134
  @@ -759,6 +759,24 @@
   /*...@unchecked@*/
   unsigned int _poptBitsK = _POPT_BITS_K;
   
  +static int _poptBitsNew(poptBits *bitsp)
  +{
  +    if (bitsp == NULL)
  +     return POPT_ERROR_NULLARG;
  +
  +    /* XXX handle negated initialization. */
  +    if (*bitsp == NULL) {
  +     if (_poptBitsN == 0) {
  +         _poptBitsN = _POPT_BITS_N;
  +         _poptBitsM = _POPT_BITS_M;
  +     }
  +     if (_poptBitsM == 0U) _poptBitsM = (3 * _poptBitsN) / 2;
  +     if (_poptBitsK == 0U || _poptBitsK > 32U) _poptBitsK = _POPT_BITS_K;
  +     *bitsp = PBM_ALLOC(_poptBitsM-1);
  +    }
  +    return 0;
  +}
  +
   /*...@-sizeoftype@*/
   int poptBitsAdd(poptBits bits, const char * s)
   {
  @@ -769,7 +787,6 @@
       if (bits == NULL || ns == 0)
        return POPT_ERROR_NULLARG;
   
  -    /* XXX parse CSV? */
       jlu32lpair(s, ns, &h0, &h1);
   
       for (ns = 0; ns < (size_t)_poptBitsK; ns++) {
  @@ -790,7 +807,6 @@
       if (bits == NULL || ns == 0)
        return POPT_ERROR_NULLARG;
   
  -    /* XXX parse CSV? */
       jlu32lpair(s, ns, &h0, &h1);
   
       for (ns = 0; ns < (size_t)_poptBitsK; ns++) {
  @@ -824,7 +840,6 @@
       if (bits == NULL || ns == 0)
        return POPT_ERROR_NULLARG;
   
  -    /* XXX parse CSV? */
       jlu32lpair(s, ns, &h0, &h1);
   
       for (ns = 0; ns < (size_t)_poptBitsK; ns++) {
  @@ -835,25 +850,80 @@
       return 0;
   }
   
  +int poptBitsIntersect(poptBits *ap, const poptBits b)
  +{
  +    __pbm_bits *abits;
  +    __pbm_bits *bbits;
  +    __pbm_bits rc = 0;
  +    size_t nw = (__PBM_IX(_poptBitsM-1) + 1);
  +    size_t i;
  +
  +    if (_poptBitsNew(ap) || b == NULL)
  +     return POPT_ERROR_NULLARG;
  +    abits = __PBM_BITS(*ap);
  +    bbits = __PBM_BITS(b);
  +
  +    for (i = 0; i < nw; i++) {
  +        abits[i] &= bbits[i];
  +     rc |= abits[i];
  +    }
  +    return (rc ? 1 : 0);
  +}
  +
  +int poptBitsUnion(poptBits *ap, const poptBits b)
  +{
  +    __pbm_bits *abits;
  +    __pbm_bits *bbits;
  +    __pbm_bits rc = 0;
  +    size_t nw = (__PBM_IX(_poptBitsM-1) + 1);
  +    size_t i;
  +
  +    if (_poptBitsNew(ap) || b == NULL)
  +     return POPT_ERROR_NULLARG;
  +    abits = __PBM_BITS(*ap);
  +    bbits = __PBM_BITS(b);
  +
  +    for (i = 0; i < nw; i++) {
  +        abits[i] |= bbits[i];
  +     rc |= abits[i];
  +    }
  +    return (rc ? 1 : 0);
  +}
  +
   int poptSaveBits(poptBits * bitsp,
                /*...@unused@*/ UNUSED(unsigned int argInfo), const char * s)
   {
  -    if (bitsp == NULL)
  +    char *tbuf = NULL;
  +    char *t, *te;
  +    int rc = 0;
  +
  +    if (_poptBitsNew(bitsp) || s == NULL || *s == '\0')
        return POPT_ERROR_NULLARG;
   
  -    /* XXX handle negated initialization. */
  -    if (*bitsp == NULL) {
  -     if (_poptBitsN == 0) {
  -         _poptBitsN = _POPT_BITS_N;
  -         _poptBitsM = _POPT_BITS_M;
  -     }
  -     if (_poptBitsM == 0U) _poptBitsM = (3 * _poptBitsN) / 2;
  -     if (_poptBitsK == 0U || _poptBitsK > 32U) _poptBitsK = _POPT_BITS_K;
  -     *bitsp = PBM_ALLOC(_poptBitsM-1);
  -    }
  +    /* Parse comma separated attributes. */
  +    te = tbuf = xstrdup(s);
  +    while ((t = te) != NULL && *t) {
  +     while (*te != '\0' && *te != ',')
  +         te++;
  +     if (*te)
  +         *te++ = '\0';
  +     /* XXX Ignore empty strings. */
  +     if (*t == '\0')
  +         continue;
  +     /* XXX Permit negated attributes. caveat emptor: false negatives. */
  +     if (*t == '!') {
  +         t++;
  +         if ((rc = poptBitsChk(*bitsp, t)) > 0)
  +             rc = poptBitsDel(*bitsp, t);
  +     } else
  +         rc = poptBitsAdd(*bitsp, t);
   /*...@-nullstate@*/
  -    return poptBitsAdd(*bitsp, s);
  +     if (rc)
  +         break;
   /*...@=nullstate@*/
  +    }
  +    tbuf = _free(tbuf);
  +    return rc;
   }
   /*...@=sizeoftype@*/
   
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/popt.h
  ============================================================================
  $ cvs diff -u -r1.74 -r1.75 popt.h
  --- popt/popt.h       25 Jul 2009 22:24:29 -0000      1.74
  +++ popt/popt.h       26 Jul 2009 16:25:23 -0000      1.75
  @@ -699,16 +699,20 @@
   extern  unsigned int _poptBitsK;
   /*...@=exportlocal =export...@*/
   
  -/*...@-exportlocal@*/
   int poptBitsAdd(/*...@null@*/poptBits bits, /*...@null@*/const char * s)
        /*...@modifies bits @*/;
  -/*...@-fcnuse@*/
   int poptBitsChk(/*...@null@*/poptBits bits, /*...@null@*/const char * s)
        /*...@*/;
   int poptBitsClr(/*...@null@*/poptBits bits)
        /*...@modifies bits @*/;
   int poptBitsDel(/*...@null@*/poptBits bits, /*...@null@*/const char * s)
        /*...@modifies bits @*/;
  +/*...@-exportlocal@*/
  +/*...@-fcnuse@*/
  +int poptBitsIntersect(/*...@null@*/ poptBits * ap, /*...@null@*/ const 
poptBits b)
  +     /*...@modifies *ap @*/;
  +int poptBitsUnion(/*...@null@*/ poptBits * ap, /*...@null@*/ const poptBits 
b)
  +     /*...@modifies *ap @*/;
   /*...@=fcnuse@*/
   /*...@=exportlocal@*/
   
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/test1.c
  ============================================================================
  $ cvs diff -u -r1.42 -r1.43 test1.c
  --- popt/test1.c      25 Jul 2009 22:24:29 -0000      1.42
  +++ popt/test1.c      26 Jul 2009 16:25:23 -0000      1.43
  @@ -66,6 +66,12 @@
   static const char ** aArgv = NULL;
   /*...@unchecked@*/ /*...@only@*/ /*...@null@*/
   static void * aBits = NULL;
  +/*...@unchecked@*/
  +static const char *attributes[] = {
  +    "foo", "bar", "baz", "bing", "bang", "boom"
  +};
  +/*...@unchecked@*/
  +static size_t nattributes = (sizeof(attributes) / sizeof(attributes[0]));
   
   /*...@unchecked@*/ /*...@null@*/
   static char * oStr = (char *) -1;
  @@ -216,10 +222,8 @@
        free(aArgv);
        aArgv = NULL;
       }
  -    if (aBits) {
  -     free(aBits);
  -     aBits = NULL;
  -    }
  +    if (aBits)
  +     poptBitsClr(aBits);
   
       oStr = (char *) -1;
   
  @@ -317,7 +321,15 @@
            fprintf(stdout, " %s", arg);
       }
       if (aBits) {
  -     fprintf(stdout, " aBits: non-null");
  +     const char * separator = " ";
  +     size_t i;
  +     fprintf(stdout, " aBits:");
  +     for (i = 0; i < nattributes; i++) {
  +         if (!poptBitsChk(aBits, attributes[i]))
  +             continue;
  +         fprintf(stdout, "%s%s", separator, attributes[i]);
  +         separator = ",";
  +     }
       }
   /*...@-nullpass@*/
       if (oStr != (char *)-1)
  @@ .
  patch -p0 <<'@@ .'
  Index: popt/testit.sh
  ============================================================================
  $ cvs diff -u -r1.30 -r1.31 testit.sh
  --- popt/testit.sh    25 Jul 2009 22:24:29 -0000      1.30
  +++ popt/testit.sh    26 Jul 2009 16:25:23 -0000      1.31
  @@ -112,7 +112,7 @@
   run test1 "test1 - 55" "arg1: 0 arg2: (none) aFlag: 0x8888" --nobitset
   run test1 "test1 - 56" "arg1: 0 arg2: (none) aFlag: 0xface" --nobitclr
   
  -run test1 "test1 - 57" "arg1: 0 arg2: (none) aBits: non-null" --bits foo 
--bits bar
  +run test1 "test1 - 57" "arg1: 0 arg2: (none) aBits: foo,baz" --bits 
foo,bar,baz,!bar
   
   run test1 "test1 - 58" "\
   Usage: lt-test1 [-I?] [-c|--cb2=STRING] [--arg1] [-2|--arg2=ARG]
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to