From nobody Sun Sep 22 16:36:15 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 4XBWwH3vVvz5XMBN; Sun, 22 Sep 2024 16:36:15 +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 4XBWwH3FfBz47dq; Sun, 22 Sep 2024 16:36:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727022975; 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=UACxf8rAcYhLb0AD703YCMwPUhIDIqb1SdG2inMgDAM=; b=SPya/rpUNXD3Rka6HASrYMNN+AWz7IAwMTGTCe1YxJlAd/AFAbh+C0NnMV0d/6RRzGK5bF oWs31yriLAlX9cLJSlOE8UoOqZCuEIYP6uG5mt6UPDuOhzZklGJpH/2R67dOSiDFeJORRv TALvdlGDUygby+663WXBpDsVfc+jcsoq0UZRPj+TScr14xKm+LfpvakO1XtCUluCZct8Ju KuIcx1aUHC+p14to+/HKpjJ7EKqeBmdLh5Kc2KgkUy0YkZqsbPsmrQxEk+ruik+HSY71UE 84xVX1rnx1xnek6ZMDwsQuuEW92heowzK0DgldOdQLZIs7gWZDrDRopr/iZsNg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727022975; a=rsa-sha256; cv=none; b=NeCu6NtH56xyRSYBlLI9oEUO4v2011xtqjgNkdZ2enGxvvaoc3fK6ga3UUUZHEOjEtPgML Y+rgd0gw/rsONYHoaeIJrDDpNBoAisO5UyDKQet2eOCQXBmO5mPobT+33Y1mC33pg1NUOO m5dK4Y9Oz8OKrNvZwnimb5mrMxBeDGTHbhJfH7pTBJk1nIC73/LTCcKwSW2B1mnGG4N0I7 Tu4ewDdx1YI6k2K3o73L3bRk6h0Z5wfCNQa7eJo5u0vGI4pnArIrDtyuGBD8/HBtzylXYU JLbOUf1NC6jZbiyw1cFprfVzbS2JV84vdDRKkXBU6bzrsuWZ9zZpqPHqFBsy4A== 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=1727022975; 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=UACxf8rAcYhLb0AD703YCMwPUhIDIqb1SdG2inMgDAM=; b=IF8LD5eW6PXknNk+TreFeRgf5UV2NwR/eUJ/uBjCRYYbGNO7RBrGig7GVfpNBzwC2KmvMR STK6Czm10aNrj34EIH1pDf1SqlPJtUg8IggGexbLDW5QlVXgAtOEwB/yniD9Vc0qHlA/kM kk+3hncglaOKvdZqWMsuLtrgYIN6nX+44ZL/OZN4W/y6y5CMeYBlCzvt1im4XBeCwfDh+b mJk2WToNVER9WZHpyMAy9ONBaeMWRjrZR5N8XxfB57zVtHH2u5Pl0F0PM1NiQeJkVTzagt qhyqYFkctPL/lEaVfmm89SAFQxHQyzHtNOa08h4Pg69AM+2fF8SjVMHzdx/0fA== 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 4XBWwH2lY1z1NgT; Sun, 22 Sep 2024 16:36:15 +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 48MGaFwa016899; Sun, 22 Sep 2024 16:36:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48MGaFDf016896; Sun, 22 Sep 2024 16:36:15 GMT (envelope-from git) Date: Sun, 22 Sep 2024 16:36:15 GMT Message-Id: <202409221636.48MGaFDf016896@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 9503fb867a43 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 9503fb867a4395378efcf132cbb838f8372e8e70 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=9503fb867a4395378efcf132cbb838f8372e8e70 commit 9503fb867a4395378efcf132cbb838f8372e8e70 Author: Valentine Astakhov AuthorDate: 2024-06-17 17:58:02 +0000 Commit: Warner Losh CommitDate: 2024-09-22 16:35:10 +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 (cherry picked from commit 8c108b341cd82d0ed9fcd573764bc94682e84125) --- 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 20d14b3a4bde..cda7580162c1 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)