#! /bin/sh

# Generate config file suilable for cardmgr using entries from a new
# style (Linux 2.6.13+) PCMCIA driver.
#
# Copyright (C) Pavel Roskin, 2005
# Licensed under GNU GPL version 2

output="$1"
shift
drivers="$@"

out ()
{
	echo "$@" >>$output
}

echo -n >$output

out "# This file was generated by `basename $0` from following drivers:"
out "# $drivers"
out

for file in $drivers; do
	drvname=`basename $file .c`
	out "device \"$drvname\""
	out "  class \"network\""
	out "  module \"hermes\", \"orinoco\", \"$drvname\""
	out
done

for file in $drivers; do
	drvname=`basename $file .c`
	lines="`sed -ne 's/.*\(PCMCIA_DEVICE_[^)]*)\).*/\1/p' $file`"
	IFS=$'\n'
	for line in $lines; do
		IFS=$' \n'
		manfid=`echo $line | sed 's/^[^(]*(\(.*\)).*$/\1/'`
		version=`echo $line | sed 's/^[^"]*\(".*"\)[^"]*$/\1/'`
		case $line in
		PCMCIA_DEVICE_MANF_CARD*)
			out "card \"$drvname\""
			out "  manfid $manfid"
			out "  bind \"$drvname\""
			out
			;;
		PCMCIA_DEVICE_PROD_ID12*)
			out "card \"$drvname\""
			out "  version $version"
			out "  bind \"$drvname\""
			out
			;;
		*)
			echo "not supported: $line"
			exit 1
		esac
	done
done

exit 0
