#!/bin/sh -eu

. "${0%/*}"/functions

inp=
name=
case "${1-}" in
	name=*) name="${1#name=}" ;;
	*) inp="${1-}" ;;
esac

find "/sys/class/input/$inp/" -mindepth 1 -maxdepth 1 -printf '%h/%l\n' |
while read path; do
	if [ -n "$name" ]; then
		if [ -f "$path/name" ]; then
			read input_name < "$path/name"
			[ -z "${input_name##$name}" ] ||
				continue
		else
			continue
		fi
	fi
	process_device "$path/device"
done | sort -u
