2015-08-04 17:23:03 +02:00
|
|
|
/*
|
2019-12-19 15:36:05 +01:00
|
|
|
Copyright(c) 2019 Red Hat Inc.
|
2015-08-04 17:23:03 +02:00
|
|
|
Copyright(c) 2014-2015 Intel Corporation
|
|
|
|
Copyright(c) 2010-2011 Texas Instruments Incorporated,
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of version 2 of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
The full GNU General Public License is included in this distribution
|
|
|
|
in the file called LICENSE.GPL.
|
|
|
|
*/
|
|
|
|
|
2021-03-26 22:44:13 +01:00
|
|
|
#include <stdbool.h>
|
2015-08-04 17:23:03 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
#include <alsa/topology.h>
|
|
|
|
#include "gettext.h"
|
2019-12-20 15:23:27 +01:00
|
|
|
#include "version.h"
|
2021-03-26 22:44:13 +01:00
|
|
|
#include "topology.h"
|
|
|
|
|
|
|
|
bool pre_process_config = false;
|
2015-08-04 17:23:03 +02:00
|
|
|
|
|
|
|
static snd_output_t *log;
|
|
|
|
|
2019-12-20 15:23:27 +01:00
|
|
|
static void usage(const char *name)
|
2015-08-04 17:23:03 +02:00
|
|
|
{
|
|
|
|
printf(
|
|
|
|
_("Usage: %s [OPTIONS]...\n"
|
|
|
|
"\n"
|
|
|
|
"-h, --help help\n"
|
2019-12-22 15:44:56 +01:00
|
|
|
"-c, --compile=FILE compile configuration file\n"
|
2021-03-26 22:44:13 +01:00
|
|
|
"-p, --pre-process pre-process Topology2.0 configuration file before compilation\n"
|
|
|
|
"-P, --pre-process=FILE pre-process Topology2.0 configuration file\n"
|
2019-12-22 15:44:56 +01:00
|
|
|
"-d, --decode=FILE decode binary topology file\n"
|
|
|
|
"-n, --normalize=FILE normalize configuration file\n"
|
|
|
|
"-u, --dump=FILE dump (reparse) configuration file\n"
|
2015-08-04 17:23:03 +02:00
|
|
|
"-v, --verbose=LEVEL set verbosity level (0...1)\n"
|
|
|
|
"-o, --output=FILE set output file\n"
|
2021-12-06 11:00:02 +01:00
|
|
|
#if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION
|
|
|
|
"-D, --define=ARGS define variables (VAR1=VAL1[,VAR2=VAL2] ...)\n"
|
2022-01-28 09:29:34 +01:00
|
|
|
" (may be used multiple times)\n"
|
2021-12-08 09:55:44 +01:00
|
|
|
"-I, --inc-dir=DIR set include path\n"
|
2021-12-06 11:00:02 +01:00
|
|
|
#endif
|
2019-12-12 19:18:28 +01:00
|
|
|
"-s, --sort sort the identifiers in the normalized output\n"
|
2019-12-19 15:36:05 +01:00
|
|
|
"-g, --group save configuration by group indexes\n"
|
|
|
|
"-x, --nocheck save configuration without additional integrity checks\n"
|
2020-01-01 17:45:06 +01:00
|
|
|
"-z, --dapm-nosort do not sort the DAPM widgets\n"
|
2019-12-20 15:23:27 +01:00
|
|
|
"-V, --version print version\n"
|
2015-08-04 17:23:03 +02:00
|
|
|
), name);
|
|
|
|
}
|
|
|
|
|
2019-12-20 15:23:27 +01:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2019-12-22 15:44:56 +01:00
|
|
|
static int load(const char *source_file, void **dst, size_t *dst_size)
|
2019-12-12 19:00:42 +01:00
|
|
|
{
|
2019-12-22 15:44:56 +01:00
|
|
|
int fd;
|
|
|
|
void *buf, *buf2;
|
2019-12-19 15:36:05 +01:00
|
|
|
size_t size, pos;
|
|
|
|
ssize_t r;
|
2019-12-12 19:00:42 +01:00
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
if (strcmp(source_file, "-") == 0) {
|
|
|
|
fd = fileno(stdin);
|
|
|
|
} else {
|
|
|
|
fd = open(source_file, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, _("Unable to open input file '%s': %s\n"),
|
|
|
|
source_file, strerror(-errno));
|
|
|
|
return 1;
|
2019-12-12 19:00:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
size = 16*1024;
|
|
|
|
pos = 0;
|
|
|
|
buf = malloc(size);
|
|
|
|
if (buf == NULL)
|
|
|
|
goto _nomem;
|
|
|
|
while (1) {
|
|
|
|
r = read(fd, buf + pos, size - pos);
|
|
|
|
if (r < 0 && (errno == EAGAIN || errno == EINTR))
|
|
|
|
continue;
|
|
|
|
if (r <= 0)
|
|
|
|
break;
|
|
|
|
pos += r;
|
|
|
|
size += 8*1024;
|
|
|
|
buf2 = realloc(buf, size);
|
2021-01-08 18:33:28 +01:00
|
|
|
if (buf2 == NULL)
|
2019-12-19 15:36:05 +01:00
|
|
|
goto _nomem;
|
|
|
|
buf = buf2;
|
|
|
|
}
|
|
|
|
if (r < 0) {
|
|
|
|
fprintf(stderr, _("Read error: %s\n"), strerror(-errno));
|
|
|
|
goto _err;
|
|
|
|
}
|
2019-12-12 19:00:42 +01:00
|
|
|
|
2020-06-09 10:29:30 +02:00
|
|
|
if (fd != fileno(stdin))
|
|
|
|
close(fd);
|
|
|
|
|
2019-12-22 15:44:56 +01:00
|
|
|
*dst = buf;
|
|
|
|
*dst_size = pos;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
_nomem:
|
|
|
|
fprintf(stderr, _("No enough memory\n"));
|
|
|
|
_err:
|
|
|
|
if (fd != fileno(stdin))
|
|
|
|
close(fd);
|
|
|
|
free(buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_topology(snd_tplg_t **tplg, char *config,
|
|
|
|
size_t config_size, int cflags)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
*tplg = snd_tplg_create(cflags);
|
|
|
|
if (*tplg == NULL) {
|
2019-12-12 19:00:42 +01:00
|
|
|
fprintf(stderr, _("failed to create new topology context\n"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-22 15:44:56 +01:00
|
|
|
err = snd_tplg_load(*tplg, config, config_size);
|
2019-12-12 19:00:42 +01:00
|
|
|
if (err < 0) {
|
2019-12-19 15:36:05 +01:00
|
|
|
fprintf(stderr, _("Unable to load configuration: %s\n"),
|
|
|
|
snd_strerror(-err));
|
|
|
|
snd_tplg_free(*tplg);
|
2019-12-12 19:00:42 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
return 0;
|
2019-12-12 19:00:42 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
static int save(const char *output_file, void *buf, size_t size)
|
2019-12-12 19:00:42 +01:00
|
|
|
{
|
2019-12-19 15:36:05 +01:00
|
|
|
char *fname = NULL;
|
|
|
|
int fd;
|
|
|
|
ssize_t r;
|
2019-12-12 19:00:42 +01:00
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
if (strcmp(output_file, "-") == 0) {
|
|
|
|
fd = fileno(stdout);
|
|
|
|
} else {
|
|
|
|
fname = alloca(strlen(output_file) + 5);
|
|
|
|
strcpy(fname, output_file);
|
|
|
|
strcat(fname, ".new");
|
2021-12-12 19:57:38 +01:00
|
|
|
fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
2019-12-19 15:36:05 +01:00
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, _("Unable to open output file '%s': %s\n"),
|
|
|
|
fname, strerror(-errno));
|
|
|
|
return 1;
|
|
|
|
}
|
2019-12-12 19:00:42 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
r = 0;
|
|
|
|
while (size > 0) {
|
|
|
|
r = write(fd, buf, size);
|
|
|
|
if (r < 0 && (errno == EAGAIN || errno == EINTR))
|
|
|
|
continue;
|
|
|
|
if (r < 0)
|
|
|
|
break;
|
|
|
|
size -= r;
|
|
|
|
buf += r;
|
2019-12-12 19:00:42 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
if (r < 0) {
|
|
|
|
fprintf(stderr, _("Write error: %s\n"), strerror(-errno));
|
|
|
|
if (fd != fileno(stdout)) {
|
2020-06-09 10:31:50 +02:00
|
|
|
if (fname && remove(fname))
|
|
|
|
fprintf(stderr, _("Unable to remove file %s: %s\n"),
|
|
|
|
fname, strerror(-errno));
|
2019-12-19 15:36:05 +01:00
|
|
|
close(fd);
|
|
|
|
}
|
2019-12-12 19:00:42 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
if (fd != fileno(stdout))
|
|
|
|
close(fd);
|
2019-12-12 19:00:42 +01:00
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
if (fname && rename(fname, output_file)) {
|
|
|
|
fprintf(stderr, _("Unable to rename file '%s' to '%s': %s\n"),
|
|
|
|
fname, output_file, strerror(-errno));
|
2019-12-12 19:00:42 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dump(const char *source_file, const char *output_file, int cflags, int sflags)
|
|
|
|
{
|
|
|
|
snd_tplg_t *tplg;
|
2019-12-22 15:44:56 +01:00
|
|
|
char *config, *text;
|
|
|
|
size_t size;
|
2019-12-19 15:36:05 +01:00
|
|
|
int err;
|
|
|
|
|
2019-12-22 15:44:56 +01:00
|
|
|
err = load(source_file, (void **)&config, &size);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = load_topology(&tplg, config, size, cflags);
|
|
|
|
free(config);
|
2019-12-19 15:36:05 +01:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = snd_tplg_save(tplg, &text, sflags);
|
|
|
|
snd_tplg_free(tplg);
|
2019-12-12 19:00:42 +01:00
|
|
|
if (err < 0) {
|
2019-12-19 15:36:05 +01:00
|
|
|
fprintf(stderr, _("Unable to save parsed configuration: %s\n"),
|
|
|
|
snd_strerror(-err));
|
2019-12-12 19:00:42 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2019-12-19 15:36:05 +01:00
|
|
|
err = save(output_file, text, strlen(text));
|
|
|
|
free(text);
|
|
|
|
return err;
|
|
|
|
}
|
2019-12-12 19:00:42 +01:00
|
|
|
|
2021-12-06 10:13:22 +01:00
|
|
|
static char *get_inc_path(const char *filename)
|
|
|
|
{
|
|
|
|
const char *s = strrchr(filename, '/');
|
|
|
|
char *r = strdup(filename);
|
2021-12-07 09:39:12 +01:00
|
|
|
if (r) {
|
|
|
|
if (s)
|
|
|
|
r[s - filename] = '\0';
|
|
|
|
else if (r[0])
|
|
|
|
strcpy(r, ".");
|
|
|
|
}
|
2021-12-06 10:13:22 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2022-01-27 14:33:20 +01:00
|
|
|
static int pre_process_run(struct tplg_pre_processor **tplg_pp,
|
|
|
|
const char *source_file, const char *output_file,
|
|
|
|
const char *pre_processor_defs, const char *include_path)
|
2021-03-26 22:44:13 +01:00
|
|
|
{
|
|
|
|
size_t config_size;
|
2021-12-06 10:13:22 +01:00
|
|
|
char *config, *inc_path;
|
2022-01-27 14:33:20 +01:00
|
|
|
snd_output_type_t output_type;
|
2021-03-26 22:44:13 +01:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = load(source_file, (void **)&config, &config_size);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* init pre-processor */
|
2022-01-27 14:33:20 +01:00
|
|
|
output_type = output_file == NULL ? SND_OUTPUT_BUFFER : SND_OUTPUT_STDIO;
|
|
|
|
err = init_pre_processor(tplg_pp, output_type, output_file);
|
2021-03-26 22:44:13 +01:00
|
|
|
if (err < 0) {
|
|
|
|
fprintf(stderr, _("failed to init pre-processor for Topology2.0\n"));
|
|
|
|
free(config);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pre-process conf file */
|
2021-12-08 06:06:29 +01:00
|
|
|
if (!include_path)
|
|
|
|
inc_path = get_inc_path(source_file);
|
|
|
|
else
|
|
|
|
inc_path = strdup(include_path);
|
2022-01-27 14:33:20 +01:00
|
|
|
err = pre_process(*tplg_pp, config, config_size, pre_processor_defs, inc_path);
|
2021-12-06 10:13:22 +01:00
|
|
|
free(inc_path);
|
2021-03-26 22:44:13 +01:00
|
|
|
|
2022-01-27 14:33:20 +01:00
|
|
|
if (err < 0)
|
2022-01-27 15:01:50 +01:00
|
|
|
free_pre_processor(*tplg_pp);
|
2022-01-27 14:33:20 +01:00
|
|
|
free(config);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert Topology2.0 conf to the existing conf syntax */
|
|
|
|
static int pre_process_conf(const char *source_file, const char *output_file,
|
|
|
|
const char *pre_processor_defs, const char *include_path)
|
|
|
|
{
|
|
|
|
struct tplg_pre_processor *tplg_pp;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = pre_process_run(&tplg_pp, source_file, output_file,
|
|
|
|
pre_processor_defs, include_path);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2021-03-26 22:44:13 +01:00
|
|
|
/* free pre-processor */
|
2022-01-27 15:01:50 +01:00
|
|
|
free_pre_processor(tplg_pp);
|
2021-03-26 22:44:13 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-11-04 20:17:24 +01:00
|
|
|
static int compile(const char *source_file, const char *output_file, int cflags,
|
2021-12-08 06:06:29 +01:00
|
|
|
const char *pre_processor_defs, const char *include_path)
|
2019-12-19 15:36:05 +01:00
|
|
|
{
|
2021-03-26 22:44:13 +01:00
|
|
|
struct tplg_pre_processor *tplg_pp = NULL;
|
2019-12-19 15:36:05 +01:00
|
|
|
snd_tplg_t *tplg;
|
2022-01-27 14:33:20 +01:00
|
|
|
char *config;
|
2019-12-19 15:36:05 +01:00
|
|
|
void *bin;
|
2019-12-22 15:44:56 +01:00
|
|
|
size_t config_size, size;
|
2019-12-19 15:36:05 +01:00
|
|
|
int err;
|
|
|
|
|
2019-12-22 15:44:56 +01:00
|
|
|
err = load(source_file, (void **)&config, &config_size);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2021-03-26 22:44:13 +01:00
|
|
|
|
|
|
|
/* pre-process before compiling */
|
|
|
|
if (pre_process_config) {
|
|
|
|
char *pconfig;
|
|
|
|
size_t size;
|
|
|
|
|
2022-01-27 14:33:20 +01:00
|
|
|
err = pre_process_run(&tplg_pp, source_file, NULL,
|
|
|
|
pre_processor_defs, include_path);
|
|
|
|
if (err < 0)
|
2021-03-26 22:44:13 +01:00
|
|
|
return err;
|
|
|
|
|
|
|
|
/* load topology */
|
|
|
|
size = snd_output_buffer_string(tplg_pp->output, &pconfig);
|
|
|
|
err = load_topology(&tplg, pconfig, size, cflags);
|
|
|
|
|
|
|
|
/* free pre-processor */
|
2022-01-27 15:01:50 +01:00
|
|
|
free_pre_processor(tplg_pp);
|
2021-03-26 22:44:13 +01:00
|
|
|
} else {
|
|
|
|
err = load_topology(&tplg, config, config_size, cflags);
|
|
|
|
}
|
2019-12-22 15:44:56 +01:00
|
|
|
free(config);
|
2019-12-19 15:36:05 +01:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = snd_tplg_build_bin(tplg, &bin, &size);
|
|
|
|
snd_tplg_free(tplg);
|
|
|
|
if (err < 0 || size == 0) {
|
2019-12-22 15:44:56 +01:00
|
|
|
fprintf(stderr, _("failed to compile context %s: %s\n"),
|
|
|
|
source_file, snd_strerror(-err));
|
2019-12-19 15:36:05 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
err = save(output_file, bin, size);
|
|
|
|
free(bin);
|
|
|
|
return err;
|
2019-12-12 19:00:42 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 15:44:56 +01:00
|
|
|
static int decode(const char *source_file, const char *output_file,
|
|
|
|
int cflags, int dflags, int sflags)
|
|
|
|
{
|
|
|
|
snd_tplg_t *tplg;
|
|
|
|
void *bin;
|
|
|
|
char *text;
|
|
|
|
size_t size;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (load(source_file, &bin, &size))
|
|
|
|
return 1;
|
|
|
|
tplg = snd_tplg_create(cflags);
|
|
|
|
if (tplg == NULL) {
|
|
|
|
fprintf(stderr, _("failed to create new topology context\n"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
err = snd_tplg_decode(tplg, bin, size, dflags);
|
|
|
|
free(bin);
|
|
|
|
if (err < 0) {
|
|
|
|
snd_tplg_free(tplg);
|
|
|
|
fprintf(stderr, _("failed to decode context %s: %s\n"),
|
|
|
|
source_file, snd_strerror(-err));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
err = snd_tplg_save(tplg, &text, sflags);
|
|
|
|
snd_tplg_free(tplg);
|
|
|
|
if (err < 0) {
|
|
|
|
fprintf(stderr, _("Unable to save parsed configuration: %s\n"),
|
|
|
|
snd_strerror(-err));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
err = save(output_file, text, strlen(text));
|
|
|
|
free(text);
|
|
|
|
return err;
|
|
|
|
}
|
2019-12-19 15:36:05 +01:00
|
|
|
|
2022-01-27 18:48:16 +01:00
|
|
|
#if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION
|
|
|
|
static int add_define(char **defs, char *d)
|
|
|
|
{
|
|
|
|
size_t len = (*defs ? strlen(*defs) : 0) + strlen(d) + 2;
|
|
|
|
char *m = realloc(*defs, len);
|
|
|
|
if (m) {
|
|
|
|
if (*defs)
|
|
|
|
strcat(m, ",");
|
|
|
|
strcat(m, d);
|
|
|
|
*defs = m;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-12-12 19:00:42 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-12-08 09:55:44 +01:00
|
|
|
static const char short_options[] = "hc:d:n:u:v:o:pP:sgxzV"
|
2021-12-06 11:00:02 +01:00
|
|
|
#if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION
|
2021-12-08 09:55:44 +01:00
|
|
|
"D:I:"
|
2021-12-06 11:00:02 +01:00
|
|
|
#endif
|
|
|
|
;
|
2015-08-04 17:23:03 +02:00
|
|
|
static const struct option long_options[] = {
|
2017-06-14 13:25:33 +02:00
|
|
|
{"help", 0, NULL, 'h'},
|
|
|
|
{"verbose", 1, NULL, 'v'},
|
|
|
|
{"compile", 1, NULL, 'c'},
|
2021-03-26 22:44:13 +01:00
|
|
|
{"pre-process", 1, NULL, 'p'},
|
2019-12-22 15:44:56 +01:00
|
|
|
{"decode", 1, NULL, 'd'},
|
2019-12-12 19:00:42 +01:00
|
|
|
{"normalize", 1, NULL, 'n'},
|
2019-12-19 15:36:05 +01:00
|
|
|
{"dump", 1, NULL, 'u'},
|
2017-06-14 13:25:33 +02:00
|
|
|
{"output", 1, NULL, 'o'},
|
2021-12-06 11:00:02 +01:00
|
|
|
#if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION
|
|
|
|
{"define", 1, NULL, 'D'},
|
2021-12-08 09:55:44 +01:00
|
|
|
{"inc-dir", 1, NULL, 'I'},
|
2021-12-06 11:00:02 +01:00
|
|
|
#endif
|
2019-12-12 19:18:28 +01:00
|
|
|
{"sort", 0, NULL, 's'},
|
2019-12-19 15:36:05 +01:00
|
|
|
{"group", 0, NULL, 'g'},
|
|
|
|
{"nocheck", 0, NULL, 'x'},
|
|
|
|
{"dapm-nosort", 0, NULL, 'z'},
|
2019-12-20 15:23:27 +01:00
|
|
|
{"version", 0, NULL, 'V'},
|
2015-08-04 17:23:03 +02:00
|
|
|
{0, 0, 0, 0},
|
|
|
|
};
|
2019-12-19 15:36:05 +01:00
|
|
|
char *source_file = NULL;
|
|
|
|
char *output_file = NULL;
|
2021-12-08 06:06:29 +01:00
|
|
|
const char *inc_path = NULL;
|
2022-01-27 18:48:16 +01:00
|
|
|
char *pre_processor_defs = NULL;
|
2019-12-22 15:44:56 +01:00
|
|
|
int c, err, op = 'c', cflags = 0, dflags = 0, sflags = 0, option_index;
|
2015-08-04 17:23:03 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
err = snd_output_stdio_attach(&log, stderr, 0);
|
|
|
|
assert(err >= 0);
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
case 'v':
|
2019-12-19 15:36:05 +01:00
|
|
|
cflags |= SND_TPLG_CREATE_VERBOSE;
|
2015-08-04 17:23:03 +02:00
|
|
|
break;
|
2019-12-19 15:36:05 +01:00
|
|
|
case 'z':
|
|
|
|
cflags |= SND_TPLG_CREATE_DAPM_NOSORT;
|
2015-08-04 17:23:03 +02:00
|
|
|
break;
|
2019-12-19 15:36:05 +01:00
|
|
|
case 'c':
|
2019-12-22 15:44:56 +01:00
|
|
|
case 'd':
|
2019-12-12 19:00:42 +01:00
|
|
|
case 'n':
|
2019-12-19 15:36:05 +01:00
|
|
|
case 'u':
|
|
|
|
if (source_file) {
|
2021-03-26 22:44:13 +01:00
|
|
|
fprintf(stderr, _("Cannot combine operations (compile, normalize, pre-process, dump)\n"));
|
2019-12-19 15:36:05 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
source_file = optarg;
|
|
|
|
op = c;
|
2019-12-12 19:00:42 +01:00
|
|
|
break;
|
2015-08-04 17:23:03 +02:00
|
|
|
case 'o':
|
|
|
|
output_file = optarg;
|
|
|
|
break;
|
2019-12-12 19:18:28 +01:00
|
|
|
case 's':
|
2019-12-19 15:36:05 +01:00
|
|
|
sflags |= SND_TPLG_SAVE_SORT;
|
|
|
|
break;
|
2021-03-26 22:44:13 +01:00
|
|
|
case 'P':
|
|
|
|
op = 'P';
|
|
|
|
source_file = optarg;
|
|
|
|
break;
|
2021-12-08 09:55:44 +01:00
|
|
|
#if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION
|
2021-12-08 06:06:29 +01:00
|
|
|
case 'I':
|
|
|
|
inc_path = optarg;
|
|
|
|
break;
|
2021-12-08 09:55:44 +01:00
|
|
|
#endif
|
2021-03-26 22:44:13 +01:00
|
|
|
case 'p':
|
|
|
|
pre_process_config = true;
|
|
|
|
break;
|
2019-12-19 15:36:05 +01:00
|
|
|
case 'g':
|
|
|
|
sflags |= SND_TPLG_SAVE_GROUPS;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
sflags |= SND_TPLG_SAVE_NOCHECK;
|
2019-12-12 19:18:28 +01:00
|
|
|
break;
|
2021-12-06 11:00:02 +01:00
|
|
|
#if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION
|
2021-11-04 20:17:24 +01:00
|
|
|
case 'D':
|
2022-01-27 18:48:16 +01:00
|
|
|
if (add_define(&pre_processor_defs, optarg)) {
|
|
|
|
fprintf(stderr, _("No enough memory"));
|
|
|
|
return 1;
|
|
|
|
}
|
2021-11-04 20:17:24 +01:00
|
|
|
break;
|
2021-12-06 11:00:02 +01:00
|
|
|
#endif
|
2019-12-20 15:23:27 +01:00
|
|
|
case 'V':
|
|
|
|
version(argv[0]);
|
|
|
|
return 0;
|
2015-08-04 17:23:03 +02:00
|
|
|
default:
|
|
|
|
fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
if (source_file == NULL || output_file == NULL) {
|
|
|
|
usage(argv[0]);
|
2015-08-04 17:23:03 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-01-27 13:03:36 +01:00
|
|
|
if ((cflags & SND_TPLG_CREATE_VERBOSE) != 0 &&
|
|
|
|
output_file && strcmp(output_file, "-") == 0) {
|
|
|
|
fprintf(stderr, _("Invalid mix of verbose level and output to stdout.\n"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
if (op == 'n') {
|
|
|
|
if (sflags != 0 && sflags != SND_TPLG_SAVE_SORT) {
|
|
|
|
fprintf(stderr, _("Wrong parameters for the normalize operation!\n"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* normalize has predefined output */
|
|
|
|
sflags = SND_TPLG_SAVE_SORT;
|
2015-08-04 17:23:03 +02:00
|
|
|
}
|
|
|
|
|
2019-12-19 15:36:05 +01:00
|
|
|
switch (op) {
|
|
|
|
case 'c':
|
2021-12-08 06:06:29 +01:00
|
|
|
err = compile(source_file, output_file, cflags, pre_processor_defs, inc_path);
|
2019-12-19 15:36:05 +01:00
|
|
|
break;
|
2019-12-22 15:44:56 +01:00
|
|
|
case 'd':
|
|
|
|
err = decode(source_file, output_file, cflags, dflags, sflags);
|
|
|
|
break;
|
2021-03-26 22:44:13 +01:00
|
|
|
case 'P':
|
2021-12-08 06:06:29 +01:00
|
|
|
err = pre_process_conf(source_file, output_file, pre_processor_defs, inc_path);
|
2021-03-26 22:44:13 +01:00
|
|
|
break;
|
2019-12-19 15:36:05 +01:00
|
|
|
default:
|
|
|
|
err = dump(source_file, output_file, cflags, sflags);
|
|
|
|
break;
|
|
|
|
}
|
2019-12-12 19:18:28 +01:00
|
|
|
|
|
|
|
snd_output_close(log);
|
2022-01-27 18:48:16 +01:00
|
|
|
free(pre_processor_defs);
|
2019-12-19 15:36:05 +01:00
|
|
|
return err ? 1 : 0;
|
2015-08-04 17:23:03 +02:00
|
|
|
}
|