170 lines
7.0 KiB
Plaintext
170 lines
7.0 KiB
Plaintext
|
##----------------------------------------------------------------------------
|
||
|
## Script : affiche_ligne.lib
|
||
|
## Module Puppet : gnc-script_core_dtsi
|
||
|
## Auteur : Emmanuel Confrere
|
||
|
## Date : 13-04-2017
|
||
|
## Version : 1.1.0
|
||
|
## Objet : Permet d'afficher sur la sortie standard un texte sous forme de tableau
|
||
|
##
|
||
|
## Fonction : fct_affiche_ligne
|
||
|
##
|
||
|
## Detail : Definition de l'entete du tableau :
|
||
|
## fct_affiche_ligne entete "{Titre}" "{Colonne_1},{Taille_1}" "{Colonne_2},{Taille_2}" "{Colonne_3},{Taille_3}" "{Colonne_4},{Taille_4}" ...
|
||
|
## fct_affiche_ligne entete "{Titre}" "Groupe1({Colonne_1},{Taille_1}:{Colonne_2},{Taille_2})" "{Colonne_3},{Taille_3}" "Groupe2({Colonne_4},{Taille_4}:...)" ...
|
||
|
##
|
||
|
## Affichage des lignes du tableau :
|
||
|
## fct_affiche_ligne "${Variable_1}" "${Variable_2}" "${Variable_3}" "${Variable_4}" ...
|
||
|
##
|
||
|
## Affichage du pied
|
||
|
## fct_affiche_ligne pied
|
||
|
##
|
||
|
## Affichage d une ligne de separation
|
||
|
## fct_affiche_ligne sep
|
||
|
##
|
||
|
## Les trois forme de declaration doivent apparaitre dans l ordre :
|
||
|
## fct_affiche_ligne entete -> Initialise le tableau
|
||
|
## fct_affiche_ligne -> Affiche une ligne
|
||
|
## fct_affiche_ligne pied -> Libere la configuration du tableau
|
||
|
##
|
||
|
# ----------------------------------------------------------------------------
|
||
|
# Mise a jour :
|
||
|
# 1.0.0 10-02-2016 - Emmanuel Confrere - Cre : Reprise du script du socle Oracle
|
||
|
# 1.1.0 13-04-2017 - Emmanuel Confrere - Evo : Ajout de l option "sep"
|
||
|
##----------------------------------------------------------------------------
|
||
|
|
||
|
function fct_affiche_ligne
|
||
|
{
|
||
|
local L_NB_PARAM=$#
|
||
|
local L_PARAM=""
|
||
|
local L_IDX_PARAM=1
|
||
|
local L_IDX_COL=1
|
||
|
local L_MESSAGE=""
|
||
|
local L_ENTETE="non"
|
||
|
local L_PIED="non"
|
||
|
local L_SEP="non"
|
||
|
local L_GROUPE="non"
|
||
|
local L_GRP_NOM=""
|
||
|
local L_TAILLE_GRP=0
|
||
|
local L_COL_LISTE=""
|
||
|
local L_COL=""
|
||
|
local L_GRP_MESS_L1=""
|
||
|
local L_GRP_MESS_L2=""
|
||
|
local L_GRP_MESS_L3=""
|
||
|
local L_OLD_IFS=""
|
||
|
|
||
|
# - recuperation des parametres en entree
|
||
|
[ -n "${IFS}" ] && L_OLD_IFS=${IFS}
|
||
|
IFS="@"
|
||
|
while [ ${L_IDX_PARAM} -le ${L_NB_PARAM} ]
|
||
|
do
|
||
|
L_PARAM[${L_IDX_PARAM}]=`echo $1|cut -d, -f1`
|
||
|
[ "${L_PARAM[1]}" = "entete" ] && L_ENTETE="oui"
|
||
|
[ "${L_PARAM[1]}" = "pied" ] && L_PIED="oui"
|
||
|
[ "${L_PARAM[1]}" = "sep" ] && L_SEP="oui"
|
||
|
if [ "${L_ENTETE}" = "oui" -a ${L_IDX_PARAM} -gt 2 ]
|
||
|
then
|
||
|
if [ `echo $1|grep -c "("` -eq 1 ]
|
||
|
then
|
||
|
L_GROUPE="oui"
|
||
|
L_TAILLE_GRP=0
|
||
|
L_GRP_NOM=`echo $1|cut -d "(" -f1`
|
||
|
L_COL_LISTE=`echo $1|sed 's/:/@/g;s/^.*(//;s/)//'`
|
||
|
for L_COL in ${L_COL_LISTE}
|
||
|
do
|
||
|
L_PARAM[${L_IDX_PARAM}]=`echo ${L_COL}|cut -d, -f1`
|
||
|
SH_TAILLE_COL[${L_IDX_COL}]=`echo ${L_COL}|cut -d, -f2`
|
||
|
[ -z "${SH_TAILLE_COL[${L_IDX_COL}]}" ] && SH_TAILLE_COL[${L_IDX_COL}]=${#L_PARAM[${L_IDX_PARAM}]}
|
||
|
[ ${SH_TAILLE_COL[${L_IDX_COL}]} -eq 0 ] && SH_TAILLE_COL[${L_IDX_COL}]=${#L_PARAM[${L_IDX_PARAM}]}
|
||
|
SH_TAILLE_COL[${L_IDX_COL}]=$(( ${SH_TAILLE_COL[${L_IDX_COL}]} + 2 ))
|
||
|
SH_TAILLE_TABLEAU=$(( ${SH_TAILLE_TABLEAU} + ${SH_TAILLE_COL[${L_IDX_COL}]} ))
|
||
|
L_TAILLE_GRP=$(( ${L_TAILLE_GRP} + ${SH_TAILLE_COL[${L_IDX_COL}]} + 1 ))
|
||
|
[ ${L_IDX_PARAM} -eq ${L_NB_PARAM} ] && L_GRP_MESS_L3="${L_GRP_MESS_L3}`fct_format "${L_PARAM[${L_IDX_PARAM}]}" ${SH_TAILLE_COL[${L_IDX_COL}]} c`"
|
||
|
[ ${L_IDX_PARAM} -ne ${L_NB_PARAM} ] && L_GRP_MESS_L3="${L_GRP_MESS_L3}`fct_format "${L_PARAM[${L_IDX_PARAM}]}" ${SH_TAILLE_COL[${L_IDX_COL}]} c`|"
|
||
|
((L_IDX_COL++))
|
||
|
((L_IDX_PARAM++))
|
||
|
((L_NB_PARAM++))
|
||
|
done
|
||
|
((L_TAILLE_GRP--))
|
||
|
((L_IDX_PARAM--))
|
||
|
((L_NB_PARAM--))
|
||
|
L_GRP_MESS_L1="${L_GRP_MESS_L1}`fct_format "${L_GRP_NOM}" ${L_TAILLE_GRP} c`|"
|
||
|
L_GRP_MESS_L2="${L_GRP_MESS_L2}`fct_format "-" ${L_TAILLE_GRP} r`|"
|
||
|
else
|
||
|
SH_TAILLE_COL[${L_IDX_COL}]=`echo $1|cut -d, -f2`
|
||
|
[ -z "${SH_TAILLE_COL[${L_IDX_COL}]}" ] && SH_TAILLE_COL[${L_IDX_COL}]=${#L_PARAM[${L_IDX_PARAM}]}
|
||
|
[ ${SH_TAILLE_COL[${L_IDX_COL}]} -eq 0 ] && SH_TAILLE_COL[${L_IDX_COL}]=${#L_PARAM[${L_IDX_PARAM}]}
|
||
|
SH_TAILLE_COL[${L_IDX_COL}]=$(( ${SH_TAILLE_COL[${L_IDX_COL}]} + 2 ))
|
||
|
SH_TAILLE_TABLEAU=$(( ${SH_TAILLE_TABLEAU} + ${SH_TAILLE_COL[${L_IDX_COL}]} ))
|
||
|
if [ ${L_IDX_PARAM} -eq ${L_NB_PARAM} ]
|
||
|
then
|
||
|
L_GRP_MESS_L1="${L_GRP_MESS_L1}`fct_format " " ${SH_TAILLE_COL[${L_IDX_COL}]} c`"
|
||
|
L_GRP_MESS_L2="${L_GRP_MESS_L2}`fct_format "${L_PARAM[${L_IDX_PARAM}]}" ${SH_TAILLE_COL[${L_IDX_COL}]} c`"
|
||
|
L_GRP_MESS_L3="${L_GRP_MESS_L3}`fct_format " " ${SH_TAILLE_COL[${L_IDX_COL}]} c`"
|
||
|
else
|
||
|
L_GRP_MESS_L1="${L_GRP_MESS_L1}`fct_format " " ${SH_TAILLE_COL[${L_IDX_COL}]} c`|"
|
||
|
L_GRP_MESS_L2="${L_GRP_MESS_L2}`fct_format "${L_PARAM[${L_IDX_PARAM}]}" ${SH_TAILLE_COL[${L_IDX_COL}]} c`|"
|
||
|
L_GRP_MESS_L3="${L_GRP_MESS_L3}`fct_format " " ${SH_TAILLE_COL[${L_IDX_COL}]} c`|"
|
||
|
fi
|
||
|
((L_IDX_COL++))
|
||
|
fi
|
||
|
fi
|
||
|
shift
|
||
|
((L_IDX_PARAM++))
|
||
|
done
|
||
|
[ "${L_ENTETE}" = "oui" ] && SH_TAILLE_TABLEAU=$(( ${SH_TAILLE_TABLEAU} + ${L_NB_PARAM} - 3 ))
|
||
|
|
||
|
# -- Affichage de la ligne
|
||
|
# -- ---------------------
|
||
|
L_IDX_PARAM=1
|
||
|
L_IDX_COL=1
|
||
|
L_MESSAGE=""
|
||
|
|
||
|
# -- Affichage de l entete du tableau
|
||
|
if [ "${L_ENTETE}" = "oui" ]
|
||
|
then
|
||
|
fct_message -cpt "`fct_format "-" ${SH_TAILLE_TABLEAU} r`"
|
||
|
fct_message -cpt -color jaune "`fct_format "${L_PARAM[2]}" ${SH_TAILLE_TABLEAU} c`"
|
||
|
fct_message -cpt "`fct_format "-" ${SH_TAILLE_TABLEAU} r`"
|
||
|
if [ "${L_GROUPE}" = "oui" ]
|
||
|
then
|
||
|
fct_message -cpt "${L_GRP_MESS_L1}"
|
||
|
fct_message -cpt "${L_GRP_MESS_L2}"
|
||
|
fct_message -cpt "${L_GRP_MESS_L3}"
|
||
|
else
|
||
|
fct_message -cpt "${L_GRP_MESS_L2}"
|
||
|
fi
|
||
|
fct_message -cpt "`fct_format "-" ${SH_TAILLE_TABLEAU} r`"
|
||
|
export SH_TAILLE_TABLEAU SH_TAILLE_COL
|
||
|
L_IDX_PARAM=3
|
||
|
fi
|
||
|
|
||
|
# -- Affichage du corp du tableau
|
||
|
while [ ${L_IDX_PARAM} -le ${L_NB_PARAM} -a "${L_PIED}" = "non" -a "${L_ENTETE}" = "non" ]
|
||
|
do
|
||
|
if [ ${L_IDX_PARAM} -eq ${L_NB_PARAM} ]
|
||
|
then
|
||
|
L_MESSAGE="${L_MESSAGE}`fct_format "${L_PARAM[${L_IDX_PARAM}]}" ${SH_TAILLE_COL[${L_IDX_COL}]} d`"
|
||
|
else
|
||
|
L_MESSAGE="${L_MESSAGE}`fct_format "${L_PARAM[${L_IDX_PARAM}]}" ${SH_TAILLE_COL[${L_IDX_COL}]} d`|"
|
||
|
fi
|
||
|
((L_IDX_PARAM++))
|
||
|
((L_IDX_COL++))
|
||
|
done
|
||
|
[ "${L_PIED}" = "non" -a "${L_ENTETE}" = "non" ] && fct_message -cpt "${L_MESSAGE}"
|
||
|
|
||
|
# -- Affichage du pied et liberation des variables de gestion
|
||
|
if [ "${L_PIED}" = "oui" ]
|
||
|
then
|
||
|
fct_message -cpt "`fct_format "-" ${SH_TAILLE_TABLEAU} r`"
|
||
|
unset SH_TAILLE_TABLEAU SH_TAILLE_COL
|
||
|
fi
|
||
|
|
||
|
# -- Affichage d une ligne de separation
|
||
|
[ "${L_SEP}" = "oui" ] && fct_message -cpt "`fct_format "-" ${SH_TAILLE_TABLEAU} r`"
|
||
|
|
||
|
[ -n "${L_OLD_IFS}" ] && IFS=${L_OLD_IFS} || unset IFS
|
||
|
|
||
|
return 0
|
||
|
}
|
||
|
typeset -Ffx fct_affiche_ligne
|