From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 10/10] cal: make cal --three to use content structures
Date: Sun, 27 Oct 2013 20:42:36 +0000 [thread overview]
Message-ID: <1382906556-16442-11-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1382906556-16442-1-git-send-email-kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 64 ++++++++++++++++++++++++--------------------------------
1 file changed, 27 insertions(+), 37 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 1e1721e..5d0a5f5 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -716,7 +716,7 @@ static void cal_output_week(int week, struct cal_month *month, const struct cal_
}
/* Determine the day that should be highlighted. */
- if ((month->month + 1) == ctl->req.month && month->year == ctl->req.year) {
+ if (((month->month + 1) == ctl->req.month || ctl->req.week) && month->year == ctl->req.year) {
if (ctl->julian)
reqday = ctl->req.day;
else
@@ -759,18 +759,11 @@ static void monthly(const struct cal_control *ctl)
static void monthly3(const struct cal_control *ctl)
{
- char lineout[FMT_ST_CHARS];
- int i;
- int rows;
- struct fmt_st out_prev;
- struct fmt_st out_curm;
- struct fmt_st out_next;
+ struct cal_month month[3];
+ int i, m;
int prev_month, next_month;
long prev_year, next_year;
- memset(&out_prev, 0, sizeof(struct fmt_st));
- memset(&out_curm, 0, sizeof(struct fmt_st));
- memset(&out_next, 0, sizeof(struct fmt_st));
if (ctl->req.month == 1) {
prev_month = MONTHS_IN_YEAR;
prev_year = ctl->req.year - 1;
@@ -785,35 +778,32 @@ static void monthly3(const struct cal_control *ctl)
next_month = ctl->req.month + 1;
next_year = ctl->req.year;
}
- if (ctl->header_hint)
- rows = FMT_ST_LINES;
- else
- rows = FMT_ST_LINES - 1;
- do_monthly(ctl->req.day, prev_month, prev_year, &out_prev, ctl);
- do_monthly(ctl->req.day, ctl->req.month, ctl->req.year, &out_curm, ctl);
- do_monthly(ctl->req.day, next_month, next_year, &out_next, ctl);
-
- for (i = 0; i < (ctl->header_hint ? 3 : 2); i++) {
- snprintf(lineout, sizeof(lineout),
- "%s %s %s\n", out_prev.s[i], out_curm.s[i], out_next.s[i]);
- my_putstring(lineout);
- }
- for (i = ctl->header_hint ? 3 : 2; i < rows; i++) {
- int w1, w2, w3;
- w1 = w2 = w3 = ctl->width.wk;
-#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP)
- /* adjust width to allow for non printable characters */
- w1 += (out_prev.s[i] == Hrow ? Slen : 0);
- w2 += (out_curm.s[i] == Hrow ? Slen : 0);
- w3 += (out_next.s[i] == Hrow ? Slen : 0);
-#endif
- snprintf(lineout, sizeof(lineout), "%-*s %-*s %-*s\n",
- w1, out_prev.s[i],
- w2, out_curm.s[i],
- w3, out_next.s[i]);
+ cal_fill_month(&(month[0]), prev_month, prev_year, ctl);
+ cal_fill_month(&(month[1]), ctl->req.month, ctl->req.year, ctl);
+ cal_fill_month(&(month[2]), next_month, next_year, ctl);
- my_putstring(lineout);
+ for (i = 0; i <= ctl->header_hint; i++) {
+ for (m = 0; m < 3; m++) {
+ cal_output_month_headers(i, &month[m], ctl);
+ if (m < 2)
+ fputs(" ", stdout);
+ }
+ fputs("\n", stdout);
+ }
+ for (m = 0; m < 3; m++) {
+ cal_output_day_header(ctl);
+ if (m < 2)
+ fputs(" ", stdout);
+ }
+ fputs("\n", stdout);
+ for (i = 0; i < MAXDAYS / DAYS_IN_WEEK; i++) {
+ for (m = 0; m < 3; m++) {
+ cal_output_week(i, &month[m], ctl);
+ if (m < 2)
+ fputs(" ", stdout);
+ }
+ fputs(" \n", stdout);
}
}
--
1.8.4.1
next prev parent reply other threads:[~2013-10-27 20:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-27 20:42 [0000/0010] cal: code revisit part I Sami Kerola
2013-10-27 20:42 ` [PATCH 01/10] cal: use control structure for run time configuration Sami Kerola
2013-10-31 11:29 ` Karel Zak
2013-10-27 20:42 ` [PATCH 02/10] cal: add input variable names to function prototypes Sami Kerola
2013-10-27 20:42 ` [PATCH 03/10] cal: make day_in_week() use same variable names as other functions Sami Kerola
2013-10-27 20:42 ` [PATCH 04/10] cal: simplify ascii_wnum() function Sami Kerola
2013-10-27 20:42 ` [PATCH 05/10] cal: determine output width at beginning of run and reuse result Sami Kerola
2013-10-31 11:34 ` Karel Zak
2013-10-27 20:42 ` [PATCH 06/10] tests: cal: take account week numbers when determing month lenght Sami Kerola
2013-10-27 20:42 ` [PATCH 07/10] cal: make user request to be part of read-only control struct Sami Kerola
2013-10-31 11:49 ` Karel Zak
2013-11-01 9:29 ` Sami Kerola
2013-10-27 20:42 ` [PATCH 08/10] cal: determine how many header lines are needed at initialization Sami Kerola
2013-10-27 20:42 ` [PATCH 09/10] cal: add month contents structure Sami Kerola
2013-10-27 20:42 ` Sami Kerola [this message]
2013-10-31 12:14 ` [0000/0010] cal: code revisit part I Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1382906556-16442-11-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox