#!/bin/sh
# load config (evaluate shellscript).
# loadconfig(configfile)
loadconfig() {
# allow to specify config via argv[1].
if [ ! x"$1" = x"" ]; then
# get absolute path of config file.
config=$(readlink -f "$1")
else
# default config location.
config="$HOME/.sfeed/sfeedrc"
fi
# load config: config is loaded here to be able to override above variables
# (sfeedpath, sfeedfile, etc).
if [ -r "$config" ]; then
. "$config"
else
echo "Configuration file \"$config\" does not exist or is not readable." >&2
exit 1
fi
}
# escape(s)
escape() {
printf '%s' "$1" | sed -e 's@"@\"@g' -e "s@'@\'@g"\
-e 's@<@\<@g' -e 's@>@\>@g'
}
# override feeds function to ouput opml XML.
# feed(name, feedurl, [basesiteurl], [encoding])
feed() {
name=$(escape "$1")
xmlurl=$(escape "$2")
htmlurl=$(escape "$3")
printf '\t\n' \
"${name}" "${name}" "${xmlurl}" "${htmlurl}"
}
# load config file.
loadconfig "$1"
cat <
opml export from sfeed
!
feeds
# wait till all items are processed (concurrently).
wait
cat <
!