#!/bin/echo Source me: .
#
# Copyright (c) 2002-2004 by Frederick Bruckman
# All rights reserved.

# Takes awk-style regular expressions or <category>/<subdirectory> specs
# as arguments. Anything with a slash is taken to be a "dir" spec, and
# must match an existing package exactly; anything without is tested as a
# regular expression against the package names. Emits a list of matching
# <category>/<subdirectory> pairs to standard out.
#
canonify () {
	awk '
		BEGIN {
			for (i = 1; i < ARGC - 1; i++) {
				if (ARGV[i] ~ /\//)
					dirs[ARGV[i]] = 0
				else
					wildcards[ARGV[i]] = 0
				ARGV[i] = ""
			}
		}
		{
			if ($1 in dirs) {
				print $1
				next
			}
			for (wildcard in wildcards)
				if (match($2, wildcard)) {
					print $1
					next
				}
		}
	' "$@" "${PKGORDERDIR}"/dir_to_pkgname
}
