File wxWidgets-find-wx-provides of Package wxWidgets.import4971

#! /bin/bash
# convert libwxfoo()() to libwxfoo(variant)()() for libraries inside wx libdir

shopt -s extglob

# redirect 3 to stdout (3 does not change in coprocesses)
exec 3>&1
# Coprocess for files outside wx libdir
coproc COPROC_NOT_WX ( /usr/lib/rpm/find-provides >&3 )
# HACK: Return stderr to place.

while read ; do
	case "$REPLY" in
	*/usr/lib*/wx-*-* )
		VARIANT=${REPLY#*/usr/lib*/wx-*-}
		VARIANT=${VARIANT%%/*}
		case "$VARIANT" in
		+([A-Za-z_]) )
			# Assign a coprocess that corresponds to the variant.
			eval "COPROC_YES_WX=(\"\${COPROC_YES_WX_$VARIANT[@]}\")"
			# Coprocess for files inside particular wx libdir
			if test -z "$COPROC_YES_WX" ; then
				# HACK: Closing stderr seems to be the only way
				# to silence warning "execute_coproc: coproc
				# [$PID:TRA] still exists"
				exec 4>&2-
				eval "coproc COPROC_YES_WX_$VARIANT ( /usr/lib/rpm/find-provides |\
					sed 's/^\([^)]*\)(/\1($VARIANT)(/' >&3 )"
				exec 2>&4
				eval "COPROC_YES_WX=(\"\${COPROC_YES_WX_$VARIANT[@]}\")"
			fi
			echo "$REPLY" >&${COPROC_YES_WX[1]}
			;;
		# invalid variant string
		* )
			echo "find-wx-provides: ERROR: invalid format of wx variant directory name" >&2
			echo "$REPLY" >&${COPROC_NOT_WX[1]}
			;;
		esac
		;;
	* )
		echo "$REPLY" >&${COPROC_NOT_WX[1]}
		;;
	esac
done

# close input of coprocesses (terminate them)
for COPROC_YES_WX in "${!COPROC_YES_WX_@}" ; do
	case $COPROC_YES_WX in
	# foo_PID variables are created by coproc builtin
	*_PID ) ;;
	* )
		eval eval exec \${$COPROC_YES_WX\[1\]}\\\>\\\&-
	;;
	esac
done
eval exec ${COPROC_NOT_WX[1]}\>\&-

# wait for coprocesses to finish
wait