#!/bin/bash

ninstalled=0
installed=
for p in `qlist -IC`; do
	installed[ninstalled]=$p
	let ninstalled++
done

idx=0
cd /usr/portage/ || exit -1
dir_list=`ls -1 --color=never -d *-*/ virtual/ | sed 's~/$~~' | sort`
for d in $dir_list ; do
	d=${d%/}
	if [[ `qlist -IC $d | wc -l` == 0 ]]; then
		echo $d/
	else
		pn_list=`ls -1 --color=never -d ${d}/*/ | sed 's~/$~~' | sort`
		for pn in $pn_list; do
			pn=${pn%/}
			
			while [[ "${installed[$idx]}" < "$pn" && $idx -lt $ninstalled ]]; do
				let idx++
			done

			if [[ "$pn" == "${installed[$idx]}" ]]; then
				let idx++
			else
				echo $pn/
			fi
		done
	fi
done

