# -*- shell-script -*- # io.sh - Bourne Again Shell Debugger Input/Output routines # # Copyright (C) 2002, 2003, 2004, 2006, 2008, 2009, 2011 Rocky Bernstein # # # This program 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. # # This program 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 bashdb; 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. typeset -a _Dbg_override_filenames # name translations given via the debugger # "file" command. # ===================== FUNCTIONS ======================================= # _Dbg_progess_show --- print the progress bar # $1: prefix string # $2: max value # $3: current value proc _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 )) { # Avoid dividing by 0. global current_length := $(max_length) } else { global current_length := $( ${max_length} * ${current_value} / ${max_value} ) } _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 proc _Dbg_progess_show_internal { typeset -i i=0 # Erase line if [[ t == $EMACS ]] { _Dbg_msg_nocr "\r\b\n" } else { _Dbg_msg_nocr "\r\b" } _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 proc _Dbg_progess_done { # Erase line if test "x$EMACS" = xt { _Dbg_msg_nocr "\r\b\n" } else { _Dbg_msg_nocr "\r\b" } _Dbg_msg $1 } (CommandList children: [ (C {(typeset)} {(-a)} {(_Dbg_override_filenames)}) (FuncDef name: _Dbg_progess_show body: (BraceGroup children: [ (C {(typeset)} {(Lit_VarLike "title=") ($ VSub_Number "$1")}) (C {(typeset)} {(-i)} {(Lit_VarLike "max_value=") ($ VSub_Number "$2")}) (C {(typeset)} {(-i)} {(Lit_VarLike "current_value=") ($ VSub_Number "$3")}) (C {(typeset)} {(-i)} {(Lit_VarLike "max_length=") (40)}) (C {(typeset)} {(-i)} {(current_length)}) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithVarRef name:max_value) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:current_length) op: Equal rhs: {(${ VSub_Name max_length)} spids: [174] ) ] spids: [174] ) ] spids: [-1 167] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:current_length) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Slash left: (ArithBinary op_id: Arith_Star left: (ArithWord w:{(${ VSub_Name max_length)}) right: (ArithWord w:{(${ VSub_Name current_value)}) ) right: (ArithWord w:{(${ VSub_Name max_value)}) ) spids: [184 203] ) } spids: [183] ) ] spids: [183] ) ] spids: [180 206] ) (C {(_Dbg_progess_show_internal)} {(DQ ($ VSub_Number "$1"))} {(${ VSub_Name max_length)} {(${ VSub_Name current_length)} ) (C {(_Dbg_printf_nocr)} {(SQ <" %3d%%">)} { (DQ (ArithSubPart anode: (ArithBinary op_id: Arith_Slash left: (ArithBinary op_id: Arith_Star left: (ArithWord w:{(Lit_Digits 100)}) right: (ArithWord w:{(${ VSub_Name current_value)}) ) right: (ArithWord w:{(${ VSub_Name max_value)}) ) spids: [233 250] ) ) } ) ] spids: [109] ) spids: [105 108] ) (FuncDef name: _Dbg_progess_show_internal body: (BraceGroup children: [ (C {(typeset)} {(-i)} {(Lit_VarLike "i=") (0)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(t)} right: {($ VSub_Name "$EMACS")} ) ) terminator: ) ] action: [ (C {(_Dbg_msg_nocr)} { (DQ (EscapedLiteralPart token:) (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) ] spids: [-1 300] ) ] else_action: [ (C {(_Dbg_msg_nocr)} { (DQ (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) ] spids: [313 324] ) (C {(_Dbg_msg_nocr)} {(DQ ($ VSub_Number "$1") (": ["))}) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:i) right: (ArithWord w:{(Lit_Digits 0)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:i) right: (ArithWord w:{($ VSub_Number "$3")}) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:i)) body: (DoGroup children:[(C {(_Dbg_msg_nocr)} {(DQ ("="))})] spids:[361371]) ) (C {(_Dbg_msg_nocr)} {(SQ <">">)}) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:i) right: (ArithWord w:{(Lit_Digits 0)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:i) right: (ArithBinary op_id: Arith_Minus left: (ArithWord w:{($ VSub_Number "$2")}) right: (ArithWord w:{($ VSub_Number "$3")}) ) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:i)) body: (DoGroup children:[(C {(_Dbg_msg_nocr)} {(SQ <" ">)})] spids:[410420]) ) (C {(_Dbg_msg_nocr)} {(SQ <"]">)}) ] spids: [271] ) spids: [267 270] ) (FuncDef name: _Dbg_progess_done body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {(DQ (x) ($ VSub_Name "$EMACS"))} {(Lit_Other "=")} {(xt)}) terminator: ) ] action: [ (C {(_Dbg_msg_nocr)} { (DQ (EscapedLiteralPart token:) (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) ] spids: [-1 460] ) ] else_action: [ (C {(_Dbg_msg_nocr)} { (DQ (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) ] spids: [473 484] ) (C {(_Dbg_msg)} {($ VSub_Number "$1")}) ] spids: [439] ) spids: [435 438] ) ] )