#!/usr/bin/env bash
#
#####################################
#####################################
#
# easybashgui "module"
#
# This file is intended to be packaged with scripts that use easybashgui.
#
# This file will try to source easybashgui_X.X.X.lib, or provide
# fallback functions, thus avoiding a hard dependency on easybashgui ".lib" file.
#
#########################
#
# Copyright (C) 2025 Vittorio Cagnetta
#
# Author: Vittorio Cagnetta <vaisarger@gmail.com>
#
# This program is free software: please, see file LICENSE along with this program.
#
#########################
#
# There are two easy methods to use easybashgui in your projects.
# 
# The basic method introduces a hard dependency on easybashgui. This means
# easybashgui must be installed on the machine your script is running on, 
# or your script will fail with an error. This method only requires to
# call "source easybashgui" (once) in your script to be able to use
# easybashgui functions if easybashgui is installed, but will make
# your script fail without it.
# 
# The easybashincl method however allows your script to run
# without easybashgui installed, or even available:
#
#  1) Ship a copy of just the "easybashgui" file from the easybashgui
#      package with your script's package.
#      (in same directory as the calling script, or in an includes/ subdirectory)
#  2) Copy the "easybashincl code snippet" from the "easybashgui" file
#      into your script.
#  3) Call "eb_incl easybashgui" from your script.
#
# If you also include the easybashgui.lib file in your package, and
# use the easybashincl method, your script will also work with any supported dialog 
# frontend without requiring a separate easybashgui download and installation
# on the target system.
 
 
### INCLUDABLE EASYBASH MODULES ###
# The easybashincl code snippet below allows easy inclusion of
# bash scripts from other bash scripts.
#
# Unlike the bash builtin "source" (or "."), it does not require the
# file to be installed in your $PATH.
#
# If the requested module (bash script file) is not in the $PATH,
# the "eb_incl" function will look for it in these places:
#
#    * same directory as the calling script
#    * includes/ subdirectory
#    * ${SHELL_LIBRARY_PATH}
#
# Improvement thanks to Stefano Borini's answer at
# http://stackoverflow.com/questions/78497/design-patterns-or-best-practices-for-shell-scripts
#
#
###################################################################
MODULE_VERSION="15.0.0"
MODULE_NAME="easybashgui-debug"
###################################################################
#
clean_temp()
	{
	local FUNCT_NAME="clean_temp"
	local IFS=$' \t\n'
	#
	if [ -f "${dir_tmp}/${file_tmp}" ] 2> /dev/null
		then
		rm -f "${dir_tmp}/${file_tmp}" 2> /dev/null
	fi
	#
	if [ -f "${dir_tmp}/${file_ignore}" ] 2> /dev/null
		then
		rm -f "${dir_tmp}/${file_ignore}" 2> /dev/null
	fi
	#
	}
#
###################################################################
# Every easybash module should prevent repeated inclusion by
# starting with an if-clause similar to the following:
#  ( With its proper module-name in the
#    "eb_incl_<module-name>__imported" variable. )
ebg_debug_check="YES"
if [ "${ebg_debug_check}" = "YES" ]
	then
	#
	# avoid "easybashgui-debug" repeated inclusion
	if [ "${eb_incl_easybashgui_debug__imported+defined}" = "defined" ]
		then
		#
		[ "${supermode:-unset}" = "unset" ] && declare supermode=""
		#
		if [ ${#supermode} -eq 0 ]
			then
			# Prevent repeated inclusion *only if* ${supermode} is not set ...
			echo "${MODULE_NAME}: INFO: easybashgui-debug not sourced (already sourced)! -supermode not set- ."
			return 0
		fi
		#
		if [ "${supermode}" = "${mode}" ]
			then
			# Prevent repeated inclusion *only if* ${supermode} = ${mode} ...
			echo "${MODULE_NAME}: INFO: easybashgui-debug not sourced (already sourced) -supermode is not different from mode- ."
			return 0
		fi
		#
	fi
	#
	echo -e "...easybashgui-debug sourcing..."
	#
	#eb_incl_easybashgui_debug__imported=1
	eb_incl_easybashgui_debug__imported=please_prevent_next_time
	#
	export easybashgui_debug_mode=YES
	#
fi
#
###################################################################

#
# Now let's source actual functions...
# =>
target="easybashgui-debug"
source easybashgui
