Permit arg units (like 100Kb), add getdate?

2008-05-01 Thread Jeff Johnson

While using popt in another program, I came across 2 usage
cases that might be usefully internalized in popt.

One usage case was an attempt to specify a memory limit as
--memory 16777216
Adding unit scaling, e.g.
--memory 16Mb
--memory 16384Kb
would not be hard to add using something like
POPT_ARG_INT | POPT_ARGFLAG_UNITS
with the usual Kb/Kib Mb/Mib Gb/Gib tokens to prescale.

Another possible popt-1.15 usage case is getdate.y, which is wonderfully
useful for time/date argument input. While it is
rather easy to use getdate.y through a popt callback, perhaps
its time to push getdate.y into libpopt, and add a
POPT_ARG_DATE
distinguished method to make it as easy as possible to use getdate.y.

I'm also seeing a need for a KEY=VALUE comma separated list popt
sub-table option parser (there's a mouthful ;-)

I'm starting to see
--option K1=V1,K2=V2,K3=V3
occurrences more often. I can think of a couple ways to use popt
to recursively parse KEY=VALUE settings, either by keeping track
of a chained popt table that is used iff a specific --option is  
encountered,

or by overloading the pointer field to be used as a option specific
subtable parse.

Opinions?

73 de Jeff
__
POPT Library   http://rpm5.org
Developer Communication List   popt-devel@rpm5.org


Named bit fields ala ancient BSD %b format

2008-05-01 Thread Jeff Johnson

While I'm thinking about popt features, here is another:

The BSD kernel (iirc) devised a means to map bit files to names
using a %b format.

A string was used to map bit# - name. E.g. here's an example
from some rpmdb code that I use for output purposes

static const char * dbtFlags =
\20\1APPMALLOC\2ISSET\3MALLOC\4PARTIAL\5REALLOC\6USERMEM 
\7DUPOK;


The same technique (of nerdy embedded octal in a string) can be used  
to assign names to bits in a set,

permitting option parsing (using the format string above):

--option PARTIAL,DUPOK

to save the value 0x48 (i.e. (1  3) | (1  6)) into the target  
storage.


OTOH, generating the %b format string can be tedious, and perhaps
a more general table like (this from LZMA):

typedef struct {
const char *name;
uint64_t id;
   } name_id_map;

with name = NULL as table end sentinel should be done.

Opinions?

73 De Jeff

__
POPT Library   http://rpm5.org
Developer Communication List   popt-devel@rpm5.org