Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions popt/README
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ This is the popt command line option parsing library. While it is similar
to getopt(3), it contains a number of enhancements, including:

1) popt is fully reentrant
2) popt can parse arbitrary argv[] style arrays while
2) popt can parse arbitrary argv[] style arrays while
getopt(2) makes this quite difficult
3) popt allows users to alias command line arguments
4) popt provides convenience functions for parsing strings
into argv[] style arrays

popt is used by rpm, the Red Hat install program, and many other Red Hat
utilities, all of which provide excellent examples of how to use popt.
utilities, all of which provide excellent examples of how to use popt.
Complete documentation on popt is available in popt.ps (included in this
tarball), which is excerpted with permission from the book "Linux
Application Development" by Michael K. Johnson and Erik Troan (available
Expand Down
60 changes: 30 additions & 30 deletions popt/lookup3.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* -------------------------------------------------------------------- */
/*
* lookup3.c, by Bob Jenkins, May 2006, Public Domain.
*
*
* These are functions for producing 32-bit hashes for hash table lookup.
* jlu32w(), jlu32l(), jlu32lpair(), jlu32b(), _JLU3_MIX(), and _JLU3_FINAL()
* are externally useful functions. Routines to test the hash are included
* jlu32w(), jlu32l(), jlu32lpair(), jlu32b(), _JLU3_MIX(), and _JLU3_FINAL()
* are externally useful functions. Routines to test the hash are included
* if SELF_TEST is defined. You can use this free for any purpose. It's in
* the public domain. It has no warranty.
*
*
* You probably want to use jlu32l(). jlu32l() and jlu32b()
* hash byte arrays. jlu32l() is is faster than jlu32b() on
* little-endian machines. Intel and AMD are little-endian machines.
* On second thought, you probably want jlu32lpair(), which is identical to
* jlu32l() except it returns two 32-bit hashes for the price of one.
* jlu32l() except it returns two 32-bit hashes for the price of one.
* You could implement jlu32bpair() if you wanted but I haven't bothered here.
*
*
* If you want to find a hash of, say, exactly 7 integers, do
* a = i1; b = i2; c = i3;
* _JLU3_MIX(a,b,c);
Expand All @@ -25,9 +25,9 @@
* then use c as the hash value. If you have a variable size array of
* 4-byte integers to hash, use jlu32w(). If you have a byte array (like
* a character string), use jlu32l(). If you have several byte arrays, or
* a mix of things, see the comments above jlu32l().
*
* Why is this so big? I read 12 bytes at a time into 3 4-byte integers,
* a mix of things, see the comments above jlu32l().
*
* Why is this so big? I read 12 bytes at a time into 3 4-byte integers,
* then mix those integers. This is fast (you can do a lot more thorough
* mixing with 12*3 instructions on 3 integers than you can with 3 instructions
* on 1 byte), but shoehorning those bytes into integers efficiently is messy.
Expand Down Expand Up @@ -60,10 +60,10 @@ static const union _dbswap {
/* -------------------------------------------------------------------- */
/*
* _JLU3_MIX -- mix 3 32-bit values reversibly.
*
*
* This is reversible, so any information in (a,b,c) before _JLU3_MIX() is
* still in (a,b,c) after _JLU3_MIX().
*
*
* If four pairs of (a,b,c) inputs are run through _JLU3_MIX(), or through
* _JLU3_MIX() in reverse, there are at least 32 bits of the output that
* are sometimes the same for one pair and different for another pair.
Expand All @@ -75,24 +75,24 @@ static const union _dbswap {
* the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
* is commonly produced by subtraction) look like a single 1-bit
* difference.
* * the base values were pseudorandom, all zero but one bit set, or
* * the base values were pseudorandom, all zero but one bit set, or
* all zero plus a counter that starts at zero.
*
*
* Some k values for my "a-=c; a^=ROTL32(c,k); c+=b;" arrangement that
* satisfy this are
* 4 6 8 16 19 4
* 9 15 3 18 27 15
* 14 9 3 7 17 3
* Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing
* for "differ" defined as + with a one-bit base and a two-bit delta. I
* used http://burtleburtle.net/bob/hash/avalanche.html to choose
* used http://burtleburtle.net/bob/hash/avalanche.html to choose
* the operations, constants, and arrangements of the variables.
*
*
* This does not achieve avalanche. There are input bits of (a,b,c)
* that fail to affect some output bits of (a,b,c), especially of a. The
* most thoroughly mixed value is c, but it doesn't really even achieve
* avalanche in c.
*
*
* This allows some parallelism. Read-after-writes are good at doubling
* the number of bits affected, so the goal of mixing pulls in the opposite
* direction as the goal of parallelism. I did what I could. Rotates
Expand All @@ -114,7 +114,7 @@ static const union _dbswap {
/* -------------------------------------------------------------------- */
/**
* _JLU3_FINAL -- final mixing of 3 32-bit values (a,b,c) into c
*
*
* Pairs of (a,b,c) values differing in only a few bits will usually
* produce values of c that look totally different. This was tested for
* * pairs that differed by one bit, by two bits, in any combination
Expand All @@ -124,9 +124,9 @@ static const union _dbswap {
* the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
* is commonly produced by subtraction) look like a single 1-bit
* difference.
* * the base values were pseudorandom, all zero but one bit set, or
* * the base values were pseudorandom, all zero but one bit set, or
* all zero plus a counter that starts at zero.
*
*
* These constants passed:
* 14 11 25 16 4 14 24
* 12 14 25 16 4 14 24
Expand Down Expand Up @@ -154,7 +154,7 @@ uint32_t jlu32w(uint32_t h, const uint32_t *k, size_t size);
* This works on all machines. To be useful, it requires
* -- that the key be an array of uint32_t's, and
* -- that the size be the number of uint32_t's in the key
*
*
* The function jlu32w() is identical to jlu32l() on little-endian
* machines, and identical to jlu32b() on big-endian machines,
* except that the size has to be measured in uint32_ts rather than in
Expand Down Expand Up @@ -213,19 +213,19 @@ uint32_t jlu32l(uint32_t h, const void *key, size_t size);
* Returns a 32-bit value. Every bit of the key affects every bit of
* the return value. Two keys differing by one or two bits will have
* totally different hash values.
*
*
* The best hash table sizes are powers of 2. There is no need to do
* mod a prime (mod is sooo slow!). If you need less than 32 bits,
* use a bitmask. For example, if you need only 10 bits, do
* h = (h & hashmask(10));
* In which case, the hash table should have hashsize(10) elements.
*
*
* If you are hashing n strings (uint8_t **)k, do it like this:
* for (i=0, h=0; i<n; ++i) h = jlu32l(h, k[i], len[i]);
*
*
* By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this
* code any way you wish, private, educational, or commercial. It's free.
*
*
* Use for hash table lookup, or anything where one collision in 2^^32 is
* acceptable. Do NOT use for cryptographic purposes.
*
Expand Down Expand Up @@ -263,7 +263,7 @@ uint32_t jlu32l(uint32_t h, const void *key, size_t size)
}

/*------------------------- handle the last (probably partial) block */
/*
/*
* "k[2]&0xffffff" actually reads beyond the end of the string, but
* then masks off the part it's not allowed to read. Because the
* string is aligned, the masked-off tail is in the same word as the
Expand Down Expand Up @@ -469,7 +469,7 @@ void jlu32lpair(const void *key, size_t size, uint32_t *pc, uint32_t *pb)
k += 3;
}
/*------------------------- handle the last (probably partial) block */
/*
/*
* "k[2]&0xffffff" actually reads beyond the end of the string, but
* then masks off the part it's not allowed to read. Because the
* string is aligned, the masked-off tail is in the same word as the
Expand Down Expand Up @@ -637,7 +637,7 @@ uint32_t jlu32b(uint32_t h, const void *key, size_t size);
* jlu32b():
* This is the same as jlu32w() on big-endian machines. It is different
* from jlu32l() on all machines. jlu32b() takes advantage of
* big-endian byte ordering.
* big-endian byte ordering.
*
* @param h the previous hash, or an arbitrary value
* @param *k the key, an array of uint8_t values
Expand Down Expand Up @@ -672,7 +672,7 @@ uint32_t jlu32b(uint32_t h, const void *key, size_t size)
}

/*------------------------- handle the last (probably partial) block */
/*
/*
* "k[2]<<8" actually reads beyond the end of the string, but
* then shifts out the part it's not allowed to read. Because the
* string is aligned, the illegal read is in the same word as the
Expand Down Expand Up @@ -811,7 +811,7 @@ static void driver2(void)
e[l]=f[l]=g[l]=h[l]=x[l]=y[l]=~((uint32_t)0);

/* check that every output bit is affected by that input bit */
for (k=0; k<MAXPAIR; k+=2) {
for (k=0; k<MAXPAIR; k+=2) {
uint32_t finished=1;
/* keys have one bit different */
for (l=0; l<hlen+1; ++l) {a[l] = b[l] = (uint8_t)0;}
Expand Down Expand Up @@ -921,7 +921,7 @@ static void driver3(void)
*(b-1)=(uint8_t)~0;
x = jlu32l(m, b, len);
y = jlu32l(m, b, len);
if ((ref != x) || (ref != y))
if ((ref != x) || (ref != y))
printf("alignment error: %.8x %.8x %.8x %u %u\n",ref,x,y, h, i);
}
}
Expand Down
14 changes: 7 additions & 7 deletions popt/popt.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static int handleAlias(poptContext con,
con->os->currAlias = con->aliases + i;
{ const char ** av;
int ac = con->os->currAlias->argc;
/* Append --foo=bar arg to alias argv array (if present). */
/* Append --foo=bar arg to alias argv array (if present). */
if (longName && nextArg != NULL && *nextArg != '\0') {
av = malloc((ac + 1 + 1) * sizeof(*av));
if (av != NULL) { /* XXX won't happen. */
Expand Down Expand Up @@ -907,7 +907,7 @@ int poptSaveString(const char *** argvp,
if (*argvp != NULL)
while ((*argvp)[argc] != NULL)
argc++;

if ((*argvp = xrealloc(*argvp, (argc + 1 + 1) * sizeof(**argvp))) != NULL) {
(*argvp)[argc++] = xstrdup(val);
(*argvp)[argc ] = NULL;
Expand Down Expand Up @@ -1406,7 +1406,7 @@ int poptGetNextOpt(poptContext con)
{
poptStripArg(con, con->os->next);
}

if (con->os->argv != NULL) { /* XXX can't happen */
if (F_ISSET(opt, OPTIONAL) &&
con->os->argv[con->os->next][0] == '-') {
Expand Down Expand Up @@ -1547,7 +1547,7 @@ poptContext poptFreeContext(poptContext con)
con->otherHelp = _free(con->otherHelp);
con->execPath = _free(con->execPath);
con->arg_strip = PBM_FREE(con->arg_strip);

con = _free(con);
return con;
}
Expand Down Expand Up @@ -1697,19 +1697,19 @@ int poptStrippedArgv(poptContext con, int argc, char ** argv)
int numargs = argc;
int j = 1;
int i;

if (con->arg_strip)
for (i = 1; i < argc; i++) {
if (PBM_ISSET(i, con->arg_strip))
numargs--;
}

for (i = 1; i < argc; i++) {
if (con->arg_strip && PBM_ISSET(i, con->arg_strip))
continue;
argv[j] = (j < numargs) ? argv[i] : NULL;
j++;
}

return numargs;
}
30 changes: 15 additions & 15 deletions popt/popt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*/

/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
file accompanying popt source distributions, available from
ftp://ftp.rpm.org/pub/rpm/dist. */

#ifndef H_POPT
Expand All @@ -21,8 +21,8 @@
#define POPT_ARG_LONG 3U /*!< arg ==> long */
#define POPT_ARG_INCLUDE_TABLE 4U /*!< arg points to table */
#define POPT_ARG_CALLBACK 5U /*!< table-wide callback... must be
set first in table; arg points
to callback, descrip points to
set first in table; arg points
to callback, descrip points to
callback data to pass */
#define POPT_ARG_INTL_DOMAIN 6U /*!< set the translation domain
for this table and any
Expand Down Expand Up @@ -173,7 +173,7 @@ typedef struct poptOption * poptOption;
/**
*/
enum poptCallbackReason {
POPT_CALLBACK_REASON_PRE = 0,
POPT_CALLBACK_REASON_PRE = 0,
POPT_CALLBACK_REASON_POST = 1,
POPT_CALLBACK_REASON_OPTION = 2
};
Expand All @@ -190,7 +190,7 @@ extern "C" {
* @param arg @todo Document.
* @param data @todo Document.
*/
typedef void (*poptCallbackType) (poptContext con,
typedef void (*poptCallbackType) (poptContext con,
enum poptCallbackReason reason,
const struct poptOption * opt,
const char * arg,
Expand Down Expand Up @@ -391,7 +391,7 @@ int poptParseArgvString(const char * s,
int * argcPtr, const char *** argvPtr);

/**
* Parses an input configuration file and returns an string that is a
* Parses an input configuration file and returns an string that is a
* command line. For use with popt. You must free the return value when done.
*
* Given the file:
Expand All @@ -400,14 +400,14 @@ int poptParseArgvString(const char * s,
# this one too
aaa
bbb
ccc
ccc
bla=bla

this_is = fdsafdas
bad_line=
bad_line=
really bad line
really bad line = again
5555= 55555
5555= 55555
test = with lots of spaces
\endverbatim
*
Expand All @@ -419,12 +419,12 @@ this_is = fdsafdas
* Passing this to poptParseArgvString() yields an argv of:
\verbatim
'--aaa'
'--bbb'
'--ccc'
'--bla=bla'
'--this_is=fdsafdas'
'--5555=55555'
'--test=with lots of spaces'
'--bbb'
'--ccc'
'--bla=bla'
'--this_is=fdsafdas'
'--5555=55555'
'--test=with lots of spaces'
\endverbatim
*
* @bug NULL is returned if file line is too long.
Expand Down
8 changes: 4 additions & 4 deletions popt/poptconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
file accompanying popt source distributions, available from
ftp://ftp.rpm.org/pub/rpm/dist. */

#include "system.h"
Expand Down Expand Up @@ -235,7 +235,7 @@ static int poptConfigLine(poptContext con, char * line)

if (con->appName == NULL)
goto exit;

memset(item, 0, sizeof(*item));

appName = se;
Expand Down Expand Up @@ -330,7 +330,7 @@ static int poptConfigLine(poptContext con, char * line)
item->argv[j] = NULL;
item->argc = j;
}

if (!strcmp(entryType, "alias"))
rc = poptAddItem(con, item, 0);
else if (!strcmp(entryType, "exec"))
Expand Down Expand Up @@ -504,7 +504,7 @@ poptInit(int argc, const char ** argv,

if ((argv0 = strrchr(argv[0], '/')) != NULL) argv0++;
else argv0 = argv[0];

con = poptGetContext(argv0, argc, (const char **)argv, options, 0);
if (con != NULL&& poptReadConfigFiles(con, configPaths))
con = poptFini(con);
Expand Down
Loading
Loading