@@ -19,29 +19,10 @@ core.trap_add() {
19
19
fi
20
20
local function=" $1 "
21
21
22
- # Validation
23
- if [ -z " $function " ]; then
24
- core.panic ' First argument must not be empty'
25
- fi
26
-
27
- if (( $# <= 1 )) ; then
28
- core.panic ' Must specify at least one signal'
29
- fi
22
+ core.private.util.validate_args " $function " $#
30
23
for signal_spec in " ${@: 2} " ; do
31
- if [ -z " $signal_spec " ]; then
32
- core.panic ' Signal must not be an empty string'
33
- fi
34
-
35
- local regex=' ^[0-9]+$'
36
- if [[ " $signal_spec " =~ $regex ]]; then
37
- core.panic ' Passing numbers for the signal specs is prohibited'
38
- fi ; unset regex
39
- signal_spec=${signal_spec# SIG}
40
- if ! declare -f " $function " & > /dev/null; then
41
- core.panic " Function '$function ' is not defined"
42
- fi
24
+ core.private.util.validate_signal " $function " " $signal_spec "
43
25
44
- # Start
45
26
___global_trap_table___[" $signal_spec " ]=" ${___global_trap_table___[$signal_spec]} " $' \x1C ' " $function "
46
27
47
28
# rho (WET)
@@ -80,29 +61,10 @@ core.trap_remove() {
80
61
fi
81
62
local function=" $1 "
82
63
83
- # Validation
84
- if [ -z " $function " ]; then
85
- core.panic ' First argument must not be empty'
86
- fi
87
-
88
- if (( $# <= 1 )) ; then
89
- core.panic ' Must specify at least one signal'
90
- fi
64
+ core.private.util.validate_args " $function " $#
91
65
for signal_spec in " ${@: 2} " ; do
92
- if [ -z " $signal_spec " ]; then
93
- core.panic ' Signal must not be an empty string'
94
- fi
95
-
96
- local regex=' ^[0-9]+$'
97
- if [[ " $signal_spec " =~ $regex ]]; then
98
- core.panic ' Passing numbers for the signal specs is prohibited'
99
- fi ; unset regex
100
- signal_spec=" ${signal_spec# SIG} "
101
- if ! declare -f " $function " & > /dev/null; then
102
- core.panic " Function '$function ' is not defined"
103
- fi
66
+ core.private.util.validate_signal " $function " " $signal_spec "
104
67
105
- # Start
106
68
local -a trap_handlers=()
107
69
local new_trap_handlers=
108
70
IFS=$' \x1C ' read -ra trap_handlers <<< " ${___global_trap_table___[$signal_spec]}"
0 commit comments