From: Takashi Iwai Subject: Re: [PATCH V2 1/7] BAT: Add initial functions Date: Fri, 02 Oct 2015 12:55:35 +0200 Message-ID: References: Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 015752608CF for ; Fri, 2 Oct 2015 12:55:34 +0200 (CEST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: han.lu@intel.com Cc: bernard.gautier@intel.com, alsa-devel@alsa-project.org, caleb@crome.org, liam.r.girdwood@intel.com List-Id: alsa-devel@alsa-project.org On Wed, 23 Sep 2015 09:48:49 +0200, han.lu@intel.com wrote: > > From: "Lu, Han" > > Add main entrance, command line parsing, parameter initiating and > thread initiating functions for BAT. > > Signed-off-by: Lu, Han > Signed-off-by: Liam Girdwood > Signed-off-by: Bernard Gautier > > diff --git a/bat/bat.c b/bat/bat.c > new file mode 100644 > index 0000000..54fe1ec > --- /dev/null > +++ b/bat/bat.c > @@ -0,0 +1,603 @@ > +/* > + * Copyright (C) 2013-2015 Intel Corporation > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "aconfig.h" > +#include "gettext.h" > +#include "version.h" > + > +#include "common.h" > + > +#include "alsa.h" > +#include "convert.h" > +#include "analyze.h" > + > +static int get_duration(struct bat *bat) > +{ > + float duration_f; > + long duration_i; > + 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; > + } > + > + 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 (*ptrf == 's') { > + bat->frames = duration_f * bat->rate; > + } else if (*ptri == 0) { > + bat->frames = duration_i; > + } else { > + fprintf(bat->err, _("invalid duration: %s\n"), bat->narg); > + return -EINVAL; > + } > + > + 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)); The messages strings could be unified to a single error message. Otherwise you'll annoy translators, as they will need to work on each different variant. > + return -EINVAL; > + } > + > + return 0; > +} > + > +static void get_sine_frequencies(struct bat *bat, char *freq) > +{ > + char *tmp1; > + > + tmp1 = strchr(freq, ','); > + if (tmp1 == NULL) { > + bat->target_freq[1] = bat->target_freq[0] = atof(optarg); > + } else { > + *tmp1 = '\0'; > + bat->target_freq[0] = atof(optarg); > + bat->target_freq[1] = atof(tmp1 + 1); > + } Note that parsing a floting point string is tricky. For example, if you run it in a locale that handles comma as the decimal point, this gets messy. Did you check it, e.g. with LANG=en_GB or such? > +static void usage(struct bat *bat, char *argv[]) > +{ > + fprintf(bat->log, > +_("Usage:%s [Option]...\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" Why there are options with and without indentation? > +), argv[0]); The program name should be a const string. Takashi