# -*- shell-script -*- # gdb-like "source" command. # # Copyright (C) 2002-2008, 2010, 2013, 2016 # 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. # Handle command-file source. If the filename's okay we just increase the # input-file descriptor by one and redirect input which will # be picked up in next debugger command loop. _Dbg_help_add source \ '**source** *file* Run debugger commands in *file*.' proc _Dbg_do_source { if (( $# == 0 )) { _Dbg_errmsg 'Need to give a filename for the "source" command.' return 1 } typeset filename _Dbg_tilde_expand_filename $1 if [[ -r $filename ]] || [[ "$filename" == '/dev/stdin' ]] { # Open new input file descriptor and save number in _Dbg_fd. exec {_Dbg_fdi}<$filename _Dbg_fd[++_Dbg_fd_last]=$_Dbg_fdi # We'll store the filename for good measure too. global _Dbg_cmdfile := '("'$filename") } else { _Dbg_errmsg "Source file \"$filename\" is not readable." return 3 } return 0 } (CommandList children: [ (C {(_Dbg_help_add)} {(source)} {(SQ <"**source** *file*\n"> <"\n"> <"Run debugger commands in *file*.">)} ) (FuncDef name: _Dbg_do_source body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(SQ <"Need to give a filename for the \"source\" command.">)}) (ControlFlow token: arg_word:{(1)}) ] spids: [-1 105] ) ] spids: [-1 120] ) (C {(typeset)} {(filename)}) (C {(_Dbg_tilde_expand_filename)} {(DQ ($ VSub_Number "$1"))}) (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (DBracket expr: (BoolUnary op_id:BoolUnary_r child:{($ VSub_Name "$filename")}) ) (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$filename"))} right: {(SQ )} ) ) ] op_id: Op_DPipe ) terminator: ) ] action: [ (SimpleCommand words: [{(exec)} {(Lit_LBrace "{") (_Dbg_fdi) (Lit_RBrace "}")}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Name "$filename"))} spids: [176] ) ] ) (C {(_Dbg_fd) (Lit_Other "[") (Lit_Other "+") (Lit_Other "+") (_Dbg_fd_last) (Lit_Other "]") (Lit_Other "=") ($ VSub_Name "$_Dbg_fdi") } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_Dbg_cmdfile) op: PlusEqual rhs: {(ArrayLiteralPart words:[{(DQ ($ VSub_Name "$filename"))}])} spids: [196] ) ] spids: [196] ) ] spids: [-1 164] ) ] else_action: [ (C {(_Dbg_errmsg)} { (DQ ("Source file ") (EscapedLiteralPart token:) ($ VSub_Name "$filename") (EscapedLiteralPart token:) (" is not readable.") ) } ) (ControlFlow token: arg_word:{(3)}) ] spids: [204 223] ) (ControlFlow token: arg_word:{(0)}) ] spids: [87] ) spids: [83 86] ) ] )