alsatplg: add -V,--version option

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2019-12-20 15:23:27 +01:00
parent cbabe7a3f0
commit 32e7016fd7
2 changed files with 21 additions and 2 deletions

View file

@ -47,6 +47,9 @@ Available options:
**-h**, **--help** **-h**, **--help**
this help this help
**-V**, **--version**
show the utility version and versions of used libraries
**-c**, **--compile** `FILE` **-c**, **--compile** `FILE`
source configuration file for the compilation source configuration file for the compilation

View file

@ -34,10 +34,11 @@
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include <alsa/topology.h> #include <alsa/topology.h>
#include "gettext.h" #include "gettext.h"
#include "version.h"
static snd_output_t *log; static snd_output_t *log;
static void usage(char *name) static void usage(const char *name)
{ {
printf( printf(
_("Usage: %s [OPTIONS]...\n" _("Usage: %s [OPTIONS]...\n"
@ -51,9 +52,20 @@ _("Usage: %s [OPTIONS]...\n"
"-s, --sort sort the identifiers in the normalized output\n" "-s, --sort sort the identifiers in the normalized output\n"
"-g, --group save configuration by group indexes\n" "-g, --group save configuration by group indexes\n"
"-x, --nocheck save configuration without additional integrity checks\n" "-x, --nocheck save configuration without additional integrity checks\n"
"-V, --version print version\n"
), name); ), name);
} }
static void version(const char *name)
{
printf(
_("%s version %s\n"
"libasound version %s\n"
"libatopology version %s\n"
), name, SND_UTIL_VERSION_STR,
snd_asoundlib_version(), snd_tplg_version());
}
static int load(snd_tplg_t **tplg, const char *source_file, int cflags) static int load(snd_tplg_t **tplg, const char *source_file, int cflags)
{ {
int fd, err; int fd, err;
@ -227,7 +239,7 @@ static int compile(const char *source_file, const char *output_file, int cflags)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
static const char short_options[] = "hc:n:u:v:o:sgxz"; static const char short_options[] = "hc:n:u:v:o:sgxzV";
static const struct option long_options[] = { static const struct option long_options[] = {
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
{"verbose", 1, NULL, 'v'}, {"verbose", 1, NULL, 'v'},
@ -239,6 +251,7 @@ int main(int argc, char *argv[])
{"group", 0, NULL, 'g'}, {"group", 0, NULL, 'g'},
{"nocheck", 0, NULL, 'x'}, {"nocheck", 0, NULL, 'x'},
{"dapm-nosort", 0, NULL, 'z'}, {"dapm-nosort", 0, NULL, 'z'},
{"version", 0, NULL, 'V'},
{0, 0, 0, 0}, {0, 0, 0, 0},
}; };
char *source_file = NULL; char *source_file = NULL;
@ -286,6 +299,9 @@ int main(int argc, char *argv[])
case 'x': case 'x':
sflags |= SND_TPLG_SAVE_NOCHECK; sflags |= SND_TPLG_SAVE_NOCHECK;
break; break;
case 'V':
version(argv[0]);
return 0;
default: default:
fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]); fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
return 1; return 1;