mirror of
https://gitee.com/openharmony/third_party_alsa-lib
synced 2025-02-20 00:32:33 +00:00
Initial code for lisp interpreter
This commit is contained in:
parent
8b1ac5a638
commit
640ee8faa7
@ -1,4 +1,4 @@
|
||||
SUBDIRS=doc include src aserver test utils
|
||||
SUBDIRS=doc include src aserver alsalisp test utils
|
||||
EXTRA_DIST=ChangeLog INSTALL TODO configure cvscompile libtool depcomp version
|
||||
|
||||
INCLUDES=-I$(top_srcdir)/include
|
||||
|
8
alsalisp/Makefile.am
Normal file
8
alsalisp/Makefile.am
Normal file
@ -0,0 +1,8 @@
|
||||
bin_PROGRAMS = alsalisp
|
||||
|
||||
alsalisp_SOURCES = alsalisp.c
|
||||
alsalisp_LDADD = ../src/libasound.la
|
||||
|
||||
all: alsalisp
|
||||
|
||||
INCLUDES=-I$(top_srcdir)/include -I$(top_srcdir)/src/alisp
|
120
alsalisp/alsalisp.c
Normal file
120
alsalisp/alsalisp.c
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* ALSA lisp implementation
|
||||
* Copyright (c) 2003 by Jaroslav Kysela <perex@suse.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;
|
||||
snd_config_t *root;
|
||||
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;
|
||||
}
|
||||
err = snd_config_top(&root);
|
||||
if (err < 0)
|
||||
fprintf(stderr, "unable to allocate config root\n");
|
||||
else {
|
||||
cfg.verbose = verbose;
|
||||
cfg.warning = warning;
|
||||
cfg.debug = debug;
|
||||
cfg.in = in;
|
||||
cfg.out = cfg.vout = cfg.wout = cfg.dout = out;
|
||||
cfg.root = root;
|
||||
cfg.node = root;
|
||||
err = alsa_lisp(&cfg);
|
||||
}
|
||||
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", file);
|
||||
snd_config_save(root, out);
|
||||
snd_output_close(out);
|
||||
snd_input_close(in);
|
||||
snd_config_delete(root);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
@ -165,7 +165,7 @@ AC_OUTPUT(Makefile doc/Makefile doc/pictures/Makefile include/Makefile
|
||||
src/pcm/Makefile src/pcm/ext/Makefile src/pcm/scopes/Makefile src/ordinary_pcm/Makefile \
|
||||
src/rawmidi/Makefile src/timer/Makefile \
|
||||
src/hwdep/Makefile src/seq/Makefile src/instr/Makefile \
|
||||
src/compat/Makefile src/conf/Makefile \
|
||||
src/compat/Makefile src/alisp/Makefile src/conf/Makefile \
|
||||
src/conf/cards/Makefile src/conf/pcm/Makefile \
|
||||
aserver/Makefile test/Makefile utils/Makefile \
|
||||
alsalisp/Makefile aserver/Makefile test/Makefile utils/Makefile \
|
||||
utils/alsa-lib.spec utils/alsa.pc)
|
||||
|
@ -9,7 +9,8 @@ alsainclude_HEADERS = asoundlib.h asoundef.h \
|
||||
hwdep.h control.h mixer.h \
|
||||
seq_event.h seq.h seqmid.h seq_midi_event.h \
|
||||
conv.h instr.h iatomic.h \
|
||||
pcm_ordinary.h mixer_ordinary.h
|
||||
pcm_ordinary.h mixer_ordinary.h \
|
||||
alisp.h
|
||||
|
||||
noinst_HEADERS = sys.h search.h list.h aserver.h local.h alsa-symbols.h
|
||||
|
||||
|
38
include/alisp.h
Normal file
38
include/alisp.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* ALSA lisp implementation
|
||||
* Copyright (c) 2003 by Jaroslav Kysela <perex@suse.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
|
||||
*
|
||||
*/
|
||||
|
||||
struct alisp_cfg {
|
||||
int verbose: 1,
|
||||
warning: 1,
|
||||
debug: 1;
|
||||
snd_input_t *in; /* program code */
|
||||
snd_output_t *out; /* program output */
|
||||
snd_output_t *vout; /* verbose output */
|
||||
snd_output_t *wout; /* warning output */
|
||||
snd_output_t *dout; /* debug output */
|
||||
snd_config_t *root;
|
||||
snd_config_t *node;
|
||||
};
|
||||
|
||||
int alsa_lisp(struct alisp_cfg *cfg);
|
||||
|
||||
extern struct alisp_object alsa_lisp_nil;
|
||||
extern struct alisp_object alsa_lisp_t;
|
@ -35,6 +35,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/poll.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/poll.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -71,6 +71,7 @@ int snd_output_printf(snd_output_t *output, const char *format, ...)
|
||||
__attribute__ ((format (printf, 2, 3)))
|
||||
#endif
|
||||
;
|
||||
int snd_output_vprintf(snd_output_t *output, const char *format, va_list args);
|
||||
int snd_output_puts(snd_output_t *output, const char *str);
|
||||
int snd_output_putc(snd_output_t *output, int c);
|
||||
int snd_output_flush(snd_output_t *output);
|
||||
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS=control mixer ordinary_mixer pcm ordinary_pcm rawmidi timer hwdep seq instr compat conf
|
||||
SUBDIRS=control mixer ordinary_mixer pcm ordinary_pcm rawmidi timer hwdep seq instr compat conf alisp
|
||||
EXTRA_DIST=Versions
|
||||
COMPATNUM=@LIBTOOL_VERSION_INFO@
|
||||
|
||||
@ -15,7 +15,7 @@ libasound_la_LIBADD = control/libcontrol.la \
|
||||
pcm/libpcm.la ordinary_pcm/libordinarypcm.la \
|
||||
rawmidi/librawmidi.la timer/libtimer.la \
|
||||
hwdep/libhwdep.la seq/libseq.la instr/libinstr.la \
|
||||
compat/libcompat.la -lm -ldl -lpthread
|
||||
compat/libcompat.la alisp/libalisp.la -lm -ldl -lpthread
|
||||
|
||||
libasound_la_LDFLAGS = -version-info $(COMPATNUM)
|
||||
LDFLAGS = $(VSYMS)
|
||||
@ -53,4 +53,7 @@ instr/libinstr.la:
|
||||
compat/libcompat.la:
|
||||
$(MAKE) -C compat libcompat.la
|
||||
|
||||
alisp/libalisp.la:
|
||||
$(MAKE) -C alisp libalisp.la
|
||||
|
||||
INCLUDES=-I$(top_srcdir)/include
|
||||
|
@ -108,3 +108,9 @@ ALSA_0.9.3 {
|
||||
snd_ctl_elem_info_get_dimensions;
|
||||
snd_ctl_elem_info_get_dimension;
|
||||
} ALSA_0.9.0;
|
||||
|
||||
ALSA_0.9.5 {
|
||||
global:
|
||||
|
||||
alsa_lisp;
|
||||
} ALSA_0.9.3;
|
||||
|
9
src/alisp/Makefile.am
Normal file
9
src/alisp/Makefile.am
Normal file
@ -0,0 +1,9 @@
|
||||
EXTRA_LTLIBRARIES = libalisp.la
|
||||
|
||||
libalisp_la_SOURCES = alisp.c
|
||||
|
||||
noinst_HEADERS = alisp_local.h
|
||||
|
||||
all: libalisp.la
|
||||
|
||||
INCLUDES=-I$(top_srcdir)/include
|
1628
src/alisp/alisp.c
Normal file
1628
src/alisp/alisp.c
Normal file
File diff suppressed because it is too large
Load Diff
92
src/alisp/alisp_local.h
Normal file
92
src/alisp/alisp_local.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* ALSA lisp implementation
|
||||
* Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
|
||||
*
|
||||
* Based on work of Sandro Sigala (slisp-1.2)
|
||||
*
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
enum alisp_tokens {
|
||||
ALISP_IDENTIFIER,
|
||||
ALISP_INTEGER,
|
||||
ALISP_STRING
|
||||
};
|
||||
|
||||
enum alisp_objects {
|
||||
ALISP_OBJ_NIL,
|
||||
ALISP_OBJ_T,
|
||||
ALISP_OBJ_INTEGER,
|
||||
ALISP_OBJ_IDENTIFIER,
|
||||
ALISP_OBJ_STRING,
|
||||
ALISP_OBJ_CONS
|
||||
};
|
||||
|
||||
struct alisp_object {
|
||||
int type;
|
||||
int gc;
|
||||
union {
|
||||
char *id;
|
||||
char *s;
|
||||
int i;
|
||||
struct {
|
||||
struct alisp_object *car;
|
||||
struct alisp_object *cdr;
|
||||
} c;
|
||||
} value;
|
||||
struct alisp_object *next;
|
||||
};
|
||||
|
||||
struct alisp_object_pair {
|
||||
struct alisp_object *name;
|
||||
struct alisp_object *value;
|
||||
struct alisp_object_pair *next;
|
||||
};
|
||||
|
||||
#define ALISP_LEX_BUF_MAX 16
|
||||
|
||||
struct alisp_instance {
|
||||
int verbose: 1,
|
||||
warning: 1,
|
||||
debug: 1;
|
||||
/* i/o */
|
||||
snd_input_t *in;
|
||||
snd_output_t *out;
|
||||
snd_output_t *vout; /* verbose output */
|
||||
snd_output_t *wout; /* warning output */
|
||||
snd_output_t *dout; /* debug output */
|
||||
/* lexer */
|
||||
int charno;
|
||||
int lineno;
|
||||
int lex_buf[ALISP_LEX_BUF_MAX];
|
||||
int *lex_bufp;
|
||||
char *token_buffer;
|
||||
int token_buffer_max;
|
||||
int thistoken;
|
||||
/* object allocator */
|
||||
int free_objs;
|
||||
int used_objs;
|
||||
struct alisp_object *free_objs_list;
|
||||
struct alisp_object *used_objs_list;
|
||||
/* set object */
|
||||
struct alisp_object_pair *setobjs_list;
|
||||
/* garbage collect */
|
||||
int gc_id;
|
||||
/* alsa configuration */
|
||||
snd_config_t *root; /* configuration root */
|
||||
snd_config_t *node; /* result */
|
||||
};
|
12
src/output.c
12
src/output.c
@ -78,6 +78,18 @@ int snd_output_printf(snd_output_t *output, const char *format, ...)
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes formatted output (like \c fprintf(3)) to an output handle.
|
||||
* \param output The output handle.
|
||||
* \param format Format string in \c fprintf format.
|
||||
* \param args Other \c fprintf arguments.
|
||||
* \return The number of characters written, or a negative error code.
|
||||
*/
|
||||
int snd_output_vprintf(snd_output_t *output, const char *format, va_list args)
|
||||
{
|
||||
return output->ops->print(output, format, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes a string to an output handle (like \c fputs(3)).
|
||||
* \param output The output handle.
|
||||
|
Loading…
x
Reference in New Issue
Block a user