From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-852449-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id 52A081388C4
	for <garchives@archives.gentoo.org>; Sun, 20 Dec 2015 00:17:45 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id A0DDE21C017;
	Sun, 20 Dec 2015 00:17:43 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id B492A21C00D
	for <gentoo-commits@lists.gentoo.org>; Sun, 20 Dec 2015 00:17:42 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 9C2BD3407E6
	for <gentoo-commits@lists.gentoo.org>; Sun, 20 Dec 2015 00:17:41 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 79558CE9
	for <gentoo-commits@lists.gentoo.org>; Sun, 20 Dec 2015 00:17:38 +0000 (UTC)
From: "Michael Orlitzky" <mjo@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Michael Orlitzky" <mjo@gentoo.org>
Message-ID: <1450567780.b363dda0a3d3bdab2874b3f12c64c9fc8beeef4c.mjo@gentoo>
Subject: [gentoo-commits] proj/eselect-php:master commit in: src/
X-VCS-Repository: proj/eselect-php
X-VCS-Files: src/php.eselect.in
X-VCS-Directories: src/
X-VCS-Committer: mjo
X-VCS-Committer-Name: Michael Orlitzky
X-VCS-Revision: b363dda0a3d3bdab2874b3f12c64c9fc8beeef4c
X-VCS-Branch: master
Date: Sun, 20 Dec 2015 00:17:38 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 68befe97-4862-458e-a9da-21a1ba143c16
X-Archives-Hash: fe31f270ecb8246e6fbbc356d2594bc7

commit:     b363dda0a3d3bdab2874b3f12c64c9fc8beeef4c
Author:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 19 23:29:40 2015 +0000
Commit:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Sat Dec 19 23:29:40 2015 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=b363dda0

Factor our the active SAPI target getter functions.

We had five functions doing essentially the same thing:

  1. get_active_cli()
  2. get_active_cgi()
  3. get_active_fpm()
  4. get_active_phpdbg()
  5. get_active_apache2()

Now that we have the sapi_active_link_path() function taking a SAPI
name as an argument, these have been refactored. One new function
get_sapi_active_target() takes a SAPI name as an argument and returns
the name of the active target (using sapi_active_link_path).

 src/php.eselect.in | 62 +++++++++++++++---------------------------------------
 1 file changed, 17 insertions(+), 45 deletions(-)

diff --git a/src/php.eselect.in b/src/php.eselect.in
index 6c1f803..fff7784 100644
--- a/src/php.eselect.in
+++ b/src/php.eselect.in
@@ -195,33 +195,6 @@ find_targets_phpdbg() {
 	done | @SORT@ | @UNIQ@
 }
 
-get_active_cli() {
-	# See get_active_apache2() for an explanation of the sed call.
-	local target=$(canonicalise "$(sapi_active_link_path cli)")
-	local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php:\1:p"
-	[[ -a "${target}" ]] &&	echo "${target}" | @SED@ -ne "${ver}"
-}
-
-get_active_cgi() {
-	# See get_active_apache2() for an explanation of the sed call.
-	local target=$(canonicalise "$(sapi_active_link_path cgi)")
-	local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php-cgi:\1:p"
-	[[ -a "${target}" ]] &&	echo "${target}" | @SED@ -ne "${ver}"
-}
-
-get_active_fpm() {
-	# See get_active_apache2() for an explanation of the sed call.
-	local target=$(canonicalise "$(sapi_active_link_path fpm)")
-	local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php-fpm:\1:p"
-	[[ -a "${target}" ]] &&	echo "${target}" | @SED@ -ne "${ver}"
-}
-
-get_active_phpdbg() {
-	# See get_active_apache2() for an explanation of the sed call.
-	local target=$(canonicalise "$(sapi_active_link_path dbg)")
-	local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/phpdbg:\1:p"
-	[[ -a "${target}" ]] &&	echo "${target}" | @SED@ -ne "${ver}"
-}
 
 # Find the active (selected) version of the apache2 module. Used to
 # decorate the output of the `eselect php list apache2` command.
