# Copyright (C) 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. if [[ -z $_Dbg_requires ]] { proc _Dbg_expand_filename { typeset -r filename="$1" # Break out basename and dirname typeset basename="$(filename##*/)" typeset -x dirname="$(filename%/*)" # No slash given in filename? Then use . for dirname [[ $dirname == $basename ]] && [[ $filename != '/' ]] && global dirname := ''.'' # Dirname is ''? Then use / for dirname global dirname := $(dirname:-/) # Handle tilde expansion in dirname global dirname := $[echo $dirname] typeset long_path if global long_path := $[ shell {cd $dirname ; pwd}] { if [[ "$long_path" == '/' ]] { echo "/$basename" } else { echo "$long_path/$basename" } return 0 } else { echo $filename return 1 } } typeset -A _Dbg_requires proc require { typeset file typeset expanded_file typeset source_dir typeset orig_dir global orig_dir := $[pwd] global source_dir := $(BASH_SOURCE[1]%/*) if [[ $source_dir != ${BASH_SOURCE[1]} ]] { builtin cd $source_dir } for file in [@Argv] { global expanded_file := $[_Dbg_expand_filename $file] if [[ -z ${_Dbg_requires[$file]} \ && -z ${_Dbg_requires[$expanded_file]} ]] { source $expanded_file _Dbg_requires[$file]=$expanded_file _Dbg_requires[$expanded_file]=$expanded_file } } [[ -n $orig_dir ]] && builtin cd $orig_dir } } (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{($ VSub_Name "$_Dbg_requires")}) ) terminator: ) ] action: [ (FuncDef name: _Dbg_expand_filename body: (BraceGroup children: [ (C {(typeset)} {(-r)} {(Lit_VarLike "filename=") (DQ ($ VSub_Number "$1"))}) (C {(typeset)} {(Lit_VarLike "basename=") (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DPound arg_word:{("*") (Lit_Slash /)}) spids: [89 94] ) ) } ) (C {(typeset)} {(-x)} {(Lit_VarLike "dirname=") (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_Percent arg_word:{(Lit_Slash /) ("*")}) spids: [104 109] ) ) } ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$dirname")} right: {($ VSub_Name "$basename")} ) ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$filename")} right: {(SQ )} ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dirname) op: Equal rhs: {(SQ <.>)} spids: [144] ) ] spids: [144] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dirname) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {(Lit_Slash /)} ) spids: [156 160] ) } spids: [155] ) ] spids: [155] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dirname) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(echo)} {($ VSub_Name "$dirname")})] ) left_token: spids: [169 173] ) } spids: [168] ) ] spids: [168] ) (C {(typeset)} {(long_path)}) (If arms: [ (if_arm cond: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:long_path) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Subshell child: (CommandList children: [ (Sentence child: (C {(cd)} {(DQ ($ VSub_Name "$dirname"))}) terminator: ) (C {(pwd)}) ] ) redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [200] ) ] spids: [188 198] ) ] ) left_token: spids: [186 203] ) } spids: [185] ) ] spids: [185] ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$long_path"))} right: {(SQ )} ) ) terminator: ) ] action: [(C {(echo)} {(DQ (/) ($ VSub_Name "$basename"))})] spids: [-1 228] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$long_path") (/) ($ VSub_Name "$basename"))} ) ] spids: [239 251] ) (ControlFlow token: arg_word: {(0)} ) ] spids: [-1 207] ) ] else_action: [ (C {(echo)} {($ VSub_Name "$filename")}) (ControlFlow token: arg_word: {(1)} ) ] spids: [259 272] ) ] spids: [67] ) spids: [63 66] ) (C {(typeset)} {(-A)} {(_Dbg_requires)}) (FuncDef name: require body: (BraceGroup children: [ (C {(typeset)} {(file)}) (C {(typeset)} {(expanded_file)}) (C {(typeset)} {(source_dir)}) (C {(typeset)} {(orig_dir)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:orig_dir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [314 316] ) } spids: [313] ) ] spids: [313] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:source_dir) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 1)})) suffix_op: (StringUnary op_id: VOp1_Percent arg_word: {(Lit_Slash /) ("*")} ) spids: [320 328] ) } spids: [319] ) ] spids: [319] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$source_dir")} right: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 1)})) spids: [339 344] ) } ) ) terminator: ) ] action: [(C {(builtin)} {(cd)} {($ VSub_Name "$source_dir")})] spids: [-1 350] ) ] spids: [-1 360] ) (ForEach iter_name: file iter_words: [{(DQ ($ VSub_At "$@"))}] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:expanded_file) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(_Dbg_expand_filename)} {(DQ ($ VSub_Name "$file"))}) ] ) left_token: spids: [379 385] ) } spids: [378] ) ] spids: [378] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolUnary op_id: BoolUnary_z child: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$file")}) ) spids: [394 399] ) } ) right: (BoolUnary op_id: BoolUnary_z child: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: {($ VSub_Name "$expanded_file")} ) ) spids: [407 412] ) } ) ) ) terminator: ) ] action: [ (C {(source)} {($ VSub_Name "$expanded_file")}) (C {(_Dbg_requires) (Lit_Other "[") ($ VSub_Name "$file") (Lit_Other "]") (Lit_Other "=") ($ VSub_Name "$expanded_file") } ) (C {(_Dbg_requires) (Lit_Other "[") ($ VSub_Name "$expanded_file") (Lit_Other "]") (Lit_Other "=") ($ VSub_Name "$expanded_file") } ) ] spids: [-1 418] ) ] spids: [-1 442] ) ] spids: [375 445] ) spids: [368 373] ) (AndOr children: [ (DBracket expr: (BoolUnary op_id:BoolUnary_n child:{($ VSub_Name "$orig_dir")}) ) (C {(builtin)} {(cd)} {($ VSub_Name "$orig_dir")}) ] op_id: Op_DAmp ) ] spids: [290] ) spids: [286 289] ) ] spids: [-1 60] ) ] spids: [-1 467] ) ] )