Skip to contentSkip to conversation

aplay: Show usage if no parameter is passed

PATCH Superseded Fabio Estevam 3 participants 4 messages Nov 13, 2012

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 aplay: Show usage if no parameter is passed

When aplay/arecord are called without any argument the application hangs forever.

Instead of hanging, print the usage and exit.

---
Changes since v2:
- return 1 instead of 0
- Use stdout for the arecord case
Changes since v1:
- Also check for isatty, so that 'aplay < file.wav' can still work

 aplay/aplay.c |    8 ++++++++
 1 file changed, 8 insertions(+)
aplay/aplay.c +8 -0
index 741979a..66cc78f 100644
@@ -493,6 +493,7 @@ int main(int argc, char *argv[])
 	int tmp, err, c;
 	int do_device_list = 0, do_pcm_list = 0;
 	snd_pcm_info_t *info;
+	FILE *direction;
 
 #ifdef ENABLE_NLS
 	setlocale(LC_ALL, "");
@@ -511,14 +512,21 @@ int main(int argc, char *argv[])
 		file_type = FORMAT_WAVE;
 		command = "arecord";
 		start_delay = 1;
+		direction = stdout;
 	} else if (strstr(argv[0], "aplay")) {
 		stream = SND_PCM_STREAM_PLAYBACK;
 		command = "aplay";
+		direction = stdin;
 	} else {
 		error(_("command should be named either arecord or aplay"));
 		return 1;
 	}
 
+	if (isatty(fileno(direction)) && (argc == 1)) {
+		usage(command);
+		return 1;	
+	}
+	
 	chunk_size = -1;
 	rhwparams.format = DEFAULT_FORMAT;
 	rhwparams.rate = DEFAULT_SPEED;
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v3 2/2 ac3dec: Show usage if no parameter is passed

When ac3dec is called without any argument the application hangs forever.

Instead of hanging, print the usage and exit.

---
Changes since v2:
- No changes
Changes since v1:
- Also check for isatty, so that 'ac3dec < file.wav' can still work

 ac3dec/ac3dec.c |    5 +++++
 1 file changed, 5 insertions(+)
ac3dec/ac3dec.c +5 -0
index 00c4f1a..ce6c507 100644
@@ -130,6 +130,11 @@ int main(int argc,char *argv[])
 	out_config.spdif = SPDIF_NONE;
 	out_config.hdmi = 0;
 
+	if (isatty(fileno(stdin)) && (argc == 1)) {
+		help();
+		return 0;
+	}
+
 	morehelp = 0;
 	while (1) {
 		int c;
Signature · 1 line
1.7.9.5
#2 lore raw
In reply to Fabio Estevam

At Tue, 13 Nov 2012 10:05:39 -0200,

Quoted 6 lines · Fabio Estevam

When aplay/arecord are called without any argument the application hangs forever.

Instead of hanging, print the usage and exit.

Applied this one. I suppose there is no v4 for aplay, right?

thanks,

Takashi

Quoted 47 lines

---
Changes since v2:
- return 1 instead of 0
- Use stdout for the arecord case
Changes since v1:
- Also check for isatty, so that 'aplay < file.wav' can still work

 aplay/aplay.c |    8 ++++++++
 1 file changed, 8 insertions(+)
aplay/aplay.c +8 -0
index 741979a..66cc78f 100644
@@ -493,6 +493,7 @@ int main(int argc, char *argv[])
 	int tmp, err, c;
 	int do_device_list = 0, do_pcm_list = 0;
 	snd_pcm_info_t *info;
+	FILE *direction;
 
 #ifdef ENABLE_NLS
 	setlocale(LC_ALL, "");
@@ -511,14 +512,21 @@ int main(int argc, char *argv[])
 		file_type = FORMAT_WAVE;
 		command = "arecord";
 		start_delay = 1;
+		direction = stdout;
 	} else if (strstr(argv[0], "aplay")) {
 		stream = SND_PCM_STREAM_PLAYBACK;
 		command = "aplay";
+		direction = stdin;
 	} else {
 		error(_("command should be named either arecord or aplay"));
 		return 1;
 	}
 
+	if (isatty(fileno(direction)) && (argc == 1)) {
+		usage(command);
+		return 1;	
+	}
+	
 	chunk_size = -1;
 	rhwparams.format = DEFAULT_FORMAT;
 	rhwparams.rate = DEFAULT_SPEED;
Signature · 1 line
1.7.9.5
#3 lore raw

Hi Takashi,

Quoted 10 lines · Takashi Iwai

At Tue, 13 Nov 2012 10:05:39 -0200,

Quoted 6 lines · Fabio Estevam

When aplay/arecord are called without any argument the application hangs forever.

Instead of hanging, print the usage and exit.

Applied this one. I suppose there is no v4 for aplay, right?

Yes, correct.

Thanks,

Fabio Estevam