~sourcemage/sorcery

4f36610e9dc99c6f2c8a982d7e918f8e1ea5e57e — Ismael Luceno 1 year, 3 months ago 248845a
sightsee: Improve parsing

Make so that the Watch line can come in any order; it was confusing before
because it needed to happen after VERSION was defined.
1 files changed, 16 insertions(+), 11 deletions(-)

M usr/lib/sorcery/cmd/sightsee
M usr/lib/sorcery/cmd/sightsee => usr/lib/sorcery/cmd/sightsee +16 -11
@@ 57,14 57,9 @@ else
fi

find "${paths[@]}" -name DETAILS -exec awk '
	function check_missing() {
		if (spell != "")
		printf "E: %s: Upstream releases page not specified\n", \
			spell >"/dev/stderr"
	}
	END { check_missing() }
	END { print_spell() }
	FNR==1 {
		check_missing()
		if (spell != "") print_spell()
		spell = FILENAME
		sub(/\/DETAILS$/, "", spell)
		sub(/.*\//, "", spell)


@@ 72,16 67,26 @@ find "${paths[@]}" -name DETAILS -exec awk '
	/^ *VERSION=/ {
		version = $0
		sub(/.*=/, "", version)
		if (watch_url != "") nextfile
	}
	/^#Watch:/ {
		watch_url = $2
		watch_regex = $3
		# TODO check syntax
		print spell, version, $2, $3
		spell = ""
		nextfile
		if (version != "") nextfile
	}
	function print_spell() {
		if (watch_url == "") {
			printf "E: %s: %s\n", spell, \
				"Upstream releases page not specified" \
				>"/dev/stderr"
		}
		print spell, version, watch_url, watch_regex
		version = watch_url = spell = ""
	}
  ' {} + |
while read spell cur_rel url regex; do
  latest_rel=$(upstream_rel_get "$url" "$regex") &&
  latest_rel=$(upstream_rel_get "$url" "$regex") || continue
  if [ "x$latest_rel" != "x$cur_rel" ]; then
    echo "$spell $latest_rel"
  elif [ -n "$verbose" ]; then