• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  ALSA lisp implementation
3  *  Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
4  *
5  *
6  *   This library is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU Lesser General Public License as
8  *   published by the Free Software Foundation; either version 2.1 of
9  *   the License, or (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <err.h>
27 
28 #include "asoundlib.h"
29 #include "alisp.h"
30 
31 static int verbose = 0;
32 static int warning = 0;
33 static int debug = 0;
34 
interpret_filename(const char * file)35 static void interpret_filename(const char *file)
36 {
37 	struct alisp_cfg cfg;
38 	snd_input_t *in;
39 	snd_output_t *out;
40 	int err;
41 
42 	memset(&cfg, 0, sizeof(cfg));
43 	if (file != NULL && strcmp(file, "-") != 0) {
44 		if ((err = snd_input_stdio_open(&in, file, "r")) < 0) {
45 			fprintf(stderr, "unable to open filename '%s' (%s)\n", file, snd_strerror(err));
46 			return;
47 		}
48 	} else {
49 		if ((err = snd_input_stdio_attach(&in, stdin, 0)) < 0) {
50 			fprintf(stderr, "unable to attach stdin '%s' (%s)\n", file, snd_strerror(err));
51 			return;
52 		}
53 	}
54 	if (snd_output_stdio_attach(&out, stdout, 0) < 0) {
55 		snd_input_close(in);
56 		fprintf(stderr, "unable to attach stdout (%s)\n", strerror(errno));
57 		return;
58 	}
59 	cfg.verbose = verbose;
60 	cfg.warning = warning;
61 	cfg.debug = debug;
62 	cfg.in = in;
63 	cfg.out = cfg.eout = cfg.vout = cfg.wout = cfg.dout = out;
64 	err = alsa_lisp(&cfg, NULL);
65 	if (err < 0)
66 		fprintf(stderr, "alsa lisp returned error %i (%s)\n", err, strerror(err));
67 	else if (verbose)
68 		printf("file %s passed ok via alsa lisp interpreter\n", file);
69 	snd_output_close(out);
70 	snd_input_close(in);
71 }
72 
usage(void)73 static void usage(void)
74 {
75 	fprintf(stderr, "usage: alsalisp [-vdw] [file...]\n");
76 	exit(1);
77 }
78 
main(int argc,char ** argv)79 int main(int argc, char **argv)
80 {
81 	int c;
82 
83 	while ((c = getopt(argc, argv, "vdw")) != -1) {
84 		switch (c) {
85 		case 'v':
86 			verbose = 1;
87 			break;
88 		case 'd':
89 			debug = 1;
90 			break;
91 		case 'w':
92 			warning = 1;
93 			break;
94 		case '?':
95 		default:
96 			usage();
97 			/* NOTREACHED */
98 		}
99 	}
100 	argc -= optind;
101 	argv += optind;
102 
103 	if (argc < 1)
104 		interpret_filename(NULL);
105 	else
106 		while (*argv)
107 			interpret_filename(*argv++);
108 
109 	return 0;
110 }
111