From 739a8290a8b05645a2d055aed8e5eb76ba2e24e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Fri, 28 Aug 2015 17:55:26 +0000 Subject: one-true indentation svn path=/trunk/externals/zexy/; revision=17537 --- src/lifop.c | 112 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 50 deletions(-) (limited to 'src/lifop.c') diff --git a/src/lifop.c b/src/lifop.c index 69e6c5b..2037c6e 100644 --- a/src/lifop.c +++ b/src/lifop.c @@ -1,4 +1,4 @@ -/* +/* * lifop: a LIFO (last-in first-out) with priorities * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * 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 . */ @@ -45,8 +45,7 @@ typedef struct _lifop_prioritylist { t_lifop_list *lifo_start; struct _lifop_prioritylist *next; } t_lifop_prioritylist; -typedef struct _lifop -{ +typedef struct _lifop { t_object x_obj; t_lifop_prioritylist *lifo_list; unsigned long counter; @@ -54,37 +53,41 @@ typedef struct _lifop t_outlet *x_out, *x_infout; } t_lifop; -static t_lifop_prioritylist*lifop_genprioritylist(t_lifop*x, t_float priority) +static t_lifop_prioritylist*lifop_genprioritylist(t_lifop*x, + t_float priority) { t_lifop_prioritylist*result=0, *dummy=0; - if(x->lifo_list!=0) - { - /* - * do we already have this priority ? - * if so, just return a pointer to that lifo - * else set the dummy-pointer to the lifo BEFORE the new one - */ - dummy=x->lifo_list; - while(dummy!=0){ - t_float prio=dummy->priority; - if(prio==priority)return dummy; - if(prio>priority)break; - result=dummy; - dummy=dummy->next; + if(x->lifo_list!=0) { + /* + * do we already have this priority ? + * if so, just return a pointer to that lifo + * else set the dummy-pointer to the lifo BEFORE the new one + */ + dummy=x->lifo_list; + while(dummy!=0) { + t_float prio=dummy->priority; + if(prio==priority) { + return dummy; + } + if(prio>priority) { + break; } - dummy=result; + result=dummy; + dummy=dummy->next; } + dummy=result; + } /* create a new priority list */ result = (t_lifop_prioritylist*)getbytes(sizeof( t_lifop_prioritylist)); result->priority=priority; result->lifo_start=0; /* insert it into the list of priority lists */ - if(dummy==0){ + if(dummy==0) { /* insert at the beginning */ result->next=x->lifo_list; - x->lifo_list=result; + x->lifo_list=result; } else { /* post insert into the list of LIFOs */ result->next=dummy->next; @@ -99,18 +102,17 @@ static int add2lifo(t_lifop_prioritylist*lifoprio, int argc, t_atom *argv) { t_lifop_list*entry=0; - if(lifoprio==0){ + if(lifoprio==0) { error("plifo: no lifos available"); return -1; } /* create an entry for the lifo */ - if(!(entry = (t_lifop_list*)getbytes(sizeof(t_lifop_list)))) - { - error("plifo: couldn't add entry to end of lifo"); - return -1; - } - if(!(entry->argv=(t_atom*)getbytes(argc*sizeof(t_atom)))){ + if(!(entry = (t_lifop_list*)getbytes(sizeof(t_lifop_list)))) { + error("plifo: couldn't add entry to end of lifo"); + return -1; + } + if(!(entry->argv=(t_atom*)getbytes(argc*sizeof(t_atom)))) { error("plifo: couldn't add list to lifo!"); return -1; } @@ -125,23 +127,27 @@ static int add2lifo(t_lifop_prioritylist*lifoprio, int argc, t_atom *argv) } static t_lifop_prioritylist*getLifo(t_lifop_prioritylist*plifo) { - if(plifo==0)return 0; + if(plifo==0) { + return 0; + } /* get the highest non-empty lifo */ - while(plifo->lifo_start==0 && plifo->next!=0)plifo=plifo->next; + while(plifo->lifo_start==0 && plifo->next!=0) { + plifo=plifo->next; + } return plifo; } -static void lifop_list(t_lifop *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void lifop_list(t_lifop *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { t_lifop_prioritylist*plifo=0; if(!(plifo=lifop_genprioritylist(x, x->priority))) { error("[lifop]: couldn't get priority lifo"); return; } - if(!add2lifo(plifo, argc, argv)) - { - x->counter++; - } + if(!add2lifo(plifo, argc, argv)) { + x->counter++; + } } static void lifop_bang(t_lifop *x) @@ -151,11 +157,11 @@ static void lifop_bang(t_lifop *x) t_atom*argv=0; int argc=0; - if(!(plifo=getLifo(x->lifo_list))){ + if(!(plifo=getLifo(x->lifo_list))) { outlet_bang(x->x_infout); return; } - if(!(lifo=plifo->lifo_start)){ + if(!(lifo=plifo->lifo_start)) { outlet_bang(x->x_infout); return; } @@ -182,25 +188,27 @@ static void lifop_bang(t_lifop *x) freebytes(argv, argc*sizeof(t_atom)); } static void lifop_query(t_lifop*x) -{ +{ z_verbose(1, "%d elements in lifo", (int)x->counter); - + outlet_float(x->x_infout, (t_float)x->counter); } static void lifop_clear(t_lifop *x) { t_lifop_prioritylist *lifo_list=x->lifo_list; - while(lifo_list){ + while(lifo_list) { t_lifop_prioritylist *lifo_list2=lifo_list; t_lifop_list*lifo=lifo_list2->lifo_start; lifo_list=lifo_list->next; - while(lifo){ + while(lifo) { t_lifop_list*lifo2=lifo; lifo=lifo->next; - if(lifo2->argv)freebytes(lifo2->argv, lifo2->argc*sizeof(t_atom)); + if(lifo2->argv) { + freebytes(lifo2->argv, lifo2->argc*sizeof(t_atom)); + } lifo2->argv=0; lifo2->argc=0; lifo2->next=0; @@ -217,7 +225,7 @@ static void lifop_clear(t_lifop *x) /* this is NOT re-entrant! */ static void lifop_dump(t_lifop*x) -{ +{ t_lifop_prioritylist*plifo=getLifo(x->lifo_list); if(!plifo||!plifo->lifo_start) { @@ -269,16 +277,20 @@ static void lifop_help(t_lifop*x) void lifop_setup(void) { lifop_class = class_new(gensym("lifop"), (t_newmethod)lifop_new, - (t_method)lifop_free, sizeof(t_lifop), 0, A_NULL); + (t_method)lifop_free, sizeof(t_lifop), 0, A_NULL); class_addbang (lifop_class, lifop_bang); class_addlist (lifop_class, lifop_list); - class_addmethod (lifop_class, (t_method)lifop_clear, gensym("clear"), A_NULL); - class_addmethod (lifop_class, (t_method)lifop_dump, gensym("dump"), A_NULL); + class_addmethod (lifop_class, (t_method)lifop_clear, gensym("clear"), + A_NULL); + class_addmethod (lifop_class, (t_method)lifop_dump, gensym("dump"), + A_NULL); - class_addmethod (lifop_class, (t_method)lifop_query, gensym("info"), A_NULL); - class_addmethod (lifop_class, (t_method)lifop_help, gensym("help"), A_NULL); + class_addmethod (lifop_class, (t_method)lifop_query, gensym("info"), + A_NULL); + class_addmethod (lifop_class, (t_method)lifop_help, gensym("help"), + A_NULL); zexy_register("lifop"); } -- cgit v1.2.1