From nobody Sun Jul 07 11:56:40 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WH5MD6TNMz5PGBJ; Sun, 07 Jul 2024 11:56:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WH5MD5Ykwz4ZQd; Sun, 7 Jul 2024 11:56:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720353400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=B9cFzKQv8KEkx3i2Eia8hE57YxjrPXRmBWqrqZOdNbc=; b=P1Sinthk5v0TH2Zs8Z8Nk+THXJhsLrt/65jfoOrA9VDTdhGsZLTnYKsy2zTpS8CyyISHMc 32lMIWjusd4iwB9usl1Md5SU5t2bIw2QdY7VtzBqpuiQX/8QhwPWasLWGypx22Z93qQjsP Bk+Vr8qREzzYkNg48yW9lRL5EzfE1wZr5iARVaD4bmxfheci8s2wr2Pb4kScX6bNKyIGvm kdaLkQcNOJc25lkk1h1qbFOVqr8WE8L4ylC0HrJYlGFPZicebtLuZuXBlMxWfQkEKWx7u8 M9RtaBxQeosxRcUkCi1mxpNkiI2Hfs/139Yy7dM3ewrycAl/RQaIRD8fB8mtsg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720353400; a=rsa-sha256; cv=none; b=OJszMmJjXiXtyD6+i3rSDi+mTQ+CyD3CXcmUVz46piXhIKUosn6dvIp6kQfNwEC0bHD9vg STP7HemxH+ajq3FfF5CJHB5bw9KZjWy2Ewb8gZVZvZHCkhIlZrbjGBn4UrGEoMDt3m7sL9 taeMEjIJOjxD12T9OJoXa3Hri9hkbBP5uHB/H5+4TtkoskWJ4e2AEXAQURigFV7PEt6D9H jvMq3Eb2pUzD46Q7eHyfNu7mtq9cUid2budRzmFkAIWoMjlPa0TQkBK5hBogD3xr3LNXnC 2b89prCYmrDjbowQpgs8bQ/jxI80XAIYE360L//uPDI33jsJU0U2Li74jtZCEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720353400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=B9cFzKQv8KEkx3i2Eia8hE57YxjrPXRmBWqrqZOdNbc=; b=AmaRt9baZqtyBFulkAgqr/SBccjOIdoaU1yPeVtUlupXBA0sMKlcoOWlUQg4dThlXi9su9 PZR58XvdhiJu7ubH1Tp/TBmAWzxNHKyBFII41MZUIJ+UD+ahFE4nBTJOjNhQ3Qh8lmm0mQ ACJ2Hng2ZI9OcIDRqicLd2mXHhGiSgfbuziS6A8tQCC5dJ7jNrRGCs/7dFZbVSlmss5p+l eQAgDKm8hMgjOtq/WWInva0yrfjb+AqJq14dmAXVJgec+FWf1IsIcK5zcXtuopfpFexhaI V6mn2yzy0F8HT4pYJXWWXSdvjPdpo0NKExV9O2NLHCId1v9g9j9HbspcPYxfKg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WH5MD4myyz1Lq7; Sun, 7 Jul 2024 11:56:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 467BuehC074116; Sun, 7 Jul 2024 11:56:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 467BueQh074113; Sun, 7 Jul 2024 11:56:40 GMT (envelope-from git) Date: Sun, 7 Jul 2024 11:56:40 GMT Message-Id: <202407071156.467BueQh074113@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 8c108b341cd8 - main - ncal: add -M to start week on Monday in cal mode List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8c108b341cd82d0ed9fcd573764bc94682e84125 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=8c108b341cd82d0ed9fcd573764bc94682e84125 commit 8c108b341cd82d0ed9fcd573764bc94682e84125 Author: Valentine Astakhov AuthorDate: 2024-06-17 17:58:02 +0000 Commit: Warner Losh CommitDate: 2024-07-07 11:55:36 +0000 ncal: add -M to start week on Monday in cal mode MFC after: 2 weeks Reviewed by: imp, Alexander Ziaee, Pull Request: https://github.com/freebsd/freebsd-src/pull/1294 --- usr.bin/ncal/ncal.1 | 16 ++++++++++------ usr.bin/ncal/ncal.c | 34 +++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/usr.bin/ncal/ncal.1 b/usr.bin/ncal/ncal.1 index a0b6889dca31..8ece31b79cc1 100644 --- a/usr.bin/ncal/ncal.1 +++ b/usr.bin/ncal/ncal.1 @@ -1,3 +1,6 @@ +.\"- +.\" SPDX-License-Identifier: BSD-2-Clause +.\" .\" Copyright (c) 1997 Wolfgang Helbig .\" All rights reserved. .\" @@ -31,7 +34,7 @@ .Nd displays a calendar and the date of Easter .Sh SYNOPSIS .Nm -.Op Fl 3hjy +.Op Fl 3hjMy .Op Fl A Ar number .Op Fl B Ar number .Oo @@ -39,7 +42,7 @@ .Ar year .Oc .Nm -.Op Fl 3hj +.Op Fl 3hjM .Op Fl A Ar number .Op Fl B Ar number .Fl m Ar month @@ -85,6 +88,10 @@ option, display date of Easter according to the Julian Calendar. Display date of Easter (for western churches). .It Fl j Display Julian days (days one-based, numbered from January 1). +.It Fl M +Display Monday as the first day of the week in +.Nm cal +mode. .It Fl m Ar month Display the specified .Ar month . @@ -186,7 +193,7 @@ X/Open System Interfaces option of the specification. .Pp The flags -.Op Fl 3hyJeopw , +.Op Fl 3ehJMopwy , as well as the ability to specify a month name as a single argument, are extensions to that specification. .Pp @@ -215,6 +222,3 @@ codes is historically naive for many countries. .Pp Not all options are compatible and using them in different orders will give varying results. -.Pp -It is not possible to display Monday as the first day of the week with -.Nm cal . diff --git a/usr.bin/ncal/ncal.c b/usr.bin/ncal/ncal.c index 6f5e1e89bf93..2829caf8a6a0 100644 --- a/usr.bin/ncal/ncal.c +++ b/usr.bin/ncal/ncal.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -162,6 +163,7 @@ static int flag_weeks; /* user wants number of week */ static int nswitch; /* user defined switch date */ static int nswitchb; /* switch date for backward compatibility */ static int highlightdate; +static bool flag_monday; /* user wants week starts on Monday */ static char *center(char *s, char *t, int w); static wchar_t *wcenter(wchar_t *s, wchar_t *t, int w); @@ -216,6 +218,7 @@ main(int argc, char *argv[]) flag_nohighlight = 0; flag_weeks = 0; + flag_monday = false; /* * Use locale to determine the country code, @@ -256,7 +259,7 @@ main(int argc, char *argv[]) before = after = -1; - while ((ch = getopt(argc, argv, "3A:B:Cd:eH:hjJm:Nops:wy")) != -1) + while ((ch = getopt(argc, argv, "3A:B:Cd:eH:hjJm:Nops:wyM")) != -1) switch (ch) { case '3': flag_3months = 1; @@ -306,6 +309,9 @@ main(int argc, char *argv[]) case 'j': flag_julian_day = 1; break; + case 'M': + flag_monday = true; + break; case 'm': if (flag_specifiedmonth) errx(EX_USAGE, "Double -m specified"); @@ -509,7 +515,7 @@ usage(void) " cal [general options] [-hj] [-m month] [year]\n" " ncal [general options] [-hJjpwy] [-s country_code] [[month] year]\n" " ncal [general options] [-hJeo] [year]\n" -"General options: [-NC3] [-A months] [-B months]\n" +"General options: [-NCM3] [-A months] [-B months]\n" "For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]\n", stderr); exit(EX_USAGE); @@ -652,10 +658,13 @@ monthrangeb(int y, int m, int jd_flag, int before, int after) /* Day of the week names. */ for (i = 0; i < count; i++) { wprintf(L"%s%ls%s%ls%s%ls%s%ls%s%ls%s%ls%s%ls ", - wdss, wds.names[6], wdss, wds.names[0], - wdss, wds.names[1], wdss, wds.names[2], - wdss, wds.names[3], wdss, wds.names[4], - wdss, wds.names[5]); + wdss, wds.names[flag_monday ? 0 : 6], + wdss, wds.names[flag_monday ? 1 : 0], + wdss, wds.names[flag_monday ? 2 : 1], + wdss, wds.names[flag_monday ? 3 : 2], + wdss, wds.names[flag_monday ? 4 : 3], + wdss, wds.names[flag_monday ? 5 : 4], + wdss, wds.names[flag_monday ? 6 : 5]); } printf("\n"); @@ -860,7 +869,7 @@ mkmonthb(int y, int m, int jd_flag, struct monthlines *mlines) date dt; /* handy date */ int dw; /* width of numbers */ int first; /* first day of month */ - int firsts; /* sunday of first week of month */ + int firstsm; /* sunday or monday of first week of month */ int i, j, k, l; /* just indices */ int jan1 = 0; /* the first day of this year */ int last; /* the first day of next month */ @@ -911,10 +920,13 @@ mkmonthb(int y, int m, int jd_flag, struct monthlines *mlines) } /* - * Set firsts to the day number of sunday of the first week of - * this month. (This might be in the last month) + * Set firstsm to the day number of sunday or monday of the first week + * of this month. (This might be in the last month) */ - firsts = first - (weekday(first)+1) % 7; + if (flag_monday) + firstsm = first - weekday(first); + else + firstsm = first - (weekday(first) + 1) % 7; /* * Fill the lines with day of month or day of year (Julian day) @@ -923,7 +935,7 @@ mkmonthb(int y, int m, int jd_flag, struct monthlines *mlines) */ for (i = 0; i != 6; i++) { l = 0; - for (j = firsts + 7 * i, k = 0; j < last && k != dw * 7; + for (j = firstsm + 7 * i, k = 0; j < last && k != dw * 7; j++, k += dw) { if (j >= first) { if (jd_flag)