Skip to content

Commit

Permalink
Making sure function definitions happen at the right scope
Browse files Browse the repository at this point in the history
  • Loading branch information
kristopolous committed Jun 26, 2016
1 parent 03f9a1c commit 4f21807
Showing 1 changed file with 55 additions and 58 deletions.
113 changes: 55 additions & 58 deletions ticktick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -374,61 +374,58 @@ __tick_fun_tokenize() {
}

## Runtime {
enable -n source
enable -n .
source() {
# echo "loading "$1
source_temp_path=`mktemp`
__tick_fun_tokenize "$1" "debug"
( __tick_fun_tokenize "$1" "debug" ) > $source_temp_path

echo $source_temp_path
#unlink $source_temp_path
#builtin . "$1"
}
.() {
source "$1"
}
__tick_runtime_length() { echo $#; }
__tick_runtime_first() { echo ${!1}; }
__tick_runtime_last() { eval 'echo $'${!#}; }
__tick_runtime_pop() { eval unset ${!#}; }

__tick_runtime_shift() {
local left=
local right=

for (( i = 1; i <= $# + 1; i++ )) ; do
if [ "$left" ]; then
eval "$left=\$$right"
fi
left=$right
right=${!i}
done
eval unset $left
}
__tick_runtime_push() {
local value="${1/\'/\\\'}"
local base=$2
local lastarg=${!#}

let nextval=${lastarg/$base/}+1
nextval=`printf "%012d" $nextval`

eval $base$nextval=\'$value\'
}

tickParse() {
eval `echo "$1" | __tick_json_tokenize | __tick_json_parse | tr '\n' ';'`
}

tickVars() {
echo "@ Line `caller | sed s/\ NULL//`:"
set | grep ^__tick_data | sed s/__tick_data_/" "/
echo
}

## } End of Runtime


[ $__tick_var_tokenized ] || __tick_fun_tokenize
if [ $__tick_var_tokenized ]; then
enable -n source
enable -n .
source() {
source_temp_path=`mktemp`
( __tick_fun_tokenize "$1" "debug" ) > $source_temp_path

builtin source "$source_temp_path"
unlink $source_temp_path
}
.() {
source "$1"
}

__tick_runtime_length() { echo $#; }
__tick_runtime_first() { echo ${!1}; }
__tick_runtime_last() { eval 'echo $'${!#}; }
__tick_runtime_pop() { eval unset ${!#}; }

__tick_runtime_shift() {
local left=
local right=

for (( i = 1; i <= $# + 1; i++ )) ; do
if [ "$left" ]; then
eval "$left=\$$right"
fi
left=$right
right=${!i}
done
eval unset $left
}
__tick_runtime_push() {
local value="${1/\'/\\\'}"
local base=$2
local lastarg=${!#}

let nextval=${lastarg/$base/}+1
nextval=`printf "%012d" $nextval`

eval $base$nextval=\'$value\'
}

tickParse() {
eval `echo "$1" | __tick_json_tokenize | __tick_json_parse | tr '\n' ';'`
}

tickVars() {
echo "@ Line `caller | sed s/\ NULL//`:"
set | grep ^__tick_data | sed s/__tick_data_/" "/
echo
}
else
__tick_fun_tokenize
fi

0 comments on commit 4f21807

Please sign in to comment.