# -*- shell-script -*- # gdb-like "file" debugger command # # Copyright (C) 2002-2008, 2010, 2013 # 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 this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. _Dbg_help_add file \ "file FILENAME Set FILENAME as the current source file." proc _Dbg_do_file { typeset filename if (( $# < 1 )) { _Dbg_errmsg "Need to give a filename for the file command" return 1 } _Dbg_tilde_expand_filename $1 if [[ ! -f "$filename" ]] && [[ ! -x "$filename" ]] { _Dbg_errmsg "Source file $filename does not exist as a readable regular file." return 1 } typeset filevar=$[_Dbg_file2var $(BASH_SOURCE[3])] _Dbg_set_assoc_scalar_entry "_Dbg_file_cmd_" $filevar $filename typeset source_file global source_file := $[_Dbg_file_canonic $(BASH_SOURCE[3])] _Dbg_msg "File $filename will be used when $source_file is referenced." return 0 } (CommandList children: [ (C {(_Dbg_help_add)} {(file)} {(DQ ("file FILENAME\n") ("\n") ("Set FILENAME as the current source file."))} ) (FuncDef name: _Dbg_do_file body: (BraceGroup children: [ (C {(typeset)} {(filename)}) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_Less left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 1)}) ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(DQ ("Need to give a filename for the file command"))}) (ControlFlow token: arg_word:{(1)}) ] spids: [-1 101] ) ] spids: [-1 116] ) (C {(_Dbg_tilde_expand_filename)} {(DQ ($ VSub_Number "$1"))}) (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_f child: {(DQ ($ VSub_Name "$filename"))} ) ) ) (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_x child: {(DQ ($ VSub_Name "$filename"))} ) ) ) ] op_id: Op_DAmp ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} { (DQ ("Source file ") ($ VSub_Name "$filename") (" does not exist as a readable regular file.") ) } ) (ControlFlow token: arg_word:{(1)}) ] spids: [-1 156] ) ] spids: [-1 173] ) (C {(typeset)} {(Lit_VarLike "filevar=") (CommandSubPart command_list: (CommandList children: [ (C {(_Dbg_file2var)} { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 3)})) spids: [182 187] ) } ) ] ) left_token: spids: [179 188] ) } ) (C {(_Dbg_set_assoc_scalar_entry)} {(DQ (_Dbg_file_cmd_))} {($ VSub_Name "$filevar")} {(DQ ($ VSub_Name "$filename"))} ) (C {(typeset)} {(source_file)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:source_file) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(_Dbg_file_canonic)} { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 3)})) spids: [214 219] ) ) } ) ] ) left_token: spids: [210 221] ) } spids: [209] ) ] spids: [209] ) (C {(_Dbg_msg)} { (DQ ("File ") ($ VSub_Name "$filename") (" will be used when ") ($ VSub_Name "$source_file") (" is referenced.") ) } ) (ControlFlow token: arg_word:{(0)}) ] spids: [77] ) spids: [73 76] ) ] )