Update of /cvsroot/alsa/alsa-lib/src/alisp In directory sc8-pr-cvs1:/tmp/cvs-serv23405/src/alisp
Modified Files: alisp.c alisp_snd.c Log Message: added snd_hctl_ctl() function ordinary mixer: - revised Ordinary Mixer I/O type - sndo_mixer_open() take PCMs rather than strings to pass the real relationship - an initial version of toplevel alisp script more alisp development: - renamed a* functions to A* functions (acall -> Acall etc.) - many improvements (unset*, exfun, Acall pcm_info, Asnderr, Asyserr) Index: alisp.c =================================================================== RCS file: /cvsroot/alsa/alsa-lib/src/alisp/alisp.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- alisp.c 3 Sep 2003 19:25:09 -0000 1.9 +++ alisp.c 9 Sep 2003 19:24:36 -0000 1.10 @@ -309,6 +309,24 @@ return obj; } +static struct alisp_object * new_cons_pointer(struct alisp_instance * instance, const char *ptr_id, void *ptr) +{ + struct alisp_object * lexpr; + + if (ptr == NULL) + return &alsa_lisp_nil; + lexpr = new_object(instance, ALISP_OBJ_CONS); + if (lexpr == NULL) + return NULL; + lexpr->value.c.car = new_string(instance, ptr_id); + if (lexpr->value.c.car == NULL) + return NULL; + lexpr->value.c.cdr = new_pointer(instance, ptr); + if (lexpr->value.c.cdr == NULL) + return NULL; + return lexpr; +} + void alsa_lisp_init_objects(void) __attribute__ ((constructor)); void alsa_lisp_init_objects(void) @@ -563,10 +581,13 @@ return first; } -static struct alisp_object * parse_quote(struct alisp_instance *instance) +static struct alisp_object * quote_object(struct alisp_instance *instance, struct alisp_object * obj) { struct alisp_object * p; + if (obj == NULL) + return NULL; + p = new_object(instance, ALISP_OBJ_CONS); if (p == NULL) return NULL; @@ -577,13 +598,16 @@ p->value.c.cdr = new_object(instance, ALISP_OBJ_CONS); if (p->value.c.cdr == NULL) return NULL; - p->value.c.cdr->value.c.car = parse_object(instance, 0); - if (p->value.c.cdr->value.c.car == NULL) - return NULL; + p->value.c.cdr->value.c.car = obj; return p; } +static inline struct alisp_object * parse_quote(struct alisp_instance *instance) +{ + return quote_object(instance, parse_object(instance, 0)); +} + static struct alisp_object * parse_object(struct alisp_instance *instance, int havetoken) { int thistoken; @@ -662,8 +686,9 @@ return p; } -static void unset_object1(struct alisp_instance *instance, const char *id) +static struct alisp_object * unset_object1(struct alisp_instance *instance, const char *id) { + struct alisp_object * res; struct alisp_object_pair *p, *p1; for (p = instance->setobjs_list, p1 = NULL; p != NULL; p1 = p, p = p->next) { @@ -673,13 +698,16 @@ p1->next = p->next; else instance->setobjs_list = p->next; + res = p->value; free(p); - return; + return res; } } + + return &alsa_lisp_nil; } -static inline void unset_object(struct alisp_instance *instance, struct alisp_object * name) +static inline struct alisp_object * unset_object(struct alisp_instance *instance, struct alisp_object * name) { return unset_object1(instance, name->value.id); } @@ -688,10 +716,11 @@ { struct alisp_object_pair *p; - for (p = instance->setobjs_list; p != NULL; p = p->next) + for (p = instance->setobjs_list; p != NULL; p = p->next) { if (p->name->value.id != NULL && !strcmp(id, p->name->value.id)) return p->value; + } return &alsa_lisp_nil; } @@ -956,18 +985,22 @@ } else { return new_float(instance, f); } - } else if (p1->type == ALISP_OBJ_STRING || p1->type == ALISP_OBJ_IDENTIFIER) { + } else if (p1->type == ALISP_OBJ_STRING) { char *str = NULL, *str1; for (;;) { - if (p1->type == ALISP_OBJ_STRING || p1->type == ALISP_OBJ_IDENTIFIER) { - str1 = realloc(str, strlen(str) + strlen(p1->value.s) + 1); + if (p1->type == ALISP_OBJ_STRING) { + str1 = realloc(str, (str ? strlen(str) : 0) + strlen(p1->value.s) + 1); if (str1 == NULL) { nomem(); if (str) free(str); return NULL; } - strcat(str, p1->value.s); + if (str == NULL) + strcpy(str1, p1->value.s); + else + strcat(str1, p1->value.s); + str = str1; } else { lisp_warn(instance, "concat with a non string or identifier operand"); } @@ -1292,6 +1325,27 @@ return &alsa_lisp_nil; } +/* + * Syntax: (exfun name) + * Test, if a function exists + */ +static struct alisp_object * F_exfun(struct alisp_instance *instance, struct alisp_object * args) +{ + struct alisp_object * p1, * p2; + + p1 = car(args); + if (p1->type != ALISP_OBJ_STRING && p1->type != ALISP_OBJ_IDENTIFIER) + return &alsa_lisp_nil; + p2 = get_object(instance, p1); + if (p2 == &alsa_lisp_nil) + return &alsa_lisp_nil; + p2 = car(p2); + if (p2->type == ALISP_OBJ_IDENTIFIER && !strcmp(p2->value.id, "lambda")) + return &alsa_lisp_t; + + return &alsa_lisp_nil; +} + static void princ_string(snd_output_t *out, char *s) { char *p; @@ -1448,31 +1502,27 @@ static int equal(struct alisp_object * p1, struct alisp_object * p2) { + int type1, type2; + if (eq(p1, p2)) return 1; - if (p1->type == ALISP_OBJ_CONS || p2->type == ALISP_OBJ_CONS) + type1 = p1->type; + type2 = p2->type; + + if (type1 == ALISP_OBJ_CONS || type2 == ALISP_OBJ_CONS) return 0; - if (p1->type == p2->type) - switch (p1->type) { - case ALISP_OBJ_IDENTIFIER: - if (!strcmp(p1->value.id, p2->value.id)) - return 1; - return 0; + if (type1 == type2) { + switch (type1) { case ALISP_OBJ_STRING: - if (!strcmp(p1->value.s, p2->value.s)) - return 1; - return 0; + return !strcmp(p1->value.s, p2->value.s); case ALISP_OBJ_INTEGER: - if (p1->value.i == p2->value.i) - return 1; - return 0; + return p1->value.i == p2->value.i; case ALISP_OBJ_FLOAT: - if (p1->value.i == p2->value.i) - return 1; - return 0; + return p1->value.i == p2->value.i; } + } return 0; } @@ -1727,7 +1777,7 @@ struct alisp_object * p1 = eval(instance, car(args)); unset_object(instance, p1); - return &alsa_lisp_nil; + return p1; } /* @@ -1757,15 +1807,15 @@ */ static struct alisp_object * F_unsetq(struct alisp_instance *instance, struct alisp_object * args) { - struct alisp_object * p = args, * p1; + struct alisp_object * p = args, * p1, * res; do { p1 = car(p); - unset_object(instance, p1); + res = unset_object(instance, p1); p = cdr(p); } while (p != &alsa_lisp_nil); - return &alsa_lisp_nil; + return res; } /* @@ -1885,7 +1935,7 @@ struct alisp_object * p = args, * p1; p1 = eval(instance, car(p)); - if (p1->type != ALISP_STRING && p1->type != ALISP_IDENTIFIER) + if (p1->type != ALISP_OBJ_STRING) return &alsa_lisp_nil; if (!strcmp(p1->value.s, "data")) return new_string(instance, DATADIR); @@ -1898,15 +1948,16 @@ struct alisp_object * F_include(struct alisp_instance *instance, struct alisp_object * args) { struct alisp_object * p = args, * p1; + int res = -ENOENT; do { p1 = eval(instance, car(p)); - if (p1->type == ALISP_STRING && p1->type == ALISP_IDENTIFIER) - alisp_include_file(instance, p1->value.s); + if (p1->type == ALISP_OBJ_STRING) + res = alisp_include_file(instance, p1->value.s); p = cdr(p); } while (p != &alsa_lisp_nil); - return p1; + return new_integer(instance, res); } /* @@ -2140,12 +2191,13 @@ { "eq", F_eq }, { "equal", F_equal }, { "eval", F_eval }, + { "exfun", F_exfun }, { "float", F_float }, { "garbage-collect", F_gc }, { "gc", F_gc }, { "if", F_if }, - { "int", F_int }, { "include", F_include }, + { "int", F_int }, { "list", F_list }, { "not", F_not }, { "nth", F_nth }, @@ -2219,7 +2271,9 @@ case ALISP_OBJ_IDENTIFIER: return get_object(instance, p); case ALISP_OBJ_INTEGER: + case ALISP_OBJ_FLOAT: case ALISP_OBJ_STRING: + case ALISP_OBJ_POINTER: return p; case ALISP_OBJ_CONS: return eval_cons(instance, p); @@ -2385,23 +2439,6 @@ unset_object(instance, omain); - for (;;) { - p = get_object1(instance, "auto-exec"); - if (p == &alsa_lisp_nil) - break; - p = get_object(instance, p); - if (p == &alsa_lisp_nil) - break; - unset_object1(instance, "auto-exec"); - p1 = eval_func(instance, p, &alsa_lisp_nil); - if (p1 == NULL) { - retval = -ENOMEM; - break; - } - garbage_collect(instance); - } - - done_lex(instance); if (_instance) *_instance = instance; else @@ -2414,6 +2451,7 @@ { if (instance == NULL) return; + done_lex(instance); free_objects(instance); free(instance); } @@ -2458,11 +2496,11 @@ const char *id, const char *args, ...) { int err = 0; - struct alisp_object *aargs = NULL, *p3, *res; + struct alisp_object *aargs = NULL, *obj, *res; if (args && *args != 'n') { va_list ap; - struct alisp_object *p, *obj; + struct alisp_object *p; p = NULL; va_start(ap, args); while (*args) { @@ -2490,6 +2528,20 @@ case 'd': obj = new_integer(instance, va_arg(ap, double)); break; + case 'p': { + char _ptrid[24]; + char *ptrid = _ptrid; + while (*args && *args != '%') + *ptrid++ = *args++; + *ptrid = 0; + if (ptrid == _ptrid) { + err = -EINVAL; + break; + } + obj = new_cons_pointer(instance, _ptrid, va_arg(ap, void *)); + obj = quote_object(instance, obj); + break; + } default: err = -EINVAL; break; @@ -2526,8 +2578,8 @@ err = -ENOENT; if (aargs == NULL) aargs = &alsa_lisp_nil; - if ((p3 = get_object1(instance, id)) != &alsa_lisp_nil) { - res = eval_func(instance, p3, aargs); + if ((obj = get_object1(instance, id)) != &alsa_lisp_nil) { + res = eval_func(instance, obj, aargs); err = 0; } else { struct intrinsic key, *item; @@ -2607,7 +2659,7 @@ seq = seq->value.c.cdr; if (seq->type == ALISP_OBJ_CONS) { p2 = seq->value.c.car; - if (p2->type != ALISP_OBJ_STRING && p2->type != ALISP_OBJ_IDENTIFIER) + if (p2->type != ALISP_OBJ_STRING) return -EINVAL; if (strcmp(p2->value.s, ptr_id)) return -EINVAL; Index: alisp_snd.c =================================================================== RCS file: /cvsroot/alsa/alsa-lib/src/alisp/alisp_snd.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- alisp_snd.c 3 Aug 2003 20:36:54 -0000 1.5 +++ alisp_snd.c 9 Sep 2003 19:24:36 -0000 1.6 @@ -243,24 +243,6 @@ return lexpr; } -static struct alisp_object * new_result4(struct alisp_instance * instance, const char *ptr_id, void *ptr) -{ - struct alisp_object * lexpr; - - if (ptr == NULL) - return &alsa_lisp_nil; - lexpr = new_object(instance, ALISP_OBJ_CONS); - if (lexpr == NULL) - return NULL; - lexpr->value.c.car = new_string(instance, ptr_id); - if (lexpr->value.c.car == NULL) - return NULL; - lexpr->value.c.cdr = new_pointer(instance, ptr); - if (lexpr->value.c.cdr == NULL) - return NULL; - return lexpr; -} - /* * macros */ @@ -326,6 +308,8 @@ item->xfunc == &snd_hctl_elem_next || item->xfunc == &snd_hctl_elem_prev) prefix1 = "hctl_elem"; + else if (item->xfunc == &snd_hctl_ctl) + prefix1 = "ctl"; else return &alsa_lisp_nil; args = eval(instance, car(args)); @@ -333,7 +317,7 @@ if (handle == NULL) return &alsa_lisp_nil; handle = ((snd_p_p_t)item->xfunc)(handle); - return new_result4(instance, prefix1, handle); + return new_cons_pointer(instance, prefix1, handle); } static struct alisp_object * FA_int_p(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) @@ -466,7 +450,7 @@ snd_ctl_elem_id_alloca(&id); if (parse_ctl_elem_id(eval(instance, car(cdr(args))), id) < 0) return &alsa_lisp_nil; - return new_result4(instance, "hctl_elem", snd_hctl_find_elem(handle, id)); + return new_cons_pointer(instance, "hctl_elem", snd_hctl_find_elem(handle, id)); } static struct alisp_object * FA_hctl_elem_info(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) @@ -660,6 +644,36 @@ return new_result(instance, err); } +static struct alisp_object * FA_pcm_info(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) +{ + snd_pcm_t *handle; + struct alisp_object * lexpr, * p1; + snd_pcm_info_t *info; + int err; + + args = eval(instance, car(args)); + handle = (snd_pcm_t *)get_ptr(args, item->prefix); + if (handle == NULL) + return &alsa_lisp_nil; + snd_pcm_info_alloca(&info); + err = snd_pcm_info(handle, info); + lexpr = new_lexpr(instance, err); + if (err < 0) + return lexpr; + p1 = add_cons(instance, lexpr->value.c.cdr, 0, "card", new_integer(instance, snd_pcm_info_get_card(info))); + p1 = add_cons(instance, p1, 1, "device", new_integer(instance, snd_pcm_info_get_device(info))); + p1 = add_cons(instance, p1, 1, "subdevice", new_integer(instance, snd_pcm_info_get_subdevice(info))); + p1 = add_cons(instance, p1, 1, "id", new_string(instance, snd_pcm_info_get_id(info))); + p1 = add_cons(instance, p1, 1, "name", new_string(instance, snd_pcm_info_get_name(info))); + p1 = add_cons(instance, p1, 1, "subdevice_name", new_string(instance, snd_pcm_info_get_subdevice_name(info))); + p1 = add_cons(instance, p1, 1, "class", new_integer(instance, snd_pcm_info_get_class(info))); + p1 = add_cons(instance, p1, 1, "subclass", new_integer(instance, snd_pcm_info_get_subclass(info))); + p1 = add_cons(instance, p1, 1, "subdevices_count", new_integer(instance, snd_pcm_info_get_subdevices_count(info))); + p1 = add_cons(instance, p1, 1, "subdevices_avail", new_integer(instance, snd_pcm_info_get_subdevices_avail(info))); + //p1 = add_cons(instance, p1, 1, "sync", new_string(instance, snd_pcm_info_get_sync(info))); + return lexpr; +} + /* * main code */ @@ -673,6 +687,7 @@ { "ctl_close", &FA_int_p, (void *)&snd_ctl_close, "ctl" }, { "ctl_open", &FA_int_pp_strp_int, (void *)&snd_ctl_open, "ctl" }, { "hctl_close", &FA_int_p, (void *)&snd_hctl_close, "hctl" }, + { "hctl_ctl", &FA_p_p, (void *)&snd_hctl_ctl, "hctl" }, { "hctl_elem_info", &FA_hctl_elem_info, (void *)&snd_hctl_elem_info, "hctl_elem" }, { "hctl_elem_next", &FA_p_p, (void *)&snd_hctl_elem_next, "hctl_elem" }, { "hctl_elem_prev", &FA_p_p, (void *)&snd_hctl_elem_prev, "hctl_elem" }, @@ -685,6 +700,7 @@ { "hctl_load", &FA_int_p, (void *)&snd_hctl_load, "hctl" }, { "hctl_open", &FA_int_pp_strp_int, (void *)&snd_hctl_open, "hctl" }, { "hctl_open_ctl", &FA_int_pp_p, (void *)&snd_hctl_open_ctl, "hctl" }, + { "pcm_info", &FA_pcm_info, NULL, "pcm" }, }; static int acall_compar(const void *p1, const void *p2) @@ -724,9 +740,60 @@ return args; } +static int common_error(snd_output_t **rout, struct alisp_instance *instance, struct alisp_object * args) +{ + struct alisp_object * p = args, * p1; + snd_output_t *out; + int err; + + err = snd_output_buffer_open(&out); + if (err < 0) + return err; + + do { + p1 = eval(instance, car(p)); + if (p1->type == ALISP_OBJ_STRING) + snd_output_printf(out, "%s", p1->value.s); + else + princ_object(out, p1); + p = cdr(p); + } while (p != &alsa_lisp_nil); + + *rout = out; + return 0; +} + +static struct alisp_object * F_snderr(struct alisp_instance *instance, struct alisp_object * args) +{ + snd_output_t *out; + char *str; + + if (common_error(&out, instance, args) < 0) + return &alsa_lisp_nil; + snd_output_buffer_string(out, &str); + SNDERR(str); + snd_output_close(out); + return &alsa_lisp_t; +} + +static struct alisp_object * F_syserr(struct alisp_instance *instance, struct alisp_object * args) +{ + snd_output_t *out; + char *str; + + if (common_error(&out, instance, args) < 0) + return &alsa_lisp_nil; + snd_output_buffer_string(out, &str); + SYSERR(str); + snd_output_close(out); + return &alsa_lisp_t; +} + static struct intrinsic snd_intrinsics[] = { - { "acall", F_acall }, - { "aerror", F_aerror }, - { "ahandle", F_ahandle }, - { "aresult", F_ahandle }, + { "Acall", F_acall }, + { "Aerror", F_aerror }, + { "Ahandle", F_ahandle }, + { "Aresult", F_ahandle }, + { "Asnderr", F_snderr }, + { "Asyserr", F_syserr } }; ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Alsa-cvslog mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/alsa-cvslog