[prev in list] [next in list] [prev in thread] [next in thread]
List: popt-devel
Subject: Named bit fields ala ancient BSD %b format
From: Jeff Johnson <n3npq () mac ! com>
Date: 2008-05-01 17:43:17
Message-ID: 09951966-FE5C-4940-A939-A838BEA37758 () mac ! com
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic