1 #// Content-Type: text/plain; charset=utf-8
3 #// bashlib is provided under 3-clause BSD license.
4 #// Copyright (C) 2011 Sofrware Design Gallery "Sage Plaisir 21" All Rights Reserved.
8 #//*********************************************************************
9 #// <<< [declare_associative_array] >>>
10 #//*********************************************************************
11 if [ "${BASH_VERSINFO[0]}" -ge "4" ];then
12 declare_associative_array="declare -A" #// bash ver4
14 declare_associative_array="declare" #// bash ver3
19 #//*********************************************************************
20 #// <<< [CallMain_func] >>>
21 #//*********************************************************************
22 function CallMain_func()
24 local is_not_err_handled=0
26 trap 'set +x ; ErrTrap_func' EXIT
27 trap 'set +x ; ErrTrap_func $LINENO ; break' ERR #// In function, it is necessary to bash -E option
28 trap 'DebugTrap_func "$LINENO" "$BASH_COMMAND" "${PIPESTATUS[@]}"
29 #// resume ${PIPESTATUS[@]}
30 case "${#g_PipeStatus[@]}" in
32 return ${g_PipeStatus[0]} | true;;
34 return ${g_PipeStatus[0]} | return ${g_PipeStatus[1]} | true;;
38 while TryStart_func; do
40 Main_func "" "AppKey4293"
43 if [ "$g_ExitStatus" != "0" ];then is_not_err_handled=1 ;fi
44 TryEnd1_func; done ;TryEnd2_func $?
47 if [ "$g_ExitStatus" != "0" ];then
48 if [ "$g_Err_Desc" == "" ];then
49 ColorText_func "<ERROR/>" "Red" "Bold"
51 ColorText_func "$g_Err_Desc" "Red" "Bold"
53 echo_e_func "$g_Ret" >&2
54 echo "Exit Status = $g_ExitStatus" >&2
56 echo "$g_Err_ErrCallStack" >&2
57 if [ "$g_Err_Desc" == "" ];then
60 echo "$g_Err_Desc" >&2
62 if [ "$is_not_err_handled" == "1" ];then
63 echo "エラー処理がされていません。ErrClass.clear_method または ErrClass.raiseOverwrite_method を呼び出してください"
73 #//*********************************************************************
74 #// <<< [DebugTrap_func] >>>
75 #//*********************************************************************
76 function DebugTrap_func()
78 if [ "$g_DebugTrapFunc" == "" ];then
88 #//*********************************************************************
89 #// <<< [EchoOn_func] >>>
90 #//*********************************************************************
91 function EchoOn_func()
93 echo "${BASH_LINENO[0]}: EchoOn_func at ${FUNCNAME[1]}() in ${BASH_SOURCE[1]}"
95 g_DebugTrapFunc="EchoOnTrap_func"
97 trap 'DebugTrap_func "$LINENO" "$BASH_COMMAND" "${PIPESTATUS[@]}"
98 #// resume ${PIPESTATUS[@]}
99 case "${#g_PipeStatus[@]}" in
101 return ${g_PipeStatus[0]} | true;;
103 return ${g_PipeStatus[0]} | return ${g_PipeStatus[1]} | true;;
107 function EchoOnTrap_func()
112 g_PipeStatus=( "$@" )
114 echo "$LineNo: $Command" >&2
119 #//*********************************************************************
120 #// <<< [EchoOff_func] >>>
121 #//*********************************************************************
122 function EchoOff_func()
129 #//*********************************************************************
130 #// <<< [echo_line_func] >>>
131 #//*********************************************************************
132 function echo_line_func()
134 echo "-------------------------------------------------------------------------------"
139 #//*********************************************************************
140 #// <<< [Pause_func] >>>
141 #//*********************************************************************
142 function Pause_func()
148 if [ "$Param" != "" ];then
150 $declare_associative_array option
152 GetLongOptions_func arguments option "$@" #//[out] arguments, option
153 Attr_func option "time_out" ; sec="$g_Ret"
156 if [ "$sec" == "" ];then
157 read -p "続行するには Enter キーを押してください . . ." key
159 for (( sec = $sec; sec >=0; sec -- )) ;do
161 if [ "$sec" == "0" ];then
162 echo "続行するには Enter キーを押してください . . . "
166 read -p "続行するには Enter キーを押してください . . . $sec " -t 1 key || key="...."
167 if [ "$key" == "" ];then break ;fi
174 #//*********************************************************************
175 #// <<< [ColorText_func] >>>
176 #//*********************************************************************
177 function ColorText_func()
181 local ColorNames=("$@")
186 #//=== initialize g_ColorText_Codes
187 Attr_func g_ColorText_Codes "Black"
188 if [ "$g_Ret" == "" ];then
190 #//=== set escape sequence
191 SetAttr_func g_ColorText_Codes "Black" 30
192 SetAttr_func g_ColorText_Codes "Red" 31
193 SetAttr_func g_ColorText_Codes "Green" 32
194 SetAttr_func g_ColorText_Codes "Yellow" 33
195 SetAttr_func g_ColorText_Codes "Blue" 34
196 SetAttr_func g_ColorText_Codes "Magenta" 35
197 SetAttr_func g_ColorText_Codes "Cyan" 36
198 SetAttr_func g_ColorText_Codes "White" 37
200 SetAttr_func g_ColorText_Codes "BlackBack" 40
201 SetAttr_func g_ColorText_Codes "RedBack" 41
202 SetAttr_func g_ColorText_Codes "GreenBack" 42
203 SetAttr_func g_ColorText_Codes "YellowBack" 43
204 SetAttr_func g_ColorText_Codes "BlueBack" 44
205 SetAttr_func g_ColorText_Codes "MagentaBack" 45
206 SetAttr_func g_ColorText_Codes "CyanBack" 46
207 SetAttr_func g_ColorText_Codes "WhiteBack" 47
209 SetAttr_func g_ColorText_Codes "Bold" 1
213 n=$(( ${#ColorNames[@]} - 1 ))
214 for (( i = 0; i <= n; i++ )) ;do
215 Attr_func g_ColorText_Codes "${ColorNames[$i]}"
216 if [ "$i" == "$n" ];then
217 str="${str}${g_Ret}m"
219 str="${str}${g_Ret};"
223 g_Ret="${str}${Text}\e[m"
226 $declare_associative_array g_ColorText_Codes
230 #//*********************************************************************
231 #// <<< [echo_e_func] >>>
232 #//*********************************************************************
233 function echo_e_func()
236 eval echo '$'"'$Text'"
241 #//*********************************************************************
242 #// <<< [Input_func] >>>
243 #//*********************************************************************
244 function Input_func()
250 if [ "$Prompt" == "" ];then Prompt=">" ;fi
252 if [ "$g_AutoInput_ArgsNextIndex" -lt "${#g_AutoInput_Args[@]}" ];then
253 key="${g_AutoInput_Args[$g_AutoInput_ArgsNextIndex]}"
256 g_AutoInput_ArgsNextIndex=$(( $g_AutoInput_ArgsNextIndex + 1 ))
259 IFS="\\" #// This can input space or tab at the end of string
260 read -p "$Prompt" -r g_Ret
267 #//*********************************************************************
268 #// <<< [SetAutoInputFromMainArg_func] >>>
269 #//*********************************************************************
271 g_AutoInput_ArgsNextIndex=0
273 function SetAutoInputFromMainArg_func()
275 g_AutoInput_Args=( "${g_Arguments[@]}" )
276 g_AutoInput_ArgsNextIndex=1
281 #//*********************************************************************
282 #// <<< [InputPath_func] >>>
283 #//*********************************************************************
284 function InputPath_func()
289 local is_file_exist_opt
290 local is_folder_exist_opt
294 $declare_associative_array options
296 GetLongOptions_func arguments options "$@" #//[out] arguments, options
300 Input_func "$Prompt$base_path" ; input_path="$g_Ret"
302 if [ "$base_path$input_path" == "" ]; then
303 Attr_func options "AllowEnterOnly"
304 if [ "$g_Ret" == "1" ]; then
311 StringClass.right_method "$input_path" 1
312 if [ "$g_Ret" == "$Tab" ];then
314 StringClass.length_method "$input_path"
315 len=$(( $g_Ret - 1 ))
316 StringClass.substring_method "$input_path" 0 "$len" ; input_path="$g_Ret"
317 InputPathSelectSub_func "$input_path" "$base_path" base_path #//[out] base_path
321 if [ "$base_path" != "" ];then
322 input_path="$base_path$input_path"
324 StringClass.substring_method "$input_path" 0 1
325 if [ "$g_Ret" == "~" ];then
326 StringClass.replace_method "$input_path" "~" "$HOME" ; input_path="$g_Ret"
328 eval "input_path=\"$input_path\""
329 GetAbsPath_func "$input_path" "$g_StartInPath" ; input_path="$g_Ret"
331 Attr_func options "ChkFileExists" ; is_file_exist_opt="$g_Ret"
332 Attr_func options "ChkFolderExists" ; is_folder_exist_opt="$g_Ret"
334 if [ x"$is_file_exist_opt" == x"" -a x"$is_folder_exist_opt" == x"" ];then
339 if [ "$is_file_exist_opt" == "1" ];then
340 if [ -f "$input_path" ]; then
346 if [ "$is_folder_exist_opt" == "1" ];then
347 if [ -d "$input_path" ]; then
353 if [ "$is_file_exist_opt" == "1" ];then
354 if [ "$is_folder_exist_opt" == "1" ];then
355 echo "ファイルまたはフォルダーが見つかりません。" >&2
357 echo "ファイルが見つかりません。" >&2
360 echo "フォルダーが見つかりません。" >&2
363 echo "$input_path" >&2
369 function InputPathSelectSub_func()
371 local PartOfPath="$1"
373 local out_SelectedPath="$3"
384 if [ "$BasePath" != "" ];then
385 PartOfPath="$BasePath$PartOfPath"
387 LeftOfLastStr_func "$PartOfPath" "/" ; folder="$g_Ret"
388 if [ x"$folder" == x"" -o x"$folder" == x"$PartOfPath" ];then
391 new_base_path="$folder/"
393 StringClass.substring_method "$folder" 0 1
394 if [ "$g_Ret" == "~" ];then
395 StringClass.replace_method "$folder" "~" "$HOME" ; folder="$g_Ret"
397 eval "folder=\"$folder\""
399 RightOfLastStr_func "$PartOfPath" "/" ; part_of_file="$g_Ret"
402 pushd "$g_StartInPath" > /dev/null
403 paths=`ls -p1A "$folder"`
405 ArrayClass.fromLines_method paths "$paths" #//[out] paths
408 StringClass.length_method "$part_of_file" ; len="$g_Ret"
409 for path in "${paths[@]}" ;do
410 StringClass.substring_method "$path" 0 "$len"
411 if [ "$g_Ret" == "$part_of_file" ];then
417 if [ "$PartOfPath" == "" ];then
418 echo "$g_StartInPath/"
420 GetAbsPath_func "$PartOfPath" "$g_StartInPath"
423 for (( i = 0; i < ${#paths2[@]}; i ++ ));do
424 echo -n "$(( $i + 1 )). ${paths2[$i]} "
426 echo -n "88. クリア 99. 戻る"
429 Input_func " >" ; num="$g_Ret"
430 if [ "$num" == "88" ];then
431 SetOutput_func "$out_SelectedPath" ""
433 elif [ x"$num" == x"99" -o x"$num" == x"" ];then
434 SetOutput_func "$out_SelectedPath" "$BasePath"
436 elif [ "$num" -le "$i" -a "$num" -ge "0" ];then
437 if [ "$new_base_path" == "" ];then
438 SetOutput_func "$out_SelectedPath" "${paths2[$(( $num - 1 ))]}"
440 SetOutput_func "$out_SelectedPath" "$new_base_path${paths2[$(( $num - 1 ))]}"
449 #//*********************************************************************
450 #// <<< [InputCommand_func] >>>
451 #//*********************************************************************
452 function InputCommand_func()
455 local Prompt="$2" ; if [ "$Prompt" == "" ];then Prompt="番号またはコマンド >" ;fi
464 local current_folder=`pwd -P`
470 SetAutoInputFromMainArg_func
471 if [ "${#g_Arguments[@]}" == "1" ];then is_prompt=1 ;else is_prompt=0 ;fi
473 Attr_func $self CommandReplace ; replaces="$g_Ret"
474 Attr_func $self MenuCaption ; captions="$g_Ret"
479 if [ "$is_prompt" != "0" ];then
485 AssociativeArrayClass.getKeys_method "$replaces" ; a1="$g_Ret"
487 if IsNumeric_func $key; then
488 Attr_func $captions $key ; caption="$g_Ret"
489 if [ "$caption" == "" ];then
490 Attr_func $replaces $key
493 echo "$key. $caption"
500 Input_func "$Prompt" ; num="$g_Ret"
501 if [ "$num" != "" ];then break ;fi
506 Input_func "$Prompt" ; num="$g_Ret"
507 if [ "$num" != "" ];then break ;fi
510 if [ "$num" == "99" ];then
511 a1=`basename "${g_Arguments[0]}"`
512 echo "(ヒント)$a1 のパラメーターに、入力する内容を指定できます。"
517 Attr_func $replaces "$num" ; func="$g_Ret"
518 if [ "$func" != "" ];then num="$func" ; Attr_func $replaces $func ; func="$g_Ret" ;fi
519 if [ "$func" == "" ];then func="$num" ;fi
520 echo " ((( $func )))"
522 if [ "$is_prompt" != "0" ];then
523 while TryStart_func; do
524 "$func" "$Opt" "$AppKey"
525 TryEnd1_func; done ;TryEnd2_func $?
527 if [ "$g_ExitStatus" != "0" ];then
528 echo "Exit Status = $g_ExitStatus"
529 if [ "$g_Err_Desc" == "" ];then
530 ColorText_func "<ERROR/>" "Red" "Bold"
532 ColorText_func "$g_Err_Desc" "Red" "Bold"
534 echo_e_func "$g_Ret" >&2
535 if [ "$g_Err_Desc" == "" ];then
536 echo "${g_Err_ErrCallStack}<ERROR/>" >&2
538 echo "${g_Err_ErrCallStack}${g_Err_Desc}" >&2
540 if [ "$is_not_err_handled" == "1" ];then
541 echo "エラー処理がされていません。ErrClass.clear_method または ErrClass.raiseOverwrite_method を呼び出してください" >&2
544 ErrClass.clear_method
546 "$func" "$Opt" "$AppKey"
555 #//*********************************************************************
556 #// <<< [sudo_func] >>>
557 #//*********************************************************************
560 g_TemporarySudo="sudo"
562 unset g_TemporarySudo
567 #//*********************************************************************
568 #// <<< [mkdir_for_it_func] >>>
569 #//*********************************************************************
570 function mkdir_for_it_func()
573 CheckArgCount_func 1 "$@"
575 folder_path=${FilePath%/*} #// parent folder
576 if [ "$folder_path" == "$FilePath" ]; then return 0 ;fi #// if not found "/"
577 if [ ! -f "$folder_path" ]; then mkdir -p "$folder_path" ;fi
582 #//*********************************************************************
583 #// <<< [GetAbsPath_func] >>>
584 #//*********************************************************************
585 function GetAbsPath_func()
589 CheckMinArgCount_func 1 "$@"
590 CheckMaxArgCount_func 2 "$@"
595 LeftOfStr_func "$StepPath" "/" ; str="$g_Ret" #// if abs path, str=""
596 if [ "$str" == "" ]; then
598 elif [ "$str" == "~" ]; then
599 StringClass.substring_method "$StepPath" 1
602 if [ "$BasePath" == "" ];then BasePath="$PWD" ;fi
604 abs_path="$BasePath/$StepPath"
606 while true; do #// "*/../" -> ""
607 echo "$abs_path" | grep "[^/]*/\.\./" > /dev/null || break
608 abs_path=`echo "$abs_path" | sed -e "s%[^/]*/\.\./%%"`
611 while true; do #// "/*/.." -> ""
612 echo "$abs_path" | grep "[^/]*/[^/]*/\.\." > /dev/null || break
613 abs_path=`echo "$abs_path" | sed -e "s%/[^/]*/\.\.$%%"`
616 while true; do #// "/./" -> "/"
617 echo "$abs_path" | grep "/\./" > /dev/null || break
618 StringClass.replace_method "$abs_path" "/./" "/" ; abs_path="$g_Ret"
621 while true; do #// "/." -> ""
622 StringClass.right_method "$abs_path" 2
623 if [ "$g_Ret" != "/." ];then break ;fi
624 StringClass.replace_method "$abs_path" "/./" "/" ; abs_path="$g_Ret"
625 abs_path=`echo "$abs_path" | sed -e "s%/\.$%%"`
634 #//*********************************************************************
635 #// <<< [GetParentAbsPath_func] >>>
636 #//*********************************************************************
637 function GetParentAbsPath_func()
640 CheckArgCount_func 1 "$@"
644 LeftOfStr_func "$Path" "/" ; str="$g_Ret" #// if abs path, str=""
645 if [ "$str" != "" ]; then
646 GetAbsPath_func "$Path" ; Path="$g_Ret"
649 if [ x"$Path" == x"/" -o x"$Path" == x"" ]; then
652 RightOfLastStr_func "$Path" "/" #// if last char is "/", str=""
653 if [ "$g_Ret" == "" ]; then
654 LeftOfLastStr_func "$Path" "/" ; Path="$g_Ret"
656 LeftOfLastStr_func "$Path" "/" ; Path="$g_Ret" #// parent folder
657 if [ "$Path" == "" ];then Path="/" ;fi
664 #//*********************************************************************
665 #// <<< [SearchParent_func] >>>
666 #//*********************************************************************
667 function SearchParent_func()
673 GetAbsPath_func "$path" "$PWD" ; path="$g_Ret"
674 if [ -e "$path" ];then g_Ret="$path" ; return ;fi
676 folder=`dirname "$path"`
677 file=` basename "$path"`
679 folder=`dirname "$folder"`
680 if [ "$folder" == "/" ];then break ;fi
681 if [ -e "$folder/$file" ];then g_Ret="$folder/$file" ; return ;fi
683 if [ -e "/$file" ];then g_Ret="/$file" ; return ;fi
689 #//*********************************************************************
690 #// <<< [local_func] >>>
691 #//*********************************************************************
692 function local_func()
695 $declare_associative_array option
706 GetLongOptions_func arguments option "$@" #//[out] arguments, option
708 Attr_func option "arg"
709 ArrayClass.fromCSV_method args "$g_Ret" #//[out] args
711 Attr_func option "local"
712 ArrayClass.fromCSV_method locals "$g_Ret" #//[out] locals
714 for param in ${args[@]} ;do
715 StringClass.substring_method "$param" 0 5 ; a1="$g_Ret"
716 StringClass.substring_method "$param" 0 8 ; a2="$g_Ret"
717 if [ "$a1" == "(out)" ];then
718 StringClass.substring_method "$param" 5 ; param="$g_Ret"
719 out_names=( "${out_names[@]}" "${arguments[$arg_num]}" )
720 elif [ "$a2" == "(in_out)" ];then
721 StringClass.substring_method "$param" 8 ; param="$g_Ret"
722 out_names=( "${out_names[@]}" "${arguments[$arg_num]}" )
724 arg_num=$(( $arg_num + 1 ))
725 code="$code local $param=\""'$'"$arg_num\";"
728 for param in "${locals[@]}" ;do
729 code="$code local $param;"
732 locals=( "${args[@]}" "${locals[@]}" )
734 for name in ${out_names[@]} ;do
735 for param in "${locals[@]}" ;do
736 if [ "$name" == "$param" ];then
737 Error_func "<ERROR msg=\"出力引数がローカル変数名と衝突しています\" name=\"$name\"/>"
747 #//*********************************************************************
748 #// <<< [GetUsableCommands_func] >>>
749 #//*********************************************************************
750 function GetUsableCommands_func()
752 local out_FoundCommands="$1"
754 local Commands=( "$@" )
759 for command in ${Commands[@]} ;do
760 while TryStart_func; do
761 which $command > /dev/null
762 TryEnd1_func; done ;TryEnd2_func $?
763 if [ "$g_ExitStatus" == "0" ];then founds=( "${founds[@]}" "$command " ) ;fi
764 ErrClass.clear_method
766 SetOutputAsArray_func $out_FoundCommands "${founds[@]}"
771 #//*********************************************************************
772 #// <<< [GetUsableApplicationsForMac_func] >>>
773 #//*********************************************************************
774 function GetUsableApplicationsForMac_func()
778 --arg=" (out)out_FoundCommands " \
779 --local=" command__, commands__, apps__, app__, path__, file_name__, paths__, i__ " \
780 "$@" ` ; eval "$code"
781 #// --arg="Applications ..."
784 local Applications=( "$@" )
786 #// list up applications
787 while TryStart_func; do
788 paths__=`ls /Applications/*.app /Applications/Utilities/*.app 2>/dev/null | grep :$`
789 TryEnd1_func; done ;TryEnd2_func $?
790 if [ "$g_ExitStatus" != "0" ]; then
791 unset $out_FoundCommands
792 unset $out_FoundCommands #// 配列をクリアするには2回必要?
793 ErrClass.clear_method
796 ArrayClass.fromLines_method paths__ "$paths__" #//[out] paths__
799 for path__ in "${paths__[@]}" ;do
800 file_name__=`basename "$path__"`
801 LeftOfLastStr_func "$file_name__" ".app:" ; apps__[$i__]="$g_Ret"
805 if [ "${#Applications[@]}" == "0" ];then
806 for (( i__ = 0; i__ < ${#apps__[@]}; i__ ++ )) ;do
807 apps__[$i__]="open -a \"$apps__[$i__]\" "
809 SetOutputAsArray_func $out_FoundCommands "${apps__[@]}"
813 #// pick up applications
815 for command__ in "${Applications[@]}" ;do
816 for app__ in "${apps__[@]}" ;do
817 if [ "$command__" == "$app__" ];then
818 commands__[$i__]="open -a \"$app__\" "
824 SetOutputAsArray_func $out_FoundCommands "${commands__[@]}"
829 #//*********************************************************************
830 #// <<< [GetLongOptions_func] >>>
831 #//*********************************************************************
832 function GetLongOptions_func()
834 local out_Arguments="$1"
835 local out_OptAssocArray="$2"
842 local locals="out_Arguments out_OptAssocArray Args__ param__ name__ value__"
844 CheckOutParamIsConflictToLocal_func "$out_Arguments" $locals
845 CheckOutParamIsConflictToLocal_func "$out_OptAssocArray" $locals
847 for param__ in "${Args__[@]}" ;do
848 StringClass.substring_method "$param__" 0 2
849 if [ "$g_Ret" == "--" ];then
850 LeftOfStr_func "$param__" "=" ; name__="$g_Ret"
851 if [ "$name__" == "$param__" ];then
854 RightOfStr_func "$param__" "=" ; value__="$g_Ret"
856 StringClass.substring_method "$name__" 2 ; name__="$g_Ret"
858 SetAttr_func $out_OptAssocArray $name__ "$value__"
860 SetArrItem_func $out_Arguments $ArgIndex__ "$param__"
861 ArgIndex__=$(( $ArgIndex__ + 1 ))
868 #//*********************************************************************
869 #// <<< [Attr_func] >>>
870 #//*********************************************************************
876 CheckArgCount_func 2 "$@"
878 eval tmp="\${${self}[\$AttrName]}"
884 #//*********************************************************************
885 #// <<< [SetArrItem_func] >>>
886 #//*********************************************************************
887 function SetArrItem_func()
892 CheckArgCount_func 3 "$@"
894 eval "$self__[$Index__]=\"$Value__\""
899 #//*********************************************************************
900 #// <<< [SetAttr_func] >>>
901 #//*********************************************************************
902 function SetAttr_func()
909 #//*********************************************************************
910 #// <<< [SetAttr_as_ArrayName_func] >>>
911 #//*********************************************************************
912 function SetAttr_as_ArrayName_func()
915 local AttrName__="$2"
918 CheckOutParamIsConflictToLocal_func "$self__" self__ AttrName__ i__ Params__
923 SetAttr_func $self__ "$AttrName__" "g_Arrays_$g_ArrayLength"
925 for (( i__ = 0; i__ < ${#Params__[@]}; i__ ++ ));do
926 eval "g_Arrays_$g_ArrayLength"'[$i__]'='${Params__[$i__]}'
929 g_ArrayLength=$(( $g_ArrayLength + 1 ))
934 #//*********************************************************************
935 #// <<< [SetAttr_as_AssociativeArrayName_func] >>>
936 #//*********************************************************************
937 function SetAttr_as_AssociativeArrayName_func()
940 local AttrName__="$2"
945 CheckOutParamIsConflictToLocal_func "$self__" self__ AttrName__ i__ Params__ key__ value__
950 SetAttr_func $self__ "$AttrName__" "g_AssociativeArrays_$g_AssociativeArrayLength"
952 for (( i__ = 0; i__ < ${#Params__[@]}; i__ = i__ + 2 ));do
953 key__=${Params__[$i__]}
954 value__=${Params__[$i__+1]}
956 SetAttr_func g_AssociativeArrays_$g_AssociativeArrayLength $key__ "$value__"
959 g_AssociativeArrayLength=$(( $g_AssociativeArrayLength + 1 ))
964 #//*********************************************************************
965 #// <<< [AssociativeArrayClass.getLength_method] >>>
966 #//*********************************************************************
967 function AssociativeArrayClass.getLength_method()
970 if [ "$self" == "" ];then Error_func "no object name" ;fi
972 eval g_Ret='${#'"$self"'[@]}'
977 #//*********************************************************************
978 #// <<< [AssociativeArrayClass.getKeys_method] >>>
979 #//*********************************************************************
980 function AssociativeArrayClass.getKeys_method()
983 if [ "$self" == "" ];then Error_func "no object name" ;fi
985 eval g_Ret='${!'"$self"'[@]}'
990 #//*********************************************************************
991 #// <<< [AssociativeArrayClass.getItems_method] >>>
992 #//*********************************************************************
993 function AssociativeArrayClass.getItems_method()
996 if [ "$self" == "" ];then Error_func "no object name" ;fi
998 eval g_Ret='${'"$self"'[@]}'
1003 #//*********************************************************************
1004 #// <<< [AssociativeArrayClass.destroy_method] >>>
1005 #//*********************************************************************
1006 function AssociativeArrayClass.destroy_method()
1016 #//*********************************************************************
1017 #// <<< [CopyArray_func] >>>
1018 #//*********************************************************************
1019 function CopyArray_func()
1021 local DstArray__="$1"
1022 local SrcArray__="$2"
1027 local locals__="DstArray__ SrcArray__ key__ keys__ code__ value__"
1028 CheckOutParamIsConflictToLocal_func "$DstArray__" $locals__
1029 CheckOutParamIsConflictToLocal_func "$SrcArray__" $locals__
1031 code__="$DstArray__=("
1032 eval keys__=( '"${!'"$SrcArray__"'[@]}"' )
1033 for key__ in "${keys__[@]}" ;do
1034 eval value__='${'$SrcArray__'[$key__]}'
1035 code__="$code__ [\"$key__\"]=\"$value__\""
1042 #//*********************************************************************
1043 #// <<< [CopyArrayAttr_func] >>>
1044 #//*********************************************************************
1045 function CopyArrayAttr_func()
1048 local AttrName__="$2"
1049 local out_Array="$3"
1053 local locals="self__ AttrName__ out_Array__ array_name__ i__ n__"
1054 CheckOutParamIsConflictToLocal_func "$self__" $locals
1055 CheckOutParamIsConflictToLocal_func "$out_Array" $locals
1057 Attr_func $self__ "$AttrName__" ; array_name__="$g_Ret"
1059 unset $out_Array #// 配列をクリアするには2回必要?
1061 eval n__='${#'"$array_name__"'[@]}'
1063 for (( i__ = 0; $i__ < $n__; i__ ++ ));do
1064 eval "$out_Array"'[$i__]=${'"$array_name__"'[$i__]}'
1070 #//*********************************************************************
1071 #// <<< [SetOutput_func] >>>
1072 #//*********************************************************************
1073 function SetOutput_func()
1077 CheckArgCount_func 2 "$@"
1078 CheckOutParamIsConflictToLocal_func "$out_Var" out_Var Value__
1080 eval $out_Var="'$Value__'"
1085 #//*********************************************************************
1086 #// <<< [SetOutputAsArray_func] >>>
1087 #//*********************************************************************
1088 function SetOutputAsArray_func()
1091 CheckMinArgCount_func 2 "$@"
1092 CheckOutParamIsConflictToLocal_func "$out_Var" out_Var
1095 eval $out_Var="(" '"$@"' ")"
1100 #//*********************************************************************
1101 #// <<< [AddIfNotExist_func] >>>
1102 #//*********************************************************************
1103 function AddIfNotExist_func()
1107 local Separator="$3"
1108 CheckArgCount_func 3 "$@"
1110 local whole_str_plus="$WholeStr$Separator"
1113 if [ "$AddStr" == "" ];then echo "$WholeStr" ; return 0 ;fi
1115 LeftOfStr_func "$whole_str_plus" "$AddStr$Separator" ; str="$g_Ret"
1116 if [ "$str" == "$whole_str_plus" ];then #// not found
1117 g_Ret="$AddStr$Separator$WholeStr"
1125 #//*********************************************************************
1126 #// <<< [IsNumeric_func] >>>
1127 #//*********************************************************************
1128 function IsNumeric_func()
1131 CheckArgCount_func 1 "$@"
1132 if [ "$Value" == "-1" ];then
1135 expr $Value + 1 > /dev/null 2>&1
1141 #//*********************************************************************
1142 #// <<< [StringClass.length_method] >>>
1143 #//*********************************************************************
1144 function StringClass.length_method()
1147 CheckArgCount_func 1 "$@"
1153 #//*********************************************************************
1154 #// <<< [StringClass.substring_method] >>>
1155 #//*********************************************************************
1156 function StringClass.substring_method()
1159 local StartIndex="$2"
1161 CheckMinArgCount_func 2 "$@"
1162 CheckMaxArgCount_func 3 "$@"
1164 if [ "$EndIndex" == "" ];then
1165 g_Ret="${self:$StartIndex}"
1167 g_Ret="${self:$StartIndex:$(( $EndIndex - $StartIndex ))}"
1173 #//*********************************************************************
1174 #// <<< [StringClass.trim_method] >>>
1175 #//*********************************************************************
1176 function StringClass.trim_method()
1186 ch="${String:$index:1}"
1187 if [ "$ch" != " " ];then
1188 if [ "$ch" != "$Tab" ];then
1189 if [ "$ch" != "$LF" ];then
1194 index=$(( $index + 1 ))
1197 String="${String:$index}"
1199 index=$(( ${#String} - 1 ))
1201 ch="${String:$index:1}"
1202 if [ "$ch" != " " ];then
1203 if [ "$ch" != "$Tab" ];then
1204 if [ "$ch" != "$LF" ];then
1209 index=$(( $index - 1 ))
1211 index=$(( $index + 1 ))
1213 g_Ret="${String:0:$index}"
1218 #//*********************************************************************
1219 #// <<< [StringClass.right_method] >>>
1220 #//*********************************************************************
1221 function StringClass.right_method()
1225 CheckArgCount_func 2 "$@"
1227 g_Ret="${String:$(( ${#String} - $Length ))}"
1232 #//*********************************************************************
1233 #// <<< [StringClass.cutLastOf_method] >>>
1234 #//*********************************************************************
1235 function StringClass.cutLastOf_method()
1239 CheckArgCount_func 2 "$@"
1241 if [ "${String:$(( ${#String} - ${#LastStr} ))}" == "$LastStr" ];then
1242 g_Ret="${String:0:$(( ${#String} - ${#LastStr} ))}"
1250 #//*********************************************************************
1251 #// <<< [LeftOfStr_func] >>>
1252 #//*********************************************************************
1253 function LeftOfStr_func()
1257 CheckArgCount_func 2 "$@"
1259 StringClass.replace_method "$Key" '\' '\\'
1260 StringClass.replace_method "$g_Ret" '*' '\*'
1262 g_Ret="${String%%$g_Ret*}"
1267 #//*********************************************************************
1268 #// <<< [LeftOfLastStr_func] >>>
1269 #//*********************************************************************
1270 function LeftOfLastStr_func()
1274 CheckArgCount_func 2 "$@"
1276 StringClass.replace_method "$Key" '\' '\\'
1277 StringClass.replace_method "$g_Ret" '*' '\*'
1279 g_Ret="${String%$g_Ret*}"
1284 #//*********************************************************************
1285 #// <<< [RightOfStr_func] >>>
1286 #//*********************************************************************
1287 function RightOfStr_func()
1291 CheckArgCount_func 2 "$@"
1293 StringClass.replace_method "$Key" '\' '\\'
1294 StringClass.replace_method "$g_Ret" '*' '\*'
1296 g_Ret="${String#*$g_Ret*}"
1301 #//*********************************************************************
1302 #// <<< [RightOfLastStr_func] >>>
1303 #//*********************************************************************
1304 function RightOfLastStr_func()
1308 CheckArgCount_func 2 "$@"
1310 StringClass.replace_method "$Key" '\' '\\'
1311 StringClass.replace_method "$g_Ret" '*' '\*'
1313 g_Ret="${String##*$g_Ret}"
1318 #//*********************************************************************
1319 #// <<< [StringClass.indexOf_method] >>>
1320 #//*********************************************************************
1321 function StringClass.indexOf_method()
1325 local StartIndex="$3"
1326 CheckMinArgCount_func 2 "$@"
1327 CheckMaxArgCount_func 3 "$@"
1329 if [ "$StartIndex" == "" ];then StartIndex=0 ;fi
1330 if [ "$StartIndex" -le "0" ];then #// -le:"<="
1331 part="${self%%$Keyword*}"
1332 if [ "$part" == "$self" ];then
1335 g_Ret=$(( ${#part} ))
1338 self="${self:$StartIndex}"
1339 part="${self%%$Keyword*}"
1340 if [ "$part" == "$self" ];then
1343 g_Ret=$(( ${#part} + $StartIndex ))
1350 #//*********************************************************************
1351 #// <<< [StringClass.lastIndexOf_method] >>>
1352 #//*********************************************************************
1353 function StringClass.lastIndexOf_method()
1357 local StartIndex="$3"
1358 CheckMinArgCount_func 2 "$@"
1359 CheckMaxArgCount_func 3 "$@"
1361 if [ "$StartIndex" == "" ];then StartIndex=0 ;fi
1362 if [ "$StartIndex" -le "0" ];then #// -le:"<="
1363 part="${self%$Keyword*}"
1364 if [ "$part" == "$self" ];then
1367 g_Ret=$(( ${#part} ))
1370 self="${self:0:$(( $StartIndex + ${#Keyword} ))}"
1371 part="${self%$Keyword*}"
1372 if [ "$part" == "$self" ];then
1382 #//*********************************************************************
1383 #// <<< [StringClass.replace_method] >>>
1384 #//*********************************************************************
1385 function StringClass.replace_method()
1391 StringEscapeUtilsClass.escapeBashReplace_method "$From"
1392 g_Ret="${String//$g_Ret/$3}"
1397 #//*********************************************************************
1398 #// <<< [StringClass.toLowerCase_method] >>>
1399 #//*********************************************************************
1400 function StringClass.toLowerCase_method()
1404 #// echo "${self,,}"
1407 g_Ret=`echo "$1" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
1412 #//*********************************************************************
1413 #// <<< [StringClass.toUpperCase_method] >>>
1414 #//*********************************************************************
1415 function StringClass.toUpperCase_method()
1419 #// echo "${self^^}"
1422 g_Ret=`echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1427 #//*********************************************************************
1428 #// <<< [StringEscapeUtilsClass.escapeGrep_method] >>>
1429 #//*********************************************************************
1430 function StringEscapeUtilsClass.escapeGrep_method()
1433 Str="${Str//\\/\\\\}"
1443 g_Ret="${Str//\?/\?}"
1448 #//*********************************************************************
1449 #// <<< [StringEscapeUtilsClass.escapeSed_method] >>>
1450 #//*********************************************************************
1451 function StringEscapeUtilsClass.escapeSed_method()
1454 Str="${Str//\\/\\\\}"
1462 g_Ret="${Str//\//\/}"
1467 #//*********************************************************************
1468 #// <<< [StringEscapeUtilsClass.escapeBashReplace_method] >>>
1469 #//*********************************************************************
1470 function StringEscapeUtilsClass.escapeBashReplace_method()
1473 Str="${Str//\\/\\\\}"
1475 Str="${Str//\(/\\(}"
1476 Str="${Str//\)/\\)}"
1477 Str="${Str//\*/\\*}"
1478 Str="${Str//\?/\\?}"
1479 g_Ret="${Str//\//\\/}"
1484 #//*********************************************************************
1485 #// <<< [StringEscapeUtilsClass.escapeBashDoubleQuot_method] >>>
1486 #//*********************************************************************
1487 function StringEscapeUtilsClass.escapeBashDoubleQuot_method()
1490 Str="${Str//\\/\\\\}"
1492 g_Ret="${Str//\//\\/}"
1497 #//*********************************************************************
1498 #// <<< [StringEscapeUtilsClass.escapeBashParam_method] >>>
1499 #//*********************************************************************
1500 function StringEscapeUtilsClass.escapeBashParam_method()
1503 Str="${Str//\\/\\\\}"
1505 g_Ret="${Str//$/\\$}"
1510 #//*********************************************************************
1511 #// <<< [ReplaceTextFile_func] >>>
1512 #//*********************************************************************
1513 function ReplaceTextFile_func()
1520 CheckMinArgCount_func 2 "$@"
1521 CheckMaxArgCount_func 4 "$@"
1526 local slashes=( "%" "/" )
1528 CheckWritable_func "$Path"
1530 if [ "$Opt" == "-i" ];then Opt="i" ;fi
1532 sed_setIsAbleToNotCaseSensitive_func
1533 if [ "$g_sed_isAbleToNotCaseSensitive" == "0" ];then
1534 StringClass.indexOf_method "$Opt" "i"
1535 if [ "$g_Ret" -ge 0 ];then
1536 Error_func "-i オプションは指定できません。"
1540 for slash in ${slashes[@]};do
1542 LeftOfStr_func "$From" "$slash" ; str1="$g_Ret"
1543 LeftOfStr_func "$To" "$slash" ; str2="$g_Ret"
1544 if [ x"$str1" == x"$From" -a x"$str2" == x"$To" ];then #// $From and $To do not have $slash.
1546 RightOfStr_func "$From" "\n" ; str1="$g_Ret"
1547 RightOfStr_func "$To" "\n" ; str2="$g_Ret"
1548 if [ x"$str1" == x"$From" -a x"$str2" == x"$To" ];then #// $str1 and $str2 are single line,
1549 sed -i.bak -e "s$slash$From$slash$To${slash}g$Opt" "$Path" ; rm "$Path.bak"
1551 RightOfStr_func "$str1" "\n" ; str2="$g_Ret"
1552 if [ "$str1" != "$str2" ];then
1553 Error_func "置き換える前の文字列は3行以上にできません。"
1557 #// sed -i.bak -e '/\n/! {;$q;N;};'"s$slash$From$slash$To${slash}g$Opt;P;D;" "$Path" ; rm "$Path.bak"
1559 #// for BSD sed in Mac OS X Snow Leopard
1560 To=`echo "$To" | sed -e 's/\\\\n/\\\\\\'"$LF"'/g' `
1561 cp "$Path" "$Path.bak" #// mv では、chmod 属性が消えてしまいます
1562 sed -e '/\n/! {;$q;N;};'"s$slash$From$slash$To${slash}g$Opt;P;D;" "$Path.bak" > $Path
1569 Error_func "ReplaceTextFile_func は、置き換える前後の文字列に / と % の両方を含むことはできません"
1574 #//*********************************************************************
1575 #// <<< [sed_setIsAbleToNotCaseSensitive_func] >>>
1576 #//*********************************************************************
1577 g_sed_isAbleToNotCaseSensitive=""
1578 function sed_setIsAbleToNotCaseSensitive_func()
1580 if [ "$g_sed_isAbleToNotCaseSensitive" == "" ];then
1582 echo -n "" | sed -e s/a/b/i > /dev/null 2>&1 || status=$?
1583 g_sed_isAbleToNotCaseSensitive=$(( 1 - $status ))
1589 #//*********************************************************************
1590 #// <<< [ReplaceTextFileLineRange_func] >>>
1591 #//*********************************************************************
1592 function ReplaceTextFileLineRange_func()
1602 CheckMinArgCount_func 3 "$@"
1603 CheckMaxArgCount_func 5 "$@"
1605 CheckWritable_func "$Path"
1607 if [ "$Opt" == "-i" ];then Opt="i" ;fi
1609 sed_setIsAbleToNotCaseSensitive_func
1610 if [ "$g_sed_isAbleToNotCaseSensitive" == "0" ];then
1611 StringClass.indexOf_method "$Opt" "i"
1612 if [ "$g_Ret" -ge 0 ];then
1613 Error_func "i オプションは指定できません。"
1617 LeftOfStr_func "$From" "%"
1618 if [ "$g_Ret" != "$From" ];then Error_func ;fi
1620 LeftOfStr_func "$FromEnd" "%"
1621 if [ "$g_Ret" != "$FromEnd" ];then Error_func ;fi
1623 Opt=`StringClass.toUpperCase_method "$Opt"`
1625 if [ "$To" != "" ];then
1627 #// To="c${To//\\n/\\${LF}}"
1629 #// for BSD sed in Mac OS X Snow Leopard
1630 if [ "$To" == "\n" ];then
1631 a1=`echo $'a\nb\nc' | sed -e '/b/c\'"${LF}" `
1632 if [ "$a1" == "a${LF}${LF}c" ];then
1637 To="c\\${LF}${To//\\n/\\${LF}}"
1643 #// if [ "$FromEnd" == "" ];then
1644 #// sed -i.bak -e '\%'"$From"'%'"$Opt$To" "$Path" ; rm "$Path.bak"
1646 #// sed -i.bak -e '\%'"$From"'%'"$Opt"',\%'"$FromEnd"'%'"$Opt$To" "$Path" ; rm "$Path.bak"
1649 #// for BSD sed in Mac OS X Snow Leopard
1650 cp "$Path" "$Path.bak" #// mv では、chmod 属性が消えてしまいます
1651 if [ "$FromEnd" == "" ];then
1652 sed -e '\%'"$From"'%'"$Opt$To" "$Path.bak" > $Path
1654 sed -e '\%'"$From"'%'"$Opt"',\%'"$FromEnd"'%'"$Opt$To" "$Path.bak" > $Path
1661 #//*********************************************************************
1662 #// <<< [MultiLine_func] >>>
1663 #//*********************************************************************
1664 function MultiLine_func()
1666 local LineFeedChar="$1"
1669 local Params=( "$@" )
1674 for line in "$@" ;do
1675 if [ "$line" == "" ];then
1676 lfs="$lfs$LineFeedChar"
1678 g_Ret="$g_Ret$lfs$line"
1686 #//*********************************************************************
1687 #// <<< [ArrayClass.getLength_method] >>>
1688 #//*********************************************************************
1689 function ArrayClass.getLength_method()
1693 eval g_Ret='${#'"$self"'[@]}'
1698 #//*********************************************************************
1699 #// <<< [ArrayClass.get_method] >>>
1700 #//*********************************************************************
1701 function ArrayClass.get_method()
1706 CheckArgCount_func 2 "$@"
1708 eval over_index='${#'"$self"'[@]}'
1709 if [ "$Index" -ge "$over_index" -o "$Index" -lt "0" ];then
1710 Error_func "<ERROR msg=\"インデックスが範囲外です\" index=\"$Index\"/>"
1713 eval g_Ret='"${'"$self"'[$Index]}"'
1718 #//*********************************************************************
1719 #// <<< [ArrayClass.set_method] >>>
1720 #//*********************************************************************
1721 function ArrayClass.set_method()
1728 CheckArgCount_func 3 "$@"
1730 eval over_index='${#'"$self"'[@]}'
1731 if [ "$Index" -lt "0" ];then
1732 Error_func "<ERROR msg=\"インデックスが範囲外です\" index=\"$Index\"/>"
1735 for (( num = over_index; $num < $Index; num++ )) ;do
1736 eval "$self"'[$num]=""'
1739 eval "$self"'[$Index]='"'$Value'"
1744 #//*********************************************************************
1745 #// <<< [ArrayClass.remove_method] >>>
1746 #//*********************************************************************
1747 function ArrayClass.remove_method()
1754 CheckArgCount_func 2 "$@"
1756 eval over_index='${#'"$self"'[@]}'
1757 if [ "$Index" -ge "$over_index" -o "$Index" -lt "0" ];then
1758 Error_func "<ERROR msg=\"インデックスが範囲外です\" index=\"$Index\"/>"
1761 last_index=$(( $over_index - 1 ))
1762 for (( num = $Index; $num < $last_index; num++ )) ;do
1763 eval "$self"'[$num]="${'"$self"'[$(( $num + 1 ))]}"'
1766 eval unset "$self"'[$last_index]'
1771 #//*********************************************************************
1772 #// <<< [ArrayClass.clear_method] >>>
1773 #//*********************************************************************
1774 function ArrayClass.clear_method()
1779 unset $self #// 配列をクリアするには2回必要?
1784 #//*********************************************************************
1785 #// <<< [ArrayClass.fromLines_method] >>>
1786 #//*********************************************************************
1787 function ArrayClass.fromLines_method()
1789 local out_Array="$1"
1795 CheckOutParamIsConflictToLocal_func $out_Array out_Array Lines line i keys
1798 unset $out_Array #// 配列をクリアするには2回必要?
1802 line="${Lines%%$LF*}"
1803 if [ "$line" != "" ];then eval $out_Array[$i]="'$line'" ;fi
1804 if [ "$line" == "$Lines" ];then break ;fi
1806 Lines=${Lines:$(( ${#line} + 1 ))} #// next line
1812 #//*********************************************************************
1813 #// <<< [ArrayClass.fromCSV_method] >>>
1814 #//*********************************************************************
1815 function ArrayClass.fromCSV_method()
1817 local out_Array="$1"
1823 CheckArgCount_func 2 "$@"
1825 CheckOutParamIsConflictToLocal_func "$out_Array" \
1826 CSV__ out_Array index__ item__ __field char__ next__
1829 unset $out_Array #// 配列をクリアするには2回必要?
1832 item__=( $CSV__ ) #// ${item__[0]} does not have space
1833 StringClass.substring_method ${item__[0]} 0 1 ; char__="$g_Ret"
1834 if [ "$char__" == "\"" ];then
1835 RightOfStr_func "$CSV__" "\"" ; CSV__="$g_Ret"
1836 LeftOfStr_func "$CSV__" "\"" ; item__="$g_Ret"
1837 RightOfStr_func "$CSV__" "\"" ; CSV__="$g_Ret"
1838 elif [ "$char__" == "" ];then
1841 LeftOfStr_func "$CSV__" "," ; item__="$g_Ret"
1842 StringClass.trim_method "$item__" ; item__="$g_Ret"
1844 RightOfStr_func "$CSV__" "," ; next__="$g_Ret"
1846 SetArrItem_func $out_Array $index__ "$item__"
1847 index__=$(( $index__ + 1 ))
1849 if [ x"$next__" == x"" -o x"$next__" == x"$CSV__" ];then break ;fi
1856 #//*********************************************************************
1857 #// <<< [IsSameArrayOutOfOrder_func] >>>
1858 #//*********************************************************************
1859 function IsSameArrayOutOfOrder_func()
1861 local ArrayACount="$1"
1862 local ArrayAB=("$@")
1868 if ! IsNumeric_func "$ArrayACount" ;then Error_func ;fi
1870 if [ ${#ArrayAB[@]} != $(( $ArrayACount * 2 + 1 )) ];then return 1 ;fi
1872 for (( b_index = $ArrayACount + 1; b_index < ${#ArrayAB[@]}; b_index ++ )) ;do
1873 for (( a_index = 1; a_index <= $ArrayACount; a_index ++ )) ;do
1874 if [ "${ArrayAB[$a_index]}" == "${ArrayAB[$b_index]}" ];then
1875 if [ "${is_same_arr[$a_index]}" == "" ];then
1876 is_same_arr[$a_index]=1
1883 for (( a_index=1; a_index <= $ArrayACount; a_index ++ )) ;do
1884 if [ "${is_same_arr[$a_index]}" == "" ];then
1893 #//*********************************************************************
1894 #// <<< [Extract_func] >>>
1895 #//*********************************************************************
1896 function Extract_func()
1898 local PackagePath="$1"
1899 local DstFolder="$2"
1905 local extract_folder
1907 local trans_option_1
1908 local trans_option_2
1911 $declare_associative_array option
1913 echo "$PackagePath -> $DstFolder $Option1"
1915 CheckWritable_func "$DstFolder"
1916 dst_name=`basename "$DstFolder"`
1918 RightOfLastStr_func "$PackagePath" "." ; ext2="$g_Ret"
1919 LeftOfLastStr_func "$PackagePath" "."
1920 RightOfLastStr_func "$g_Ret" "." ; ext1="$g_Ret"
1922 #// --transform option
1923 GetLongOptions_func arguments option "$@" #//[out] arguments, option
1924 Attr_func option "transform_from" ; trans_option_1="$g_Ret"
1927 if [ "$trans_option_1" == "" ];then
1929 #// set one_folder_path
1930 ListUpIn_func "$PackagePath" > /tmp/_Extract_func.txt #// tar write error, if pipe was used
1931 one_folder_path=`head -n 1 /tmp/_Extract_func.txt`
1933 StringClass.substring_method "$one_folder_path" 0 1
1934 if [ "$g_Ret" == "/" ];then
1937 StringClass.substring_method "$one_folder_path" 0 2
1938 if [ "$g_Ret" == "./" ];then
1939 StringClass.indexOf_method "$one_folder_path" "/" 2
1941 StringClass.indexOf_method "$one_folder_path" "/"
1943 if [ "$g_Ret" == "-1" ];then
1946 StringClass.substring_method "$one_folder_path" 0 $g_Ret ; one_folder_path="$g_Ret"
1951 #// set one_folder_path="", if there was two folders
1952 if [ "$one_folder_path" != "" ];then
1954 cat /tmp/_Extract_func.txt | grep -v "^$one_folder_path/" || status=$?
1955 CheckPipeStatus_func "${PIPESTATUS[@]}"
1956 if [ "$status" == "0" ];then #// found out of one_folder_path
1960 rm /tmp/_Extract_func.txt
1963 #// set trans_option
1964 if [ "$one_folder_path" != "" ];then
1965 if [ "$ext2" == "zip" ];then
1966 trans_option_1="$one_folder_path"
1968 GetExtractTransformOptionName_func "$DstFolder"
1969 if [ "$g_Ret" == "--transform" ];then
1970 trans_option_1="--transform=s%^$one_folder_path%$dst_name%"
1973 trans_option_2="%^$one_folder_path/%$dst_name/%"
1979 #// set extract_folder
1980 if [ "$one_folder_path" == "" ];then
1981 extract_folder="$DstFolder"
1983 GetParentAbsPath_func "$DstFolder" ; extract_folder="$g_Ret"
1988 #// modify trans_option
1989 StringClass.right_method "$trans_option_1" 1
1990 if [ "$g_Ret" == "/" ];then
1991 StringClass.length_method "$trans_option_1"
1992 StringClass.substring_method "$trans_option_1" 0 $(( $g_Ret - 1 ))
1993 trans_option_1="$g_Ret"
1995 dst_name=`basename "$DstFolder"`
1997 if [ "$ext2" != "zip" ];then
1998 GetExtractTransformOptionName_func "$DstFolder"
1999 if [ "$g_Ret" == "--transform" ];then
2000 trans_option_1="--transform=s%^$trans_option_1%$dst_name%"
2002 trans_option_2="%^$trans_option_1%$dst_name%"
2006 extract_folder=`dirname "$DstFolder"`
2011 if [ x"$ext1" != x"tar" -a x"$ext2" == x"gz" ];then
2012 ExtractGZ_func "$PackagePath" "$extract_folder"
2013 elif [ "$ext2" == "zip" ];then
2014 ExtractZip_func "$PackagePath" "$DstFolder" "$trans_option_1"
2016 if [ ! -e "$extract_folder" ];then mkdir -p "$extract_folder" ;fi
2017 if [ "$trans_option_1" == "" ];then
2018 echo "tar xvf \"$PackagePath\" -C \"$extract_folder\""
2019 tar xvf "$PackagePath" -C "$extract_folder"
2021 echo "tar xvf \"$PackagePath\" -C \"$extract_folder\" \"$trans_option_1\" \"$trans_option_2\""
2022 tar xvf "$PackagePath" -C "$extract_folder" "$trans_option_1" "$trans_option_2"
2028 declare g_ExtractTransformOptionName #// "-s" or "--transform"
2030 function GetExtractTransformOptionName_func()
2032 if [ "$g_ExtractTransformOptionName" == "" ];then
2034 local WorkDstFolder="$1"
2040 for (( i = 1; i < 100; i ++ ));do
2041 if [ "$i" == "99" ];then Error_func "$WorkDstFolder にフォルダーが作れません" ;fi
2042 a1="$WorkDstFolder/_extract_trans_test_$i"
2043 if [ ! -e "$a1" ];then
2049 while TryStart_func; do
2051 mkdir -p "$WorkDstFolder"
2052 pushd "$WorkDstFolder" > /dev/null
2056 tar cvjf "a.tar.bz2" "a.txt" > /dev/null
2059 tar xvf "a.tar.bz2" --transform="s%a.txt%b.txt%" > /dev/null 2>&1 || status=$?
2061 if [ "$status" == "0" -a -e "b.txt" ];then
2062 g_ExtractTransformOptionName="--transform"
2065 tar xvf "a.tar.bz2" -s "%a.txt%b.txt%" > /dev/null 2>&1 || status=$?
2067 if [ "$status" == "0" -a -e "b.txt" ];then
2068 g_ExtractTransformOptionName="-s"
2074 TryEnd1_func; done ;TryEnd2_func $?
2076 if [ "$is_pushd" == "1" ];then popd > /dev/null ;fi
2077 rm_func "$WorkDstFolder"
2078 if [ "$g_ExitStatus" != "0" ]; then ErrClass.raiseOverwrite_method ;fi
2079 ErrClass.clear_method
2081 g_Ret="$g_ExtractTransformOptionName"
2086 #//*********************************************************************
2087 #// <<< [ExtractGZ_func] >>>
2088 #//*********************************************************************
2089 function ExtractGZ_func()
2092 local ExtractedPath="$2"
2093 CheckArgCount_func 2 "$@"
2095 if [ "$TMPDIR" == "" ]; then temp_folder="$HOME" ;else temp_folder="$TMPDIR" ;fi
2097 if [ "$GzPath" == "${ExtractedPath}.gz" ]; then
2098 if [ -e "$temp_folder/_ExtractGZ_func.gz" -o -e "$temp_folder/_ExtractGZ_func" ]; then
2099 unset ERROR;${ERROR:?exist _ExtractGZ_func.gz is for temporary} ;fi
2101 cp -ap "$GzPath" "$temp_folder/_ExtractGZ_func.gz"
2102 echo "gunzip \"$temp_folder/_ExtractGZ_func.gz\""
2103 gunzip "$temp_folder/_ExtractGZ_func.gz"
2104 mv "$temp_folder/_ExtractGZ_func" "$ExtractedPath"
2106 cp -ap "$GzPath" "${ExtractedPath}.gz"
2107 rm_func "$ExtractedPath"
2108 echo "gunzip \"${ExtractedPath}.gz\""
2109 gunzip "${ExtractedPath}.gz"
2115 #//*********************************************************************
2116 #// <<< [ExtractZip_func] >>>
2117 #//*********************************************************************
2118 function ExtractZip_func()
2120 local PackagePath="$1"
2121 local DstFolder="$2"
2122 local TarnsformFrom="$3"
2123 local dst_name ; dst_name=`basename "$DstFolder"`
2124 local from_name ; from_name=`basename "$TarnsformFrom"`
2126 if [ "$DstFolder" == "" ];then DstFolder="$PWD" ;fi
2128 if [ x"$TarnsformFrom" == x"" ];then
2129 mkdir_func "$DstFolder"
2130 echo "unzip -o -d \"$DstFolder\" \"$PackagePath\""
2131 unzip -o -d "$DstFolder" "$PackagePath"
2132 elif [ x"$dst_name" == x"$from_name" ];then
2133 GetParentAbsPath_func "$DstFolder"
2135 mkdir_func "$DstFolder"
2136 echo "unzip -o -d \"$DstFolder\" \"$PackagePath\""
2137 unzip -o -d "$DstFolder" "$PackagePath"
2143 tmp_folder="$DstFolder/_extracting_"
2144 for (( num = 1; ; num ++ )) ;do
2145 if [ "$num" == 1000 ];then Error_func ;fi
2146 if [ ! -e "$tmp_folder$num" ];then break ;fi
2148 tmp_folder="$tmp_folder$num"
2149 mkdir -p "$tmp_folder"
2151 link_path="$tmp_folder/$from_name"
2152 StringClass.substring_method "$DstFolder" 0 1
2153 if [ "$g_Ret" == "/" ];then
2154 ln -s "$DstFolder" "$link_path"
2156 ln -s ".." "$link_path"
2159 echo "unzip -o -d \"$tmp_folder\" \"$PackagePath\""
2160 unzip -o -d "$tmp_folder" "$PackagePath"
2169 #//*********************************************************************
2170 #// <<< [ListUpIn_func] >>>
2171 #//*********************************************************************
2172 function ListUpIn_func()
2174 local PackagePath="$1"
2180 RightOfLastStr_func "$PackagePath" "." ; ext2="$g_Ret"
2181 LeftOfLastStr_func "$PackagePath" "."
2182 RightOfLastStr_func "$g_Ret" "." ; ext1="$g_Ret"
2184 if [ x"$ext1" == x"tar" -a x"$ext2" == x"bz2" ];then
2185 bzip2 -dkc "$PackagePath" | tar t
2186 elif [ x"$ext1" == x"tar" -a x"$ext2" == x"gz" ];then
2187 tar tfz "$PackagePath"
2188 elif [ x"$ext1" != x"tar" -a x"$ext2" == x"gz" ];then
2189 LeftOfLastStr_func "$PackagePath" "." ; name="$g_Ret"
2191 elif [ "$ext2" == "zip" ];then
2192 unzip -l "$PackagePath" | sed -e "1,3d" -e '/^ ---/,$d' -e "s/.*:[0-9]* *//"
2193 CheckPipeStatus_func "${PIPESTATUS[@]}"
2195 Error_func ".$ext.$ext2 形式は、サポートしていません。"
2201 #//*********************************************************************
2202 #// <<< [ExpandWildcard_func] >>>
2203 #//*********************************************************************
2204 function ExpandWildcard_func()
2210 #//=== call ExpandWildcardSub_func
2211 list=`ExpandWildcardSub_func "$@" `
2212 ArrayClass.fromLines_method out_StepPaths "$list" #//[out] out_StepPaths
2214 #//=== 最後の要素は、フォルダーのパスなので、out_StepPaths へ移動します。
2215 ArrayClass.getLength_method out_StepPaths
2216 last=$(( $g_Ret - 1 ))
2217 ArrayClass.get_method out_StepPaths $last ; folder="$g_Ret"
2219 StringClass.length_method "$folder" ; length="$g_Ret"
2220 length=$(( $length + 1 ))
2222 ArrayClass.remove_method out_StepPaths $last
2224 #//=== change to step_path
2225 for (( last = $last - 1 ; $last >= 0 ; last -- )) ;do
2226 ArrayClass.get_method out_StepPaths $last
2227 StringClass.substring_method "$g_Ret" $length
2228 if [ "$g_Ret" == "" ];then g_Ret="." ;fi
2229 ArrayClass.set_method out_StepPaths $last "$g_Ret"
2232 g_Ret2=( "${out_StepPaths[@]}" )
2236 function ExpandWildcardSub_func()
2238 local WildcardPath="$1"
2240 $declare_associative_array option
2247 GetLongOptions_func arguments option "$@" #//[out] arguments, option
2249 unset $out_StepPaths
2250 unset $out_StepPaths #// 配列をクリアするには2回必要?
2252 a1=`dirname "$WildcardPath"`
2253 if [ "$a1" == "" ];then a1="." ;fi
2254 GetAbsPath_func "$a1" ; folder="$g_Ret"
2256 file_name=`basename "$WildcardPath"`
2258 Attr_func option "SubFolder"
2259 if [ "$g_Ret" == "" ];then
2260 options="${options} -maxdepth 1"
2265 Attr_func option "File"
2266 if [ "$g_Ret" == "1" ];then
2267 find "$folder" $options -name "$file_name" -type f -print
2271 Attr_func option "Folder"
2272 if [ "$g_Ret" == "1" ];then
2273 find "$folder" $options -name "$file_name" -type d -print
2277 Attr_func option "Link"
2278 if [ "$g_Ret" == "1" ];then
2279 find "$folder" $options -name "$file_name" -type l -print
2283 if [ "$all_type" == "1" ];then
2284 find "$folder" $options -name "$file_name" -print
2292 #//*********************************************************************
2293 #// <<< [rm_func] >>>
2294 #//*********************************************************************
2297 local Paths=( "$@" )
2300 for path in "${Paths[@]}" ;do
2301 if [ "$path" != "" ];then
2302 CheckWritable_func "$path"
2304 if [ -d "$path" ]; then
2305 $g_TemporarySudo chmod -R a+rw "$path"
2306 $g_TemporarySudo rm -rf "$path"
2307 elif [ -f "$path" ]; then
2308 $g_TemporarySudo chmod a+rw "$path"
2309 $g_TemporarySudo rm -f "$path"
2310 elif [ -e "$path" -o -L "$path" ]; then
2311 $g_TemporarySudo rm -f "$path"
2319 #//*********************************************************************
2320 #// <<< [mkdir_func] >>>
2321 #//*********************************************************************
2322 function mkdir_func()
2325 CheckArgCount_func 1 "$@"
2327 CheckWritable_func "$Path"
2329 if [ ! -d "$Path" ];then
2330 $g_TemporarySudo mkdir -p "$Path"
2336 #//*********************************************************************
2337 #// <<< [MakeSymbolicLink_func] >>>
2338 #//*********************************************************************
2339 function MakeSymbolicLink_func()
2341 local LinkSrcPath="$1"
2343 CheckArgCount_func 2 "$@"
2345 CheckWritable_func "$LinkSrcPath"
2347 if [ -d "$LinkSrcPath" ];then
2348 if [ -L "$LinkSrcPath" ];then
2350 $g_TemporarySudo ln -s "$Target" "$LinkSrcPath"
2352 Error_func "フォルダーが存在します"
2355 $g_TemporarySudo ln -sf "$Target" "$LinkSrcPath"
2361 #//*********************************************************************
2362 #// <<< [chown_it_and_parent_func] >>>
2363 #//*********************************************************************
2364 function chown_it_and_parent_func()
2368 if [ "$Owner" == "-R" ];then
2376 CheckWritable_func "$Path"
2378 GetParentAbsPath_func "$Path" ; parent="$g_Ret"
2380 if [ -e "$Path" ];then
2381 $g_TemporarySudo chown $Option "$Owner" "$Path"
2384 if [ ! -d "$parent" ];then
2385 $g_TemporarySudo mkdir -p "$parent"
2387 $g_TemporarySudo chown $Option "$Owner" "$parent"
2392 #//*********************************************************************
2393 #// <<< [AppKeyClass.newWritable_method] >>>
2394 #//*********************************************************************
2395 function AppKeyClass.newWritable_method()
2403 if [ "$AppKey" != "AppKey4293" ]; then Error_func "AppKeyClass.newWritable_method needs \$2 of Main_func" ;fi
2405 unset g_WritableFolders8920
2406 unset g_WritableFolders8920 #// 配列をクリアするには2回必要?
2409 for (( index = 0; index < ${#Args[@]}; index ++ ));do
2410 if [ "${Args[$index]}" != "" ];then
2411 GetAbsPath_func "${Args[$index]}"
2412 g_WritableFolders8920[$count]="$g_Ret"
2413 count=$(( $count + 1 ))
2420 #//*********************************************************************
2421 #// <<< [CheckWritable_func] >>>
2422 #//*********************************************************************
2423 function CheckWritable_func()
2426 CheckArgCount_func 1 "$@"
2431 GetAbsPath_func "$Path" "$PWD" ; Path="$g_Ret"
2433 if [ "$g_WritableFolders8920" == "" ]; then \
2434 Error_func "<ERROR msg=\"Not call AppKeyClass.newWritable_method\" Path=\"$Path\"/>" ;fi
2435 for writable in ${g_WritableFolders8920[@]};do
2436 if [ "${Path%%$writable*}" == "" ]; then is_break=1 ; break ;fi
2438 if [ ! "$is_break" == "1" ]; then
2439 Error_func "<ERROR msg=\"AppKeyClass.newWritable_method による書き込み許可がされていません。\"" \
2440 "Path=\"$Path\" Writable=\"$g_WritableFolders8920\"/>"
2446 #//*********************************************************************
2447 #// <<< [EchoTestStart_func] >>>
2448 #//*********************************************************************
2449 function EchoTestStart_func()
2452 if [ "${#args[@]}" == "0" ];then
2454 echo "((( ${FUNCNAME[1]} )))"
2463 #//*********************************************************************
2465 #//*********************************************************************
2468 g_DebugTrapFunc="StepRunning_func"
2470 trap 'DebugTrap_func "$LINENO" "$BASH_COMMAND" "${PIPESTATUS[@]}"
2471 #// resume ${PIPESTATUS[@]}
2472 case "${#g_PipeStatus[@]}" in
2474 return ${g_PipeStatus[0]} | true;;
2476 return ${g_PipeStatus[0]} | return ${g_PipeStatus[1]} | true;;
2480 function StepRunning_func()
2483 local Command__="$2"
2485 g_PipeStatus=( "$@" )
2490 if [ "$step_running_guided" == "" ]; then
2491 ErrClass.getCallTree_method "$LINENO" 2 1
2493 echo "--- デバッガ情報 -------------------------" >&2
2494 echo "ステップ実行 … Enter キーを押してください" >&2
2495 echo "変数の値を表示 … 変数名を入力" >&2
2496 echo "------------------------------------------" >&2
2499 echo "${FUNCNAME[2]}() ${BASH_SOURCE[2]}:${BASH_LINENO[1]}" >&2
2500 key__="goto_in_while"
2501 while [ "$key__" != "" ]; do
2502 read -p "$LineNo__: $Command__ " key__ #// break at the line
2504 #// inspect variable's value
2505 if [ "$key__" != "" ]; then
2508 "LineNo__" | "Command__" | "key__" | "a1__" )
2509 echo "変数 $key__ の値の表示はサポートしていません。";;
2512 CheckOutParamIsConflictToLocal_func key__
2514 key__=${key__/$/} #// cut first $, if exists
2515 WS $key__ #// call WS function
2521 step_running_guided=1
2526 #//*********************************************************************
2528 #//*********************************************************************
2531 local ExpressionArray__=("$@")
2532 local Expression__="$@"
2535 echo "Watch> ${FUNCNAME[1]}() ${BASH_SOURCE[1]}(${BASH_LINENO[0]})" >&2
2536 if [ "${#ExpressionArray__[@]}" != "0" ];then
2538 CheckEvalParamIsConflictToLocal_func "$Expression__" ExpressionArray__ Expression__ evaled__
2540 evaled__=`eval echo "\"""$Expression__""\""`
2541 if [ "$Expression__" == "$evaled__" ];then
2542 echo "Watch> \"$Expression__\"" >&2
2544 echo "Watch> \"$Expression__\" == '""$evaled__""'" >&2
2551 #//*********************************************************************
2553 #//*********************************************************************
2562 if [ "$g_ExitStatus" == "0" ];then
2563 CheckArgCount_func 1 "$@"
2565 CheckOutParamIsConflictToLocal_func "$Name__" Name__ keys__ value__ index__
2568 eval keys__=( '"${!'"$Name__"'[@]}"' )
2571 if [ x"$keys__" == x"" -o x"$keys__" == x"0" ];then is__=1 ;fi
2573 if [ "${#keys__[@]}" -le "1" -a "$is__" == "1" ];then
2574 eval value__='"${'"$Name__"'}"'
2575 StringClass.indexOf_method "$Name__" "["
2576 if [ "$g_Ret" -ge "0" ];then
2577 echo -n 'Dump "${'"$Name__"}'" == ' >&2
2579 echo -n 'Dump "$'"$Name__"'" == ' >&2
2581 echo "'""$value__""'" >&2
2582 echo -n "$value__" | hexdump -C >&2
2583 #// hexdump -C <<< "$value__" >&2
2585 for index__ in "${keys__[@]}" ;do
2586 WS $Name__[$index__]
2593 #//*********************************************************************
2594 #// <<< [Error_func] >>>
2595 #//*********************************************************************
2596 function Error_func()
2598 ErrClass.getErrStr_method "$@" ; g_Err_Desc="$g_Ret"
2604 #//*********************************************************************
2605 #// <<< [return_func] >>>
2606 #//*********************************************************************
2607 function return_func()
2609 if [ "$g_Err_LineNo" == "???" ];then g_Err_LineNo=${BASH_LINENO[0]} ;fi
2615 #//*********************************************************************
2616 #// <<< [CheckPipeStatus_func] >>>
2617 #//*********************************************************************
2618 function CheckPipeStatus_func()
2620 local pipe_status="$@"
2623 for state in ${pipe_status[@]};do
2624 if [ "$state" != "0" ]; then
2625 echo '${PIPESTATUS[@]} = '"${pipe_status[@]}" >&2
2626 g_Err_LineNo=${BASH_LINENO[0]}
2634 #//*********************************************************************
2635 #// <<< [CheckArgCount_func] >>>
2636 #//*********************************************************************
2637 function CheckArgCount_func()
2639 local RequestArgumentCount="$1"
2641 local Arguments=( "$@" )
2644 if [ "${#Arguments[@]}" -ne "$RequestArgumentCount" ];then
2645 str="パラメーターの数が合っていません。 指定=${#Arguments[@]}, 要求=$RequestArgumentCount,"
2646 str="$str コマンドライン: ${FUNCNAME[1]} ${Arguments[@]}"
2653 #//*********************************************************************
2654 #// <<< [CheckMinArgCount_func] >>>
2655 #//*********************************************************************
2656 function CheckMinArgCount_func()
2658 local RequestArgumentCount="$1"
2660 local Arguments=( "$@" )
2661 if [ "${#Arguments[@]}" -lt "$RequestArgumentCount" ];then
2662 echo "パラメーターが少なすぎます。 指定=${#Arguments[@]}, 要求=$RequestArgumentCount" >&2
2663 echo "コマンドライン: ${FUNCNAME[1]} ${Arguments[@]}" >&2
2670 #//*********************************************************************
2671 #// <<< [CheckMaxArgCount_func] >>>
2672 #//*********************************************************************
2673 function CheckMaxArgCount_func()
2675 local RequestArgumentCount="$1"
2677 local Arguments=( "$@" )
2678 if [ "${#Arguments[@]}" -gt "$RequestArgumentCount" ];then
2679 echo "パラメーターが多すぎます。 指定=${#Arguments[@]}, 要求=$RequestArgumentCount" >&2
2680 echo "コマンドライン: ${FUNCNAME[1]} ${Arguments[@]}" >&2
2687 #//*********************************************************************
2688 #// <<< [CheckOutParamIsConflictToLocal_func] >>>
2689 #//*********************************************************************
2690 function CheckOutParamIsConflictToLocal_func()
2692 local OutParamName__="$1"
2694 local LocalNames__=( "$@" )
2698 if [ "$OutParamName__" == "" ];then Error_func "出力変数名が指定されていません" ;fi
2700 for name__ in "${LocalNames__[@]}" ;do
2701 if [ "$OutParamName__" == "$name__" ];then
2702 a1__="<ERROR msg=\"ローカル変数名が衝突しています\" "
2703 a1__="${a1__}local=\"$name__\"/>"
2711 #//*********************************************************************
2712 #// <<< [CheckEvalParamIsConflictToLocal_func] >>>
2713 #//*********************************************************************
2714 function CheckEvalParamIsConflictToLocal_func()
2716 local EvalExpression="$1"
2718 local LocalNames=( "$@" )
2722 for name in "${LocalNames[@]}" ;do
2723 if [ "${EvalExpression%%$name*}" != "$EvalExpression" ];then
2724 s="<ERROR msg=\"ローカル変数名が衝突している可能性があります\" "
2725 s="${s}local=\"$name\"/>"
2733 #//*********************************************************************
2734 #// <<< [Assert_func] >>>
2735 #//*********************************************************************
2736 function Assert_func()
2738 local Expression__="$*"
2743 eval ' if [ '"$Expression__"' ]; then is_pass__=1 ;else is_pass__=0 ;fi '
2745 if [ "$is_pass__" == "0" ];then result__="`eval echo "$Expression__"`" ;fi
2747 if false; then #// ture, if debug
2748 echo "<Assert_func" >&2
2749 echo "Expression__='$Expression__'" >&2
2750 echo "result__='$result__'" >&2
2751 echo "is_pass__='$is_pass__'/>" >&2
2754 if [ "$is_pass__" == "0" ];then
2755 message__=`echo -n "<ERROR msg=\"Assert failed\"><Expression><![CDATA[${LF}$Expression__${LF}]]></Expression>"`
2756 if [ "$Expression__" != "$result__" ];then
2757 message__="$message__"`echo -n "<Result><![CDATA[${LF}$result__${LF}]]></Result>"`
2759 message__="$message__</ERROR>"
2760 Error_func "$message__"
2766 #//*********************************************************************
2767 #// <<< [TryStart_func] >>>
2768 #// <<< [TryEnd1_func] >>>
2769 #// <<< [TryEnd2_func] >>>
2770 #//*********************************************************************
2771 function TryStart_func()
2774 g_Err_NestLevel=$(( $g_Err_NestLevel + 1 ))
2777 function TryEnd1_func()
2782 function TryEnd2_func()
2784 if [ "$g_ExitStatus" == "0" ];then
2787 g_Err_NestLevel=$(( $g_Err_NestLevel - 1 ))
2792 #//*********************************************************************
2793 #// <<< [ErrTrap_func] >>>
2794 #//*********************************************************************
2809 function ErrTrap_func()
2813 if [ "$g_Err_IsDone" == "1" ];then
2815 elif [ "$g_Err_IsOverwrite" == "1" ];then
2819 g_Err_ErrID=$(( $g_Err_ErrID + 1 ))
2821 if [ "$g_ExitStatus" == "0" ];then
2822 if [ "$g_Err_LineNo" == "???" ];then g_Err_LineNo=$1 ;fi
2823 if [ "$g_Err_LineNo" == "???" ]; then
2824 a1="${a1}(ヒント)現在の行番号は、${FUNCNAME[1]} 関数の最初で \"EchoOn_func\" を呼ぶと表示されます。${LF}"
2826 a1="${a1}(開発者向けヒント)ステップ実行したいときは、開始するところから \"Step\" 関数を呼び出してください。 "
2827 a1="${a1}下記コールツリーの最も下の関数が、\` \` を使って echo 出力を取得しているときは、取得しないようにすると、更にコール先の関数が表示されます。${LF}"
2828 ErrClass.getCallTree_method "$g_Err_LineNo" 2 1
2830 g_Err_ErrCallStack="$a1"
2832 echo "<ERROR msg=\"エラー処理中に別のエラーが発生しました。\"/>" >&2
2833 ErrClass.getCallTree_method "${BASH_LINENO[0]}" 2 1
2841 #//*********************************************************************
2842 #// <<< [done_func] >>>
2843 #//*********************************************************************
2844 function done_func()
2846 CheckArgCount_func 1 "$@"
2847 if [ "$1" != "0" ];then g_Err_IsDone=1 ;fi
2848 return "$1" #// if not 0, throw again
2853 #//*********************************************************************
2854 #// <<< [ErrClass.raiseOverwrite_method] >>>
2855 #//*********************************************************************
2856 function ErrClass.raiseOverwrite_method()
2858 local message ; ErrClass.getErrStr_method "$@" ; message="$g_Ret"
2859 local exit_status="$g_ExitStatus"
2861 if [ "$message" != "" ];then
2862 g_Err_Desc="$message"
2865 if [ "$exit_status" == "0" ];then
2875 #//*********************************************************************
2876 #// <<< [ErrClass.clear_method] >>>
2877 #//*********************************************************************
2878 function ErrClass.clear_method()
2888 #//*********************************************************************
2889 #// <<< [ErrClass.getErrStr_method] >>>
2890 #//*********************************************************************
2891 function ErrClass.getErrStr_method()
2895 if [ "$Message" != "" ]; then
2896 if [ "${Message%%<ERROR *}" == "" ]; then
2899 StringClass.replace_method "$Message" "&" "&"
2900 StringClass.replace_method "$g_Ret" "<" "<"
2901 StringClass.replace_method "$g_Ret" "\"" """
2902 g_Ret="<ERROR msg=\"$g_Ret\"/>"
2911 #//*********************************************************************
2912 #// <<< [ErrClass.getCallTree_method] >>>
2913 #//*********************************************************************
2914 function ErrClass.getCallTree_method()
2918 local IsAbleLastCut="$3"
2923 i=$(( ${#FUNCNAME[@]} - 1 ))
2924 s="$s${LF}""(global) ${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]}"
2925 for(( i=${#FUNCNAME[@]} - 2; i > $TopIndex; i-- ));do
2926 s="$s${LF}${indent}${FUNCNAME[$i]}() ${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]}"
2930 case "${FUNCNAME[$TopIndex]}" in
2931 "Error_func" | "DebugTrap_func" ) ;;
2932 *) IsAbleLastCut=0 ;;
2934 if [ "$IsAbleLastCut" != "1" ];then
2935 s="$s${LF}${indent}${FUNCNAME[$TopIndex]}() ${BASH_SOURCE[$TopIndex]}:$LineNo"
2942 #//*********************************************************************
2943 #// <<< [Exit_func] >>>
2944 #//*********************************************************************
2945 function Exit_func()
2954 #//*********************************************************************
2955 #// <<< [declare_associative_array] >>>
2956 #//*********************************************************************
2957 if [ "$declare_associative_array" == "" ];then
2958 if [ "${BASH_VERSINFO[0]}" -ge "4" ];then
2959 declare_associative_array="declare -A"
2961 declare_associative_array="declare"
2967 #//*********************************************************************
2968 #// <<< [g_ArrayLength] >>>
2969 #//*********************************************************************
2974 #//*********************************************************************
2975 #// <<< [g_AssociativeArrayMaxLength] >>>
2976 #//*********************************************************************
2977 if [ "$g_AssociativeArrayMaxLength" == "" ];then g_AssociativeArrayMaxLength=100 ;fi
2979 g_AssociativeArrayLength=0
2980 for (( i = 0; i < $g_AssociativeArrayMaxLength; i ++ ));do
2981 $declare_associative_array g_AssociativeArrays_$i
2986 #//*********************************************************************
2989 #//*********************************************************************
2990 LF=`echo_e_func "\nx"`; LF="${LF:0:1}"
2991 Tab=`echo_e_func "\t"`