From ronald@klop.ws  Thu Jan 29 11:30:44 2004
Return-Path: <ronald@klop.ws>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id AB03716A4CF
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Jan 2004 11:30:35 -0800 (PST)
Received: from klop.ws (node1f673.a2000.nl [24.132.246.115])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7ED9643D46
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Jan 2004 11:30:33 -0800 (PST)
	(envelope-from ronald@klop.ws)
Received: from klop.ws (localhost [127.0.0.1])
	by henk.thuis.klop.ws (8.12.10/8.12.10) with ESMTP id i0TJ4gVa001389;
	Thu, 29 Jan 2004 20:04:42 +0100 (CET)
	(envelope-from ronald@klop.ws)
Received: (from ronald@localhost)
	by klop.ws (8.12.10/8.12.10/Submit) id i0TJ4gEO001388;
	Thu, 29 Jan 2004 20:04:42 +0100 (CET)
	(envelope-from ronald)
Message-Id: <200401291904.i0TJ4gEO001388@klop.ws>
Date: Thu, 29 Jan 2004 20:04:42 +0100 (CET)
From: Ronald Klop <ronald@cs.vu.nl>
Reply-To: Ronald Klop <ronald@cs.vu.nl>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Ronald Klop <ronald@cs.vu.nl>
Subject: Make it possible to abbreviate device names. (patch included)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         62077
>Category:       bin
>Synopsis:       [sound] [patch] Make it possible to abbreviate mixer(8) device names
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 29 11:40:16 PST 2004
>Closed-Date:    
>Last-Modified:  Mon Jul 27 09:23:55 UTC 2009
>Originator:     Ronald Klop
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
>Environment:
System: FreeBSD klop.ws 5.2-CURRENT FreeBSD 5.2-CURRENT #0: Wed Jan 28 07:46:30 CET 2004 root@henk.thuis.klop.ws:/usr/obj/usr/src/sys/HENK i386


	
>Description:
	This patch makes it possible to abbreviate device names when changing
	mixer settings.
	So I can issue 'mixer sp 0' in stead of 'mixer speaker 0'.
	It only accepts non-ambigious abbreviations.
	I also updated the man page for this.
>How-To-Repeat:
	
>Fix:

	

--- mixer.diff begins here ---
diff -ruN0 /usr/src/usr.sbin/mixer/mixer.8 mixer/mixer.8
--- /usr/src/usr.sbin/mixer/mixer.8	Fri Sep 26 13:21:19 2003
+++ mixer/mixer.8	Thu Jan 29 12:33:15 2004
@@ -90,0 +91,3 @@
+The argument 
+.Ar dev
+may be abbreviated to its shortest non-ambigious form.
diff -ruN0 /usr/src/usr.sbin/mixer/mixer.c mixer/mixer.c
--- /usr/src/usr.sbin/mixer/mixer.c	Thu Jan 22 23:01:13 2004
+++ mixer/mixer.c	Thu Jan 29 12:28:03 2004
@@ -62 +62 @@
-	int foo;
+	int device, i, matches;
@@ -64,3 +64,7 @@
-	for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++)
-		if ((1 << foo) & mask && !strcmp(names[foo], name))
-			break;
+	matches = 0;
+	for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
+		if ((1 << i) & mask
+				&& !strncmp(names[i], name, strlen(name))) {
+			device = i;
+			matches++;
+		}
@@ -68 +72 @@
-	return foo == SOUND_MIXER_NRDEVICES ? -1 : foo;
+	return (matches == 1 ? device : -1);
--- mixer.diff ends here ---


>Release-Note:
>Audit-Trail:

From: Ronald Klop <ronald@cs.vu.nl>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/62077: Make it possible to abbreviate device names. (patch included)
Date: Fri, 30 Jan 2004 00:28:17 +0100

 I just noticed that the strlen can be moved out of the loop and calculated 
 once. This wil save some cpu cycles. ;-)
 
 Ronald.
 
 -- 
   Ronald Klop
   Vrije Universiteit, Amsterdam, The Netherlands
>Unformatted:
