# -*- shell-script -*- # 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. # Command aliases are stored here. typeset -A _Dbg_aliases # Add an new alias in the alias table proc _Dbg_alias_add { (( $# != 2 )) && return 1 _Dbg_aliases[$1]="$2" return 0 } # Remove alias $1 from our list of command aliases. proc _Dbg_alias_remove { (( $# != 1 )) && return 1 unset "_Dbg_aliases[$1]" return 0 } # Expand alias $1. The result is set in variable expanded_alias which # could be declared local in the caller. proc _Dbg_alias_expand { (( $# != 1 )) && return 1 global expanded_alias := $1 [[ -z "$1" ]] && return 0 [[ -n ${_Dbg_aliases[$1]} ]] && global expanded_alias := $(_Dbg_aliases[$1]) return 0 } # Echo the index in _Dbg_command_names if found. Return # 0 if found and 1 if not there. proc _Dbg_alias_find_index { typeset find_name=$1 typeset -i i for ((i=0; i <= _Dbg_alias_max_index; i++)) ; do [[ ${_Dbg_alias_names[i]} == "$find_name" ]] && echo $i && return 0 done return 1 } # Return in help_aliases an array of strings that are aliases # of $1 proc _Dbg_alias_find_aliased { (($# != 1)) && return 255 typeset find_name=$1 global aliases_found := '''' typeset -i i for alias in [$(!_Dbg_aliases[@])] { if [[ ${_Dbg_aliases[$alias]} == "$find_name" ]] { [[ -n $aliases_found ]] && global aliases_found := '', '' global aliases_found := $alias } } return 0 } (CommandList children: [ (C {(typeset)} {(-A)} {(_Dbg_aliases)}) (FuncDef name: _Dbg_alias_add body: (BraceGroup children: [ (AndOr children: [ (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 2)}) ) ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DAmp ) (C {(_Dbg_aliases) (Lit_Other "[") ($ VSub_Number "$1") (Lit_Other "]") (Lit_Other "=") (DQ ($ VSub_Number "$2")) } ) (ControlFlow token: arg_word:{(0)}) ] spids: [66] ) spids: [62 65] ) (FuncDef name: _Dbg_alias_remove body: (BraceGroup children: [ (AndOr children: [ (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 1)}) ) ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DAmp ) (C {(unset)} {(DQ ("_Dbg_aliases[") ($ VSub_Number "$1") ("]"))}) (ControlFlow token: arg_word:{(0)}) ] spids: [111] ) spids: [107 110] ) (FuncDef name: _Dbg_alias_expand body: (BraceGroup children: [ (AndOr children: [ (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 1)}) ) ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:expanded_alias) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [179] ) ] spids: [179] ) (AndOr children: [ (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{(DQ ($ VSub_Number "$1"))}) ) (ControlFlow token: arg_word:{(0)}) ] op_id: Op_DAmp ) (AndOr children: [ (DBracket expr: (BoolUnary op_id: BoolUnary_n child: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Number "$1")})) spids: [206 211] ) } ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:expanded_alias) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Number "$1")})) spids: [218 223] ) } spids: [217] ) ] spids: [217] ) ] op_id: Op_DAmp ) (ControlFlow token: arg_word:{(0)}) ] spids: [158] ) spids: [154 157] ) (FuncDef name: _Dbg_alias_find_index body: (BraceGroup children: [ (C {(typeset)} {(Lit_VarLike "find_name=") ($ VSub_Number "$1")}) (C {(typeset)} {(-i)} {(i)}) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:i) right: (ArithWord w:{(Lit_Digits 0)}) ) cond: (ArithBinary op_id: Arith_LessEqual left: (ArithVarRef name:i) right: (ArithVarRef name:_Dbg_alias_max_index) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:i)) body: (DoGroup children: [ (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithVarRef name:i)) spids: [286 291] ) } right: {(DQ ($ VSub_Name "$find_name"))} ) ) (AndOr children: [ (C {(echo)} {($ VSub_Name "$i")}) (ControlFlow token: arg_word: {(0)} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [281 314] ) ) (ControlFlow token: arg_word:{(1)}) ] spids: [243] ) spids: [239 242] ) (FuncDef name: _Dbg_alias_find_aliased body: (BraceGroup children: [ (AndOr children: [ (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 1)}) ) ) (ControlFlow token: arg_word:{(255)}) ] op_id: Op_DAmp ) (C {(typeset)} {(Lit_VarLike "find_name=") ($ VSub_Number "$1")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:aliases_found) op:Equal rhs:{(SQ )} spids:[359])] spids: [359] ) (C {(typeset)} {(-i)} {(i)}) (ForEach iter_name: alias iter_words: [ { (BracedVarSub token: prefix_op: VSub_Bang bracket_op: (WholeArray op_id:Lit_At) spids: [377 383] ) } ] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$alias")}) ) spids: [394 399] ) } right: {(DQ ($ VSub_Name "$find_name"))} ) ) terminator: ) ] action: [ (AndOr children: [ (DBracket expr: (BoolUnary op_id: BoolUnary_n child: {($ VSub_Name "$aliases_found")} ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:aliases_found) op: PlusEqual rhs: {(SQ <", ">)} spids: [425] ) ] spids: [425] ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:aliases_found) op: PlusEqual rhs: {(DQ ($ VSub_Name "$alias"))} spids: [431] ) ] spids: [431] ) ] spids: [-1 411] ) ] spids: [-1 437] ) ] spids: [387 440] ) spids: [376 385] ) (ControlFlow token: arg_word:{(0)}) ] spids: [334] ) spids: [330 333] ) ] )