OSDN Git Service

Added snd_hctl_open_ctl() function.
[android-x86/external-alsa-lib.git] / alsalisp / alsalisp.c
1 /*
2  *  ALSA lisp implementation
3  *  Copyright (c) 2003 by Jaroslav Kysela <perex@suse.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 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
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         snd_config_t *root;
41         int err;
42
43         memset(&cfg, 0, sizeof(cfg));
44         if (file != NULL && strcmp(file, "-") != 0) {
45                 if ((err = snd_input_stdio_open(&in, file, "r")) < 0) {
46                         fprintf(stderr, "unable to open filename '%s' (%s)\n", file, snd_strerror(err));
47                         return;
48                 }
49         } else {
50                 if ((err = snd_input_stdio_attach(&in, stdin, 0)) < 0) {
51                         fprintf(stderr, "unable to attach stdin '%s' (%s)\n", file, snd_strerror(err));
52                         return;
53                 }
54         }
55         if (snd_output_stdio_attach(&out, stdout, 0) < 0) {
56                 snd_input_close(in);
57                 fprintf(stderr, "unable to attach stdout (%s)\n", strerror(errno));
58                 return;
59         }
60         err = snd_config_top(&root);
61         if (err < 0)
62                 fprintf(stderr, "unable to allocate config root\n");
63         else {
64                 cfg.verbose = verbose;
65                 cfg.warning = warning;
66                 cfg.debug = debug;
67                 cfg.in = in;
68                 cfg.out = cfg.eout = cfg.vout = cfg.wout = cfg.dout = out;
69                 cfg.root = root;
70                 cfg.node = root;
71                 err = alsa_lisp(&cfg, NULL);
72         }
73         if (err < 0)
74                 fprintf(stderr, "alsa lisp returned error %i (%s)\n", err, strerror(err));
75         else if (verbose)
76                 printf("file %s passed ok via alsa lisp interpreter\n", file);
77         snd_config_save(root, out);
78         snd_output_close(out);
79         snd_input_close(in);
80         snd_config_delete(root);
81 }
82
83 static void usage(void)
84 {
85         fprintf(stderr, "usage: alsalisp [-vdw] [file...]\n");
86         exit(1);
87 }
88
89 int main(int argc, char **argv)
90 {
91         int c;
92
93         while ((c = getopt(argc, argv, "vdw")) != -1) {
94                 switch (c) {
95                 case 'v':
96                         verbose = 1;
97                         break;
98                 case 'd':
99                         debug = 1;
100                         break;
101                 case 'w':
102                         warning = 1;
103                         break;
104                 case '?':
105                 default:
106                         usage();
107                         /* NOTREACHED */
108                 }
109         }
110         argc -= optind;
111         argv += optind;
112
113         if (argc < 1)
114                 interpret_filename(NULL);
115         else
116                 while (*argv)
117                         interpret_filename(*argv++);
118
119         return 0;
120 }