Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Aug 2011 14:13:08 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r224578 - projects/hid/usr.bin/usbhidaction
Message-ID:  <201108011413.p71ED8Et000414@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Aug  1 14:13:08 2011
New Revision: 224578
URL: http://svn.freebsd.org/changeset/base/224578

Log:
  Add support for # in item name and substring matches following usbhidctl.

Modified:
  projects/hid/usr.bin/usbhidaction/usbhidaction.c

Modified: projects/hid/usr.bin/usbhidaction/usbhidaction.c
==============================================================================
--- projects/hid/usr.bin/usbhidaction/usbhidaction.c	Mon Aug  1 13:54:48 2011	(r224577)
+++ projects/hid/usr.bin/usbhidaction/usbhidaction.c	Mon Aug  1 14:13:08 2011	(r224578)
@@ -280,12 +280,11 @@ parse_conf(const char *conf, report_desc
 	char *p;
 	int line;
 	char buf[SIZE], name[SIZE], value[SIZE], debounce[SIZE], action[SIZE];
-	char usbuf[SIZE], coll[SIZE];
+	char usbuf[SIZE], coll[SIZE], *tmp;
 	struct command *cmd, *cmds;
 	struct hid_data *d;
 	struct hid_item h;
-	int u, lo, hi, range;
-	
+	int inst, cinst, u, lo, hi, range, t;
 
 	f = fopen(conf, "r");
 	if (f == NULL)
@@ -317,6 +316,12 @@ parse_conf(const char *conf, report_desc
 				     ", syntax error: %s", conf, line, buf);
 			}
 		}
+		tmp = strchr(name, '#');
+		if (tmp != NULL) {
+			*tmp = 0;
+			inst = atoi(tmp + 1);
+		} else
+			inst = 0;
 
 		cmd = malloc(sizeof *cmd);
 		if (cmd == NULL)
@@ -361,6 +366,7 @@ parse_conf(const char *conf, report_desc
 		}
 
 		coll[0] = 0;
+		cinst = 0;
 		for (d = hid_start_parse(repd, 1 << hid_input, reportid);
 		     hid_get_item(d, &h); ) {
 			if (verbose > 2)
@@ -380,24 +386,29 @@ parse_conf(const char *conf, report_desc
 					range = 0;
 				}
 				for (u = lo; u <= hi; u++) {
-					snprintf(usbuf, sizeof usbuf,  "%s:%s",
-						 hid_usage_page(HID_PAGE(u)), 
-						 hid_usage_in_page(u));
-					if (verbose > 2)
-						printf("usage %s\n", usbuf);
-					if (!strcasecmp(usbuf, name))
-						goto foundhid;
 					if (coll[0]) {
 						snprintf(usbuf, sizeof usbuf,
 						  "%s.%s:%s", coll+1,
-						  hid_usage_page(HID_PAGE(u)), 
+						  hid_usage_page(HID_PAGE(u)),
+						  hid_usage_in_page(u));
+					} else {
+						snprintf(usbuf, sizeof usbuf,
+						  "%s:%s",
+						  hid_usage_page(HID_PAGE(u)),
 						  hid_usage_in_page(u));
-						if (verbose > 2)
-							printf("usage %s\n",
-							       usbuf);
-						if (!strcasecmp(usbuf, name))
-							goto foundhid;
 					}
+					if (verbose > 2)
+						printf("usage %s\n", usbuf);
+					t = strlen(usbuf) - strlen(name);
+					if (t > 0) {
+						if (strcmp(usbuf + t, name))
+							continue;
+						if (usbuf[t - 1] != '.')
+							continue;
+					} else if (strcmp(usbuf, name))
+						continue;
+					if (inst == cinst++)
+						goto foundhid;
 				}
 				break;
 			case hid_collection:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108011413.p71ED8Et000414>