Skip to contentSkip to conversation

Some fixes against previous comments

PATCH Applied [email protected] 2 participants 6 messages Oct 20, 2015

lore
Share & tools
lore
#0 lore raw

v4 cover Some fixes against previous comments

From: "Lu, Han" <[email protected]>

Some fixes and adjustments against previous comments of Takashi

Lu, Han (4):
BAT: Remove redundant message strings
BAT: Use colon instead of comma for separation
BAT: Change comments and interface of usage()
BAT: Use dynamic temp file

 bat/bat.c    | 106 +++++++++++++++++++++++++++++++----------------------------
 bat/common.h |   2 +-
 2 files changed, 57 insertions(+), 51 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/4 BAT: Remove redundant message strings

From: "Lu, Han" <[email protected]>

Cutting down 6 message strings to 2, as translators need to work on each different variant.

bat/bat.c +16 -26
index 24c74e8..4320e22 100644
@@ -41,43 +41,33 @@ static int get_duration(struct bat *bat)
 	char *ptrf, *ptri;
 
 	duration_f = strtof(bat->narg, &ptrf);
-	if (duration_f == HUGE_VALF || duration_f == -HUGE_VALF) {
-		fprintf(bat->err, _("duration float overflow: %f %d\n"),
-				duration_f, -errno);
-		return -errno;
-	} else if (duration_f == 0.0 && errno != 0) {
-		fprintf(bat->err, _("duration float underflow: %f %d\n"),
-				duration_f, -errno);
-		return -errno;
-	}
+	if (duration_f == HUGE_VALF || duration_f == -HUGE_VALF
+			|| (duration_f == 0.0 && errno != 0))
+		goto err_exit;
 
 	duration_i = strtol(bat->narg, &ptri, 10);
-	if (duration_i == LONG_MAX) {
-		fprintf(bat->err, _("duration long overflow: %ld %d\n"),
-				duration_i, -errno);
-		return -errno;
-	} else if (duration_i == LONG_MIN) {
-		fprintf(bat->err, _("duration long underflow: %ld %d\n"),
-				duration_i, -errno);
-		return -errno;
-	}
+	if (duration_i == LONG_MAX || duration_i == LONG_MIN)
+		goto err_exit;
 
-	if (*ptrf == 's') {
+	if (*ptrf == 's')
 		bat->frames = duration_f * bat->rate;
-	} else if (*ptri == 0) {
+	else if (*ptri == 0)
 		bat->frames = duration_i;
-	} else {
-		fprintf(bat->err, _("invalid duration: %s\n"), bat->narg);
-		return -EINVAL;
-	}
+	else
+		bat->frames = -1;
 
 	if (bat->frames <= 0 || bat->frames > MAX_FRAMES) {
-		fprintf(bat->err, _("duration out of range: (0, %d(%ds))\n"),
-				MAX_FRAMES, (bat->frames / bat->rate));
+		fprintf(bat->err, _("Invalid duration. Range: (0, %d(%fs))\n"),
+				MAX_FRAMES, (double)MAX_FRAMES / bat->rate);
 		return -EINVAL;
 	}
 
 	return 0;
+
+err_exit:
+	fprintf(bat->err, _("Duration overflow/underflow: %d\n"), -errno);
+
+	return -errno;
 }
 
 static void get_sine_frequencies(struct bat *bat, char *freq)
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 2/4 BAT: Use colon instead of comma for separation

In reply to [email protected]

From: "Lu, Han" <[email protected]>

Use colon instead of comma to separate frequency parameters, for in several locale comma may be handled as decimal point.

bat/bat.c +1 -1
index 4320e22..2320984 100644
@@ -74,7 +74,7 @@ static void get_sine_frequencies(struct bat *bat, char *freq)
 {
 	char *tmp1;
 
-	tmp1 = strchr(freq, ',');
+	tmp1 = strchr(freq, ':');
 	if (tmp1 == NULL) {
 		bat->target_freq[1] = bat->target_freq[0] = atof(optarg);
 	} else {
Signature · 1 line
1.9.1
#3 lore raw

PATCH v4 3/4 BAT: Change comments and interface of usage()

In reply to [email protected]

From: "Lu, Han" <[email protected]>

1. Change comment strings to make the descriptions more clear;
2. Add indent for option lines that have no indent;
3. Use a const string instead of argv[0] as program name.

bat/bat.c +19 -20
index 2320984..2be3efb 100644
@@ -268,28 +268,27 @@ static void test_capture(struct bat *bat)
 	}
 }
 
