Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30951
Modified Files:
Tag: desiredata
kernel.c
Log Message:
shrink code
Index: kernel.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** kernel.c 13 Dec 2006 19:45:34 -0000 1.1.2.1
--- kernel.c 13 Dec 2006 20:08:42 -0000 1.1.2.2
***************
*** 1,12 ****
! /* Copyright (c) 1997-1999 Miller Puckette.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
! * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
#include <stdlib.h>
#include <string.h>
- #include "desire.h"
-
/* T.Grill - include SIMD functionality */
#include "m_simd.h"
/* T.Grill - bit alignment for signal vectors (must be a multiple of 8!) */
--- 1,13 ----
! /* Copyright (c) 2006 Mathieu Bouchard */
! /* Copyright (c) 1997-1999 Miller Puckette except the hashtable.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
! * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+ #include "desire.h"
#include <stdlib.h>
#include <string.h>
/* T.Grill - include SIMD functionality */
#include "m_simd.h"
+ #include <stdio.h>
/* T.Grill - bit alignment for signal vectors (must be a multiple of 8!) */
***************
*** 120,131 ****
return (ret);
}
- /* independent hash table for PureData */
- /* Copyright (c) 2006 Mathieu Bouchard */
- /* Part of PureData devel_0_39 */
- /* Licensed under SIBSD */
-
- #include "m_pd.h"
- #include <stdlib.h>
- #include <stdio.h>
t_class *hash_class;
--- 121,124 ----
***************
*** 229,291 ****
(t_method)hash_free, sizeof(t_object), CLASS_PD, A_GIMME, 0);
}
- /* Copyright (c) 1997-1999 Miller Puckette.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
- #include "m_pd.h"
- #include <stdio.h>
- #include <string.h>
! /* convenience routines for checking and getting values of
! atoms. There's no "pointer" version since there's nothing
! safe to return if there's an error. */
! t_float atom_getfloat(t_atom *a)
! {
! if (a->a_type == A_FLOAT) return (a->a_w.w_float);
! else return (0);
}
! t_int atom_getint(t_atom *a)
! {
! return (atom_getfloat(a));
! }
! t_symbol *atom_getsymbol(t_atom *a) /* LATER think about this more carefully */
! {
! char buf[30];
! if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol);
! else return (&s_float);
}
! t_symbol *atom_gensym(t_atom *a) /* this works better for graph labels */
! {
char buf[30];
if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol);
! else if (a->a_type == A_FLOAT)
! sprintf(buf, "%g", a->a_w.w_float);
else strcpy(buf, "???");
! return (gensym(buf));
}
! t_float atom_getfloatarg(int which, int argc, t_atom *argv)
! {
! if (argc <= which) return (0);
argv += which;
! if (argv->a_type == A_FLOAT) return (argv->a_w.w_float);
! else return (0);
}
t_int atom_getintarg(int which, int argc, t_atom *argv)
! {
! return (atom_getfloatarg(which, argc, argv));
! }
! t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv)
! {
! if (argc <= which) return (&s_);
argv += which;
! if (argv->a_type == A_SYMBOL) return (argv->a_w.w_symbol);
! else return (&s_);
}
--- 222,262 ----
(t_method)hash_free, sizeof(t_object), CLASS_PD, A_GIMME, 0);
}
! /* convenience routines for checking and getting values of
! atoms. There's no "pointer" version since there's nothing
! safe to return if there's an error. */
! t_float atom_getfloat(t_atom *a) {
! return a->a_type==A_FLOAT ? a->a_w.w_float : 0;
}
! t_int atom_getint(t_atom *a) {return atom_getfloat(a);}
! /* why return &s_float here? */
! t_symbol *atom_getsymbol(t_atom *a) {
! return a->a_type==A_SYMBOL ? a->a_w.w_symbol : &s_float;
}
! t_symbol *atom_gensym(t_atom *a) { /* this works better for graph labels */
char buf[30];
if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol);
! else if (a->a_type == A_FLOAT) sprintf(buf, "%g", a->a_w.w_float);
else strcpy(buf, "???");
! return gensym(buf);
}
! t_float atom_getfloatarg(int which, int argc, t_atom *argv) {
! if (argc <= which) return 0;
argv += which;
! return argv->a_type==A_FLOAT ? argv->a_w.w_float : 0;
}
t_int atom_getintarg(int which, int argc, t_atom *argv)
! {return atom_getfloatarg(which, argc, argv);}
! t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv) {
! if (argc <= which) return &s_;
argv += which;
! return argv->a_type==A_SYMBOL ? argv->a_w.w_symbol : &s_;
}
***************
*** 296,309 ****
*/
! void atom_string(t_atom *a, char *buf, unsigned int bufsize)
! {
char tbuf[30];
! switch(a->a_type)
! {
! case A_SEMI: strcpy(buf, ";"); break;
! case A_COMMA: strcpy(buf, ","); break;
! case A_POINTER:
! strcpy(buf, "(pointer)");
! break;
case A_FLOAT:
sprintf(tbuf, "%g", a->a_w.w_float);
--- 267,280 ----
*/
! static int should_quote(char *s) {
! return *s==';' || *s==',' || *s=='\\' || (*s=='$' && s[1]>='0' && s[1]<='9');
! }
!
! void atom_string(t_atom *a, char *buf, unsigned int bufsize) {
char tbuf[30];
! switch(a->a_type) {
! case A_SEMI: strcpy(buf, ";"); break;
! case A_COMMA: strcpy(buf, ","); break;
! case A_POINTER: strcpy(buf, "(pointer)"); break;
case A_FLOAT:
sprintf(tbuf, "%g", a->a_w.w_float);
***************
*** 312,367 ****
else strcat(buf, "+");
break;
! case A_SYMBOL:
! {
char *sp;
! unsigned int len;
! int quote;
! for (sp = a->a_w.w_symbol->s_name, len = 0, quote = 0; *sp; sp++, len++)
! if (*sp == ';' || *sp == ',' || *sp == '\\' ||
! (*sp == '$' && sp[1] >= '0' && sp[1] <= '9'))
! quote = 1;
! if (quote)
! {
char *bp = buf, *ep = buf + (bufsize-2);
sp = a->a_w.w_symbol->s_name;
! while (bp < ep && *sp)
! {
! if (*sp == ';' || *sp == ',' || *sp == '\\' ||
! (*sp == '$' && sp[1] >= '0' && sp[1] <= '9'))
! *bp++ = '\\';
*bp++ = *sp++;
}
if (*sp) *bp++ = '*';
*bp = 0;
! /* post("quote %s -> %s", a->a_w.w_symbol->s_name, buf); */
! }
! else
! {
! if (len < bufsize-1) strcpy(buf, a->a_w.w_symbol->s_name);
! else
! {
strncpy(buf, a->a_w.w_symbol->s_name, bufsize - 2);
strcpy(buf + (bufsize - 2), "*");
}
}
! }
! break;
! case A_DOLLAR:
! sprintf(buf, "$%d", a->a_w.w_index);
! break;
! case A_DOLLSYM:
! strncpy(buf, a->a_w.w_symbol->s_name, bufsize);
! buf[bufsize-1] = 0;
! break;
! default:
! bug("atom_string");
}
}
- /* Copyright (c) 1997-1999 Miller Puckette.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
- #include <stdlib.h>
- #include "desire.h"
t_hash *object_table;
--- 283,314 ----
else strcat(buf, "+");
break;
! case A_SYMBOL: {
char *sp;
! unsigned int len=0;
! int quote=0;
! for (sp = a->a_w.w_symbol->s_name; *sp; sp++, len++) if (should_quote(sp)) quote = 1;
! if (quote) {
char *bp = buf, *ep = buf + (bufsize-2);
sp = a->a_w.w_symbol->s_name;
! while (bp < ep && *sp) {
! if (should_quote(sp)) *bp++ = '\\';
*bp++ = *sp++;
}
if (*sp) *bp++ = '*';
*bp = 0;
! } else {
! if (len < bufsize-1) {
! strcpy(buf, a->a_w.w_symbol->s_name);
! } else {
strncpy(buf, a->a_w.w_symbol->s_name, bufsize - 2);
strcpy(buf + (bufsize - 2), "*");
}
}
! } break;
! case A_DOLLAR: sprintf(buf, "$%d", a->a_w.w_index); break;
! case A_DOLLSYM: strncpy(buf, a->a_w.w_symbol->s_name, bufsize); buf[bufsize-1] = 0; break;
! default: bug("atom_string");
}
}
t_hash *object_table;
***************
*** 417,422 ****
} t_bindelem;
! typedef struct _bindlist
! {
t_pd b_pd;
t_bindelem *b_list;
--- 364,368 ----
} t_bindelem;
! typedef struct _bindlist {
t_pd b_pd;
t_bindelem *b_list;
***************
*** 425,448 ****
#define bind_each(e,x) for (e = x->b_list; e; e = e->e_next)
static void bindlist_bang(t_bindlist *x) {
! t_bindelem *e; bind_each(e,x) pd_bang(e->e_who);
! }
static void bindlist_float(t_bindlist *x, t_float f) {
! t_bindelem *e; bind_each(e,x) pd_float(e->e_who, f);
! }
static void bindlist_symbol(t_bindlist *x, t_symbol *s) {
! t_bindelem *e; bind_each(e,x) pd_symbol(e->e_who, s);
! }
static void bindlist_pointer(t_bindlist *x, t_gpointer *gp) {
! t_bindelem *e; bind_each(e,x) pd_pointer(e->e_who, gp);
! }
static void bindlist_list(t_bindlist *x, t_symbol *s, int argc, t_atom *argv) {
! t_bindelem *e; bind_each(e,x) pd_list(e->e_who, s, argc, argv);
! }
static void bindlist_anything(t_bindlist *x, t_symbol *s, int argc, t_atom *argv) {
! t_bindelem *e; bind_each(e,x) pd_typedmess(e->e_who, s, argc, argv);
! }
! void m_pd_setup(void)
! {
bindlist_class = class_new(gensym("bindlist"), 0, 0,
sizeof(t_bindlist), CLASS_PD, 0);
--- 371,387 ----
#define bind_each(e,x) for (e = x->b_list; e; e = e->e_next)
static void bindlist_bang(t_bindlist *x) {
! t_bindelem *e; bind_each(e,x) pd_bang(e->e_who);}
static void bindlist_float(t_bindlist *x, t_float f) {
! t_bindelem *e; bind_each(e,x) pd_float(e->e_who, f);}
static void bindlist_symbol(t_bindlist *x, t_symbol *s) {
! t_bindelem *e; bind_each(e,x) pd_symbol(e->e_who, s);}
static void bindlist_pointer(t_bindlist *x, t_gpointer *gp) {
! t_bindelem *e; bind_each(e,x) pd_pointer(e->e_who, gp);}
static void bindlist_list(t_bindlist *x, t_symbol *s, int argc, t_atom *argv) {
! t_bindelem *e; bind_each(e,x) pd_list(e->e_who, s, argc, argv);}
static void bindlist_anything(t_bindlist *x, t_symbol *s, int argc, t_atom *argv) {
! t_bindelem *e; bind_each(e,x) pd_typedmess(e->e_who, s, argc, argv);}
! void m_pd_setup(void) {
bindlist_class = class_new(gensym("bindlist"), 0, 0,
sizeof(t_bindlist), CLASS_PD, 0);
***************
*** 455,464 ****
}
! void pd_bind(t_pd *x, t_symbol *s)
! {
! if (s->s_thing)
! {
! if (*s->s_thing == bindlist_class)
! {
t_bindlist *b = (t_bindlist *)s->s_thing;
t_bindelem *e = (t_bindelem *)getbytes(sizeof(t_bindelem));
--- 394,400 ----
}
! void pd_bind(t_pd *x, t_symbol *s) {
! if (s->s_thing) {
! if (*s->s_thing == bindlist_class) {
t_bindlist *b = (t_bindlist *)s->s_thing;
t_bindelem *e = (t_bindelem *)getbytes(sizeof(t_bindelem));
***************
*** 466,472 ****
e->e_who = x;
b->b_list = e;
! }
! else
! {
t_bindlist *b = (t_bindlist *)pd_new(bindlist_class);
t_bindelem *e1 = (t_bindelem *)getbytes(sizeof(t_bindelem));
--- 402,406 ----
e->e_who = x;
b->b_list = e;
! } else {
t_bindlist *b = (t_bindlist *)pd_new(bindlist_class);
t_bindelem *e1 = (t_bindelem *)getbytes(sizeof(t_bindelem));
***************
*** 479,517 ****
s->s_thing = &b->b_pd;
}
! }
! else s->s_thing = x;
}
! void pd_unbind(t_pd *x, t_symbol *s)
! {
if (s->s_thing == x) s->s_thing = 0;
! else if (s->s_thing && *s->s_thing == bindlist_class)
! {
! /* bindlists always have at least two elements... if the number
! goes down to one, get rid of the bindlist and bind the symbol
! straight to the remaining element. */
!
t_bindlist *b = (t_bindlist *)s->s_thing;
t_bindelem *e, *e2;
! if ((e = b->b_list)->e_who == x)
! {
b->b_list = e->e_next;
freebytes(e, sizeof(t_bindelem));
}
! else for (e = b->b_list; e2 = e->e_next; e = e2)
! if (e2->e_who == x)
! {
e->e_next = e2->e_next;
freebytes(e2, sizeof(t_bindelem));
break;
}
! if (!b->b_list->e_next)
! {
s->s_thing = b->b_list->e_who;
freebytes(b->b_list, sizeof(t_bindelem));
pd_free(&b->b_pd);
}
! }
! else pd_error(x, "%s: couldn't unbind", s->s_name);
}
--- 413,442 ----
s->s_thing = &b->b_pd;
}
! } else s->s_thing = x;
}
! void pd_unbind(t_pd *x, t_symbol *s) {
if (s->s_thing == x) s->s_thing = 0;
! else if (s->s_thing && *s->s_thing == bindlist_class) {
! /* bindlists always have at least two elements... if the number
! goes down to one, get rid of the bindlist and bind the symbol
! straight to the remaining element. */
t_bindlist *b = (t_bindlist *)s->s_thing;
t_bindelem *e, *e2;
! if ((e = b->b_list)->e_who == x) {
b->b_list = e->e_next;
freebytes(e, sizeof(t_bindelem));
}
! else for (e = b->b_list; e2 = e->e_next; e = e2) if (e2->e_who == x) {
e->e_next = e2->e_next;
freebytes(e2, sizeof(t_bindelem));
break;
}
! if (!b->b_list->e_next) {
s->s_thing = b->b_list->e_who;
freebytes(b->b_list, sizeof(t_bindelem));
pd_free(&b->b_pd);
}
! } else pd_error(x, "%s: couldn't unbind", s->s_name);
}
***************
*** 544,549 ****
}
! /* stack for maintaining bindings for the #X symbol during nestable loads.
! */
#undef g_next
--- 469,473 ----
}
! /* stack for maintaining bindings for the #X symbol during nestable loads. */
#undef g_next
***************
*** 624,630 ****
}
- /* Copyright (c) 1997-1999 Miller Puckette.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
/* this file handles Max-style patchable objects, i.e., objects which
--- 548,551 ----
***************
*** 632,638 ****
behavior for "gobjs" appears at the end of this file. */
- #include "desire.h"
- #include <stdio.h>
-
/* T.Grill - define for a modified, more portable method to detect stack overflows */
/* tb: threadsafe stack overflow detection */
--- 553,556 ----
***************
*** 715,722 ****
}
! static void inlet_wrong(t_inlet *x, t_symbol *s)
! {
! pd_error(x->i_owner, "inlet: expected '%s' but got '%s'",
! x->i_symfrom->s_name, s->s_name);
}
--- 633,638 ----
}
! static void inlet_wrong(t_inlet *x, t_symbol *s) {
! pd_error(x->i_owner, "inlet: expected '%s' but got '%s'", x->i_symfrom->s_name, s->s_name);
}
***************
*** 731,735 ****
}
! /* LATER figure out how to make these efficient: */
static void inlet_bang(t_inlet *x) {
if (x->i_symfrom == &s_bang) pd_vmess(x->i_dest, x->i_symto, "");
--- 647,651 ----
}
! /* LATER figure out how to make these efficient: */
static void inlet_bang(t_inlet *x) {
if (x->i_symfrom == &s_bang) pd_vmess(x->i_dest, x->i_symto, "");