tarina

git clone https://git.tarina.org/tarina
Log | Files | Refs | README | LICENSE

topology.c (2852B)


      1 /*
      2   Copyright(c) 2014-2015 Intel Corporation
      3   Copyright(c) 2010-2011 Texas Instruments Incorporated,
      4   All rights reserved.
      5 
      6   This program is free software; you can redistribute it and/or modify
      7   it under the terms of version 2 of the GNU General Public License as
      8   published by the Free Software Foundation.
      9 
     10   This program is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13   General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public License
     16   along with this program; if not, write to the Free Software
     17   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
     18   The full GNU General Public License is included in this distribution
     19   in the file called LICENSE.GPL.
     20 */
     21 
     22 #include <stdlib.h>
     23 #include <stdio.h>
     24 #include <stdint.h>
     25 #include <fcntl.h>
     26 #include <unistd.h>
     27 #include <errno.h>
     28 #include <string.h>
     29 #include <sys/stat.h>
     30 #include <dlfcn.h>
     31 #include <getopt.h>
     32 #include <assert.h>
     33 
     34 #include <alsa/asoundlib.h>
     35 #include <alsa/topology.h>
     36 #include "gettext.h"
     37 
     38 static snd_output_t *log;
     39 
     40 static void usage(char *name)
     41 {
     42 	printf(
     43 _("Usage: %s [OPTIONS]...\n"
     44 "\n"
     45 "-h, --help              help\n"
     46 "-c, --compile=FILE      compile file\n"
     47 "-v, --verbose=LEVEL     set verbosity level (0...1)\n"
     48 "-o, --output=FILE       set output file\n"
     49 ), name);
     50 }
     51 
     52 int main(int argc, char *argv[])
     53 {
     54 	snd_tplg_t *snd_tplg;
     55 	static const char short_options[] = "hc:v:o:";
     56 	static const struct option long_options[] = {
     57 		{"help", 0, 0, 'h'},
     58 		{"verbose", 0, 0, 'v'},
     59 		{"compile", 0, 0, 'c'},
     60 		{"output", 0, 0, 'o'},
     61 		{0, 0, 0, 0},
     62 	};
     63 	char *source_file = NULL, *output_file = NULL;
     64 	int c, err, verbose = 0, option_index;
     65 
     66 #ifdef ENABLE_NLS
     67 	setlocale(LC_ALL, "");
     68 	textdomain(PACKAGE);
     69 #endif
     70 
     71 	err = snd_output_stdio_attach(&log, stderr, 0);
     72 	assert(err >= 0);
     73 
     74 	while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
     75 		switch (c) {
     76 		case 'h':
     77 			usage(argv[0]);
     78 			return 0;
     79 		case 'v':
     80 			verbose = atoi(optarg);
     81 			break;
     82 		case 'c':
     83 			source_file = optarg;
     84 			break;
     85 		case 'o':
     86 			output_file = optarg;
     87 			break;
     88 		default:
     89 			fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
     90 			return 1;
     91 		}
     92 	}
     93 
     94 	if (source_file == NULL || output_file == NULL) {
     95 		usage(argv[0]);
     96 		return 1;
     97 	}
     98 
     99 	snd_tplg = snd_tplg_new();
    100 	if (snd_tplg == NULL) {
    101 		fprintf(stderr, _("failed to create new topology context\n"));
    102 		return 1;
    103 	}
    104 
    105 	snd_tplg_verbose(snd_tplg, verbose);
    106 
    107 	err = snd_tplg_build_file(snd_tplg, source_file, output_file);
    108 	if (err < 0) {
    109 		fprintf(stderr, _("failed to compile context %s\n"), source_file);
    110 		snd_tplg_free(snd_tplg);
    111 		return 1;
    112 	}
    113 
    114 	snd_tplg_free(snd_tplg);
    115 	return 0;
    116 }
    117