#!/bin/bash
# Show the report of all writes done by CDControl

cdc_rel() {
 local L_TMPFILE
if ! ls -F ${LOG_DIR}|grep -v '/'|grep '[a-zA-Z]';then
     ${DIALOG} --backtitle $"CDcontrol v${CDC_VERSION}" \
         --msgbox $"'No one report was found. Press <Enter> to return" 0 0
 exit 1
fi

# Create the temporary file that will be used for return value of dialog menus
L_TMPFILE=`mktemp /tmp/fileXXXXXX`


while true;do
 ${DIALOG} --backtitle $"CDcontrol v${CDC_VERSION}" --clear \
        --title $"Show a report" \
        --menu $"Use the arrow keys and press <Enter>.\n\
Press <Esc> ou select 'Cancel' to exit:" 20 60 10 \
`ls -F ${LOG_DIR} | grep -v '/' | sed -e s/"^"/"\""/ | \
  sed -e s/"$"/'\" \"\" \\ '/` 2>${L_TMPFILE}

 L_RETVAL=$?
 L_REL_NAME=`cat ${L_TMPFILE}`

 case ${L_RETVAL} in
   0)
    L_REL_NAME=`echo ${L_REL_NAME}|sed -e s/"\""//g`
    clear
    ${PAGER-more} ${LOG_DIR}/${L_REL_NAME}
    echo $"Press ENTER to continue";read
   ;;
   1)
     rm -f ${L_TMPFILE}
     exit 1
     ;;
   255)
     rm -f ${L_TMPFILE}
     exit 1
     ;;
 esac
done
rm -f ${L_TMPFILE}
}
cdc_rel
