Re: [PATCH 01/10] cal: use control structure for run time configuration

Karel Zak
2013-10-31T11:29:26Z

On Sun, Oct 27, 2013 at 08:42:27PM +0000, Sami Kerola wrote:
> +struct cal_control {
> + const char *full_month[MONTHS_IN_YEAR]; /* month names */
> + int colormode; /* day and week number highlight */
> + int num_months; /* number of months horizontally in print out */
> + int weekstart; /* day the week starts, often Sun or Mon */
> + int wflag; /* uses WEEK_NUM_ enum */
> + int wnum; /* requested --week=number */

hmm... you duplicate information the struct

wnum == wflag & WEEK_NUM_MASK

Anyway, I think the whole WEEK_NUM_MASK thing is unnecessary if you
have the control struct, just use:

struct cal_control {
...
int weekstart;
int weektype; /* WEEK_TYPE_{NONE,ISO,US} */
int weeknum; /* --week=<num> */
...
}

Note more readable "week" rather than "w" prefix :-)

> - if (wflag) {
> - wflag = wnum & WEEK_NUM_MASK;
> - wflag |= (weekstart == MONDAY ? WEEK_NUM_ISO : WEEK_NUM_US);
> + if (ctl.wflag) {
> + ctl.wflag = ctl.wnum & WEEK_NUM_MASK;
> + ctl.wflag |= (ctl.weekstart == MONDAY ? WEEK_NUM_ISO : WEEK_NUM_US);
> }

In the original code is wnum main()-only variable.

Karel

--
Karel Zak <kzak@redhat.com>