Blame alsalisp/alsalisp.c

Packit 4a16fb
/*
Packit 4a16fb
 *  ALSA lisp implementation
Packit 4a16fb
 *  Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 *
Packit 4a16fb
 *
Packit 4a16fb
 *   This library is free software; you can redistribute it and/or modify
Packit 4a16fb
 *   it under the terms of the GNU Lesser General Public License as
Packit 4a16fb
 *   published by the Free Software Foundation; either version 2.1 of
Packit 4a16fb
 *   the License, or (at your option) any later version.
Packit 4a16fb
 *
Packit 4a16fb
 *   This program is distributed in the hope that it will be useful,
Packit 4a16fb
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4a16fb
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 4a16fb
 *   GNU Lesser General Public License for more details.
Packit 4a16fb
 *
Packit 4a16fb
 *   You should have received a copy of the GNU Lesser General Public
Packit 4a16fb
 *   License along with this library; if not, write to the Free Software
Packit 4a16fb
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 4a16fb
 *
Packit 4a16fb
 */
Packit 4a16fb
Packit 4a16fb
#include <stdio.h>
Packit 4a16fb
#include <stdlib.h>
Packit 4a16fb
#include <string.h>
Packit 4a16fb
#include <unistd.h>
Packit 4a16fb
#include <err.h>
Packit 4a16fb
Packit 4a16fb
#include "asoundlib.h"
Packit 4a16fb
#include "alisp.h"
Packit 4a16fb
Packit 4a16fb
static int verbose = 0;
Packit 4a16fb
static int warning = 0;
Packit 4a16fb
static int debug = 0;
Packit 4a16fb
Packit 4a16fb
static void interpret_filename(const char *file)
Packit 4a16fb
{
Packit 4a16fb
	struct alisp_cfg cfg;
Packit 4a16fb
	snd_input_t *in;
Packit 4a16fb
	snd_output_t *out;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	memset(&cfg, 0, sizeof(cfg));
Packit 4a16fb
	if (file != NULL && strcmp(file, "-") != 0) {
Packit 4a16fb
		if ((err = snd_input_stdio_open(&in, file, "r")) < 0) {
Packit 4a16fb
			fprintf(stderr, "unable to open filename '%s' (%s)\n", file, snd_strerror(err));
Packit 4a16fb
			return;
Packit 4a16fb
		}
Packit 4a16fb
	} else {
Packit 4a16fb
		if ((err = snd_input_stdio_attach(&in, stdin, 0)) < 0) {
Packit 4a16fb
			fprintf(stderr, "unable to attach stdin '%s' (%s)\n", file, snd_strerror(err));
Packit 4a16fb
			return;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
	if (snd_output_stdio_attach(&out, stdout, 0) < 0) {
Packit 4a16fb
		snd_input_close(in);
Packit 4a16fb
		fprintf(stderr, "unable to attach stdout (%s)\n", strerror(errno));
Packit 4a16fb
		return;
Packit 4a16fb
	}
Packit 4a16fb
	cfg.verbose = verbose;
Packit 4a16fb
	cfg.warning = warning;
Packit 4a16fb
	cfg.debug = debug;
Packit 4a16fb
	cfg.in = in;
Packit 4a16fb
	cfg.out = cfg.eout = cfg.vout = cfg.wout = cfg.dout = out;
Packit 4a16fb
	err = alsa_lisp(&cfg, NULL);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		fprintf(stderr, "alsa lisp returned error %i (%s)\n", err, strerror(err));
Packit 4a16fb
	else if (verbose)
Packit 4a16fb
		printf("file %s passed ok via alsa lisp interpreter\n", file);
Packit 4a16fb
	snd_output_close(out);
Packit 4a16fb
	snd_input_close(in);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void usage(void)
Packit 4a16fb
{
Packit 4a16fb
	fprintf(stderr, "usage: alsalisp [-vdw] [file...]\n");
Packit 4a16fb
	exit(1);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int main(int argc, char **argv)
Packit 4a16fb
{
Packit 4a16fb
	int c;
Packit 4a16fb
Packit 4a16fb
	while ((c = getopt(argc, argv, "vdw")) != -1) {
Packit 4a16fb
		switch (c) {
Packit 4a16fb
		case 'v':
Packit 4a16fb
			verbose = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'd':
Packit 4a16fb
			debug = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'w':
Packit 4a16fb
			warning = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case '?':
Packit 4a16fb
		default:
Packit 4a16fb
			usage();
Packit 4a16fb
			/* NOTREACHED */
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
	argc -= optind;
Packit 4a16fb
	argv += optind;
Packit 4a16fb
Packit 4a16fb
	if (argc < 1)
Packit 4a16fb
		interpret_filename(NULL);
Packit 4a16fb
	else
Packit 4a16fb
		while (*argv)
Packit 4a16fb
			interpret_filename(*argv++);
Packit 4a16fb
Packit 4a16fb
	return 0;
Packit 4a16fb
}