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

# This builds the transpose of the dependencies list, so whereas
# a record in the first argument lists all the packages required
# to build the key package, a record in the second argument
# will list all the packages which require the key package.
#
#     Argument #1: the name of the dir-to-dependencies file (input)
#     Argument #2: the name of the dir-to-dependents file (output)
#
transpose_deps () {
	echo "Transposing dependencies list..." >> /dev/tty
	awk -v dir2dependents_idx="$2" '
	{
		for (i=2; i<=NF; i++) {
			if ($i in dirs)
				dirs[$i] = dirs[$i] OFS $1
			else
				dirs[$i] = $1
		}
	}
	END {
		for (dir in dirs) {
			tabs = ""
			numtabs = 5 - int(length(dir) / 8)
			while (numtabs--)
				tabs = tabs "\t"
			print dir tabs dirs[dir] > dir2dependents_idx
		}
	}' "$1"
}
