#!/bin/sh

cols="footprint,devmap,bom-pn-lcsc,footprint-todo,devmap-todo"

fptool()
{
	awk -v cols="$cols" '
		BEGIN {
			split("@," cols, COLS, ",")
		}

		{
			name = $1
			for(n = 2; n <= NF; n++)
				ATTR[COLS[n]] = $n

			if (ATTR["footprint"] == "-") {
				print $0
			}
		}
	'
}

help()
{
echo 'sch-rnd-fptool - print missing footprints
Syntax: sch-rnd-fptool <files>

Print a TSV list of abstract components with missing footprint attribute.
'
}


# process command line arguments
original_count=$#

# Iterate exactly once through the original set
i=0
while test "$i" -lt "$original_count"
do
	case "$1" in
		--help)       help; exit 0;;
	*)
		# append anything else to the END of the parameter list.
		arg="$1"
		shift 1
		set -- "$@" "$arg"
	;;
	esac
	i=$((i + 1))
done

# now $@ contains only arguments we did not remove; run the export on it
sch-rnd-abst2tsv --omit-nets --cols "$cols" "$@" | fptool
