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@free.fr>
This commit is contained in:
Christophe CURIS 2014-06-07 21:21:58 +02:00 committed by Carlos R. Mafra
parent ccff1cf409
commit d37962fd46

View file

@ -262,12 +262,15 @@ void mixer_init(const char *mixer_device, bool verbose, const char * exclude[])
} }
if (verbose) { 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:"); puts("Supported channels:");
} }
for (count = 0; count < SOUND_MIXER_NRDEVICES; count++) { for (count = 0; count < SOUND_MIXER_NRDEVICES; count++) {
mask = 1 << 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].name = channel_names[count];
mixer[n_channels].sname = short_names[count]; mixer[n_channels].sname = short_names[count];
mixer[n_channels].dev = 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; mixer[n_channels].is_muted = false;
++n_channels; ++n_channels;
if (verbose) if (verbose)
printf(" %d: %s \t(%s)\n", n_channels, printf(" %d: %s \t(%s)\n", n_channels, channel_names[count], short_names[count]);
channel_names[count], } else if (verbose)
short_names[count]); printf(" x: %s \t(%s) - disabled\n", channel_names[count], short_names[count]);
} else if ((mask & devmask) && verbose)
printf(" x: %s \t(%s) - disabled\n", channel_names[count],
short_names[count]);
} }
get_mixer_state(); get_mixer_state();
} }
@ -414,11 +414,38 @@ bool mixer_can_rec(void)
bool is_exclude(const char *short_name, const char *exclude[]) bool is_exclude(const char *short_name, const char *exclude[])
{ {
int count = 0; int count;
while (count < SOUND_MIXER_NRDEVICES && exclude[count] != NULL){ int len;
if ( strcmp(short_name, exclude[count]) == 0 )
return true; for (count = 0; count < SOUND_MIXER_NRDEVICES; count++) {
count++; if (exclude[count] == NULL)
} break;
return false;
/*
* 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;
} }