On Monday 14 July 2008 03:02, L. Gabriel Somlo wrote:
> On Sun, Jul 13, 2008 at 02:13:56AM +0200, Denys Vlasenko wrote:
>
> > enum {
> > OPT_extended = 0x4,
> > OPT_showroute = 0x100,
> > - OPT_widedisplay = 0x200 * ENABLE_FEATURE_NETSTAT_WIDE,
> > + OPT_widedisplay = 0x200,
> > + OPT_showprog = 0x400,
> >
> > Why this change?
>
> Mainly for uniform handling of *optional* options. Originally,
> NETSTAT_OPTS had a conditional USE_FEATURE_NETSTAT_WIDE("W"). Couldn't
> add "p" the same way, or else we'd never know which one of them is
> 0x200 and which one is 0x400 :) Once I decided to put them both in
> there regardless of whether support for them was compiled in or not, I
> wanted to allow usage to be printed out if -W was selected on the
> command line w/o support for it being compiled in:
>
> if (opt & OPT_widedisplay) { // -W
> #if ENABLE_FEATURE_NETSTAT_WIDE
> net_conn_line = PRINT_NET_CONN_WIDE;
> net_conn_line_header = PRINT_NET_CONN_HEADER_WIDE;
> #else
> bb_show_usage();
> #endif
> }
Known problem; and solution is devised. Here is an example from tar.c.
Basically, we use enum's feature of automatically incremented values,
thus all enabled options get successive bit positions (OPTBIT_xxx).
Then OPT_xxx mask is simply (1 << OPTBIT_xxx) if enabled, or 0 if disabled:
enum {
OPTBIT_KEEP_OLD = 7,
USE_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
USE_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
USE_FEATURE_TAR_BZIP2( OPTBIT_BZIP2 ,)
USE_FEATURE_TAR_LZMA( OPTBIT_LZMA ,)
USE_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
USE_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
USE_FEATURE_TAR_GZIP( OPTBIT_GZIP ,)
USE_FEATURE_TAR_COMPRESS(OPTBIT_COMPRESS ,)
OPTBIT_NOPRESERVE_OWN,
OPTBIT_NOPRESERVE_PERM,
OPT_TEST = 1 << 0, // t
OPT_EXTRACT = 1 << 1, // x
OPT_BASEDIR = 1 << 2, // C
OPT_TARNAME = 1 << 3, // f
OPT_2STDOUT = 1 << 4, // O
OPT_P = 1 << 5, // p
OPT_VERBOSE = 1 << 6, // v
OPT_KEEP_OLD = 1 << 7, // k
OPT_CREATE = USE_FEATURE_TAR_CREATE( (1<<OPTBIT_CREATE )) +
0, // c
OPT_DEREFERENCE = USE_FEATURE_TAR_CREATE( (1<<OPTBIT_DEREFERENCE )) +
0, // h
OPT_BZIP2 = USE_FEATURE_TAR_BZIP2( (1<<OPTBIT_BZIP2 )) +
0, // j
OPT_LZMA = USE_FEATURE_TAR_LZMA( (1<<OPTBIT_LZMA )) +
0, // a
OPT_INCLUDE_FROM = USE_FEATURE_TAR_FROM( (1<<OPTBIT_INCLUDE_FROM)) +
0, // T
OPT_EXCLUDE_FROM = USE_FEATURE_TAR_FROM( (1<<OPTBIT_EXCLUDE_FROM)) +
0, // X
OPT_GZIP = USE_FEATURE_TAR_GZIP( (1<<OPTBIT_GZIP )) +
0, // z
OPT_COMPRESS = USE_FEATURE_TAR_COMPRESS((1<<OPTBIT_COMPRESS )) +
0, // Z
OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, //
no-same-permissions
};
Cool eh? ;) Can you do the same?
> *_do_one() functions, I guess we'd better let it stay. Besides, it's
> one lonely integer, nothing compared to the prg_hash table itself...
Lately there is a trend to have all new applets to be like this:
# size mdev.o
text data bss dec hex filename
2176 0 0 2176 880 mdev.o
zero zero :)
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox