Menu

[377ccc]: / source / assume.sh  Maximize  Restore  History

Download this file

88 lines (63 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
include defaults.sh
include log.sh
include misc.sh
include null.sh
include useextglob.sh
#
# assume.sh
#
# Author: konsolebox
# Copyright free
# Created and updated 2008-2012
#
# void assume (string <expression>, [meta <arg>, ...], ["--", string <info>, ...])
#
function assume {
eval "[[ $1 ]] 2>&$NULL" || assume_reportfailure "$@"
}
# void assume_reportfailure (...)
#
function assume_reportfailure {
log_fcall "$@"
# EXPR
local EXPR=$1
shift
# INFO and ARGS
local -a INFO=() ARGS=()
local -i I J
for (( I = $#; I; --I )); do
[[ ${!I} = -- ]] && break
done
if [[ I -gt 0 ]]; then
INFO=("${@:I + 1}")
ARGS=("${@:1:I - 1}")
else
ARGS=("$@")
fi
# MESSAGE
local -a MESSAGE=()
local -i L=0
local IFS=$DEFAULTS_IFS
MESSAGE[L++]="Expression $EXPR failed in function ${FUNCNAME[2]}()."
if [[ ${#INFO[@]} -gt 0 ]]; then
MESSAGE[L++]=''
MESSAGE[L++]='Info:'
MESSAGE[L++]=''
MESSAGE[L++]=$'\t'"${INFO[*]}"
fi
if [[ ${#ARGS[@]} -gt 0 ]]; then
MESSAGE[L++]=''
MESSAGE[L++]='Arguments:'
MESSAGE[L++]=''
for I in "${!ARGS[@]}"; do
MESSAGE[L++]=$'\t$'$(( I + 2 ))": \"${ARGS[I]}\""
done
fi
IFS=$'\n'
dumpvariables
MESSAGE[L++]=''
MESSAGE[L++]="Variables dumped in \"$__\"."
$GLOBALS_USERLOGDIR/variables.dump
log_fatalerror "${MESSAGE[*]}"
exit 1
}