~sourcemage/sorcery

9d048092e6e1bb61b9feab4d459e28112e9de138 — Paul Mahon 16 years ago 11b4fd9 devel-debug-namespace
Adding libdebug module
1 files changed, 59 insertions(+), 0 deletions(-)

A var/lib/sorcery/modules/libdebug
A var/lib/sorcery/modules/libdebug => var/lib/sorcery/modules/libdebug +59 -0
@@ 0,0 1,59 @@
#!/bin/bash


#---------------------------------------------------------------------
## @param type
## @param message
##
## Enters a debug message if the type of debug message != 'n'
##
## The 'type' is usually the name of the file the debug statement
## comes from. i.e. SORCERY_DEBUG_liblock, SORCERY_DEBUG_libsorcery, 
## sorcery_DEBUG_cast etc.
## The normal way of calling this function is using $STD_SORCERY_DEBUG
## which adds in the line number and automatically adds the type 
## STD_SORCERY_DEBUG_HEAD also adds the function parameters
##
#---------------------------------------------------------------------
function debug_message()  {
  [[ $SORCERY_DEBUG ]] || return 0
  
  local debugVar="SORCERY_DEBUG_${1}"
  local i
  if ! [[ ${!debugVar} ]] ; then
    echo -n "$1($$): " >>$SORCERY_DEBUG
    shift
    for i in "$@" ; do
      echo -n " \"$i\"" >>$SORCERY_DEBUG
    done
    echo >>$SORCERY_DEBUG
  fi

  true
}

function init_debugging() {
  local i
  for i in ${SORCERY_DEBUG_FILTER} ; do
    eval "SORCERY_DEBUG_$i=n"
  done

  if [[ $SORCERY_DEBUG ]] && [[ $SORCERY_DEBUG != "/dev/null" ]] && touch $SORCERY_DEBUG 2>/dev/null ; then
    if [[ $SORCERY_ENTRY_DEBUG != "n" ]] ; then
      # Standard debug line:
      # file "function@line" "all" "args"
      STD_SORCERY_DEBUG_HEAD='eval local _stddbg_file=${BASH_SOURCE[0]} ; 
        _stddbg_file=${_stddbg_file##*/};
        debug_message "${_stddbg_file}" "${FUNCNAME[0]}@$LINENO" "$@"'
    else
      STD_SORCERY_DEBUG_HEAD=':'
    fi
    STD_SORCERY_DEBUG='eval local _stddbg_file=${BASH_SOURCE[0]} ; 
      _stddbg_file=${_stddbg_file##*/};
      debug_message "${_stddbg_file}" "${FUNCNAME[0]}@$LINENO"'
  else
    STD_SORCERY_DEBUG_HEAD=':'
    STD_SORCERY_DEBUG=':'
  fi
}