# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/misc/output/parse-config
# ROCK Linux is Copyright (C) 1998 - 2005 Clifford Wolf
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at https://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---

. misc/output/terminal

output_proc() {
	plugins=""
	for x in $( ls misc/output ); do
		if [ -f misc/output/$x/functions.sh ]; then
			eval "y=\$ROCKCFG_OUTPUT_$( echo $x | tr a-z A-Z )"
			if [ "$y" = 1 ]; then
				. misc/output/$x/functions.sh
				plugins="$plugins $x"
			fi
		fi
	done

	while read type data; do
		for plugin in $plugins; do
			eval "echo_${type}_${plugin} $data"
		done
	done
	exit 0
}

if [ -z "$ROCK_OUPUT_PLUGIN_PROC_ACTIVE" ]; then
	export ROCK_OUPUT_PLUGIN_PROC_ACTIVE=1
	exec 199> >( output_proc )
fi

echo_sched() {
	local request="$1" tag
	local nl=$'\n' tc="'"
	shift

	echo_${request}_terminal "$@"

	for tag; do
		tag=${tag//\\\\/\\\\}
		tag=${tag//$tc/\\$tc}
		tag=${tag//$nl/\\n}
		request="$request \$'$tag'"
	done

	echo "$request" >&199
}

echo_header()     { echo_sched header     "$@" ; }
echo_status()     { echo_sched status     "$@" ; }
echo_error()      { echo_sched error      "$@" ; }
echo_pkg_deny()   { echo_sched pkg_deny   "$@" ; }
echo_pkg_start()  { echo_sched pkg_start  "$@" ; }
echo_pkg_finish() { echo_sched pkg_finish "$@" ; }
echo_pkg_abort()  { echo_sched pkg_abort  "$@" ; }
echo_errorquote() { echo_sched errorquote "$@" ; }

