From nobody Fri Apr 12 06:40:37 2024 X-Original-To: dev-commits-doc-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 4VG6QG3RRJz5Gmnr for ; Fri, 12 Apr 2024 06:40:38 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VG6QG1R0Zz4tTH; Fri, 12 Apr 2024 06:40:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712904038; 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=kI3e+c7jtWGgI/aJNfPan+wPeDKiunwdniad35Og890=; b=s/jzztX0N/QZoX93eGUQRkQugQn8lXDXCIwwhksbA2ipFU0PDcefNLCt28TduoyPy6PaTk galAp2C6Zau+k/GEzcbIHbzojIyVwF6VbKilij68Y1gKLx0APmY1FfP4h8STnbYucXVJzI ysz6BnH041K4YySpjZh++U2pQ3ihDUysZ1HYnB9pk2YYYHsJqgx5lAei25mDMVbviV4DbH //AqZwTrnvvY8ppMGOisZJQl1HZzaW87GkKadcqUkkgJqJGKB/c41hGjmBXDcUigwj5cVb xy0oiEsQ9C0THs69Sm7gcH1nUY0bFM5uMgB44e05z5y1Mc4DxY2JXYx8iVFRDg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712904038; a=rsa-sha256; cv=none; b=bQLrs16DqTIC7SQt++AGgJpnlxc+mJRjZARjX5NNHiyHxtMYxhSMKT10TnGvqwn9PpCPKc cVo5/GjTsw1mIpuyH1uN0lvwz07EgWcC7EBlqPPJr01nNyrX0HZqyNYlaPNcACI2Dd6i2o 1Z3yp6h1iPSVVBL+IbTFctFLmAhYhAQUULhGdhOVxqyAylY1RYl4C1YQHEsdfiuPkuB+5K CAaZz8is8Dh8Xbpwp9hTUAIrCG1dYwto2+eoWbPXOHyNGdqLlANrBPYEFWfA64PNHJ9lPc CqNvnrgR3L2UfuGCBNOPbxNUzKKeGfSndpInGqgXGq+Nsqui7teMwg/L2fwEYQ== 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=1712904038; 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=kI3e+c7jtWGgI/aJNfPan+wPeDKiunwdniad35Og890=; b=epKYD9Udm2w06ljMtMjeXVh3T6dcaL0QIf0u5ZvgPRdSW9A26YLddLBRmuSorNobiuxAwC bfPMqPe0MPTAeaPvtCGE/pxIWKtdYtXRyem/UVu31kDb0EbFpJvqRgM1vdWa0cFrGvQfYD qLfD7w8tcTyhz+0MB6UzlzB5l6jYLlnk3onTnLmhyeHputrG83hHLU3PuvGl2WRUl6PcPM rVx+kW6VDlxHCtO1acpdbTAiok5aM3OA5Rjhfi1yigqdaRygRg1mrRfkqXN1xndKqZsLjG Vs+w2WnQAEXfvkfn8bMiwziKKFVEHxkNlOspqjMiehuEJImrdWvDvC+A+9Kd4A== 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 4VG6QG12wJzfNy; Fri, 12 Apr 2024 06:40:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43C6ebW8001804; Fri, 12 Apr 2024 06:40:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43C6eb7W001801; Fri, 12 Apr 2024 06:40:37 GMT (envelope-from git) Date: Fri, 12 Apr 2024 06:40:37 GMT Message-Id: <202404120640.43C6eb7W001801@gitrepo.freebsd.org> To: doc-committers@FreeBSD.org, dev-commits-doc-all@FreeBSD.org From: Wolfram Schneider Subject: git: e88c60320d - main - rewrite function for sorting manpath List-Id: Commit messages for all branches of the doc repository List-Archive: https://lists.freebsd.org/archives/dev-commits-doc-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: dev-commits-doc-all+owner@freebsd.org X-BeenThere: dev-commits-doc-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wosch X-Git-Repository: doc X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e88c60320d067741f72bd4317ce355c44e2320dc Auto-Submitted: auto-generated The branch main has been updated by wosch: URL: https://cgit.FreeBSD.org/doc/commit/?id=e88c60320d067741f72bd4317ce355c44e2320dc commit e88c60320d067741f72bd4317ce355c44e2320dc Author: Wolfram Schneider AuthorDate: 2024-04-12 06:38:33 +0000 Commit: Wolfram Schneider CommitDate: 2024-04-12 06:40:06 +0000 rewrite function for sorting manpath This makes the sorting more robust in some edge cases. Also, the code is more readable. --- website/content/en/cgi/man.cgi | 61 +++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/website/content/en/cgi/man.cgi b/website/content/en/cgi/man.cgi index 3c3fc5868b..0afb4de294 100755 --- a/website/content/en/cgi/man.cgi +++ b/website/content/en/cgi/man.cgi @@ -1099,6 +1099,32 @@ while ( ( $key, $val ) = each %manPath ) { 'minix', 'Minix 3.3.0', ); +# pre-build a hash to get relevant information for sorting +my $sort_manpath_hash; +sub sort_manpath { + my $manpath = shift; + my @list = keys %$manpath; + + $sort_manpath_hash = {}; + foreach my $name (@list) { + my $name_lc = lc($name); + my $os_lc; + + # a release has at least 2 numbers seperated by a dot: + # FreeBSD 11.1-RELEASE ports + # X11R7.4 + my ($os, $version, $ports) = ( $name =~ m,^(.*?)(\d+\.[\d\.]+)(.*)$, ); + $os //= $name; + $os_lc = lc($os); + $version //= "0.0"; + $ports //= ""; + + $sort_manpath_hash->{$name} = { 'os' => $os, 'os_lc' => $os_lc, 'version' => $version, 'ports' => $ports }; + } + + return sort { &sort_versions } keys %$manpath; +} + # # sort by OS release number, highest version first # @@ -1114,24 +1140,17 @@ while ( ( $key, $val ) = each %manPath ) { # XFree86 10.0 # sub sort_versions { - - # a release has at least 2 numbers seperated by a dot: - # FreeBSD 11.1-RELEASE ports - # X11R7.4 - my @a = ( lc($a) =~ m,^(.*?)(\d+\.[\d\.]+)(.*)$, ); - my @b = ( lc($b) =~ m,^(.*?)(\d+\.[\d\.]+)(.*)$, ); - - if (@a and @b) { - return $a[0] cmp $b[0] || # FreeBDS <=> IRIX - &version($a[1], $b[1]) || # 6.5.30 <=> 6.5.31 - $a[2] cmp $a[2] || # RELEASE <=> ports - $a cmp $b; # rest - } else { - # for the rest: basic string compare - return $a cmp $b; - } + my $h = $sort_manpath_hash; + + return + $h->{$a}->{'os_lc'} cmp $h->{$b}->{'os_lc'} || # freebsd <=> irix + $h->{$a}->{'os'} cmp $h->{$b}->{'os'} || # FreeBSD <=> freebsd + &version($h->{$a}->{'version'}, $h->{$b}->{'version'}) || # 6.5.30 <=> 6.5.31 + $h->{$a}->{'ports'} cmp $h->{$b}->{'ports'} || # RELEASE <=> ports (release first) + $a cmp $b; # for the rest: basic string compare } +# reverse order, newest release first sub version { return &version_compare(@_) * -1; } @@ -1172,7 +1191,7 @@ sub freebsd_first { return @data; } -foreach ( sort { &sort_versions } keys %manPathAliases ) { +foreach ( &sort_manpath(\%manPathAliases) ) { # delete non-existing aliases if ( !defined( $manPath{ $manPathAliases{$_} } ) ) { @@ -1625,8 +1644,6 @@ sub man { $html_name = &encode_data($name); $html_section = &encode_data($section); - #print Dumper($sectionpath); - #print "yy $section yy $manpath\n"; if ( $name =~ /^\s*$/ ) { print "
"; print "Empty input. Please type a manual page and search again.\n"; @@ -2098,7 +2115,7 @@ ETX print qq{\n