local -A loaded
local ffile fname xtrace

# disable tracing for noisy part
! [[ -o xtrace ]]; xtrace=$?
(($xtrace)) && set +x

# check which autoloadable functions are loaded
for ffile in $^fpath/*(.N); do
	fname=$ffile:t
	if (($+functions[$fname])) && \
		[[ $functions[$fname] != 'builtin autoload -XU' ]] && \
		! (($+loaded[$fname])); then
		loaded[$fname]=$ffile
	fi
done

# restore tracing
(($xtrace)) && set -x

# print service's script file, explicit restart files and autoloaded
# functions into restart.files
print -rl - $svtab_src[$zsv_name] $restart_files $loaded >$zsv_dir/restart.files

# add the executable to restart.files
if [[ $run[1] == /* ]]; then
	# absolute path
	print -r - $run[1] >>$zsv_dir/restart.files
elif (($+commands[$run[1]])); then
	# command found in path
	print -r - $commands[$run[1]] >>$zsv_dir/restart.files
fi

if (($#reload_files)); then
	print -rl - $reload_files >$zsv_dir/reload.files
elif [[ -e $zsv_dir/reload.files ]]; then
	rm -f $zsv_dir/reload.files
fi
# vim: ft=zsh noet ts=4 sts=4 sw=4