# -*- shell-script -*- # Debugger Edit command # Copyright (C) 2008, 2010, 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 this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. #================ VARIABLE INITIALIZATIONS ====================# _Dbg_help_add edit \ "**edit** [*line-number*] Edit specified file at *line-number*. If *line-number* is not given, use the current line number. Uses \"EDITOR\" environment variable contents as editor (or ex as default). Assumes the editor positions at a file using options \"+linenumber filename\"." proc _Dbg_do_edit { if (($# > 2)) { _Dbg_errmsg "got $Argc parameters, but need 0 or 1." return 2 } typeset editor=$(EDITOR:-ex) typeset -i line_number if (( $# == 0 )) { global line_number := $_Dbg_frame_last_lineno global full_filename := $_Dbg_frame_last_filename } else { _Dbg_linespec_setup $1 } if [[ ! -r $full_filename ]] { _Dbg_errmsg "File $full_filename is not readable" return 2 } $editor +$line_number $full_filename global rc := $Status ((rc==0)) && global _Dbg_last_cmd := ''edit'' return $rc } _Dbg_alias_add 'ed' 'edit' (CommandList children: [ (C {(_Dbg_help_add)} {(edit)} { (DQ ("**edit** [*line-number*]\n") ("\n") ("Edit specified file at *line-number*.\n") ("\n") ("If *line-number* is not given, use the current line number.\n") ("Uses ") (EscapedLiteralPart token:) (EDITOR) (EscapedLiteralPart token:) (" environment variable contents as editor (or ex as default).\n") ("Assumes the editor positions at a file using options ") (EscapedLiteralPart token:) ("+linenumber filename") (EscapedLiteralPart token:) (.) ) } ) (FuncDef name: _Dbg_do_edit body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_Great left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 2)}) ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(DQ ("got ") ($ VSub_Pound "$#") (" parameters, but need 0 or 1."))} ) (ControlFlow token: arg_word:{(2)}) ] spids: [-1 104] ) ] spids: [-1 121] ) (C {(typeset)} {(Lit_VarLike "editor=") (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(ex)}) spids: [127 131] ) } ) (C {(typeset)} {(-i)} {(line_number)}) (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: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:line_number) op: Equal rhs: {($ VSub_Name "$_Dbg_frame_last_lineno")} spids: [159] ) ] spids: [159] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:full_filename) op: Equal rhs: {(DQ ($ VSub_Name "$_Dbg_frame_last_filename"))} spids: [163] ) ] spids: [163] ) ] spids: [-1 156] ) ] else_action: [(C {(_Dbg_linespec_setup)} {(DQ ($ VSub_Number "$1"))})] spids: [169 179] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_r child: {($ VSub_Name "$full_filename")} ) ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(DQ ("File ") ($ VSub_Name "$full_filename") (" is not readable"))} ) (ControlFlow token: arg_word:{(2)}) ] spids: [-1 196] ) ] spids: [-1 213] ) (C {($ VSub_Name "$editor")} {(Lit_Other "+") ($ VSub_Name "$line_number")} {($ VSub_Name "$full_filename")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:rc) op: Equal rhs: {($ VSub_QMark "$?")} spids: [224] ) ] spids: [224] ) (AndOr children: [ (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithVarRef name:rc) right: (ArithWord w:{(Lit_Digits 0)}) ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_Dbg_last_cmd) op: Equal rhs: {(SQ )} spids: [237] ) ] spids: [237] ) ] op_id: Op_DAmp ) (ControlFlow token: arg_word:{($ VSub_Name "$rc")}) ] spids: [88] ) spids: [84 87] ) (C {(_Dbg_alias_add)} {(SQ )} {(SQ )}) ] )