#!/bin/sh

################################################################################
################################################################################
# Copyright 2023-2025 by NI SP Software GmbH, All rights reserved.
# Copyright 1999-2023 by Nice, srl., All rights reserved.
#
# This software includes confidential and proprietary information
# of NI SP Software GmbH ("Confidential Information").
# You shall not disclose such Confidential Information
# and shall use it only in accordance with the terms of
# the license agreement you entered into with NI SP Software.
################################################################################
################################################################################

################################################################################
# SVN $Id$
################################################################################

#-------------------------------------------------------------------------------
# This is a library of common functions used by the RFB processing scripts
#-------------------------------------------------------------------------------

# Source ${EF_ROOT}/plugins/ef/lib/files
. "${EF_ROOT}/plugins/ef/lib/files"


# --------------------------------------------------------------------------- #
# EF_check_erfb
# =============
# Check if must to invoke an external RFB.
# EF_PLUGIN_PATH is changed to reflect the new plug-in being invoked.
#
# Arguments:
# 1) the initial path
# --------------------------------------------------------------------------- #

ef_check_erfb() {
    _e_rfb_plugin="`echo $_target | grep @ | sed 's/^.*@//'`"

    if [ -n "${_e_rfb_plugin}" ] ; then
        _e_rfb_plugin_path="${EF_ROOT}/plugins/${_e_rfb_plugin}"
        _e_rfb="${_e_rfb_plugin_path}/bin/ef.rfb"

        if [ -f "${_e_rfb}" ] ; then
            if [ -z "${EF_PLUGIN_PATH}" -o "$EF_PLUGIN_PATH" = "$EF_ROOT" ] ; then
                EF_PLUGIN_PATH="${_e_rfb_plugin_path}"
                export EF_PLUGIN_PATH
            fi
            "${_e_rfb}" "$1"
            _exit_code="$?"
            exit "$_exit_code"
        fi
        exit 1
    fi
}


# --------------------------------------------------------------------------- #
# EF_set_list_files_from_target
# =============================
# Sets 'list_files' into environment based on '$_target' environment variable
# The variable is set to 'true' if it's missing (default value), contains 'file', or contains 'both'
#
# Arguments: none, it uses '$_target' environment variable
# --------------------------------------------------------------------------- #

ef_set_list_files_from_target() {
    _real_target="`echo $_target | grep @ | sed 's/@.*$//'`"
    if [ -z "${_real_target}" ] ; then
        _real_target="$_target"
    fi
    if [ -z "${_real_target}" -o "${_real_target}" = "file" -o "${_real_target}" = "both" ] ; then
        list_files="true"
        export list_files
    fi
}
