File: dbg-log.inc

package info (click to toggle)
bashdb 3.1.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 3,252 kB
  • ctags: 117
  • sloc: sh: 4,880; pascal: 3,186; lisp: 484; makefile: 315; ansic: 294
file content (144 lines) | stat: -rw-r--r-- 3,901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# dbg-set.inc - Bourne Again Shell Debugger set/show logging
#
#   Copyright (C) 2006 Rocky Bernstein rockyb@users.sourceforge.net
#
#   Bash is free software; you can redistribute it and/or modify it under
#   the terms of the GNU General Public License as published by the Free
#   Software Foundation; either version 2, or (at your option) any later
#   version.
#
#   Bash is distributed in the hope that it will be useful, but WITHOUT ANY
#   WARRANTY; without even the implied warranty of MERCHANTABILITY or
#   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
#   for more details.
#   
#   You should have received a copy of the GNU General Public License along
#   with Bash; see the file COPYING.  If not, write to the Free Software
#   Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.

# Sets whether or not to display command to be executed in debugger prompt.
# If yes, always show. If auto, show only if the same line is to be run
# but the command is different.

# 1 if we are logging output. 
typeset _Dbg_logging=0

# Location of logging file *when* we are set logging is on.
typeset _Dbg_logging_file="bashdb.txt"

# If 1 overwrite existing logging file? 
typeset _Dbg_logging_overwrite=0

# If 1, log file is sufficient, don't also print to stdout. 
typeset _Dbg_logging_redirect=0

_Dbg_do_set_logging()
{
  local -a args=($*)
  if (( ${#args[@]} > 0 )) ; then
    case ${args[0]} in 
      off )
	if (( $_Dbg_logging != 0 )) ; then
	  # Lose logfile
	  _Dbg_logging=0
	fi
	;;
      on )
	if (( $_Dbg_logging == 0 )) ; then
	  _Dbg_logging=1
	  if (( $_Dbg_logging_overwrite )) ; then
	    cat /dev/null >$_Dbg_logging_file
	  fi
	fi
	;;
      overwrite )
	local onoff=${2:-'on'}
	case $onoff in 
	  on | 1 ) 
	    _Dbg_write_journal_eval "_Dbg_logging_overwrite=1"
	    ;;
	  off | 0 )
	    _Dbg_write_journal_eval "_Dbg_logging_overwrite=0"
	    ;;
	  * )
	  _Dbg_msg "\"on\" or \"off\" expected."
	esac
	;;
      redirect )
	local onoff=${2:-'on'}
	case $onoff in 
	  on | 1 ) 
	    _Dbg_write_journal_eval "_Dbg_logging_redirect=1"
	    ;;
	  off | 0 )
	    _Dbg_write_journal_eval "_Dbg_logging_redirect=0"
	    ;;
	  * )
	    _Dbg_msg "\"on\" or \"off\" expected."
        esac
	;;
      file )
	if (( ${#args[@]} == 2 )) ; then
	  _Dbg_write_journal_eval "_Dbg_logging_file=${args[1]}"
	else 
	  _Dbg_msg "Expecting a single file argument in 'set logging file'."
	fi
	;;
      * )
	_Dbg_msg "Usage: set logging on"
	_Dbg_msg "set logging off"
	_Dbg_msg "set logging file FILENAME"
	_Dbg_msg "set logging overwrite [on|off]"
	_Dbg_msg "set logging redirect [on|off]"
	;;
      esac
 fi
set +x
}

_Dbg_do_show_logging()
{
  local -a args=($*)
  if (( ${#args[@]} == 0 )) ; then
    _Dbg_msg "Future logs will be written to $_Dbg_logging_file"
    if (( $_Dbg_logging_overwrite )) ; then
      _Dbg_msg 'Logs will overwrite the log file.'
    else
      _Dbg_msg 'Logs will be appended to the log file.'
      if (( $_Dbg_logging_redirect )) ; then
	_Dbg_msg "Output will be sent only to the log file."
      else
	_Dbg_msg "Output will be logged and displayed."
      fi
    fi
  else
    case ${args[0]} in 
      overwrite )
	local onoff="off."
	(( $_Dbg_logging_overwrite != 0 )) && onoff='on.'
      _Dbg_msg \
"Whether logging overwrites or appends to the log file is ${onoff}"
	;;
      redirect )
	local onoff="off."
	(( $_Dbg_logging_redirect != 0 )) && onoff='on.'
	_Dbg_msg "The logging output mode is ${onoff}."
	;;
      file )
	_Dbg_msg "The current logfile is ${_Dbg_logging_file}"
	;;
      * )
	_Dbg_undefined_cmd "show logging" "${args[0]}"
	;;
     esac
  fi
}

# This is put at the so we have something at the end when we debug this.
typeset -r _Dbg_log_ver=\
'$Id: dbg-log.inc,v 1.2 2006/06/13 09:11:44 rockyb Exp $'

#;;; Local Variables: ***
#;;; mode:shell-script ***
#;;; eval: (sh-set-shell "bash") ***
#;;; End: ***