Blob Blame History Raw
#!/usr/bin/awk -f

# Filters the joystick parameter file, keeping everything but sections
# matching the contents of the kernel, name, serial, vendor and
# product variables (typically specified on the command line),
# repectively kernel device, joystick name, joystick serial number,
# USB vendor code, USB product code.

BEGIN {
    FS = "\"";
    seckernel = "";
    secname = "";
    secserial = "";
    secvendor = "";
    secproduct = "";
    secoutput = 0;
}

/^DEVICE=/ {
    seckernel = $2;
}

/^NAME=/ {
    secname = $2;
}

/^SERIAL=/ {
    secserial = $2;
}

/^VENDOR=/ {
    secvendor = $2;
}

/^PRODUCT/ {
    secproduct = $2;
}

/(^js)|(^$)/ {
    # Command or empty line, ends the match criteria for a given
    # section
    if ((kernel == "" || seckernel == kernel) &&
	(name == "" || secname == name) &&
	(serial == "" || secserial == serial) &&
	(vendor == "" || secvendor == vendor) &&
	(product == "" || secproduct == product)) {
	# The section matches, skip it
    } else {
	# The section doesn't match, output it
	if (secoutput == 0) {
	    if (seckernel != "") {
		print "DEVICE=\"" seckernel "\"";
	    }
	    if (secname != "") {
		print "NAME=\"" secname "\"";
	    }
	    if (secserial != "") {
		print "SERIAL=\"" secserial "\"";
	    }
	    if (secvendor != "") {
		print "VENDOR=\"" secvendor "\"";
	    }
	    if (secproduct != "") {
		print "PRODUCT=\"" secproduct "\"";
	    }
	    secoutput = 1;
	}
	print $0;
	if ($0 ~ /$^/) {
	    # New section, clear the section information
	    secoutput = 0;
	    seckernel = "";
	    secname = "";
	    secserial = "";
	    secvendor = "";
	    secproduct = "";
	}
    }
}