File: alsalisp.c

package info (click to toggle)
alsa-lib 1.0.25-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,824 kB
  • sloc: ansic: 76,035; sh: 9,109; makefile: 691
file content (110 lines) | stat: -rw-r--r-- 2,678 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 *  ALSA lisp implementation
 *  Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
 *
 *
 *   This library is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as
 *   published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <err.h>

#include "asoundlib.h"
#include "alisp.h"

static int verbose = 0;
static int warning = 0;
static int debug = 0;

static void interpret_filename(const char *file)
{
	struct alisp_cfg cfg;
	snd_input_t *in;
	snd_output_t *out;
	int err;

	memset(&cfg, 0, sizeof(cfg));
	if (file != NULL && strcmp(file, "-") != 0) {
		if ((err = snd_input_stdio_open(&in, file, "r")) < 0) {
			fprintf(stderr, "unable to open filename '%s' (%s)\n", file, snd_strerror(err));
			return;
		}
	} else {
		if ((err = snd_input_stdio_attach(&in, stdin, 0)) < 0) {
			fprintf(stderr, "unable to attach stdin '%s' (%s)\n", file, snd_strerror(err));
			return;
		}
	}
	if (snd_output_stdio_attach(&out, stdout, 0) < 0) {
		snd_input_close(in);
		fprintf(stderr, "unable to attach stdout (%s)\n", strerror(errno));
		return;
	}
	cfg.verbose = verbose;
	cfg.warning = warning;
	cfg.debug = debug;
	cfg.in = in;
	cfg.out = cfg.eout = cfg.vout = cfg.wout = cfg.dout = out;
	err = alsa_lisp(&cfg, NULL);
	if (err < 0)
		fprintf(stderr, "alsa lisp returned error %i (%s)\n", err, strerror(err));
	else if (verbose)
		printf("file %s passed ok via alsa lisp interpreter\n", file);
	snd_output_close(out);
	snd_input_close(in);
}

static void usage(void)
{
	fprintf(stderr, "usage: alsalisp [-vdw] [file...]\n");
	exit(1);
}

int main(int argc, char **argv)
{
	int c;

	while ((c = getopt(argc, argv, "vdw")) != -1) {
		switch (c) {
		case 'v':
			verbose = 1;
			break;
		case 'd':
			debug = 1;
			break;
		case 'w':
			warning = 1;
			break;
		case '?':
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 1)
		interpret_filename(NULL);
	else
		while (*argv)
			interpret_filename(*argv++);

	return 0;
}