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

# Extracts the settings for a given joystick from the joystick
# parameter file, 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.
# The exit code is 0 if a section was found, 1 otherwise. If multiple
# sections match, only the first is kept.

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

/^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, output the command or exit if we've
	# reached the end of the section
	if ($0 ~ /^js/) {
	    print $0;
	} else {
	    exit 0;
	}
    }
}