Paste number 96719: xh.sh

Paste number 96719: xh.sh
Pasted by: tziker
When:1 year, 10 months ago
Share:Tweet this! | http://paste.lisp.org/+22MN
Channel:None
Paste contents:
Raw Source | XML | Display As
#!/bin/ksh -p

export LANG=C
export LC_ALL=C
unset LC_CTYPE LC_COLLATE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME

CLEANFILES=""

function msg
{
	local text="$*"
	echo "$text" >&2
}

function cleanup
{
	if test -n "${CLEANFILES}" ; then
		for fname in ${CLEANFILES} ; do
			rm -f "${file}"
		done
	fi
}
trap "cleanup ; exit 0" 0
trap "msg 'Interrupted.' ; cleanup ; exit 1" 1 2 15

TMPFILE=$(mktemp "/tmp/xh.$$.XXXX")
if test $? -ne 0 ; then
	msg "cannot create temp page file"
	exit 1
else
	CLEANFILES="${CLEANFILES} ${TMPFILE}"
fi

function err
{
	local rc=$1
	shift
	local msg="$*"

	echo "error: ${msg}" >&2
	exit ${rc}
}

function dopage
{
	local flist="$1"
	local page="$2"

	test -z "${flist}" && err 1 "dopage: no flist"
	test -z "${page}" && err 1 "dopage: no page url"
	msg "fetching page ${page}"
	wget -q -nd -np -O "${TMPFILE}" "${page}"
	if test $? -ne 0 ; then
		msg "cannot fetch page ${page}"
		return 1
	fi
	srv=$( expand "${TMPFILE}" | \
	    sed -n -e "/'srv'/ s/.*'srv'[ ]*:[ ]*'\\([^']*\\)'.*/\\1/p" )
	file=$( expand "${TMPFILE}" | \
	    sed -n -e "/'file'/ s/.*'file'[ ]*:[ ]*'\\([^']*\\)'.*/\\1/p" )

	if test -z "${srv}" ; then
		msg "no server object"
		return 1
	fi
	if test -z "${file}" ; then
		msg "no file object"
		return 1
	fi

	echo "${srv}/flv2/${file}"
	return 0
}

function doflist
{
	local flist="$1"

	test -z "${flist}" && err 1 "doflist: no flist"
	while read page ; do
		dopage "${flist}" "${page}"
	done < "${flist}"
}

for flist in "$@" ; do
	doflist "${flist}"
done

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.