#!/usr/bin/perl
#
# Copyright (c) 2000 Neil Blakey-Milner
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

$ata = 0;

while (<>) {
	/^$/ && do { print; next };
	s/^(\w+[ \t]*)"([^"]+)"(.*)$/\1\2\3/;
	s/^(#?)(?:controller|disk)/\1device/;

	# ata stuff
	/options[ \t]+ATAPI(_STATIC)?[ \t]/ && next;
	/options[ \t]+CMD640[ \t]/ && next;
	s/^(#?)device[ \t]+wdc/\1device ata/ && $ata++;
	/^#?device[ \t]+wd[0-9]+/ && next;
	# victims of wdc*
	/^#?device[ \t]+(wfd|acd|wst)/ && next;
	if (!/ata/ && $ata > 0) {
		print <<EOF;
device          ata
device          atadisk                 # ATA disk drives
device          atapicd                 # ATAPI CDROM drives
device          atapifd                 # ATAPI floppy drives
device          atapist                 # ATAPI tape drives
options         ATA_STATIC_ID           #Static device numbering
#options        ATA_ENABLE_ATAPI_DMA    #Enable DMA on ATAPI devices
EOF
		$ata = -99;
	};
	s/^(#?device[ \t]*[a-z]+[0-9]?[^#]*)"([^"]*)"(.*)?$/\1\2\3/g;
	s/^(#?device[ \t]*[a-z]+[0-9]?[^#]*) (?:bio|conflicts|tty|cam|net)(.*)?$/\1\2/g;
	s/^(#?device[ \t]*[a-z]+[0-9]?[^#]*)(?:port ?\?)(.*)?$/\1\2/g;
	s/^(#?device[ \t]*[a-z]+[0-9]?[^#]*)(?:irq ?\?)(.*)?$/\1\2/g;
	s/^(#?device[ \t]*[a-z]+[0-9]?[^#]*)(?:at ppbus ?\?)(.*)?$/\1\2/g;
	s/^(device[ \t]*)([a-z]+)0([ \t]*(?:#.*)?)$/\1\2\3/;
	s/^(pseudo-device[ \t]*)(tun|pty)[ \t]*[0-9]+([ \t]*(?:#.*)?)$/\1\2\3/;
	s/^(pseudo-device[ \t]*)bpfilter [ \t]*[0-9]+([ \t]*(?:#.*)?)$/\1bpf\2/;
	s/^(options[ \t]*)MFS_ROOT([ \t]*(?:#.*)?)$/\1MD_ROOT\2/;

	s/^(device[ \t]*)(ida).*?$/\1\2/;
	/^(device[ \t]*)id[0-9]+/ && next;

	# no longer around devices
	/^#?device[ \t]+(al|ax|mx|pn|ze|zp)/ && next; # some network cards
	/^#?device[ \t]+(sctarg|olpt)/ && next;
	/^config/ && next;
	/^device[ \t]+pnp/ && next;
	/options[ \t]+(DPT_SHUTDOWN_SLEEP|DPT_INTR_DELAY|DPT_FREELIST_IS_STACK|DPT_RESTRICTED_FREELIST|DPT_VERIFY_HINTR|SCSI_NCR_DFLT_TAGS|KEY_DEBUG|AVM_A1_PCMCIA|AVM_PNP|ITKIX1|DYNALINK|ITKIX1|EXTRA_SIO|FDC_PRINT_BOGUS_CHIPTYPE|FDC_YE|STD8X16FONT|PSM_HOOKAPM|TUNE_1542|SCSI_REPORT_GEOMETRY|CD9660_ROOTDELAY|EXPORTMFS|VM86|MD5|LKM|FAILSAFE)/ && next;
	print;
}