-static void usage(struct bat *bat, char *argv[])
+static void usage(struct bat *bat)
 {
 	fprintf(bat->log,
-_("Usage:%s [Option]...\n"
+_("Usage: bat [-options]...\n"
 "\n"
-"-h, --help             help\n"
-"-D                     sound card\n"
-"-P                     playback pcm\n"
-"-C                     capture pcm\n"
-"-f                     sample size\n"
-"-c                     number of channels\n"
-"-r                     sampling rate\n"
-"-n                     frames to capture\n"
-"-k                     sigma k\n"
-"-F                     target frequency\n"
-"-p                     total number of periods to play/capture\n"
-"    --log=#            path of log file. if not set, logs be put to stdout,\n"
-"                       and errors be put to stderr.\n"
-"    --file=#           input file\n"
-"    --saveplay=#       save playback content to target file, for debug\n"
-"    --local            internal loop, bypass hardware\n"
-), argv[0]);
+"  -h, --help             this help\n"
+"  -D                     pcm device for both playback and capture\n"
+"  -P                     pcm device for playback\n"
+"  -C                     pcm device for capture\n"
+"  -f                     sample format\n"
+"  -c                     number of channels\n"
+"  -r                     sampling rate\n"
+"  -n                     frames to playback or capture\n"
+"  -k                     parameter for frequency detecting threshold\n"
+"  -F                     target frequency\n"
+"  -p                     total number of periods to play/capture\n"
+"      --log=#            file that both stdout and strerr redirecting to\n"
+"      --file=#           file for playback\n"
+"      --saveplay=#       file that storing playback content, for debug\n"
+"      --local            internal loop, set to bypass pcm hardware devices\n"
+));
 	fprintf(bat->log, _("Recognized sample formats are: %s %s %s %s\n"),
 			snd_pcm_format_name(SND_PCM_FORMAT_U8),
 			snd_pcm_format_name(SND_PCM_FORMAT_S16_LE),
@@ -402,7 +401,7 @@ static void parse_arguments(struct bat *bat, int argc, char *argv[])
 			break;
 		case 'h':
 		default:
-			usage(bat, argv);
+			usage(bat);
 			exit(EXIT_SUCCESS);
 		}
 	}
Signature · 1 line
1.9.1
#4 lore raw

PATCH v4 4/4 BAT: Use dynamic temp file

In reply to [email protected]

From: "Lu, Han" <[email protected]>

Use dynamic temp file instead of fixed temp file to store recorded wav data, for better security.

bat/bat.c +20 -3
index 2be3efb..e1343fb 100644
@@ -451,6 +451,7 @@ static int validate_options(struct bat *bat)
 static int bat_init(struct bat *bat)
 {
 	int err = 0;
+	char name[] = TEMP_RECORD_FILE_NAME;
 
 	/* Determine logging to a file or stdout and stderr */
 	if (bat->logarg) {
@@ -473,10 +474,23 @@ static int bat_init(struct bat *bat)
 	}
 
 	/* Determine capture file */
-	if (bat->local)
+	if (bat->local) {
 		bat->capture.file = bat->playback.file;
-	else
-		bat->capture.file = TEMP_RECORD_FILE_NAME;
+	} else {
+		/* create temp file for sound record and analysis */
+		err = mkstemp(name);
+		if (err == -1) {
+			fprintf(bat->err, _("Fail to create record file: %d\n"),
+					-errno);
+			return -errno;
+		}
+		/* store file name which is dynamically created */
+		bat->capture.file = strdup(name);
+		if (bat->capture.file == NULL)
+			return -errno;
+		/* close temp file */
+		close(err);
+	}
 
 	/* Initial for playback */
 	if (bat->playback.file == NULL) {
@@ -590,8 +604,11 @@ analyze:
 	err = analyze_capture(&bat);
 out:
 	fprintf(bat.log, _("\nReturn value is %d\n"), err);
+
 	if (bat.logarg)
 		fclose(bat.log);
+	if (!bat.local)
+		free(bat.capture.file);
 
 	return err;
 }
bat/common.h +1 -1
index f0254ab..90bc3e2 100644
@@ -15,7 +15,7 @@
 
 #include <alsa/asoundlib.h>
 
-#define TEMP_RECORD_FILE_NAME		"/tmp/bat.wav"
+#define TEMP_RECORD_FILE_NAME		"/tmp/bat.wav.XXXXXX"
 
 #define OPT_BASE			300
 #define OPT_LOG				(OPT_BASE + 1)
Signature · 1 line
1.9.1
Applied
#5 lore raw
In reply to [email protected]
Quoted 4 lines · On Tue, 20 Oct 2015 10:45:44 +0200, [email protected] wrote:

From: "Lu, Han" <[email protected]>

Some fixes and adjustments against previous comments of Takashi

Applied all four patches now. Thanks.

Takashi

Quoted 13 lines

Lu, Han (4):
BAT: Remove redundant message strings
BAT: Use colon instead of comma for separation
BAT: Change comments and interface of usage()
BAT: Use dynamic temp file

 bat/bat.c    | 106 +++++++++++++++++++++++++++++++----------------------------
 bat/common.h |   2 +-
 2 files changed, 57 insertions(+), 51 deletions(-)
Signature · 1 line
1.9.1