[Pkg-wmaker-commits] [wmix] 30/44: wmix: do not count space padding in channel short name when comparing names for exclusion

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Sep 29 10:40:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository wmix.

commit 0dccc05c716e51703ab3da7523d95cfe4d3668e5
Author: Christophe CURIS <christophe.curis at free.fr>
Date:   Sat Jun 7 21:21:58 2014 +0200

    wmix: do not count space padding in channel short name when comparing names for exclusion
    
    The names for channels provided by <sys/soundcard.h> have a padding with
    space when their name is shorter than 6 characters, and this cause
    excluding them difficult.
    The new comparison code makes sure this padding is properly handled during
    the match search.
    
    Took the opportunity to bring light changes to try to improve the
    readability of the channel listing code.
    
    Signed-off-by: Christophe CURIS <christophe.curis at free.fr>
---
 mixer-oss.c | 57 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 15 deletions(-)

diff --git a/mixer-oss.c b/mixer-oss.c
index e561608..3f0ca8f 100644
--- a/mixer-oss.c
+++ b/mixer-oss.c
@@ -262,12 +262,15 @@ void mixer_init(const char *mixer_device, bool verbose, const char * exclude[])
     }
 
     if (verbose) {
-	printf("%s (%s)\n", m_info.name, m_info.id);
+	printf("Sound card: %s (%s)\n", m_info.name, m_info.id);
 	puts("Supported channels:");
     }
     for (count = 0; count < SOUND_MIXER_NRDEVICES; count++) {
 	mask = 1 << count;
-	if ((mask & devmask) && (!is_exclude((short_names[count]),exclude))) {
+	if (!(mask & devmask))
+		continue;
+
+	if (!is_exclude(short_names[count], exclude)) {
 	    mixer[n_channels].name = channel_names[count];
 	    mixer[n_channels].sname = short_names[count];
 	    mixer[n_channels].dev = count;
@@ -278,12 +281,9 @@ void mixer_init(const char *mixer_device, bool verbose, const char * exclude[])
 	    mixer[n_channels].is_muted = false;
 	    ++n_channels;
 	    if (verbose)
-		printf("  %d: %s \t(%s)\n", n_channels, 
-		       channel_names[count],
-		       short_names[count]);    
-	} else if ((mask & devmask) && verbose)
-	  printf("  x: %s \t(%s) - disabled\n", channel_names[count],
-		 short_names[count]);
+		printf("  %d: %s \t(%s)\n", n_channels, channel_names[count], short_names[count]);
+	} else if (verbose)
+	    printf("  x: %s \t(%s) - disabled\n", channel_names[count], short_names[count]);
     }
     get_mixer_state();
 }
@@ -414,11 +414,38 @@ bool mixer_can_rec(void)
 
 bool is_exclude(const char *short_name, const char *exclude[])
 {
-  int count = 0;
-  while (count < SOUND_MIXER_NRDEVICES && exclude[count] != NULL){
-    if ( strcmp(short_name, exclude[count]) == 0 )
-      return true;
-    count++;
-  }
-  return false;
+	int count;
+	int len;
+
+	for (count = 0; count < SOUND_MIXER_NRDEVICES; count++) {
+		if (exclude[count] == NULL)
+			break;
+
+		/*
+		 * Short names may be padded with spaces, because apparently there is a minimum
+		 * length requirement of 6 characters for the name, and we do not want to
+		 * include this padding in the match
+		 */
+		len = strlen(short_name);
+		while (len > 0) {
+			if (short_name[len - 1] == ' ')
+				len--;
+			else
+				break;
+		}
+
+		if (strncmp(short_name, exclude[count], len) != 0)
+			continue;
+
+		if (exclude[count][len] != '\0')
+			continue;
+
+		/* Check the remaining in short name is only space */
+		while (short_name[len] == ' ')
+			len++;
+
+		if (short_name[len] == '\0')
+			return true;
+	}
+	return false;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmix.git



More information about the Pkg-wmaker-commits mailing list