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_AssociativeArrayClass] >>>
10 #//*********************************************************************
11 if [ "${BASH_VERSINFO[0]}" -ge "4" ];then
12 declare_AssociativeArrayClass="declare -A" #// bash ver4
14 declare_AssociativeArrayClass="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 GetAbsPath_func "`basename "${g_Arguments[0]}"`" ; g_Arguments[0]="$g_Ret"
40 while TryStart_func; do
42 Main_func "" "AppKey4293"
45 if [ "$g_ExitStatus" != "0" ];then is_not_err_handled=1 ;fi
46 TryEnd1_func; done ;TryEnd2_func $?
49 if [ "$g_ExitStatus" != "0" ];then
50 if [ "$g_Err_Desc" == "" ];then
51 ColorText_func "<ERROR/>" "Red" "Bold"
53 ColorText_func "$g_Err_Desc" "Red" "Bold"
55 echo_e_func "$g_Ret" >&2
56 echo "Exit Status = $g_ExitStatus" >&2
58 echo -n "$g_Err_ErrCallStack" >&2
59 if [ "$g_Err_Desc" == "" ];then
62 echo "$g_Err_Desc" >&2
64 if [ "$is_not_err_handled" == "1" ];then
65 echo "エラー処理がされていません。ErrClass.clear_method または ErrClass.raiseOverwrite_method を呼び出してください"
75 #//*********************************************************************
76 #// <<< [DebugTrap_func] >>>
77 #//*********************************************************************
78 function DebugTrap_func()
80 if [ "$g_DebugTrapFunc" == "" ];then
90 #//*********************************************************************
91 #// <<< [EchoOn_func] >>>
92 #//*********************************************************************
93 function EchoOn_func()
95 echo "${BASH_LINENO[0]}: EchoOn_func at ${FUNCNAME[1]}() in ${BASH_SOURCE[1]}" >&2
97 g_DebugTrapFunc="EchoOnTrap_func"
99 trap 'DebugTrap_func "$LINENO" "$BASH_COMMAND" "${PIPESTATUS[@]}"
100 #// resume ${PIPESTATUS[@]}
101 case "${#g_PipeStatus[@]}" in
103 return ${g_PipeStatus[0]} | true;;
105 return ${g_PipeStatus[0]} | return ${g_PipeStatus[1]} | true;;
109 function EchoOnTrap_func()
114 g_PipeStatus=( "$@" )
116 echo "$LineNo: $Command" >&2
121 #//*********************************************************************
122 #// <<< [EchoOff_func] >>>
123 #//*********************************************************************
124 function EchoOff_func()
131 #//*********************************************************************
132 #// <<< [echo_line_func] >>>
133 #//*********************************************************************
134 function echo_line_func()
136 echo "-------------------------------------------------------------------------------"
141 #//*********************************************************************
142 #// <<< [Pause_func] >>>
143 #//*********************************************************************
144 function Pause_func()
150 if [ "$Param" != "" ];then
152 $declare_AssociativeArrayClass option
154 GetLongOptions_func arguments option "$@" #//[out] arguments, option
155 Attr_func option "time_out" ; sec="$g_Ret"
156 AssociativeArrayClass.destroy_method option
159 if [ "$sec" == "" ];then
160 read -p "続行するには Enter キーを押してください . . ." key
162 for (( sec = $sec; sec >=0; sec -- )) ;do
164 if [ "$sec" == "0" ];then
165 echo "続行するには Enter キーを押してください . . . "
169 read -p "続行するには Enter キーを押してください . . . $sec " -t 1 key || key="...."
170 if [ "$key" == "" ];then break ;fi
177 #//*********************************************************************
178 #// <<< [ColorText_func] >>>
179 #//*********************************************************************
180 function ColorText_func()
184 local ColorNames=("$@")
189 #//=== initialize g_ColorText_Codes
190 Attr_func g_ColorText_Codes "Black"
191 if [ "$g_Ret" == "" ];then
193 #//=== set escape sequence
194 SetAttr_func g_ColorText_Codes "Black" 30
195 SetAttr_func g_ColorText_Codes "Red" 31
196 SetAttr_func g_ColorText_Codes "Green" 32
197 SetAttr_func g_ColorText_Codes "Yellow" 33
198 SetAttr_func g_ColorText_Codes "Blue" 34
199 SetAttr_func g_ColorText_Codes "Magenta" 35
200 SetAttr_func g_ColorText_Codes "Cyan" 36
201 SetAttr_func g_ColorText_Codes "White" 37
203 SetAttr_func g_ColorText_Codes "BlackBack" 40
204 SetAttr_func g_ColorText_Codes "RedBack" 41
205 SetAttr_func g_ColorText_Codes "GreenBack" 42
206 SetAttr_func g_ColorText_Codes "YellowBack" 43
207 SetAttr_func g_ColorText_Codes "BlueBack" 44
208 SetAttr_func g_ColorText_Codes "MagentaBack" 45
209 SetAttr_func g_ColorText_Codes "CyanBack" 46
210 SetAttr_func g_ColorText_Codes "WhiteBack" 47
212 SetAttr_func g_ColorText_Codes "Bold" 1
216 n=$(( ${#ColorNames[@]} - 1 ))
217 for (( i = 0; i <= n; i++ )) ;do
218 Attr_func g_ColorText_Codes "${ColorNames[$i]}"
219 if [ "$i" == "$n" ];then
220 str="${str}${g_Ret}m"
222 str="${str}${g_Ret};"
226 g_Ret="${str}${Text}\e[m"
229 $declare_AssociativeArrayClass g_ColorText_Codes
233 #//*********************************************************************
234 #// <<< [echo_e_func] >>>
235 #//*********************************************************************
236 function echo_e_func()
239 eval echo '$'"'$Text'"
244 #//*********************************************************************
245 #// <<< [Input_func] >>>
246 #//*********************************************************************
247 function Input_func()
253 if [ "$Prompt" == "" ];then Prompt=">" ;fi
255 if [ "$g_AutoInput_ArgsNextIndex" -lt "${#g_AutoInput_Args[@]}" ];then
256 key="${g_AutoInput_Args[$g_AutoInput_ArgsNextIndex]}"
259 g_AutoInput_ArgsNextIndex=$(( $g_AutoInput_ArgsNextIndex + 1 ))
262 IFS="\\" #// This can input space or tab at the end of string
263 read -p "$Prompt" -r g_Ret
270 #//*********************************************************************
271 #// <<< [SetAutoInputFromMainArg_func] >>>
272 #//*********************************************************************
274 g_AutoInput_ArgsNextIndex=0
276 function SetAutoInputFromMainArg_func()
278 g_AutoInput_Args=( "${g_Arguments[@]}" )
279 g_AutoInput_ArgsNextIndex=1
284 #//*********************************************************************
285 #// <<< [InputPath_func] >>>
286 #//*********************************************************************
287 function InputPath_func()
292 local is_file_exist_opt
293 local is_folder_exist_opt
294 local is_not_exist_opt
298 $declare_AssociativeArrayClass options
300 GetLongOptions_func arguments options "$@" #//[out] arguments, options
303 Input_func "$Prompt$base_path" ; input_path="$g_Ret"
305 if [ "$base_path$input_path" == "" ]; then
306 Attr_func options "AllowEnterOnly"
307 if [ "$g_Ret" == "1" ]; then
314 StringClass.right_method "$input_path" 1
315 if [ "$g_Ret" == "$Tab" ];then
317 StringClass.length_method "$input_path"
318 len=$(( $g_Ret - 1 ))
319 StringClass.substring_method "$input_path" 0 "$len" ; input_path="$g_Ret"
320 InputPathSelectSub_func "$input_path" "$base_path" base_path #//[out] base_path
324 if [ "$base_path" != "" ];then
325 input_path="$base_path$input_path"
327 StringClass.substring_method "$input_path" 0 1
328 if [ "$g_Ret" == "~" ];then
329 StringClass.replace_method "$input_path" "~" "$HOME" ; input_path="$g_Ret"
331 eval "input_path=\"$input_path\""
332 GetAbsPath_func "$input_path" "$g_StartInPath" ; input_path="$g_Ret"
334 Attr_func options "ChkFileExists" ; is_file_exist_opt="$g_Ret"
335 Attr_func options "ChkFolderExists" ; is_folder_exist_opt="$g_Ret"
336 Attr_func options "ChkNotExists" ; is_not_exist_opt="$g_Ret"
338 if [ "$is_not_exist_opt" == "1" ];then
339 Assert_func '"$is_file_exist_opt" != "1"'
340 Assert_func '"$is_folder_exist_opt" != "1"'
343 if [ x"$is_file_exist_opt" == x"" -a \
344 x"$is_folder_exist_opt" == x"" -a \
345 x"$is_not_exist_opt" == x"" ];then
350 if [ "$is_not_exist_opt" == "1" ];then
351 if [ -f "$input_path" ]; then
352 echo "すでにファイルが存在しています。" >&2
353 elif [ -d "$input_path" ]; then
354 echo "すでにフォルダーが存在しています。" >&2
360 if [ "$is_file_exist_opt" == "1" ];then
361 if [ -f "$input_path" ]; then
367 if [ "$is_folder_exist_opt" == "1" ];then
368 if [ -d "$input_path" ]; then
374 if [ "$is_file_exist_opt" == "1" ];then
375 if [ "$is_folder_exist_opt" == "1" ];then
376 echo "ファイルまたはフォルダーが見つかりません。" >&2
378 echo "ファイルが見つかりません。" >&2
381 echo "フォルダーが見つかりません。" >&2
384 echo "$input_path" >&2
388 AssociativeArrayClass.destroy_method options
392 function InputPathSelectSub_func()
394 local PartOfPath="$1"
396 local out_SelectedPath="$3"
407 if [ "$BasePath" != "" ];then
408 PartOfPath="$BasePath$PartOfPath"
410 LeftOfLastStr_func "$PartOfPath" "/" ; folder="$g_Ret"
411 if [ x"$folder" == x"" -o x"$folder" == x"$PartOfPath" ];then
414 new_base_path="$folder/"
416 StringClass.substring_method "$folder" 0 1
417 if [ "$g_Ret" == "~" ];then
418 StringClass.replace_method "$folder" "~" "$HOME" ; folder="$g_Ret"
420 eval "folder=\"$folder\""
422 RightOfLastStr_func "$PartOfPath" "/" ; part_of_file="$g_Ret"
425 pushd "$g_StartInPath" > /dev/null
426 paths=`ls -p1A "$folder"`
428 ArrayClass.fromLines_method paths "$paths" #//[out] paths
431 StringClass.length_method "$part_of_file" ; len="$g_Ret"
432 for path in "${paths[@]}" ;do
433 StringClass.substring_method "$path" 0 "$len"
434 if [ "$g_Ret" == "$part_of_file" ];then
440 if [ "$PartOfPath" == "" ];then
441 echo "$g_StartInPath/"
443 GetAbsPath_func "$PartOfPath" "$g_StartInPath"
446 for (( i = 0; i < ${#paths2[@]}; i ++ ));do
447 echo -n "$(( $i + 1 )). ${paths2[$i]} "
449 echo -n "88. クリア 99. 戻る"
452 Input_func " >" ; num="$g_Ret"
453 if [ "$num" == "88" ];then
454 SetOutput_func "$out_SelectedPath" ""
456 elif [ x"$num" == x"99" -o x"$num" == x"" ];then
457 SetOutput_func "$out_SelectedPath" "$BasePath"
459 elif [ "$num" -le "$i" -a "$num" -ge "0" ];then
460 if [ "$new_base_path" == "" ];then
461 SetOutput_func "$out_SelectedPath" "${paths2[$(( $num - 1 ))]}"
463 SetOutput_func "$out_SelectedPath" "$new_base_path${paths2[$(( $num - 1 ))]}"
472 #//*********************************************************************
473 #// <<< [InputCommand_func] >>>
474 #//*********************************************************************
475 function InputCommand_func()
478 local Prompt="$2" ; if [ "$Prompt" == "" ];then Prompt="番号またはコマンド >" ;fi
487 local current_folder=`pwd`
493 SetAutoInputFromMainArg_func
494 if [ "${#g_Arguments[@]}" == "1" ];then is_prompt=1 ;else is_prompt=0 ;fi
496 Attr_func $self CommandReplace ; replaces="$g_Ret"
497 Attr_func $self MenuCaption ; captions="$g_Ret"
502 if [ "$is_prompt" != "0" ];then
504 echo "$g_StartInPath>"
508 AssociativeArrayClass.getKeys_method "$replaces" ; a1="$g_Ret"
510 IsNumeric_func $key ; if [ "$g_Ret" == "1" ]; then
511 Attr_func $captions $key ; caption="$g_Ret"
512 if [ "$caption" == "" ];then
513 Attr_func $replaces $key
516 echo "$key. $caption"
523 Input_func "$Prompt" ; num="$g_Ret"
524 if [ "$num" != "" ];then break ;fi
529 Input_func "$Prompt" ; num="$g_Ret"
530 if [ "$num" != "" ];then break ;fi
533 if [ "$num" == "99" ];then
534 a1=`basename "${g_Arguments[0]}"`
535 echo "(ヒント)$a1 のパラメーターに、入力する内容を指定できます。"
540 Attr_func $replaces "$num" ; func="$g_Ret"
541 if [ "$func" != "" ];then num="$func" ; Attr_func $replaces $func ; func="$g_Ret" ;fi
542 if [ "$func" == "" ];then func="$num" ;fi
543 echo " ((( $func )))"
545 if [ "$is_prompt" != "0" ];then
546 while TryStart_func; do
547 StringClass.right_method "$func" 5
548 if [ "$g_Ret" == "_func" ];then
549 $func "$Opt" "$AppKey"
552 eval $func #// eval is for reference variables
554 TryEnd1_func; done ;TryEnd2_func $?
556 if [ "$g_ExitStatus" != "0" ];then
557 echo "Exit Status = $g_ExitStatus"
558 if [ "$g_Err_Desc" == "" ];then
559 ColorText_func "<ERROR/>" "Red" "Bold"
561 ColorText_func "$g_Err_Desc" "Red" "Bold"
563 echo_e_func "$g_Ret" >&2
564 if [ "$g_Err_Desc" == "" ];then
565 echo "${g_Err_ErrCallStack}<ERROR/>" >&2
567 echo "${g_Err_ErrCallStack}${g_Err_Desc}" >&2
569 if [ "$is_not_err_handled" == "1" ];then
570 echo "エラー処理がされていません。ErrClass.clear_method または ErrClass.raiseOverwrite_method を呼び出してください" >&2
573 ErrClass.clear_method
575 "$func" "$Opt" "$AppKey"
584 #//*********************************************************************
585 #// <<< [InputOption_func] >>>
586 #//*********************************************************************
587 function InputOption_func()
598 $declare_AssociativeArrayClass option__
600 GetLongOptions_func Options__ option__ "$@" #//[out] arguments__, option__
601 Attr_func option__ comment
602 ArrayClass.fromCSV_method comments__ "$g_Ret" #//[out] comments__
604 SetAutoInputFromMainArg_func
608 #// finish auto input
609 if [ "$g_AutoInput_ArgsNextIndex" -ge "${#g_AutoInput_Args[@]}" -a \
610 "$g_AutoInput_ArgsNextIndex" -ge "2" -a \
611 "$is_err__" != "1" ];then
618 for name__ in "${Options__[@]}" ;do
619 eval echo "--$name__="'"\"$'"$name__"'\" ${comments__[$i__]}"'
622 echo "Enter または . :設定完了"
623 Input_func "オプションを入力してください(例:--${Options__[0]}=\"abc\"、--flag)>"
625 if [ x"$key__" == x"" -o x"$key__" == x"." ];then break ;fi
627 if [ "${key__:0:2}" == "--" ];then
629 elif [ "${key__:0:1}" == "-" ];then
632 LeftOfStr_func "$key__" "=" ; left__="$g_Ret"
633 if [ "$key__" == "$left__" ];then
636 RightOfStr_func "$key__" "=" ; eval right__="$g_Ret"
639 for name__ in "${Options__[@]}" ;do
640 if [ "$name__" == "$left__" ];then
641 SetOutput_func $name__ "$right__"
646 if [ "$left__" != "" ];then
647 echo "オプション $left__ はありません。"
655 #//*********************************************************************
656 #// <<< [sudo_func] >>>
657 #//*********************************************************************
660 g_TemporarySudo="sudo"
662 unset g_TemporarySudo
667 #//*********************************************************************
668 #// <<< [mkdir_for_it_func] >>>
669 #//*********************************************************************
670 function mkdir_for_it_func()
673 CheckArgCount_func 1 "$@"
675 folder_path=${FilePath%/*} #// parent folder
676 if [ "$folder_path" == "$FilePath" ]; then return 0 ;fi #// if not found "/"
677 if [ ! -f "$folder_path" ]; then mkdir -p "$folder_path" ;fi
682 #//*********************************************************************
683 #// <<< [readlink_func] >>>
684 #//*********************************************************************
685 function readlink_func()
688 CheckArgCount_func 1 "$@"
690 if [ "$g_is_readlink_f" == "" ];then
691 while TryStart_func; do
692 g_Ret=`readlink -f "$LinkPath" 2> /dev/null`
693 TryEnd1_func; done ;TryEnd2_func $?
694 if [ "$g_ExitStatus" == "0" ]; then g_is_readlink_f=1 ; return ;fi
695 ErrClass.clear_method
699 if [ "$g_is_readlink_f" == "1" ];then
700 g_Ret=`readlink -f "$LinkPath"`
707 folder=`dirname "$LinkPath"`
708 if [ "$folder" != "" ];then pushd "$folder" > /dev/null ;fi
711 name=`basename "$LinkPath"`
712 ph_name=`readlink "$name"` || :
713 if [ "$ph_name" == "" ];then
714 g_Ret="$ph_folder/$name"
716 g_Ret="$ph_folder/$ph_name"
718 if [ "$folder" != "" ];then popd > /dev/null ;fi
726 #//*********************************************************************
727 #// <<< [GetAbsPath_func] >>>
728 #//*********************************************************************
729 function GetAbsPath_func()
733 CheckMinArgCount_func 1 "$@"
734 CheckMaxArgCount_func 2 "$@"
739 LeftOfStr_func "$StepPath" "/" ; str="$g_Ret" #// if abs path, str=""
740 if [ "$str" == "" ]; then
742 elif [ "$str" == "~" ]; then
743 StringClass.substring_method "$StepPath" 1
746 if [ "$BasePath" == "" ];then BasePath="$PWD" ;fi
748 abs_path="$BasePath/$StepPath"
750 while true; do #// "*/../" -> ""
751 echo "$abs_path" | grep "[^/]*/\.\./" > /dev/null || break
752 abs_path=`echo "$abs_path" | sed -e "s%[^/]*/\.\./%%"`
755 while true; do #// "/*/.." -> ""
756 echo "$abs_path" | grep "[^/]*/[^/]*/\.\." > /dev/null || break
757 abs_path=`echo "$abs_path" | sed -e "s%/[^/]*/\.\.$%%"`
760 while true; do #// "/./" -> "/"
761 echo "$abs_path" | grep "/\./" > /dev/null || break
762 StringClass.replace_method "$abs_path" "/./" "/" ; abs_path="$g_Ret"
765 while true; do #// "/." -> ""
766 StringClass.right_method "$abs_path" 2
767 if [ "$g_Ret" != "/." ];then break ;fi
768 StringClass.replace_method "$abs_path" "/./" "/" ; abs_path="$g_Ret"
769 abs_path=`echo "$abs_path" | sed -e "s%/\.$%%"`
778 #//*********************************************************************
779 #// <<< [GetParentAbsPath_func] >>>
780 #//*********************************************************************
781 function GetParentAbsPath_func()
784 CheckArgCount_func 1 "$@"
788 LeftOfStr_func "$Path" "/" ; str="$g_Ret" #// if abs path, str=""
789 if [ "$str" != "" ]; then
790 GetAbsPath_func "$Path" ; Path="$g_Ret"
793 if [ x"$Path" == x"/" -o x"$Path" == x"" ]; then
796 RightOfLastStr_func "$Path" "/" #// if last char is "/", str=""
797 if [ "$g_Ret" == "" ]; then
798 LeftOfLastStr_func "$Path" "/" ; Path="$g_Ret"
800 LeftOfLastStr_func "$Path" "/" ; Path="$g_Ret" #// parent folder
801 if [ "$Path" == "" ];then Path="/" ;fi
808 #//*********************************************************************
809 #// <<< [SearchParent_func] >>>
810 #//*********************************************************************
811 function SearchParent_func()
817 GetAbsPath_func "$path" "$PWD" ; path="$g_Ret"
818 if [ -e "$path" ];then g_Ret="$path" ; return ;fi
820 folder=`dirname "$path"`
821 file=` basename "$path"`
823 folder=`dirname "$folder"`
824 if [ "$folder" == "/" ];then break ;fi
825 if [ -e "$folder/$file" ];then g_Ret="$folder/$file" ; return ;fi
827 if [ -e "/$file" ];then g_Ret="/$file" ; return ;fi
833 #//*********************************************************************
834 #// <<< [local_func] >>>
835 #//*********************************************************************
836 function local_func()
839 $declare_AssociativeArrayClass option
850 GetLongOptions_func arguments option "$@" #//[out] arguments, option
852 Attr_func option "arg"
853 ArrayClass.fromCSV_method args "$g_Ret" #//[out] args
855 Attr_func option "local"
856 ArrayClass.fromCSV_method locals "$g_Ret" #//[out] locals
858 for param in ${args[@]} ;do
859 StringClass.substring_method "$param" 0 5 ; a1="$g_Ret"
860 StringClass.substring_method "$param" 0 8 ; a2="$g_Ret"
861 if [ "$a1" == "(out)" ];then
862 StringClass.substring_method "$param" 5 ; param="$g_Ret"
863 out_names=( "${out_names[@]}" "${arguments[$arg_num]}" )
864 elif [ "$a2" == "(in_out)" ];then
865 StringClass.substring_method "$param" 8 ; param="$g_Ret"
866 out_names=( "${out_names[@]}" "${arguments[$arg_num]}" )
868 arg_num=$(( $arg_num + 1 ))
869 code="$code local $param=\""'$'"$arg_num\";"
872 for param in "${locals[@]}" ;do
873 code="$code local $param;"
876 locals=( "${args[@]}" "${locals[@]}" )
878 for name in ${out_names[@]} ;do
879 for param in "${locals[@]}" ;do
880 if [ "$name" == "$param" ];then
881 AssociativeArrayClass.destroy_method option
882 Error_func "<ERROR msg=\"出力引数がローカル変数名と衝突しています\" name=\"$name\"/>"
887 AssociativeArrayClass.destroy_method option
893 #//*********************************************************************
894 #// <<< [GetUsableCommands_func] >>>
895 #//*********************************************************************
896 function GetUsableCommands_func()
898 local out_FoundCommands="$1"
900 local Commands=( "$@" )
905 for command in ${Commands[@]} ;do
906 while TryStart_func; do
907 which $command > /dev/null
908 TryEnd1_func; done ;TryEnd2_func $?
909 if [ "$g_ExitStatus" == "0" ];then founds=( "${founds[@]}" "$command " ) ;fi
910 ErrClass.clear_method
912 SetOutputAsArray_func $out_FoundCommands "${founds[@]}"
917 #//*********************************************************************
918 #// <<< [GetUsableApplicationsForMac_func] >>>
919 #//*********************************************************************
920 function GetUsableApplicationsForMac_func()
923 --arg=" (out)out_FoundCommands " \
924 --local=" command__, commands__, apps__, app__, path__, file_name__, paths__, i__ " \
926 #// --arg="Applications ..."
929 local Applications=( "$@" )
931 #// list up applications
932 while TryStart_func; do
933 paths__=`ls /Applications/*.app /Applications/Utilities/*.app 2>/dev/null | grep :$`
934 TryEnd1_func; done ;TryEnd2_func $?
935 if [ "$g_ExitStatus" != "0" ]; then
936 unset $out_FoundCommands
937 unset $out_FoundCommands #// 配列をクリアするには2回必要?
938 ErrClass.clear_method
941 ArrayClass.fromLines_method paths__ "$paths__" #//[out] paths__
944 for path__ in "${paths__[@]}" ;do
945 file_name__=`basename "$path__"`
946 LeftOfLastStr_func "$file_name__" ".app:" ; apps__[$i__]="$g_Ret"
950 if [ "${#Applications[@]}" == "0" ];then
951 for (( i__ = 0; i__ < ${#apps__[@]}; i__ ++ )) ;do
952 apps__[$i__]="open -a \"$apps__[$i__]\" "
954 SetOutputAsArray_func $out_FoundCommands "${apps__[@]}"
958 #// pick up applications
960 for command__ in "${Applications[@]}" ;do
961 for app__ in "${apps__[@]}" ;do
962 if [ "$command__" == "$app__" ];then
963 commands__[$i__]="open -a \"$app__\" "
969 if [ "$i__" == "0" ];then ArrayClass.clear_method commands__ ;fi #// because local sets ${#commands__[@]}=1
970 SetOutputAsArray_func $out_FoundCommands "${commands__[@]}"
975 #//*********************************************************************
976 #// <<< [IsMac_func] >>>
977 #//*********************************************************************
978 function IsMac_func()
980 SystemClass.getProperty_method "os.name"
981 StringClass.indexOf_method "$g_Ret" "Mac OS X"
982 if [ "$g_Ret" == "-1" ];then
991 #//*********************************************************************
992 #// <<< [SystemClass.getProperty_method] >>>
993 #//*********************************************************************
994 function SystemClass.getProperty_method()
996 local PropertyName="$1"
998 if [ "$PropertyName" == "os.name" ];then
999 if [ -e "/Applications/App Store.app" ];then
1000 g_Ret="Mac OS X ..."
1011 #//*********************************************************************
1012 #// <<< [IsInstalled_func] >>>
1013 #//*********************************************************************
1014 function IsInstalled_func()
1016 local PackageSymbol="$1"
1019 dpkg -l "$PackageSymbol" | grep ^ii\ *"$PackageSymbol" > /dev/null|| status=$?
1020 if [ "$status" == "0" ];then
1029 #//*********************************************************************
1030 #// <<< [AppKeyClass.enableInstall_method] >>>
1031 #//*********************************************************************
1032 function AppKeyClass.enableInstall_method()
1036 if [ "$AppKey" != "AppKey4293" ]; then Error_func "AppKeyClass.enableInstall_method needs \$2 of Main_func" ;fi
1038 g_IsEnableInstall3192="1310"
1043 #//*********************************************************************
1044 #// <<< [InstallIfNot_func] >>>
1045 #//*********************************************************************
1046 g_IsEnableInstall3192="0"
1048 function InstallIfNot_func()
1050 local PackageSymbol="$1"
1052 IsInstalled_func "$PackageSymbol"
1053 if [ "$g_Ret" == "0" ];then
1054 if [ "$g_IsEnableInstall3192" != "1310" ];then #// チェックのみ
1055 Error_func "apt-get が許可されていません。参照:AppKeyClass.enableInstall_method"
1057 echo "apt-get install \"$PackageSymbol\""
1058 $g_TemporarySudo apt-get install "$PackageSymbol" <<HereDocument
1067 #//*********************************************************************
1068 #// <<< [Uninstall_func] >>>
1069 #//*********************************************************************
1070 function Uninstall_func()
1072 local PackageSymbol="$1"
1074 if [ "$g_IsEnableInstall3192" != "1310" ];then #// チェックのみのときは、IsInstalled_func
1075 Error_func "apt-get が許可されていません。参照:AppKeyClass.enableInstall_method"
1078 IsInstalled_func "$PackageSymbol"
1079 if [ "$g_Ret" == "1" ];then
1080 echo "apt-get remove \"$PackageSymbol\""
1081 $g_TemporarySudo apt-get remove "$PackageSymbol" <<HereDocument
1089 #//*********************************************************************
1090 #// <<< [GetLongOptions_func] >>>
1091 #//*********************************************************************
1092 function GetLongOptions_func()
1094 local out_Arguments="$1"
1095 local out_OptAssocArray="$2"
1103 local locals="out_Arguments out_OptAssocArray Args__ param__ name__ value__ locals"
1104 CheckOutParamIsConflictToLocal_func "$out_Arguments" $locals
1105 CheckOutParamIsConflictToLocal_func "$out_OptAssocArray" $locals
1107 AssociativeArrayClass.clear_method $out_OptAssocArray
1109 for param__ in "${Args__[@]}" ;do
1110 StringClass.substring_method "$param__" 0 2
1111 if [ "$g_Ret" == "--" ];then
1112 LeftOfStr_func "$param__" "=" ; name__="$g_Ret"
1113 if [ "$name__" == "$param__" ];then
1116 RightOfStr_func "$param__" "=" ; value__="$g_Ret"
1118 StringClass.substring_method "$name__" 2 ; name__="$g_Ret"
1120 SetAttr_func $out_OptAssocArray $name__ "$value__"
1122 SetArrItem_func $out_Arguments $ArgIndex__ "$param__"
1123 ArgIndex__=$(( $ArgIndex__ + 1 ))
1130 #//*********************************************************************
1131 #// <<< [Attr_func] >>>
1132 #//*********************************************************************
1133 function Attr_func()
1138 CheckArgCount_func 2 "$@"
1140 eval tmp="\${${self}[\$AttrName]}"
1146 #//*********************************************************************
1147 #// <<< [SetArrItem_func] >>>
1148 #//*********************************************************************
1149 function SetArrItem_func()
1154 CheckArgCount_func 3 "$@"
1156 eval "$self__[$Index__]=\"$Value__\""
1161 #//*********************************************************************
1162 #// <<< [SetAttr_func] >>>
1163 #//*********************************************************************
1164 function SetAttr_func()
1166 SetArrItem_func "$@"
1171 #//*********************************************************************
1172 #// <<< [SetAttr_as_ArrayName_func] >>>
1173 #//*********************************************************************
1174 function SetAttr_as_ArrayName_func()
1177 local AttrName__="$2"
1180 CheckOutParamIsConflictToLocal_func "$self__" self__ AttrName__ i__ Params__
1185 SetAttr_func $self__ "$AttrName__" "g_Arrays_$g_ArrayLength"
1187 for (( i__ = 0; i__ < ${#Params__[@]}; i__ ++ ));do
1188 eval "g_Arrays_$g_ArrayLength"'[$i__]'='${Params__[$i__]}'
1191 g_ArrayLength=$(( $g_ArrayLength + 1 ))
1196 #//*********************************************************************
1197 #// <<< [SetAttr_as_AssociativeArrayName_func] >>>
1198 #//*********************************************************************
1199 function SetAttr_as_AssociativeArrayName_func()
1202 local AttrName__="$2"
1207 CheckOutParamIsConflictToLocal_func "$self__" self__ AttrName__ i__ Params__ key__ value__
1212 SetAttr_func $self__ "$AttrName__" "g_AssociativeArrays_$g_AssociativeArrayLength"
1214 for (( i__ = 0; i__ < ${#Params__[@]}; i__ = i__ + 2 ));do
1215 key__=${Params__[$i__]}
1216 value__=${Params__[$i__+1]}
1218 SetAttr_func g_AssociativeArrays_$g_AssociativeArrayLength $key__ "$value__"
1221 g_AssociativeArrayLength=$(( $g_AssociativeArrayLength + 1 ))
1226 #//*********************************************************************
1227 #// <<< [AssociativeArrayClass.getLength_method] >>>
1228 #//*********************************************************************
1229 function AssociativeArrayClass.getLength_method()
1232 if [ "$self" == "" ];then Error_func "no object name" ;fi
1234 eval g_Ret='${#'"$self"'[@]}'
1239 #//*********************************************************************
1240 #// <<< [AssociativeArrayClass.getKeys_method] >>>
1241 #//*********************************************************************
1242 function AssociativeArrayClass.getKeys_method()
1245 if [ "$self" == "" ];then Error_func "no object name" ;fi
1247 eval g_Ret='${!'"$self"'[@]}'
1252 #//*********************************************************************
1253 #// <<< [AssociativeArrayClass.getItems_method] >>>
1254 #//*********************************************************************
1255 function AssociativeArrayClass.getItems_method()
1258 if [ "$self" == "" ];then Error_func "no object name" ;fi
1260 eval g_Ret='${'"$self"'[@]}'
1265 #//*********************************************************************
1266 #// <<< [AssociativeArrayClass.clear_method] >>>
1267 #//*********************************************************************
1268 function AssociativeArrayClass.clear_method()
1273 local locals__="self__ key__ keys__ locals"
1274 CheckOutParamIsConflictToLocal_func "$self__" $locals__
1276 eval keys__='${!'"$self__"'[@]}'
1277 for key__ in "${keys__[@]}" ;do
1278 if [ "$key__" != "" ];then
1279 unset "$self__[$key__]"
1286 #//*********************************************************************
1287 #// <<< [AssociativeArrayClass.destroy_method] >>>
1288 #//*********************************************************************
1289 function AssociativeArrayClass.destroy_method()
1299 #//*********************************************************************
1300 #// <<< [CopyArray_func] >>>
1301 #//*********************************************************************
1302 function CopyArray_func()
1304 local DstArray__="$1"
1305 local SrcArray__="$2"
1310 local locals__="DstArray__ SrcArray__ key__ keys__ code__ value__ locals"
1311 CheckOutParamIsConflictToLocal_func "$DstArray__" $locals__
1312 CheckOutParamIsConflictToLocal_func "$SrcArray__" $locals__
1314 code__="$DstArray__=("
1315 eval keys__=( '"${!'"$SrcArray__"'[@]}"' )
1316 for key__ in "${keys__[@]}" ;do
1317 eval value__='${'$SrcArray__'[$key__]}'
1318 code__="$code__ [\"$key__\"]=\"$value__\""
1325 #//*********************************************************************
1326 #// <<< [CopyArrayAttr_func] >>>
1327 #//*********************************************************************
1328 function CopyArrayAttr_func()
1331 local AttrName__="$2"
1332 local out_Array="$3"
1336 local locals="self__ AttrName__ out_Array__ array_name__ i__ n__ locals"
1337 CheckOutParamIsConflictToLocal_func "$self__" $locals
1338 CheckOutParamIsConflictToLocal_func "$out_Array" $locals
1340 Attr_func $self__ "$AttrName__" ; array_name__="$g_Ret"
1342 unset $out_Array #// 配列をクリアするには2回必要?
1344 eval n__='${#'"$array_name__"'[@]}'
1346 for (( i__ = 0; $i__ < $n__; i__ ++ ));do
1347 eval "$out_Array"'[$i__]=${'"$array_name__"'[$i__]}'
1353 #//*********************************************************************
1354 #// <<< [SetOutput_func] >>>
1355 #//*********************************************************************
1356 function SetOutput_func()
1360 CheckArgCount_func 2 "$@"
1361 CheckOutParamIsConflictToLocal_func "$out_Var" out_Var Value__
1363 eval $out_Var="'$Value__'"
1368 #//*********************************************************************
1369 #// <<< [SetOutputAsArray_func] >>>
1370 #//*********************************************************************
1371 function SetOutputAsArray_func()
1374 CheckMinArgCount_func 1 "$@"
1375 CheckOutParamIsConflictToLocal_func "$out_Var" out_Var
1378 eval $out_Var="(" '"$@"' ")"
1383 #//*********************************************************************
1384 #// <<< [AddIfNotExist_func] >>>
1385 #//*********************************************************************
1386 function AddIfNotExist_func()
1390 local Separator="$3"
1391 CheckArgCount_func 3 "$@"
1393 local whole_str_plus="$WholeStr$Separator"
1396 if [ "$AddStr" == "" ];then echo "$WholeStr" ; return 0 ;fi
1398 LeftOfStr_func "$whole_str_plus" "$AddStr$Separator" ; str="$g_Ret"
1399 if [ "$str" == "$whole_str_plus" ];then #// not found
1400 g_Ret="$AddStr$Separator$WholeStr"
1408 #//*********************************************************************
1409 #// <<< [IsNumeric_func] >>>
1410 #//*********************************************************************
1411 function IsNumeric_func()
1414 CheckArgCount_func 1 "$@"
1415 if [ "$Value" == "-1" ];then
1419 expr $Value + 1 > /dev/null 2>&1 || status=$?
1420 if [ "$status" == "0" ];then
1430 #//*********************************************************************
1431 #// <<< [StringClass.length_method] >>>
1432 #//*********************************************************************
1433 function StringClass.length_method()
1436 CheckArgCount_func 1 "$@"
1442 #//*********************************************************************
1443 #// <<< [StringClass.substring_method] >>>
1444 #//*********************************************************************
1445 function StringClass.substring_method()
1448 local StartIndex="$2"
1450 CheckMinArgCount_func 2 "$@"
1451 CheckMaxArgCount_func 3 "$@"
1453 if [ "$EndIndex" == "" ];then
1454 g_Ret="${self:$StartIndex}"
1456 g_Ret="${self:$StartIndex:$(( $EndIndex - $StartIndex ))}"
1462 #//*********************************************************************
1463 #// <<< [StringClass.trim_method] >>>
1464 #//*********************************************************************
1465 function StringClass.trim_method()
1475 ch="${String:$index:1}"
1476 if [ "$ch" != " " ];then
1477 if [ "$ch" != "$Tab" ];then
1478 if [ "$ch" != "$LF" ];then
1483 index=$(( $index + 1 ))
1486 String="${String:$index}"
1488 index=$(( ${#String} - 1 ))
1490 ch="${String:$index:1}"
1491 if [ "$ch" != " " ];then
1492 if [ "$ch" != "$Tab" ];then
1493 if [ "$ch" != "$LF" ];then
1498 index=$(( $index - 1 ))
1500 index=$(( $index + 1 ))
1502 g_Ret="${String:0:$index}"
1507 #//*********************************************************************
1508 #// <<< [StringClass.right_method] >>>
1509 #//*********************************************************************
1510 function StringClass.right_method()
1514 CheckArgCount_func 2 "$@"
1516 g_Ret="${String:$(( ${#String} - $Length ))}"
1521 #//*********************************************************************
1522 #// <<< [StringClass.cutLastOf_method] >>>
1523 #//*********************************************************************
1524 function StringClass.cutLastOf_method()
1528 CheckArgCount_func 2 "$@"
1530 if [ "${String:$(( ${#String} - ${#LastStr} ))}" == "$LastStr" ];then
1531 g_Ret="${String:0:$(( ${#String} - ${#LastStr} ))}"
1539 #//*********************************************************************
1540 #// <<< [LeftOfStr_func] >>>
1541 #//*********************************************************************
1542 function LeftOfStr_func()
1546 CheckArgCount_func 2 "$@"
1548 StringClass.replace_method "$Key" '\' '\\'
1549 StringClass.replace_method "$g_Ret" '*' '\*'
1551 g_Ret="${String%%$g_Ret*}"
1556 #//*********************************************************************
1557 #// <<< [LeftOfLastStr_func] >>>
1558 #//*********************************************************************
1559 function LeftOfLastStr_func()
1563 CheckArgCount_func 2 "$@"
1565 StringClass.replace_method "$Key" '\' '\\'
1566 StringClass.replace_method "$g_Ret" '*' '\*'
1568 g_Ret="${String%$g_Ret*}"
1573 #//*********************************************************************
1574 #// <<< [RightOfStr_func] >>>
1575 #//*********************************************************************
1576 function RightOfStr_func()
1580 CheckArgCount_func 2 "$@"
1582 StringClass.replace_method "$Key" '\' '\\'
1583 StringClass.replace_method "$g_Ret" '*' '\*'
1585 g_Ret="${String#*$g_Ret*}"
1590 #//*********************************************************************
1591 #// <<< [RightOfLastStr_func] >>>
1592 #//*********************************************************************
1593 function RightOfLastStr_func()
1597 CheckArgCount_func 2 "$@"
1599 StringClass.replace_method "$Key" '\' '\\'
1600 StringClass.replace_method "$g_Ret" '*' '\*'
1602 g_Ret="${String##*$g_Ret}"
1607 #//*********************************************************************
1608 #// <<< [StringClass.indexOf_method] >>>
1609 #//*********************************************************************
1610 function StringClass.indexOf_method()
1614 local StartIndex="$3"
1615 CheckMinArgCount_func 2 "$@"
1616 CheckMaxArgCount_func 3 "$@"
1618 if [ "$StartIndex" == "" ];then StartIndex=0 ;fi
1619 if [ "$StartIndex" -le "0" ];then #// -le:"<="
1620 part="${self%%$Keyword*}"
1621 if [ "$part" == "$self" ];then
1624 g_Ret=$(( ${#part} ))
1627 self="${self:$StartIndex}"
1628 part="${self%%$Keyword*}"
1629 if [ "$part" == "$self" ];then
1632 g_Ret=$(( ${#part} + $StartIndex ))
1639 #//*********************************************************************
1640 #// <<< [StringClass.lastIndexOf_method] >>>
1641 #//*********************************************************************
1642 function StringClass.lastIndexOf_method()
1646 local StartIndex="$3"
1647 CheckMinArgCount_func 2 "$@"
1648 CheckMaxArgCount_func 3 "$@"
1650 if [ "$StartIndex" == "" ];then StartIndex=0 ;fi
1651 if [ "$StartIndex" -le "0" ];then #// -le:"<="
1652 part="${self%$Keyword*}"
1653 if [ "$part" == "$self" ];then
1656 g_Ret=$(( ${#part} ))
1659 self="${self:0:$(( $StartIndex + ${#Keyword} ))}"
1660 part="${self%$Keyword*}"
1661 if [ "$part" == "$self" ];then
1671 #//*********************************************************************
1672 #// <<< [StringClass.replace_method] >>>
1673 #//*********************************************************************
1674 function StringClass.replace_method()
1680 StringEscapeUtilsClass.escapeBashReplace_method "$From"
1681 g_Ret="${String//$g_Ret/$3}"
1686 #//*********************************************************************
1687 #// <<< [StringClass.toLowerCase_method] >>>
1688 #//*********************************************************************
1689 function StringClass.toLowerCase_method()
1693 #// echo "${self,,}"
1696 g_Ret=`echo "$1" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
1701 #//*********************************************************************
1702 #// <<< [StringClass.toUpperCase_method] >>>
1703 #//*********************************************************************
1704 function StringClass.toUpperCase_method()
1708 #// echo "${self^^}"
1711 g_Ret=`echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1716 #//*********************************************************************
1717 #// <<< [StringEscapeUtilsClass.escapeGrep_method] >>>
1718 #//*********************************************************************
1719 function StringEscapeUtilsClass.escapeGrep_method()
1722 Str="${Str//\\/\\\\}"
1733 g_Ret="${Str//\?/\?}"
1738 #//*********************************************************************
1739 #// <<< [StringEscapeUtilsClass.escapeSed_method] >>>
1740 #//*********************************************************************
1741 function StringEscapeUtilsClass.escapeSed_method()
1744 Str="${Str//\\/\\\\}"
1752 g_Ret="${Str//\//\/}"
1757 #//*********************************************************************
1758 #// <<< [StringEscapeUtilsClass.escapeBashReplace_method] >>>
1759 #//*********************************************************************
1760 function StringEscapeUtilsClass.escapeBashReplace_method()
1763 Str="${Str//\\/\\\\}"
1765 Str="${Str//\(/\\(}"
1766 Str="${Str//\)/\\)}"
1767 Str="${Str//\*/\\*}"
1768 Str="${Str//\?/\\?}"
1769 g_Ret="${Str//\//\\/}"
1774 #//*********************************************************************
1775 #// <<< [StringEscapeUtilsClass.escapeBashDoubleQuot_method] >>>
1776 #//*********************************************************************
1777 function StringEscapeUtilsClass.escapeBashDoubleQuot_method()
1780 Str="${Str//\\/\\\\}"
1782 g_Ret="${Str//\//\\/}"
1787 #//*********************************************************************
1788 #// <<< [StringEscapeUtilsClass.escapeBashParam_method] >>>
1789 #//*********************************************************************
1790 function StringEscapeUtilsClass.escapeBashParam_method()
1793 Str="${Str//\\/\\\\}"
1795 g_Ret="${Str//$/\\$}"
1800 #//*********************************************************************
1801 #// <<< [ReplaceTextFile_func] >>>
1802 #//*********************************************************************
1803 function ReplaceTextFile_func()
1810 CheckMinArgCount_func 2 "$@"
1811 CheckMaxArgCount_func 4 "$@"
1816 local slashes=( "%" "/" )
1818 CheckWritable_func "$Path"
1820 if [ "$Opt" == "-i" ];then Opt="i" ;fi
1822 sed_setIsAbleToNotCaseSensitive_func
1823 if [ "$g_sed_isAbleToNotCaseSensitive" == "0" ];then
1824 StringClass.indexOf_method "$Opt" "i"
1825 if [ "$g_Ret" -ge 0 ];then
1826 Error_func "-i オプションは指定できません。"
1830 for slash in ${slashes[@]};do
1832 LeftOfStr_func "$From" "$slash" ; str1="$g_Ret"
1833 LeftOfStr_func "$To" "$slash" ; str2="$g_Ret"
1834 if [ x"$str1" == x"$From" -a x"$str2" == x"$To" ];then #// $From and $To do not have $slash.
1836 RightOfStr_func "$From" "\n" ; str1="$g_Ret"
1837 RightOfStr_func "$To" "\n" ; str2="$g_Ret"
1838 if [ x"$str1" == x"$From" -a x"$str2" == x"$To" ];then #// $str1 and $str2 are single line,
1839 sed -i.bak -e "s$slash$From$slash$To${slash}g$Opt" "$Path" ; rm "$Path.bak"
1841 RightOfStr_func "$str1" "\n" ; str2="$g_Ret"
1842 if [ "$str1" != "$str2" ];then
1843 Error_func "置き換える前の文字列は3行以上にできません。"
1847 #// sed -i.bak -e '/\n/! {;$q;N;};'"s$slash$From$slash$To${slash}g$Opt;P;D;" "$Path" ; rm "$Path.bak"
1849 #// for BSD sed in Mac OS X Snow Leopard
1850 To=`echo "$To" | sed -e 's/\\\\n/\\\\\\'"$LF"'/g' `
1851 cp "$Path" "$Path.bak" #// mv では、chmod 属性が消えてしまいます
1852 sed -e '/\n/! {;$q;N;};'"s$slash$From$slash$To${slash}g$Opt;P;D;" "$Path.bak" > $Path
1859 Error_func "ReplaceTextFile_func は、置き換える前後の文字列に / と % の両方を含むことはできません"
1864 #//*********************************************************************
1865 #// <<< [sed_setIsAbleToNotCaseSensitive_func] >>>
1866 #//*********************************************************************
1867 g_sed_isAbleToNotCaseSensitive=""
1868 function sed_setIsAbleToNotCaseSensitive_func()
1870 if [ "$g_sed_isAbleToNotCaseSensitive" == "" ];then
1872 echo -n "" | sed -e s/a/b/i > /dev/null 2>&1 || status=$?
1873 g_sed_isAbleToNotCaseSensitive=$(( 1 - $status ))
1879 #//*********************************************************************
1880 #// <<< [ReplaceTextFileLineRange_func] >>>
1881 #//*********************************************************************
1882 function ReplaceTextFileLineRange_func()
1892 CheckMinArgCount_func 3 "$@"
1893 CheckMaxArgCount_func 5 "$@"
1895 CheckWritable_func "$Path"
1897 if [ "$Opt" == "-i" ];then Opt="i" ;fi
1899 sed_setIsAbleToNotCaseSensitive_func
1900 if [ "$g_sed_isAbleToNotCaseSensitive" == "0" ];then
1901 StringClass.indexOf_method "$Opt" "i"
1902 if [ "$g_Ret" -ge 0 ];then
1903 Error_func "i オプションは指定できません。"
1907 LeftOfStr_func "$From" "%"
1908 if [ "$g_Ret" != "$From" ];then Error_func ;fi
1910 LeftOfStr_func "$FromEnd" "%"
1911 if [ "$g_Ret" != "$FromEnd" ];then Error_func ;fi
1913 Opt=`StringClass.toUpperCase_method "$Opt"`
1915 if [ "$To" != "" ];then
1917 #// To="c${To//\\n/\\${LF}}"
1919 #// for BSD sed in Mac OS X Snow Leopard
1920 if [ "$To" == "\n" ];then
1921 a1=`echo $'a\nb\nc' | sed -e '/b/c\'"${LF}" `
1922 if [ "$a1" == "a${LF}${LF}c" ];then
1927 To="c\\${LF}${To//\\n/\\${LF}}"
1933 #// if [ "$FromEnd" == "" ];then
1934 #// sed -i.bak -e '\%'"$From"'%'"$Opt$To" "$Path" ; rm "$Path.bak"
1936 #// sed -i.bak -e '\%'"$From"'%'"$Opt"',\%'"$FromEnd"'%'"$Opt$To" "$Path" ; rm "$Path.bak"
1939 #// for BSD sed in Mac OS X Snow Leopard
1940 cp "$Path" "$Path.bak" #// mv では、chmod 属性が消えてしまいます
1941 if [ "$FromEnd" == "" ];then
1942 sed -e '\%'"$From"'%'"$Opt$To" "$Path.bak" > $Path
1944 sed -e '\%'"$From"'%'"$Opt"',\%'"$FromEnd"'%'"$Opt$To" "$Path.bak" > $Path
1951 #//*********************************************************************
1952 #// <<< [MultiLine_func] >>>
1953 #//*********************************************************************
1954 function MultiLine_func()
1956 local LineFeedChar="$1"
1959 local Params=( "$@" )
1964 for line in "$@" ;do
1965 if [ "$line" == "" ];then
1966 lfs="$lfs$LineFeedChar"
1968 g_Ret="$g_Ret$lfs$line"
1976 #//*********************************************************************
1977 #// <<< [ArrayClass.getLength_method] >>>
1978 #//*********************************************************************
1979 function ArrayClass.getLength_method()
1983 eval g_Ret='${#'"$self"'[@]}'
1988 #//*********************************************************************
1989 #// <<< [ArrayClass.get_method] >>>
1990 #//*********************************************************************
1991 function ArrayClass.get_method()
1996 CheckArgCount_func 2 "$@"
1998 eval over_index='${#'"$self"'[@]}'
1999 if [ "$Index" -ge "$over_index" -o "$Index" -lt "0" ];then
2000 Error_func "<ERROR msg=\"インデックスが範囲外です\" index=\"$Index\"/>"
2003 eval g_Ret='"${'"$self"'[$Index]}"'
2008 #//*********************************************************************
2009 #// <<< [ArrayClass.set_method] >>>
2010 #//*********************************************************************
2011 function ArrayClass.set_method()
2018 CheckArgCount_func 3 "$@"
2020 eval over_index='${#'"$self"'[@]}'
2021 if [ "$Index" -lt "0" ];then
2022 Error_func "<ERROR msg=\"インデックスが範囲外です\" index=\"$Index\"/>"
2025 for (( num = over_index; $num < $Index; num++ )) ;do
2026 eval "$self"'[$num]=""'
2029 eval "$self"'[$Index]='"'$Value'"
2034 #//*********************************************************************
2035 #// <<< [ArrayClass.remove_method] >>>
2036 #//*********************************************************************
2037 function ArrayClass.remove_method()
2044 CheckArgCount_func 2 "$@"
2046 eval over_index='${#'"$self"'[@]}'
2047 if [ "$Index" -ge "$over_index" -o "$Index" -lt "0" ];then
2048 Error_func "<ERROR msg=\"インデックスが範囲外です\" index=\"$Index\"/>"
2051 last_index=$(( $over_index - 1 ))
2052 for (( num = $Index; $num < $last_index; num++ )) ;do
2053 eval "$self"'[$num]="${'"$self"'[$(( $num + 1 ))]}"'
2056 eval unset "$self"'[$last_index]'
2061 #//*********************************************************************
2062 #// <<< [ArrayClass.clear_method] >>>
2063 #//*********************************************************************
2064 function ArrayClass.clear_method()
2069 unset $self #// 配列をクリアするには2回必要?
2074 #//*********************************************************************
2075 #// <<< [ArrayClass.fromLines_method] >>>
2076 #//*********************************************************************
2077 function ArrayClass.fromLines_method()
2079 local out_Array="$1"
2085 CheckOutParamIsConflictToLocal_func $out_Array out_Array Lines line i keys
2088 unset $out_Array #// 配列をクリアするには2回必要?
2092 line="${Lines%%$LF*}"
2093 if [ "$line" != "" ];then eval $out_Array[$i]="'$line'" ;fi
2094 if [ "$line" == "$Lines" ];then break ;fi
2096 Lines=${Lines:$(( ${#line} + 1 ))} #// next line
2102 #//*********************************************************************
2103 #// <<< [ArrayClass.fromCSV_method] >>>
2104 #//*********************************************************************
2105 function ArrayClass.fromCSV_method()
2107 local out_Array="$1"
2113 CheckArgCount_func 2 "$@"
2115 CheckOutParamIsConflictToLocal_func "$out_Array" \
2116 CSV__ out_Array index__ item__ __field char__ next__
2119 unset $out_Array #// 配列をクリアするには2回必要?
2122 item__=( $CSV__ ) #// ${item__[0]} does not have space
2123 StringClass.substring_method ${item__[0]} 0 1 ; char__="$g_Ret"
2124 if [ "$char__" == "\"" ];then
2125 RightOfStr_func "$CSV__" "\"" ; CSV__="$g_Ret"
2126 LeftOfStr_func "$CSV__" "\"" ; item__="$g_Ret"
2127 RightOfStr_func "$CSV__" "\"" ; CSV__="$g_Ret"
2128 elif [ "$char__" == "" ];then
2131 LeftOfStr_func "$CSV__" "," ; item__="$g_Ret"
2132 StringClass.trim_method "$item__" ; item__="$g_Ret"
2134 RightOfStr_func "$CSV__" "," ; next__="$g_Ret"
2136 SetArrItem_func $out_Array $index__ "$item__"
2137 index__=$(( $index__ + 1 ))
2139 if [ x"$next__" == x"" -o x"$next__" == x"$CSV__" ];then break ;fi
2146 #//*********************************************************************
2147 #// <<< [IsSameArrayOutOfOrder_func] >>>
2148 #//*********************************************************************
2149 function IsSameArrayOutOfOrder_func()
2151 local ArrayACount="$1"
2152 local ArrayAB=("$@")
2158 IsNumeric_func "$ArrayACount" ; if [ "$g_Ret" == "0" ];then Error_func ;fi
2160 if [ ${#ArrayAB[@]} != $(( $ArrayACount * 2 + 1 )) ];then g_Ret="0" ; return ;fi
2162 for (( b_index = $ArrayACount + 1; b_index < ${#ArrayAB[@]}; b_index ++ )) ;do
2163 for (( a_index = 1; a_index <= $ArrayACount; a_index ++ )) ;do
2164 if [ "${ArrayAB[$a_index]}" == "${ArrayAB[$b_index]}" ];then
2165 if [ "${is_same_arr[$a_index]}" == "" ];then
2166 is_same_arr[$a_index]=1
2173 for (( a_index=1; a_index <= $ArrayACount; a_index ++ )) ;do
2174 if [ "${is_same_arr[$a_index]}" == "" ];then
2183 #//*********************************************************************
2184 #// <<< [Extract_func] >>>
2185 #//*********************************************************************
2186 function Extract_func()
2188 local PackagePath="$1"
2189 local DstFolder="$2"
2195 local extract_folder
2197 local trans_option_1
2198 local trans_option_2
2201 $declare_AssociativeArrayClass option
2203 echo "$PackagePath -> $DstFolder $Option1"
2205 CheckWritable_func "$DstFolder"
2206 dst_name=`basename "$DstFolder"`
2208 RightOfLastStr_func "$PackagePath" "." ; ext2="$g_Ret"
2209 LeftOfLastStr_func "$PackagePath" "."
2210 RightOfLastStr_func "$g_Ret" "." ; ext1="$g_Ret"
2212 #// --transform option
2213 GetLongOptions_func arguments option "$@" #//[out] arguments, option
2214 Attr_func option "transform_from" ; trans_option_1="$g_Ret"
2217 if [ "$trans_option_1" == "" ];then
2219 #// set one_folder_path
2220 ListUpIn_func "$PackagePath" > /tmp/_Extract_func.txt #// tar write error, if pipe was used
2221 one_folder_path=`head -n 1 /tmp/_Extract_func.txt`
2223 StringClass.substring_method "$one_folder_path" 0 1
2224 if [ "$g_Ret" == "/" ];then
2227 StringClass.substring_method "$one_folder_path" 0 2
2228 if [ "$g_Ret" == "./" ];then
2229 StringClass.indexOf_method "$one_folder_path" "/" 2
2231 StringClass.indexOf_method "$one_folder_path" "/"
2233 if [ "$g_Ret" == "-1" ];then
2236 StringClass.substring_method "$one_folder_path" 0 $g_Ret ; one_folder_path="$g_Ret"
2241 #// set one_folder_path="", if there was two folders
2242 if [ "$one_folder_path" != "" ];then
2244 cat /tmp/_Extract_func.txt | grep -v "^$one_folder_path/" || status=$?
2245 CheckPipeStatus_func "${PIPESTATUS[@]}"
2246 if [ "$status" == "0" ];then #// found out of one_folder_path
2250 rm /tmp/_Extract_func.txt
2253 #// set trans_option
2254 if [ "$one_folder_path" != "" ];then
2255 if [ "$ext2" == "zip" ];then
2256 trans_option_1="$one_folder_path"
2258 GetExtractTransformOptionName_func "$DstFolder"
2259 if [ "$g_Ret" == "--transform" ];then
2260 trans_option_1="--transform=s%^$one_folder_path%$dst_name%"
2263 trans_option_2="%^$one_folder_path/%$dst_name/%"
2269 #// set extract_folder
2270 if [ "$one_folder_path" == "" ];then
2271 extract_folder="$DstFolder"
2273 GetParentAbsPath_func "$DstFolder" ; extract_folder="$g_Ret"
2278 #// modify trans_option
2279 StringClass.right_method "$trans_option_1" 1
2280 if [ "$g_Ret" == "/" ];then
2281 StringClass.length_method "$trans_option_1"
2282 StringClass.substring_method "$trans_option_1" 0 $(( $g_Ret - 1 ))
2283 trans_option_1="$g_Ret"
2285 dst_name=`basename "$DstFolder"`
2287 if [ "$ext2" != "zip" ];then
2288 GetExtractTransformOptionName_func "$DstFolder"
2289 if [ "$g_Ret" == "--transform" ];then
2290 trans_option_1="--transform=s%^$trans_option_1%$dst_name%"
2292 trans_option_2="%^$trans_option_1%$dst_name%"
2296 extract_folder=`dirname "$DstFolder"`
2301 if [ x"$ext1" != x"tar" -a x"$ext2" == x"gz" ];then
2302 ExtractGZ_func "$PackagePath" "$extract_folder"
2303 elif [ "$ext2" == "zip" ];then
2304 ExtractZip_func "$PackagePath" "$DstFolder" "$trans_option_1"
2306 if [ ! -e "$extract_folder" ];then mkdir -p "$extract_folder" ;fi
2307 if [ "$trans_option_1" == "" ];then
2308 echo "tar xvf \"$PackagePath\" -C \"$extract_folder\""
2309 tar xvf "$PackagePath" -C "$extract_folder"
2311 echo "tar xvf \"$PackagePath\" -C \"$extract_folder\" \"$trans_option_1\" \"$trans_option_2\""
2312 tar xvf "$PackagePath" -C "$extract_folder" "$trans_option_1" "$trans_option_2"
2316 AssociativeArrayClass.destroy_method option
2320 declare g_ExtractTransformOptionName #// "-s" or "--transform"
2322 function GetExtractTransformOptionName_func()
2324 if [ "$g_ExtractTransformOptionName" == "" ];then
2326 local WorkDstFolder="$1"
2332 for (( i = 1; i < 100; i ++ ));do
2333 if [ "$i" == "99" ];then Error_func "$WorkDstFolder にフォルダーが作れません" ;fi
2334 a1="$WorkDstFolder/_extract_trans_test_$i"
2335 if [ ! -e "$a1" ];then
2341 while TryStart_func; do
2343 mkdir -p "$WorkDstFolder"
2344 pushd "$WorkDstFolder" > /dev/null
2348 tar cvjf "a.tar.bz2" "a.txt" > /dev/null
2351 tar xvf "a.tar.bz2" --transform="s%a.txt%b.txt%" > /dev/null 2>&1 || status=$?
2353 if [ "$status" == "0" -a -e "b.txt" ];then
2354 g_ExtractTransformOptionName="--transform"
2357 tar xvf "a.tar.bz2" -s "%a.txt%b.txt%" > /dev/null 2>&1 || status=$?
2359 if [ "$status" == "0" -a -e "b.txt" ];then
2360 g_ExtractTransformOptionName="-s"
2366 TryEnd1_func; done ;TryEnd2_func $?
2368 if [ "$is_pushd" == "1" ];then popd > /dev/null ;fi
2369 rm_func "$WorkDstFolder"
2370 if [ "$g_ExitStatus" != "0" ]; then ErrClass.raiseOverwrite_method ;fi
2372 g_Ret="$g_ExtractTransformOptionName"
2377 #//*********************************************************************
2378 #// <<< [ExtractGZ_func] >>>
2379 #//*********************************************************************
2380 function ExtractGZ_func()
2383 local ExtractedPath="$2"
2384 CheckArgCount_func 2 "$@"
2386 if [ "$TMPDIR" == "" ]; then temp_folder="$HOME" ;else temp_folder="$TMPDIR" ;fi
2388 if [ "$GzPath" == "${ExtractedPath}.gz" ]; then
2389 if [ -e "$temp_folder/_ExtractGZ_func.gz" -o -e "$temp_folder/_ExtractGZ_func" ]; then
2390 unset ERROR;${ERROR:?exist _ExtractGZ_func.gz is for temporary} ;fi
2392 cp -ap "$GzPath" "$temp_folder/_ExtractGZ_func.gz"
2393 echo "gunzip \"$temp_folder/_ExtractGZ_func.gz\""
2394 gunzip "$temp_folder/_ExtractGZ_func.gz"
2395 mv "$temp_folder/_ExtractGZ_func" "$ExtractedPath"
2397 cp -ap "$GzPath" "${ExtractedPath}.gz"
2398 rm_func "$ExtractedPath"
2399 echo "gunzip \"${ExtractedPath}.gz\""
2400 gunzip "${ExtractedPath}.gz"
2406 #//*********************************************************************
2407 #// <<< [ExtractZip_func] >>>
2408 #//*********************************************************************
2409 function ExtractZip_func()
2411 local PackagePath="$1"
2412 local DstFolder="$2"
2413 local TarnsformFrom="$3"
2414 local dst_name ; dst_name=`basename "$DstFolder"`
2415 local from_name ; from_name=`basename "$TarnsformFrom"`
2417 if [ "$DstFolder" == "" ];then DstFolder="$PWD" ;fi
2419 if [ x"$TarnsformFrom" == x"" ];then
2420 mkdir_func "$DstFolder"
2421 echo "unzip -o -d \"$DstFolder\" \"$PackagePath\""
2422 unzip -o -d "$DstFolder" "$PackagePath"
2423 elif [ x"$dst_name" == x"$from_name" ];then
2424 GetParentAbsPath_func "$DstFolder"
2426 mkdir_func "$DstFolder"
2427 echo "unzip -o -d \"$DstFolder\" \"$PackagePath\""
2428 unzip -o -d "$DstFolder" "$PackagePath"
2434 tmp_folder="$DstFolder/_extracting_"
2435 for (( num = 1; ; num ++ )) ;do
2436 if [ "$num" == 1000 ];then Error_func ;fi
2437 if [ ! -e "$tmp_folder$num" ];then break ;fi
2439 tmp_folder="$tmp_folder$num"
2440 mkdir -p "$tmp_folder"
2442 link_path="$tmp_folder/$from_name"
2443 StringClass.substring_method "$DstFolder" 0 1
2444 if [ "$g_Ret" == "/" ];then
2445 ln -s "$DstFolder" "$link_path"
2447 ln -s ".." "$link_path"
2450 echo "unzip -o -d \"$tmp_folder\" \"$PackagePath\""
2451 unzip -o -d "$tmp_folder" "$PackagePath"
2460 #//*********************************************************************
2461 #// <<< [ListUpIn_func] >>>
2462 #//*********************************************************************
2463 function ListUpIn_func()
2465 local PackagePath="$1"
2471 RightOfLastStr_func "$PackagePath" "." ; ext2="$g_Ret"
2472 LeftOfLastStr_func "$PackagePath" "."
2473 RightOfLastStr_func "$g_Ret" "." ; ext1="$g_Ret"
2475 if [ x"$ext1" == x"tar" -a x"$ext2" == x"bz2" ];then
2476 bzip2 -dkc "$PackagePath" | tar t
2477 elif [ x"$ext1" == x"tar" -a x"$ext2" == x"gz" ];then
2478 tar tfz "$PackagePath"
2479 elif [ x"$ext1" != x"tar" -a x"$ext2" == x"gz" ];then
2480 LeftOfLastStr_func "$PackagePath" "." ; name="$g_Ret"
2482 elif [ "$ext2" == "zip" ];then
2483 unzip -l "$PackagePath" | sed -e "1,3d" -e '/^ *---/,$d' -e "s/.*:[0-9]* *//"
2484 CheckPipeStatus_func "${PIPESTATUS[@]}"
2486 Error_func ".$ext.$ext2 形式は、サポートしていません。"
2492 #//*********************************************************************
2493 #// <<< [ExpandWildcard_func] >>>
2494 #//*********************************************************************
2495 function ExpandWildcard_func()
2497 local out_FolderAbsPath="$2"
2498 local out_StepPaths="$3"
2501 local physical_folder__
2503 CheckMinArgCount_func 3 "$@"
2505 local locals="out_FolderAbsPath out_StepPaths list__ last__ physical_folder__ locals"
2506 CheckOutParamIsConflictToLocal_func $out_FolderAbsPath $locals
2507 CheckOutParamIsConflictToLocal_func $out_StepPaths $locals
2509 #//=== call ExpandWildcardSub_func
2510 list__=`ExpandWildcardSub_func "$@" `
2511 ArrayClass.fromLines_method $out_StepPaths "$list__" #//[out] $out_StepPaths
2513 #//=== get physical_folder__
2514 ArrayClass.getLength_method $out_StepPaths
2515 last__=$(( $g_Ret - 1 ))
2516 ArrayClass.get_method $out_StepPaths $last__ ; physical_folder__="$g_Ret"
2518 StringClass.length_method "$physical_folder__" ; length="$g_Ret"
2519 length=$(( $length + 1 ))
2521 ArrayClass.remove_method $out_StepPaths $last__
2523 #//=== get $out_FolderAbsPath
2524 last__=$(( $last__ - 1 ))
2525 ArrayClass.get_method $out_StepPaths $last__
2526 SetOutput_func $out_FolderAbsPath "$g_Ret"
2527 ArrayClass.remove_method $out_StepPaths $last__
2529 #//=== change to step_path
2530 for (( last__ = $last__ - 1 ; $last__ >= 0 ; last__ -- )) ;do
2531 ArrayClass.get_method $out_StepPaths $last__
2532 StringClass.substring_method "$g_Ret" $length
2533 if [ "$g_Ret" == "" ];then g_Ret="." ;fi
2534 ArrayClass.set_method $out_StepPaths $last__ "$g_Ret"
2539 function ExpandWildcardSub_func()
2541 local WildcardPath="$1"
2543 $declare_AssociativeArrayClass option
2546 local physical_folder
2551 local locals="WildcardPath arguments option a1 folder physical_folder options file_name all_type locals"
2552 CheckOutParamIsConflictToLocal_func $WildcardPath $locals
2554 GetLongOptions_func arguments option "$@" #//[out] arguments, option
2556 unset $out_StepPaths
2557 unset $out_StepPaths #// 配列をクリアするには2回必要?
2559 a1=`dirname "$WildcardPath"`
2560 if [ "$a1" == "" ];then a1="." ;fi
2561 GetAbsPath_func "$a1" ; folder="$g_Ret"
2562 readlink_func "$folder" ; physical_folder="$g_Ret"
2564 file_name=`basename "$WildcardPath"`
2566 Attr_func option "SubFolder"
2567 if [ "$g_Ret" == "" ];then
2568 options="${options} -maxdepth 1"
2573 Attr_func option "Folder"
2574 if [ "$g_Ret" == "1" ];then
2575 find "$physical_folder" $options -name "$file_name" -type d -print
2579 Attr_func option "File"
2580 if [ "$g_Ret" == "1" ];then
2581 find "$physical_folder" $options -name "$file_name" -type f -print
2585 Attr_func option "Link"
2586 if [ "$g_Ret" == "1" ];then
2587 find "$physical_folder" $options -name "$file_name" -type l -print
2591 if [ "$all_type" == "1" ];then
2592 find "$physical_folder" $options -name "$file_name" -print
2595 AssociativeArrayClass.destroy_method option
2597 echo "$physical_folder"
2602 #//*********************************************************************
2603 #// <<< [rm_func] >>>
2604 #//*********************************************************************
2607 local Paths=( "$@" )
2610 for path in "${Paths[@]}" ;do
2611 if [ "$path" != "" ];then
2612 CheckWritable_func "$path"
2614 if [ -d "$path" ]; then
2615 $g_TemporarySudo chmod -R a+rw "$path"
2616 $g_TemporarySudo rm -rf "$path"
2617 elif [ -f "$path" ]; then
2618 $g_TemporarySudo chmod a+rw "$path"
2619 $g_TemporarySudo rm -f "$path"
2620 elif [ -e "$path" -o -L "$path" ]; then
2621 $g_TemporarySudo rm -f "$path"
2629 #//*********************************************************************
2630 #// <<< [mkdir_func] >>>
2631 #//*********************************************************************
2632 function mkdir_func()
2635 CheckArgCount_func 1 "$@"
2637 CheckWritable_func "$Path"
2639 if [ ! -d "$Path" ];then
2640 $g_TemporarySudo mkdir -p "$Path"
2646 #//*********************************************************************
2647 #// <<< [chmod_x_func] >>>
2648 #//*********************************************************************
2649 function chmod_x_func()
2651 local FolderPath="$1"
2653 local UnsetPaths="$3"
2660 ArrayClass.fromCSV_method wildcards "$SetPaths" #//[out] wildcards
2661 for wildcard in "${wildcards[@]}" ;do
2662 if [ "$wildcard" != "." ];then
2663 ExpandWildcard_func "$work_folder/$wildcard" folder step_paths --File --SubFolder #//[out]folder, step_paths
2664 for path in "${step_paths[@]}" ;do
2665 echo "chmod +x \"$folder/$path\""
2666 chmod +x "$folder/$path"
2671 ArrayClass.fromCSV_method wildcards "$UnsetPaths" #//[out] wildcards
2672 for wildcard in "${wildcards[@]}" ;do
2673 if [ "$wildcard" != "." ];then
2674 ExpandWildcard_func "$work_folder/$wildcard" folder step_paths --File --SubFolder #//[out]folder, step_paths
2675 for path in "${step_paths[@]}" ;do
2676 echo "chmod -x \"$folder/$path\""
2677 chmod -x "$folder/$path"
2685 #//*********************************************************************
2686 #// <<< [MakeSymbolicLink_func] >>>
2687 #//*********************************************************************
2688 function MakeSymbolicLink_func()
2690 local LinkSrcPath="$1"
2692 CheckArgCount_func 2 "$@"
2694 CheckWritable_func "$LinkSrcPath"
2696 if [ -d "$LinkSrcPath" ];then
2697 if [ -L "$LinkSrcPath" ];then
2699 $g_TemporarySudo ln -s "$Target" "$LinkSrcPath"
2701 Error_func "フォルダーが存在します"
2704 $g_TemporarySudo ln -sf "$Target" "$LinkSrcPath"
2710 #//*********************************************************************
2711 #// <<< [chown_it_and_parent_func] >>>
2712 #//*********************************************************************
2713 function chown_it_and_parent_func()
2717 if [ "$Owner" == "-R" ];then
2725 CheckWritable_func "$Path"
2727 GetParentAbsPath_func "$Path" ; parent="$g_Ret"
2729 if [ -e "$Path" ];then
2730 $g_TemporarySudo chown $Option "$Owner" "$Path"
2733 if [ ! -d "$parent" ];then
2734 $g_TemporarySudo mkdir -p "$parent"
2736 $g_TemporarySudo chown $Option "$Owner" "$parent"
2741 #//*********************************************************************
2742 #// <<< [AppKeyClass.newWritable_method] >>>
2743 #//*********************************************************************
2744 function AppKeyClass.newWritable_method()
2752 if [ "$AppKey" != "AppKey4293" ]; then Error_func "AppKeyClass.newWritable_method needs \$2 of Main_func" ;fi
2754 unset g_WritableFolders8920
2755 unset g_WritableFolders8920 #// 配列をクリアするには2回必要?
2758 for (( index = 0; index < ${#Args[@]}; index ++ ));do
2759 if [ "${Args[$index]}" != "" ];then
2760 GetAbsPath_func "${Args[$index]}"
2761 g_WritableFolders8920[$count]="$g_Ret"
2762 count=$(( $count + 1 ))
2769 #//*********************************************************************
2770 #// <<< [CheckWritable_func] >>>
2771 #//*********************************************************************
2772 function CheckWritable_func()
2775 CheckArgCount_func 1 "$@"
2780 GetAbsPath_func "$Path" "$PWD" ; Path="$g_Ret"
2782 if [ "$g_WritableFolders8920" == "" ]; then \
2783 Error_func "<ERROR msg=\"Not call AppKeyClass.newWritable_method\" Path=\"$Path\"/>" ;fi
2784 for writable in ${g_WritableFolders8920[@]};do
2785 if [ "${Path%%$writable*}" == "" ]; then is_break=1 ; break ;fi
2787 if [ ! "$is_break" == "1" ]; then
2788 Error_func "<ERROR msg=\"AppKeyClass.newWritable_method による書き込み許可がされていません。\"" \
2789 "Path=\"$Path\" Writable=\"$g_WritableFolders8920\"/>"
2795 #//*********************************************************************
2796 #// <<< [EchoTestStart_func] >>>
2797 #//*********************************************************************
2798 function EchoTestStart_func()
2801 if [ "${#args[@]}" == "0" ];then
2803 echo "((( ${FUNCNAME[1]} )))"
2812 #//*********************************************************************
2813 #// <<< [debugger] >>>
2814 #//*********************************************************************
2822 g_DebugTrapFunc="StepRunning_func"
2824 trap 'DebugTrap_func "$LINENO" "$BASH_COMMAND" "${PIPESTATUS[@]}"
2825 #// resume ${PIPESTATUS[@]}
2826 case "${#g_PipeStatus[@]}" in
2828 return ${g_PipeStatus[0]} | true;;
2830 return ${g_PipeStatus[0]} | return ${g_PipeStatus[1]} | true;;
2834 function StepRunning_func()
2837 local Command__="$2"
2839 g_PipeStatus=( "$@" )
2844 if [ "$step_running_guided" == "" ]; then
2845 ErrClass.getCallTree_method "$LINENO" 2 1
2847 echo "--- デバッガ情報 -------------------------" >&2
2848 echo "ステップ実行 … Enter キーを押してください" >&2
2849 echo "変数の値を表示 … 変数名を入力" >&2
2850 echo "------------------------------------------" >&2
2853 echo "${FUNCNAME[2]}() ${BASH_SOURCE[2]}:${BASH_LINENO[1]}" >&2
2854 key__="goto_in_while"
2855 while [ "$key__" != "" ]; do
2856 read -p "$LineNo__: $Command__ " key__ #// break at the line
2858 #// inspect variable's value
2859 if [ "$key__" != "" ]; then
2862 "LineNo__" | "Command__" | "key__" | "a1__" )
2863 echo "変数 $key__ の値の表示はサポートしていません。";;
2866 CheckOutParamIsConflictToLocal_func key__
2868 key__=${key__/$/} #// cut first $, if exists
2869 es $key__ #// call es function
2875 step_running_guided=1
2880 #//*********************************************************************
2882 #//*********************************************************************
2885 local ExpressionArray__=("$@")
2886 local Expression__="$@"
2889 echo "ec> ${FUNCNAME[1]}() ${BASH_SOURCE[1]}(${BASH_LINENO[0]})" >&2
2890 if [ "${#ExpressionArray__[@]}" != "0" ];then
2892 CheckEvalParamIsConflictToLocal_func "$Expression__" ExpressionArray__ Expression__ evaled__
2894 evaled__=`eval echo "\"""$Expression__""\""`
2895 if [ "$Expression__" == "$evaled__" ];then
2896 echo "ec> \"$Expression__\"" >&2
2898 echo "ec> \"$Expression__\" == '""$evaled__""'" >&2
2905 #//*********************************************************************
2907 #//*********************************************************************
2916 if [ "$g_ExitStatus" == "0" ];then
2917 CheckArgCount_func 1 "$@"
2919 CheckOutParamIsConflictToLocal_func "$Name__" Name__ keys__ value__ index__
2922 eval keys__=( '"${!'"$Name__"'[@]}"' )
2925 if [ x"$keys__" == x"" -o x"$keys__" == x"0" ];then is__=1 ;fi
2927 if [ "${#keys__[@]}" -le "1" -a "$is__" == "1" ];then
2928 eval value__='"${'"$Name__"'}"'
2929 StringClass.indexOf_method "$Name__" "["
2930 if [ "$g_Ret" -ge "0" ];then
2931 echo -n 'Dump "${'"$Name__"}'" == ' >&2
2933 echo -n 'Dump "$'"$Name__"'" == ' >&2
2935 echo "'""$value__""'" >&2
2936 if [ "$value__" == "" ];then
2937 echo "00000000 ||" >&2
2940 echo -n "$value__" | hexdump -C >&2
2942 #// hexdump -C <<< "$value__" >&2
2944 for index__ in "${keys__[@]}" ;do
2945 es $Name__[$index__]
2952 #//*********************************************************************
2953 #// <<< [Error_func] >>>
2954 #//*********************************************************************
2955 function Error_func()
2957 ErrClass.getErrStr_method "$@" ; g_Err_Desc="$g_Ret"
2963 #//*********************************************************************
2964 #// <<< [return_func] >>>
2965 #//*********************************************************************
2966 function return_func()
2968 if [ "$g_Err_LineNo" == "???" ];then g_Err_LineNo=${BASH_LINENO[0]} ;fi
2974 #//*********************************************************************
2975 #// <<< [CheckPipeStatus_func] >>>
2976 #//*********************************************************************
2977 function CheckPipeStatus_func()
2979 local pipe_status="$@"
2982 for state in ${pipe_status[@]};do
2983 if [ "$state" != "0" ]; then
2984 echo '${PIPESTATUS[@]} = '"${pipe_status[@]}" >&2
2985 g_Err_LineNo=${BASH_LINENO[0]}
2993 #//*********************************************************************
2994 #// <<< [CheckArgCount_func] >>>
2995 #//*********************************************************************
2996 function CheckArgCount_func()
2998 local RequestArgumentCount="$1"
3000 local Arguments=( "$@" )
3003 if [ "${#Arguments[@]}" -ne "$RequestArgumentCount" ];then
3004 str="パラメーターの数が合っていません。 指定=${#Arguments[@]}, 要求=$RequestArgumentCount,"
3005 str="$str コマンドライン: ${FUNCNAME[1]} ${Arguments[@]}"
3012 #//*********************************************************************
3013 #// <<< [CheckMinArgCount_func] >>>
3014 #//*********************************************************************
3015 function CheckMinArgCount_func()
3017 local RequestArgumentCount="$1"
3019 local Arguments=( "$@" )
3020 if [ "${#Arguments[@]}" -lt "$RequestArgumentCount" ];then
3021 echo "パラメーターが少なすぎます。 指定=${#Arguments[@]}, 要求=$RequestArgumentCount" >&2
3022 echo "コマンドライン: ${FUNCNAME[1]} ${Arguments[@]}" >&2
3029 #//*********************************************************************
3030 #// <<< [CheckMaxArgCount_func] >>>
3031 #//*********************************************************************
3032 function CheckMaxArgCount_func()
3034 local RequestArgumentCount="$1"
3036 local Arguments=( "$@" )
3037 if [ "${#Arguments[@]}" -gt "$RequestArgumentCount" ];then
3038 echo "パラメーターが多すぎます。 指定=${#Arguments[@]}, 要求=$RequestArgumentCount" >&2
3039 echo "コマンドライン: ${FUNCNAME[1]} ${Arguments[@]}" >&2
3046 #//*********************************************************************
3047 #// <<< [CheckOutParamIsConflictToLocal_func] >>>
3048 #//*********************************************************************
3049 function CheckOutParamIsConflictToLocal_func()
3051 local OutParamName__="$1"
3053 local LocalNames__=( "$@" )
3057 if [ "$OutParamName__" == "" ];then Error_func "出力変数名が指定されていません" ;fi
3059 for name__ in "${LocalNames__[@]}" ;do
3060 if [ "$OutParamName__" == "$name__" ];then
3061 a1__="<ERROR msg=\"ローカル変数名が衝突しています\" "
3062 a1__="${a1__}local=\"$name__\"/>"
3070 #//*********************************************************************
3071 #// <<< [CheckEvalParamIsConflictToLocal_func] >>>
3072 #//*********************************************************************
3073 function CheckEvalParamIsConflictToLocal_func()
3075 local EvalExpression="$1"
3077 local LocalNames=( "$@" )
3081 for name in "${LocalNames[@]}" ;do
3082 if [ "${EvalExpression%%$name*}" != "$EvalExpression" ];then
3083 s="<ERROR msg=\"ローカル変数名が衝突している可能性があります\" "
3084 s="${s}local=\"$name\"/>"
3092 #//*********************************************************************
3093 #// <<< [Assert_func] >>>
3094 #//*********************************************************************
3095 function Assert_func()
3097 local Expression__="$*"
3102 eval ' if [ '"$Expression__"' ]; then is_pass__=1 ;else is_pass__=0 ;fi '
3104 if [ "$is_pass__" == "0" ];then result__="`eval echo "$Expression__"`" ;fi
3106 if false; then #// ture, if debug
3107 echo "<Assert_func" >&2
3108 echo "Expression__='$Expression__'" >&2
3109 echo "result__='$result__'" >&2
3110 echo "is_pass__='$is_pass__'/>" >&2
3113 if [ "$is_pass__" == "0" ];then
3114 message__=`echo -n "<ERROR msg=\"Assert failed\"><Expression><![CDATA[${LF}$Expression__${LF}]]></Expression>"`
3115 if [ "$Expression__" != "$result__" ];then
3116 message__="$message__"`echo -n "<Result><![CDATA[${LF}$result__${LF}]]></Result>"`
3118 message__="$message__</ERROR>"
3119 Error_func "$message__"
3125 #//*********************************************************************
3126 #// <<< [TryStart_func] >>>
3127 #// <<< [TryEnd1_func] >>>
3128 #// <<< [TryEnd2_func] >>>
3129 #//*********************************************************************
3130 function TryStart_func()
3133 g_Err_NestLevel=$(( $g_Err_NestLevel + 1 ))
3136 function TryEnd1_func()
3141 function TryEnd2_func()
3143 CheckArgCount_func 1 "$@"
3144 if [ "$g_ExitStatus" == "0" ];then
3147 g_Err_NestLevel=$(( $g_Err_NestLevel - 1 ))
3148 g_Err_Desc1st="$g_Err_Desc"
3153 #//*********************************************************************
3154 #// <<< [ErrTrap_func] >>>
3155 #//*********************************************************************
3171 function ErrTrap_func()
3175 if [ "$g_Err_IsDone" == "1" ];then
3177 elif [ "$g_Err_IsOverwrite" == "1" ];then
3181 g_Err_ErrID=$(( $g_Err_ErrID + 1 ))
3183 if [ "$g_ExitStatus" == "0" ];then
3184 if [ "$g_Err_LineNo" == "???" ];then g_Err_LineNo=$1 ;fi
3185 if [ "$g_Err_LineNo" == "???" ]; then
3186 a1="${a1}(ヒント)現在の行番号は、${FUNCNAME[1]} 関数の最初で \"EchoOn_func\" を呼ぶと表示されます。${LF}"
3188 a1="${a1}(開発者向けヒント)ステップ実行したいときは、開始するところから \"debugger\" 関数を呼び出してください。 "
3189 a1="${a1}下記コールツリーの最も下の関数が、\` \` を使って echo 出力を取得しているときは、取得しないようにすると、更にコール先の関数が表示されます。${LF}"
3190 ErrClass.getCallTree_method "$g_Err_LineNo" 2 1
3191 g_Err_ErrCallStack="$a1$g_Ret$LF"
3193 echo "<ERROR msg=\"エラー処理中に別のエラーが発生しました。\"/>" >&2
3195 ErrClass.getErrStr_method "$g_Err_Desc"
3196 if [ "$g_Ret" == "" ];then g_Ret="<ERROR/>" ;fi
3197 ColorText_func "$g_Ret" "Red" "Bold"
3198 echo_e_func "$g_Ret"
3200 ErrClass.getCallTree_method "${BASH_LINENO[0]}" 2 1
3202 g_Err_Desc="$g_Err_Desc1st"
3209 #//*********************************************************************
3210 #// <<< [done_func] >>>
3211 #//*********************************************************************
3212 function done_func()
3214 CheckArgCount_func 1 "$@"
3215 if [ "$1" != "0" ];then g_Err_IsDone=1 ;fi
3216 return "$1" #// if not 0, throw again
3221 #//*********************************************************************
3222 #// <<< [ErrClass.raiseOverwrite_method] >>>
3223 #//*********************************************************************
3224 function ErrClass.raiseOverwrite_method()
3226 local message ; ErrClass.getErrStr_method "$@" ; message="$g_Ret"
3227 local exit_status="$g_ExitStatus"
3229 if [ "$message" != "" ];then
3230 g_Err_Desc="$message"
3233 if [ "$exit_status" == "0" ];then
3243 #//*********************************************************************
3244 #// <<< [ErrClass.clear_method] >>>
3245 #//*********************************************************************
3246 function ErrClass.clear_method()
3257 #//*********************************************************************
3258 #// <<< [ErrClass.getErrStr_method] >>>
3259 #//*********************************************************************
3260 function ErrClass.getErrStr_method()
3264 if [ "$Message" != "" ]; then
3265 if [ "${Message%%<ERROR *}" == "" ]; then
3268 StringClass.replace_method "$Message" "&" "&"
3269 StringClass.replace_method "$g_Ret" "<" "<"
3270 StringClass.replace_method "$g_Ret" "\"" """
3271 g_Ret="<ERROR msg=\"$g_Ret\"/>"
3280 #//*********************************************************************
3281 #// <<< [ErrClass.getCallTree_method] >>>
3282 #//*********************************************************************
3283 function ErrClass.getCallTree_method()
3287 local IsAbleLastCut="$3"
3292 i=$(( ${#FUNCNAME[@]} - 1 ))
3293 s="$s${LF}""(global) ${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]}"
3294 for(( i=${#FUNCNAME[@]} - 2; i > $TopIndex; i-- ));do
3295 s="$s${LF}${indent}${FUNCNAME[$i]}() ${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]}"
3299 case "${FUNCNAME[$TopIndex]}" in
3300 "Error_func" | "DebugTrap_func" ) ;;
3301 *) IsAbleLastCut=0 ;;
3303 if [ "$IsAbleLastCut" != "1" ];then
3304 if [ "$g_DebugTrapFunc" == "EchoOnTrap_func" ];then
3305 s="$s${LF}${indent}${FUNCNAME[$TopIndex]}() ${BASH_SOURCE[$TopIndex]}:$LineNo ?(->EchoOn_func)"
3307 s="$s${LF}${indent}${FUNCNAME[$TopIndex]}() ${BASH_SOURCE[$TopIndex]}:$LineNo"
3315 #//*********************************************************************
3316 #// <<< [Exit_func] >>>
3317 #//*********************************************************************
3318 function Exit_func()
3327 #//*********************************************************************
3328 #// <<< [g_ArrayLength] >>>
3329 #//*********************************************************************
3334 #//*********************************************************************
3335 #// <<< [g_AssociativeArrayMaxLength] >>>
3336 #//*********************************************************************
3337 if [ "$g_AssociativeArrayMaxLength" == "" ];then g_AssociativeArrayMaxLength=100 ;fi
3339 g_AssociativeArrayLength=0
3340 for (( i = 0; i < $g_AssociativeArrayMaxLength; i ++ ));do
3341 $declare_AssociativeArrayClass g_AssociativeArrays_$i
3346 #//*********************************************************************
3349 #//*********************************************************************
3350 LF=`echo_e_func "\nx"`; LF="${LF:0:1}"
3351 Tab=`echo_e_func "\t"`