Re: [PATCH 13/19] dmesg: make time format parsing to use enum bit field

Karel Zak
2013-06-03T08:45:55Z

On Sun, Jun 02, 2013 at 06:51:19PM +0100, Sami Kerola wrote:
> +enum {
> + TIMEFTM_NONE = (1 << 0),
> + TIMEFTM_CTIME = (1 << 1),
> + TIMEFTM_DELTA = (1 << 2),
> + TIMEFTM_RELTIME = (1 << 3),
> +};

Do we really need to use the time formats as flags? Would be better
to use it as a real enums?

I know that it means that for "delta" we need more types, but it's
probably better than assume arbitrary combination of all the types.

enum {
DMESG_TIMEFTM_NONE = 0
DMESG_TIMEFTM_TIME, /* [time] */
DMESG_TIMEFTM_CTIME, /* [ctime] */
DMESG_TIMEFTM_CTIME_DELTA, /* [ctime <delta>] */
DMESG_TIMEFTM_TIME_DELTA, /* [time <delta>] */
DMESG_TIMEFTM_DELTA, /* [<delta>] */
DMESG_TIMEFTM_RELTIME /* [relative] */
};

and all you need is to set any default (DMESG_TIMEFTM_TIME) and clear the
default if --notime is specified.

In the code you can check for "if (ctl->time_fmt)" or add

#define is_timefmt(c, f) (c->time_fmt == (TIMEFTM_ ##f))

and use

if (is_timefmt(ctl, DELTA))

Karel

--
Karel Zak <kzak@redhat.com>