From nobody Mon Dec 16 13:35:21 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 4YBgtL0zDDz5hRHt; Mon, 16 Dec 2024 13:35:22 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YBgtK66r1z4GYc; Mon, 16 Dec 2024 13:35:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734356121; 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=98haQMvLH3cFbTRrESUw7g9cxEqP8fjlm22l2qGixRE=; b=Ip+zxpMi8Y7HMkEsUMzyYzx0CUHGr2RN7SctnvxLPAZAxHKaONTYUz7p/qlqYOxRExiRye EYMC5EdM4JeJc+XUhqJU7OM5ht5R1wws1hrgvj6FYwlcLSIEccenNAQcyUCkF+ojfxWaGo j0i9Hxaf/yghaEwtP6vS5ktwW/GdIquKjf5U6U6cez6N1lEfiHdVc83pxzJTlRerYOSTP8 OH63MiFTG95AHqfiWKsosmUwsA0qGZrkMXFV8sjk74JTMglC4LcKVMKBEqYA7HUUiRQWkk mPCoE7QBd4Cgmg9R6Fv2I1ro8+7Voy0j55LUDSSSUUzYJMX5jg3ijo09DxkLkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734356121; 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=98haQMvLH3cFbTRrESUw7g9cxEqP8fjlm22l2qGixRE=; b=ExRvYFNyMq6ji9me8VsGxEQabZkS/TL2TSuhSq2aMBNVmjTWgL3zAwqoXy2sp4c3SAT77C Uga6CJJ7qbEiJEr1DYOj/bGQ8C0vvhEifbqQO27vh3MnzOwD8VBUmymR/bYiEukC1Z2FLO iJBpCdNnxWUJHEru0KsDUOaPvln/0Ex3mrUdTSSfAGcHkUlDBJFZbNojY0qGdypPtL3mQj tI+erekAR/9aGQmd189A32ZZReptz5Ub4lOzEIEpXkzzl6v/ffd0IYmx4ob870mbCBGK+L 0u0A008IuxQazRrjYOOs6dVB4b0IULNCI9UbV+XeEl0rBiHWnWbTMczxalxLaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734356121; a=rsa-sha256; cv=none; b=s40gRb466MLQfCgAFu4DAFcvR1k0D1kFO+9AJ9ZRWDVWdc/2lcV/3Fi22ioN9gjY6vxsNW 5WI5u4NWSNFMELiwLszeGSjB5sWJVup8UGs6oFzo208guAA2G+gmcHro+opXOYEl/kkzxd h0/f2SEBjfNTbrn1XnswKs75CAXJo5dtRlUGGUNxa3tbuwmqXN7G5r91tt/sg8KP+Xd8aA gRoX/5Yw0kNnutSNLekMaX+Dd29mm4408+qdyR81KqF+k7HK7BUqKpGCOtRjtL/FPi+2x+ jjn49+SnOnI4eCoTojdHuJfta4mrNbDhg6KLAyh1dWI2dF2LB96lMx1XCQEwfg== 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 4YBgtK5l3Fzw2B; Mon, 16 Dec 2024 13:35:21 +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 4BGDZLKK020258; Mon, 16 Dec 2024 13:35:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BGDZLxJ020255; Mon, 16 Dec 2024 13:35:21 GMT (envelope-from git) Date: Mon, 16 Dec 2024 13:35:21 GMT Message-Id: <202412161335.4BGDZLxJ020255@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 3a052d2d36ba - stable/13 - uniq: Correctly document the -D option. 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: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3a052d2d36ba46e842fe3aaed4d069e647f45ae7 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=3a052d2d36ba46e842fe3aaed4d069e647f45ae7 commit 3a052d2d36ba46e842fe3aaed4d069e647f45ae7 Author: Dag-Erling Smørgrav AuthorDate: 2024-12-09 19:44:34 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-12-16 10:38:58 +0000 uniq: Correctly document the -D option. The -D option takes an optional argument; modify the usage message and the manual page's synopsis to correctly reflect this. Also update the tests to exercise -D with and without an argument. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: asomers Differential Revision: https://reviews.freebsd.org/D47999 (cherry picked from commit b93791f5e7b0246b121dd98c10d6563298d6b2b0) uniq: Fix off-by-one bug in -cD case. When printing only duplicated lines, the first line of each set is not printed until we encounter the second. When that happens, we need to increment the repetition count between printing the first and the second line, so that if we are also printing counts, we don't print the same (pre-increment) count twice. MFC after: 1 week PR: 275764 Reported by: Yu-Sheng Ma Submitted by: Daniel Tameling (original patch) Sponsored by: Klara, Inc. Reviewed by: tamelingdaniel_gmail.com, asomers, emaste Differential Revision: https://reviews.freebsd.org/D48000 (cherry picked from commit c3f8900e696998c410dc16f9bd9d45c24c413e6b) --- usr.bin/uniq/tests/uniq_test.sh | 33 +++++++++++++++++++++++++++++++++ usr.bin/uniq/uniq.1 | 6 +++--- usr.bin/uniq/uniq.c | 7 ++++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh index 804e82ce7766..b1d7a94ae60a 100755 --- a/usr.bin/uniq/tests/uniq_test.sh +++ b/usr.bin/uniq/tests/uniq_test.sh @@ -53,7 +53,12 @@ count_repeated_head() { count_repeated_body() { printf "a\na\nb\nb\na\n" >input printf " 2 a\n 2 b\n" >expected + atf_check_uniq -cd + atf_check_uniq -c -d + atf_check_uniq -dc + atf_check_uniq -d -c atf_check_uniq --count --repeated + atf_check_uniq --repeated --count } atf_test_case all_repeated @@ -64,7 +69,34 @@ all_repeated_body() { printf "a\na\nb\na\na\n" >input printf "a\na\na\na\n" >expected atf_check_uniq -D + atf_check_uniq -Dnone atf_check_uniq --all-repeated + atf_check_uniq --all-repeated=none + printf "\na\na\n\na\na\n" >expected + atf_check_uniq -Dprepend + atf_check_uniq --all-repeated=prepend + printf "a\na\n\na\na\n" >expected + atf_check_uniq -Dseparate + atf_check_uniq --all-repeated=separate +} + +atf_test_case count_all_repeated +count_all_repeated_head() { + atf_set descr "count and print every instance of repeated lines" +} +count_all_repeated_body() { + printf "a\na\nb\na\na\n" >input + printf " 1 a\n 2 a\n 1 a\n 2 a\n" >expected + atf_check_uniq -D -c + atf_check_uniq -Dnone -c + atf_check_uniq -cD + atf_check_uniq -cDnone + atf_check_uniq -c -D + atf_check_uniq -c -Dnone + atf_check_uniq --all-repeated --count + atf_check_uniq --all-repeated=none --count + atf_check_uniq --count --all-repeated + atf_check_uniq --count --all-repeated=none } atf_test_case skip_fields @@ -181,6 +213,7 @@ atf_init_test_cases() atf_add_test_case repeated atf_add_test_case count_repeated atf_add_test_case all_repeated + atf_add_test_case count_all_repeated atf_add_test_case skip_fields atf_add_test_case skip_fields_tab atf_add_test_case ignore_case diff --git a/usr.bin/uniq/uniq.1 b/usr.bin/uniq/uniq.1 index 3fc1d26774ca..19d167ddc4cc 100644 --- a/usr.bin/uniq/uniq.1 +++ b/usr.bin/uniq/uniq.1 @@ -30,7 +30,7 @@ .\" .\" From: @(#)uniq.1 8.1 (Berkeley) 6/6/93 .\" -.Dd January 12, 2024 +.Dd December 9, 2024 .Dt UNIQ 1 .Os .Sh NAME @@ -38,8 +38,8 @@ .Nd report or filter out repeated lines in a file .Sh SYNOPSIS .Nm -.Op Fl c | Fl d | Fl D | Fl u -.Op Fl i +.Op Fl cdiu +.Op Fl D Ns Op Ar septype .Op Fl f Ar num .Op Fl s Ar chars .Oo diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c index 5b675600e56c..17c5da6e952d 100644 --- a/usr.bin/uniq/uniq.c +++ b/usr.bin/uniq/uniq.c @@ -237,12 +237,13 @@ main (int argc, char *argv[]) fputc('\n', ofp); show(ofp, prevline); } - show(ofp, thisline); } else if (dflag && !cflag) { if (repeats == 0) show(ofp, prevline); } ++repeats; + if (Dflag) + show(ofp, thisline); } } if (ferror(ifp)) @@ -378,7 +379,7 @@ obsolete(char *argv[]) static void usage(void) { - (void)fprintf(stderr, -"usage: uniq [-c | -d | -D | -u] [-i] [-f fields] [-s chars] [input [output]]\n"); + (void)fprintf(stderr, "usage: uniq [-cdiu] [-D[septype]] " + "[-f fields] [-s chars] [input [output]]\n"); exit(1); }