svn commit: trunk/busybox/coreutils

Denis Vlasenko vda.linux at googlemail.com
Thu Apr 5 00:44:42 UTC 2007


On Wednesday 04 April 2007 16:01, aldot at busybox.net wrote:
> +#define OP_bs		0 + 1
> +#define OP_count	OP_bs + 1
> +#define OP_seek		OP_count + 1
> +#define OP_skip		OP_seek + 1
> +#define OP_if		OP_skip + 1
> +#define OP_of		OP_if + 1
> +#define OP_ibs		OP_of + ENABLE_FEATURE_DD_IBS_OBS
> +#define OP_obs		OP_ibs + ENABLE_FEATURE_DD_IBS_OBS
> +#define OP_conv		OP_obs + ENABLE_FEATURE_DD_IBS_OBS
> +#define OP_conv_notrunc	OP_conv + ENABLE_FEATURE_DD_IBS_OBS
> +#define OP_conv_sync	OP_conv_notrunc + ENABLE_FEATURE_DD_IBS_OBS
> +#define OP_conv_noerror	OP_conv_sync + ENABLE_FEATURE_DD_IBS_OBS

You do not use (), this is dangerous.

This can be done better with enum. Example from find:

        enum {
                                PARM_a         ,
                                PARM_o         ,
        USE_FEATURE_FIND_NOT(   PARM_char_not  ,)
                                PARM_print     ,
        USE_FEATURE_FIND_PRINT0(PARM_print0    ,)
                                PARM_name      ,
        USE_FEATURE_FIND_TYPE(  PARM_type      ,)
        USE_FEATURE_FIND_PERM(  PARM_perm      ,)
        USE_FEATURE_FIND_MTIME( PARM_mtime     ,)
        USE_FEATURE_FIND_MMIN(  PARM_mmin      ,)
        USE_FEATURE_FIND_NEWER( PARM_newer     ,)
        USE_FEATURE_FIND_INUM(  PARM_inum      ,)
        USE_FEATURE_FIND_EXEC(  PARM_exec      ,)
        USE_FEATURE_FIND_USER(  PARM_user      ,)
        USE_FEATURE_FIND_GROUP( PARM_group     ,)
        USE_FEATURE_FIND_DEPTH( PARM_depth     ,)
        USE_FEATURE_FIND_PAREN( PARM_char_brace,)
        USE_FEATURE_FIND_SIZE(  PARM_prune     ,)
        USE_FEATURE_FIND_PRUNE( PARM_size      ,)
#if ENABLE_DESKTOP
                                PARM_and       ,
                                PARM_or        ,
        USE_FEATURE_FIND_NOT(   PARM_not       ,)
#endif
        };


This way adjacent lines are not "linked" together by referencing
first line from the second - OP_of here:

> +#define OP_of		OP_if + 1
> +#define OP_ibs		OP_of + ENABLE_FEATURE_DD_IBS_OBS

and thus it's easier to reorder lines without adding bugs.
Also, OP_conv_noerror with not expand to

0 + 1 + 1 + 1 + 1 + 0 + ... + 1

but to simple named integer constant.
--
vda



More information about the busybox mailing list