9front - general discussion about 9front
 help / color / mirror / Atom feed
From: igor@9lab.org
To: 9front@9front.org
Cc: igor@9lab.org
Subject: [9front] cmd/cal: fix days of week alignment for year view (patch)
Date: Sat, 19 Jun 2021 00:34:06 +0200	[thread overview]
Message-ID: <4813B9A38B4F2483B8CEB8EC70C9CA96@9lab.org> (raw)

Inline below is a patch fixing the alignment of the rows
printing days of the week when viewing the whole year.

  term% cal -s1 2021
                                  2021
  
           Jan                    Feb                    Mar
   M Tu  W Th  F Sa Su     M Tu  W Th  F Sa Su     M Tu  W Th  F Sa Su 
               1  2  3    1  2  3  4  5  6  7    1  2  3  4  5  6  7
   4  5  6  7  8  9 10    8  9 10 11 12 13 14    8  9 10 11 12 13 14
  11 12 13 14 15 16 17   15 16 17 18 19 20 21   15 16 17 18 19 20 21
  18 19 20 21 22 23 24   22 23 24 25 26 27 28   22 23 24 25 26 27 28
  25 26 27 28 29 30 31                          29 30 31
  …

Note how the days (i.e. ' M Tu  W Th  F Sa Su') for Feb and Mar
do not align with the day numbers.

This is because an extra space is left *before* adding the terminating
'\0' via the pointer `dayw`.

With the patch applied the calendar aligns nicely for the year view:

  term% cal -s1 2021
                                  2021
  
           Jan                    Feb                    Mar
   M Tu  W Th  F Sa Su    M Tu  W Th  F Sa Su    M Tu  W Th  F Sa Su
               1  2  3    1  2  3  4  5  6  7    1  2  3  4  5  6  7
   4  5  6  7  8  9 10    8  9 10 11 12 13 14    8  9 10 11 12 13 14
  11 12 13 14 15 16 17   15 16 17 18 19 20 21   15 16 17 18 19 20 21
  18 19 20 21 22 23 24   22 23 24 25 26 27 28   22 23 24 25 26 27 28
  25 26 27 28 29 30 31                          29 30 31
  …

Patch:

term% git/diff /sys/src/cmd/cal.c
--- //.git/fs/object/b3215c807556cdaaa0f949f1fb3f97c484ffd1da/tree//sys/src/cmd/cal.c
+++ /sys/src/cmd/cal.c
@@ -60,7 +60,7 @@
 	Binit(&bout, 1, OWRITE);
 
 	dayw = dayws + 3*wstart;
-	dayw[3*7] = '\0';
+	dayw[(3*7)-1] = '\0';
 
 /*
  * no arg, print current month


             reply	other threads:[~2021-06-19  5:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 22:34 igor [this message]
2021-06-19 12:01 ` kvik

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=4813B9A38B4F2483B8CEB8EC70C9CA96@9lab.org \
    --to=igor@9lab.org \
    --cc=9front@9front.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;
as well as URLs for NNTP newsgroup(s).