From owner-svn-src-stable@freebsd.org Fri Oct 30 14:41:22 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 00C564536EA; Fri, 30 Oct 2020 14:41:22 +0000 (UTC) (envelope-from markj@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CN4kT6D63z43qb; Fri, 30 Oct 2020 14:41:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B9EE717D5C; Fri, 30 Oct 2020 14:41:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09UEfL7o080339; Fri, 30 Oct 2020 14:41:21 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09UEfKCB080331; Fri, 30 Oct 2020 14:41:20 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202010301441.09UEfKCB080331@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 30 Oct 2020 14:41:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r367171 - in stable/12/usr.bin/col: . tests X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in stable/12/usr.bin/col: . tests X-SVN-Commit-Revision: 367171 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Oct 2020 14:41:22 -0000 Author: markj Date: Fri Oct 30 14:41:19 2020 New Revision: 367171 URL: https://svnweb.freebsd.org/changeset/base/367171 Log: MFC r366577: col(1): Fix a couple of bugs PR: 249308 Added: stable/12/usr.bin/col/tests/hlf.in - copied unchanged from r366577, head/usr.bin/col/tests/hlf.in stable/12/usr.bin/col/tests/hlf2.in - copied unchanged from r366577, head/usr.bin/col/tests/hlf2.in stable/12/usr.bin/col/tests/nl.in - copied unchanged from r366577, head/usr.bin/col/tests/nl.in stable/12/usr.bin/col/tests/nl2.in - copied unchanged from r366577, head/usr.bin/col/tests/nl2.in stable/12/usr.bin/col/tests/nl3.in - copied unchanged from r366577, head/usr.bin/col/tests/nl3.in stable/12/usr.bin/col/tests/rlf3.in - copied unchanged from r366577, head/usr.bin/col/tests/rlf3.in Modified: stable/12/usr.bin/col/col.c stable/12/usr.bin/col/tests/Makefile stable/12/usr.bin/col/tests/col_test.sh (contents, props changed) Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.bin/col/col.c ============================================================================== --- stable/12/usr.bin/col/col.c Fri Oct 30 14:40:48 2020 (r367170) +++ stable/12/usr.bin/col/col.c Fri Oct 30 14:41:19 2020 (r367171) @@ -100,7 +100,7 @@ struct line_str { }; static void addto_lineno(int *, int); -static LINE *alloc_line(void); +static LINE *alloc_line(void); static void dowarn(int); static void flush_line(LINE *); static void flush_lines(int); @@ -109,7 +109,7 @@ static void free_line(LINE *); static void usage(void); static CSET last_set; /* char_set of last char printed */ -static LINE *lines; +static LINE *lines; static int compress_spaces; /* if doing space -> tab conversion */ static int fine; /* if `fine' resolution (half lines) */ static int max_bufd_lines; /* max # of half lines to keep in memory */ @@ -340,8 +340,16 @@ main(int argc, char **argv) } if (ferror(stdin)) err(1, NULL); - if (extra_lines) + if (extra_lines) { + /* + * Extra lines only exist if no lines have been flushed + * yet. This means that 'lines' must point to line zero + * after we flush the extra lines. + */ flush_lines(extra_lines); + l = lines; + this_line = 0; + } /* goto the last line that had a character on it */ for (; l->l_next; l = l->l_next) @@ -353,14 +361,22 @@ main(int argc, char **argv) PUTC(SI); /* flush out the last few blank lines */ - if (max_line > this_line) - nblank_lines = max_line - this_line; - if (max_line & 1) - nblank_lines++; + if (max_line >= this_line) + nblank_lines = max_line - this_line + (max_line & 1); + if (nblank_lines == 0) + /* end with a newline even if the source doesn't */ + nblank_lines = 2; flush_blanks(); exit(0); } +/* + * Prints the first 'nflush' lines. Printed lines are freed. + * After this function returns, 'lines' points to the first + * of the remaining lines, and 'nblank_lines' will have the + * number of half line feeds between the final flushed line + * and the first remaining line. + */ static void flush_lines(int nflush) { @@ -372,11 +388,10 @@ flush_lines(int nflush) if (l->l_line) { flush_blanks(); flush_line(l); + free(l->l_line); } - if (l->l_line || l->l_next) + if (l->l_next) nblank_lines++; - if (l->l_line) - (void)free(l->l_line); free_line(l); } if (lines) @@ -384,9 +399,8 @@ flush_lines(int nflush) } /* - * Print a number of newline/half newlines. If fine flag is set, nblank_lines - * is the number of half line feeds, otherwise it is the number of whole line - * feeds. + * Print a number of newline/half newlines. + * nblank_lines is the number of half line feeds. */ static void flush_blanks(void) Modified: stable/12/usr.bin/col/tests/Makefile ============================================================================== --- stable/12/usr.bin/col/tests/Makefile Fri Oct 30 14:40:48 2020 (r367170) +++ stable/12/usr.bin/col/tests/Makefile Fri Oct 30 14:41:19 2020 (r367171) @@ -4,8 +4,14 @@ PACKAGE= tests ATF_TESTS_SH= col_test -${PACKAGE}FILES+= \ +${PACKAGE}FILES+= \ + hlf.in \ + hlf2.in \ + nl.in \ + nl2.in \ + nl3.in \ rlf.in \ - rlf2.in + rlf2.in \ + rlf3.in .include Modified: stable/12/usr.bin/col/tests/col_test.sh ============================================================================== --- stable/12/usr.bin/col/tests/col_test.sh Fri Oct 30 14:40:48 2020 (r367170) +++ stable/12/usr.bin/col/tests/col_test.sh Fri Oct 30 14:41:19 2020 (r367171) @@ -1,5 +1,44 @@ # $FreeBSD$ +atf_test_case nl + +nl_head() +{ + atf_set "descr" "testing just newlines" +} +nl_body() +{ + atf_check \ + -o inline:"a\nb\n" \ + -e empty \ + -s exit:0 \ + col < $(atf_get_srcdir)/nl.in + + atf_check \ + -o inline:"a\nb\n" \ + -e empty \ + -s exit:0 \ + col -f < $(atf_get_srcdir)/nl.in + + atf_check \ + -o inline:"a\nb\n" \ + -e empty \ + -s exit:0 \ + col < $(atf_get_srcdir)/nl2.in + + atf_check \ + -o inline:"a\nb\n" \ + -e empty \ + -s exit:0 \ + col -f < $(atf_get_srcdir)/nl2.in + + atf_check \ + -o inline:"a\n\nb\n\n" \ + -e empty \ + -s exit:0 \ + col < $(atf_get_srcdir)/nl3.in +} + atf_test_case rlf rlf_head() @@ -25,9 +64,53 @@ rlf_body() -e empty \ -s exit:0 \ col -x < $(atf_get_srcdir)/rlf2.in + + atf_check \ + -o inline:" b\na\n" \ + -e empty \ + -s exit:0 \ + col < $(atf_get_srcdir)/rlf3.in } +atf_test_case hlf + +hlf_head() +{ + atf_set "descr" "testing half line feed" +} +hlf_body() +{ + atf_check \ + -o inline:"a f\naf\n" \ + -e empty \ + -s exit:0 \ + col < $(atf_get_srcdir)/hlf.in + + atf_check \ + -o inline:"a f9 + f9 +a\n" \ + -e empty \ + -s exit:0 \ + col -f < $(atf_get_srcdir)/hlf.in + + atf_check \ + -o inline:"a\n f\n" \ + -e empty \ + -s exit:0 \ + col < $(atf_get_srcdir)/hlf2.in + + atf_check \ + -o inline:"a9 + f\n9" \ + -e empty \ + -s exit:0 \ + col -f < $(atf_get_srcdir)/hlf2.in +} + atf_init_test_cases() { + atf_add_test_case nl atf_add_test_case rlf + atf_add_test_case hlf } Copied: stable/12/usr.bin/col/tests/hlf.in (from r366577, head/usr.bin/col/tests/hlf.in) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.bin/col/tests/hlf.in Fri Oct 30 14:41:19 2020 (r367171, copy of r366577, head/usr.bin/col/tests/hlf.in) @@ -0,0 +1,2 @@ +a +a8f8f Copied: stable/12/usr.bin/col/tests/hlf2.in (from r366577, head/usr.bin/col/tests/hlf2.in) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.bin/col/tests/hlf2.in Fri Oct 30 14:41:19 2020 (r367171, copy of r366577, head/usr.bin/col/tests/hlf2.in) @@ -0,0 +1 @@ +a9f Copied: stable/12/usr.bin/col/tests/nl.in (from r366577, head/usr.bin/col/tests/nl.in) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.bin/col/tests/nl.in Fri Oct 30 14:41:19 2020 (r367171, copy of r366577, head/usr.bin/col/tests/nl.in) @@ -0,0 +1,2 @@ +a +b Copied: stable/12/usr.bin/col/tests/nl2.in (from r366577, head/usr.bin/col/tests/nl2.in) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.bin/col/tests/nl2.in Fri Oct 30 14:41:19 2020 (r367171, copy of r366577, head/usr.bin/col/tests/nl2.in) @@ -0,0 +1,2 @@ +a +b \ No newline at end of file Copied: stable/12/usr.bin/col/tests/nl3.in (from r366577, head/usr.bin/col/tests/nl3.in) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.bin/col/tests/nl3.in Fri Oct 30 14:41:19 2020 (r367171, copy of r366577, head/usr.bin/col/tests/nl3.in) @@ -0,0 +1,4 @@ +a + +b + Copied: stable/12/usr.bin/col/tests/rlf3.in (from r366577, head/usr.bin/col/tests/rlf3.in) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.bin/col/tests/rlf3.in Fri Oct 30 14:41:19 2020 (r367171, copy of r366577, head/usr.bin/col/tests/rlf3.in) @@ -0,0 +1 @@ +a b