@@ -235,21 +208,20 @@ get_active_phpdbg() {
 # The "display name" of the active apache2 module. For example,
 # "php5.6" or "php7.0".
 #
-get_active_apache2() {
-	local active_symlink target ver
-
-	# The symlink to our active module.
-	active_symlink="$(sapi_active_link_path apache2)"
-
-	# This sed expression finds the "display name" of the PHP version
-	# corresponding to a copy of libphp. For example, it parses the
-	# string "php5.6" out of "/usr/lib64/php5.6/apache2/libphp5.so".
-	ver="s:.*/usr/.*/\(php[0-9]\.[0-9]\)/apache2/libphp[57].so:\1:p"
+get_sapi_active_target() {
+	local sapi="${1}"
+	local active_symlink=$(sapi_active_link_path "${sapi}")
 
 	if [[ -L "${active_symlink}" ]] ; then
-		target=$(canonicalise "${active_symlink}")
-		if [[ -a "${target}" ]] ; then
-			echo "${target}" | @SED@ -ne "${ver}"
+		local active_file=$(canonicalise "${active_symlink}")
+		if [[ -a "${active_file}" ]] ; then
+			# This sed command (regular expression) finds a target name
+			# contained in a filesystem path. For example, it parses
+			# "php5.6" from "/usr/lib64/php5.6/apache2/libphp5.so".
+			# The curly braces are an attempt to avoid '+' which is
+			# a GNU extension.
+			local sed_cmd='s:.*/\(php[0-9]\.[0-9]\{1,\}\)/.*:\1:p'
+			echo "${active_file}" | @SED@ -ne "${sed_cmd}"
 		fi
 	fi
 }
@@ -305,7 +277,7 @@ list_apache2() {
 	local targets
 	local a
 	targets=( $(find_targets_apache2) )
-	a=$(get_active_apache2)
+	a=$(get_sapi_active_target apache2)
 	for (( i = 0; i < ${#targets[@]}; i++ )) ; do
 		if [[ $a == ${targets[i]} ]] ; then
 			targets[i]=$(highlight_marker "${targets[i]}")
@@ -318,7 +290,7 @@ list_cli() {
 	local targets
 	local a
 	targets=( $(find_targets_cli) )
-	a=$(get_active_cli)
+	a=$(get_sapi_active_target cli)
 	for (( i = 0; i < ${#targets[@]}; i++ )) ; do
 		if [[ $a == ${targets[i]} ]] ; then
 			targets[i]=$(highlight_marker "${targets[i]}")
@@ -331,7 +303,7 @@ list_cgi() {
 	local targets
 	local a
 	targets=( $(find_targets_cgi) )
-	a=$(get_active_cgi)
+	a=$(get_sapi_active_target cgi)
 	for (( i = 0; i < ${#targets[@]}; i++ )) ; do
 		if [[ $a == ${targets[i]} ]] ; then
 			targets[i]=$(highlight_marker "${targets[i]}")
@@ -344,7 +316,7 @@ list_fpm() {
 	local targets
 	local a
 	targets=( $(find_targets_fpm) )
-	a=$(get_active_fpm)
+	a=$(get_sapi_active_target fpm)
 	for (( i = 0; i < ${#targets[@]}; i++ )) ; do
 		if [[ $a == ${targets[i]} ]] ; then
 			targets[i]=$(highlight_marker "${targets[i]}")
@@ -357,7 +329,7 @@ list_phpdbg() {
 	local targets
 	local a
 	targets=( $(find_targets_phpdbg) )
-	a=$(get_active_phpdbg)
+	a=$(get_sapi_active_target dbg)
 	for (( i = 0; i < ${#targets[@]}; i++ )) ; do
 		if [[ $a == ${targets[i]} ]] ; then
 			targets[i]=$(highlight_marker "${targets[i]}")