rocky / kshdb

Korn Shell (93t 2008-10-22 or greater) Debugger

This URL has Read+Write access

kshdb / dbg-io.sh
100644 110 lines (93 sloc) 3.286 kb
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
# -*- shell-script -*-
# dbg-io.inc - Korn Shell Debugger Input/Output routines
#
# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
#
# Kshdb 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.
#
# Kshdb 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 Kshdb; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
# ==================== VARIABLES =======================================
 
# _Dbg_source_mungedfilename is an array which contains source_lines for
# filename
# _Dbg_read_mungedfilename is array which contains the value '1' if the
# filename has been read in.
 
# ===================== FUNCTIONS =======================================
 
# Common funnel for "Undefined command" message
_Dbg_undefined_cmd() {
  _Dbg_msg "Undefined $1 command \"$2\""
}
 
# _Dbg_progess_show --- print the progress bar
# $1: prefix string
# $2: max value
# $3: current value
function _Dbg_progess_show {
    typeset title=$1
    typeset -i max_value=$2
    typeset -i current_value=$3
    typeset -i max_length=40
    typeset -i current_length
 
    if (( max_value == 0 )) ; then
# Avoid dividing by 0.
current_length=${max_length}
    else
current_length=$(( ${max_length} * ${current_value} / ${max_value} ))
    fi
_Dbg_progess_show_internal "$1" ${max_length} ${current_length}
    _Dbg_printf_nocr ' %3d%%' "$(( 100 * ${current_value} / ${max_value} ))"
}
# _Dbg_progess_show_internal --- internal function for _Dbg_progess_show
# $1: prefix string
# $2: max length
# $3: current length
function _Dbg_progess_show_internal {
    typeset -i i=0
 
    # Erase line
    if [[ t == $EMACS ]]; then
_Dbg_msg_nocr "\r\b\n"
    else
_Dbg_msg_nocr "\r\b"
    fi
_Dbg_msg_nocr "$1: ["
    for (( i=0; i < $3 ; i++ )); do
_Dbg_msg_nocr "="
    done
_Dbg_msg_nocr '>'
 
    for (( i=0; i < $2 - $3 ; i++ )); do
_Dbg_msg_nocr ' '
    done
_Dbg_msg_nocr ']'
}
 
# clean up progress bar
function _Dbg_progess_done {
    # Erase line
    if test "x$EMACS" = xt; then
_Dbg_msg_nocr "\r\b\n"
    else
_Dbg_msg_nocr "\r\b"
    fi
_Dbg_msg $1
}
 
 
# Return text for source line for line $1 of filename $2 in variable
# $source_line. The hope is that this has been declared "typeset" in the
# caller.
 
# If $2 is omitted, # use .sh.file, if $1 is omitted use _curline.
function _Dbg_get_source_line {
  typeset lineno=${1:-$_curline}
  typeset filename=${2:-${.sh.file}}
  typeset is_read=$(_Dbg_get_assoc_scalar_entry "_Dbg_read_" $filevar)
  [[ $is_read ]] || _Dbg_readin $filename
  
  source_line=`_Dbg_get_assoc_array_entry _Dbg_source_${filevar} $lineno`
}
 
# This is put at the so we have something at the end when we debug this.
[[ -z _Dbg_io_ver ]] && typeset -r _Dbg_io_ver=\
'$Id: dbg-io.inc,v 1.13 2008/05/27 03:51:45 rockyb Exp $'