Blame topology/topology.c

Packit 229ac0
/*
Packit 229ac0
  Copyright(c) 2014-2015 Intel Corporation
Packit 229ac0
  Copyright(c) 2010-2011 Texas Instruments Incorporated,
Packit 229ac0
  All rights reserved.
Packit 229ac0
Packit 229ac0
  This program is free software; you can redistribute it and/or modify
Packit 229ac0
  it under the terms of version 2 of the GNU General Public License as
Packit 229ac0
  published by the Free Software Foundation.
Packit 229ac0
Packit 229ac0
  This program is distributed in the hope that it will be useful, but
Packit 229ac0
  WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 229ac0
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 229ac0
  General Public License for more details.
Packit 229ac0
Packit 229ac0
  You should have received a copy of the GNU General Public License
Packit 229ac0
  along with this program; if not, write to the Free Software
Packit 229ac0
  Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
Packit 229ac0
  The full GNU General Public License is included in this distribution
Packit 229ac0
  in the file called LICENSE.GPL.
Packit 229ac0
*/
Packit 229ac0
Packit 229ac0
#include <stdlib.h>
Packit 229ac0
#include <stdio.h>
Packit 229ac0
#include <stdint.h>
Packit 229ac0
#include <fcntl.h>
Packit 229ac0
#include <unistd.h>
Packit 229ac0
#include <errno.h>
Packit 229ac0
#include <string.h>
Packit 229ac0
#include <sys/stat.h>
Packit 229ac0
#include <getopt.h>
Packit 229ac0
#include <assert.h>
Packit 229ac0
Packit 229ac0
#include <alsa/asoundlib.h>
Packit 229ac0
#include <alsa/topology.h>
Packit 229ac0
#include "gettext.h"
Packit 229ac0
Packit 229ac0
static snd_output_t *log;
Packit 229ac0
Packit 229ac0
static void usage(char *name)
Packit 229ac0
{
Packit 229ac0
	printf(
Packit 229ac0
_("Usage: %s [OPTIONS]...\n"
Packit 229ac0
"\n"
Packit 229ac0
"-h, --help              help\n"
Packit 229ac0
"-c, --compile=FILE      compile file\n"
Packit 229ac0
"-v, --verbose=LEVEL     set verbosity level (0...1)\n"
Packit 229ac0
"-o, --output=FILE       set output file\n"
Packit 229ac0
), name);
Packit 229ac0
}
Packit 229ac0
Packit 229ac0
int main(int argc, char *argv[])
Packit 229ac0
{
Packit 229ac0
	snd_tplg_t *snd_tplg;
Packit 229ac0
	static const char short_options[] = "hc:v:o:";
Packit 229ac0
	static const struct option long_options[] = {
Packit 229ac0
		{"help", 0, NULL, 'h'},
Packit 229ac0
		{"verbose", 1, NULL, 'v'},
Packit 229ac0
		{"compile", 1, NULL, 'c'},
Packit 229ac0
		{"output", 1, NULL, 'o'},
Packit 229ac0
		{0, 0, 0, 0},
Packit 229ac0
	};
Packit 229ac0
	char *source_file = NULL, *output_file = NULL;
Packit 229ac0
	int c, err, verbose = 0, option_index;
Packit 229ac0
Packit 229ac0
#ifdef ENABLE_NLS
Packit 229ac0
	setlocale(LC_ALL, "");
Packit 229ac0
	textdomain(PACKAGE);
Packit 229ac0
#endif
Packit 229ac0
Packit 229ac0
	err = snd_output_stdio_attach(&log, stderr, 0);
Packit 229ac0
	assert(err >= 0);
Packit 229ac0
Packit 229ac0
	while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
Packit 229ac0
		switch (c) {
Packit 229ac0
		case 'h':
Packit 229ac0
			usage(argv[0]);
Packit 229ac0
			return 0;
Packit 229ac0
		case 'v':
Packit 229ac0
			verbose = atoi(optarg);
Packit 229ac0
			break;
Packit 229ac0
		case 'c':
Packit 229ac0
			source_file = optarg;
Packit 229ac0
			break;
Packit 229ac0
		case 'o':
Packit 229ac0
			output_file = optarg;
Packit 229ac0
			break;
Packit 229ac0
		default:
Packit 229ac0
			fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
Packit 229ac0
			return 1;
Packit 229ac0
		}
Packit 229ac0
	}
Packit 229ac0
Packit 229ac0
	if (source_file == NULL || output_file == NULL) {
Packit 229ac0
		usage(argv[0]);
Packit 229ac0
		return 1;
Packit 229ac0
	}
Packit 229ac0
Packit 229ac0
	snd_tplg = snd_tplg_new();
Packit 229ac0
	if (snd_tplg == NULL) {
Packit 229ac0
		fprintf(stderr, _("failed to create new topology context\n"));
Packit 229ac0
		return 1;
Packit 229ac0
	}
Packit 229ac0
Packit 229ac0
	snd_tplg_verbose(snd_tplg, verbose);
Packit 229ac0
Packit 229ac0
	err = snd_tplg_build_file(snd_tplg, source_file, output_file);
Packit 229ac0
	if (err < 0) {
Packit 229ac0
		fprintf(stderr, _("failed to compile context %s\n"), source_file);
Packit 229ac0
		snd_tplg_free(snd_tplg);
Packit 229ac0
		unlink(output_file);
Packit 229ac0
		return 1;
Packit 229ac0
	}
Packit 229ac0
Packit 229ac0
	snd_tplg_free(snd_tplg);
Packit 229ac0
	return 0;
Packit 229ac0
}
Packit 229ac0