From e8479343f6a6db1d28e362469dfafaccca378421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 21 Sep 2011 08:49:22 +0000 Subject: allow anythings for pack/unpack svn path=/trunk/externals/zexy/; revision=15326 --- src/unpack.c | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'src/unpack.c') diff --git a/src/unpack.c b/src/unpack.c index 0ec3641..c18861c 100644 --- a/src/unpack.c +++ b/src/unpack.c @@ -1,21 +1,30 @@ -/****************************************************** +/* + * unpack: a type-agnostic version of [unpack] * - * zexy - implementation file + * (c) 2007-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) * - * copyleft (c) IOhannes m zmölnig + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . +/* + +/* + * this version of [unpack] does not care about types, so the arguments are merely there for documentation reasons + * (and to determine the number of outlets) + * e.g. sending [symbol foo( to [zexy/unpack 0] will output [symbol foo( * - * 1999:forum::für::umläute:2004 - * - * institute of electronic music and acoustics (iem) - * - ****************************************************** - * - * license: GNU General Public License v.2 - * - ******************************************************/ - + * for know this object is named [zexy/unpack], as there might be some issues with compatibility with the original [unpack] + */ -/* 2305:forum::für::umläute:2001 */ #include "zexy.h" @@ -32,13 +41,23 @@ typedef struct _zunpack t_int x_numouts; } t_zunpack; -static void zunpack_list(t_zunpack *x, t_symbol *s, int argc, t_atom *argv) +static void zunpack_any(t_zunpack *x, t_symbol *s, int argc, t_atom *argv) { - int count=(argc<(x->x_numouts))?argc:x->x_numouts; + int offset=(s!=NULL)?1:0; + int count=((argc+offset)<(x->x_numouts))?(argc+offset):x->x_numouts; - while(count--) { - outlet_list(x->x_out[count], gensym("list"), 1, argv+count); + while(count-->offset) { + outlet_list(x->x_out[count], gensym("list"), 1, argv+count-offset); } + + if(s!=NULL) { + outlet_symbol(x->x_out[0], s); + } +} + +static void zunpack_list(t_zunpack *x, t_symbol *s, int argc, t_atom *argv) +{ + zunpack_any(x, 0, argc, argv); } static void zunpack_bang(t_zunpack *x) @@ -88,6 +107,7 @@ void zunpack_setup(void) class_addbang(zunpack_class, zunpack_bang); class_addlist(zunpack_class, zunpack_list); + class_addanything(zunpack_class, zunpack_any); zexy_register("unpack"); } -- cgit v1.2.1