diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/common/props.c | 98 | ||||
-rw-r--r-- | shared/common/props.h | 2 | ||||
-rw-r--r-- | shared/getridof.baddeps | 16 | ||||
-rw-r--r-- | shared/toxy/scriptlet.c | 19 | ||||
-rw-r--r-- | shared/toxy/scriptlet.h | 2 |
5 files changed, 90 insertions, 47 deletions
diff --git a/shared/common/props.c b/shared/common/props.c index 6b6181a..6079308 100644 --- a/shared/common/props.c +++ b/shared/common/props.c @@ -13,6 +13,7 @@ #define PROPS_MAXOTHERS 32 enum { PROPS_NONE = 0, PROPS_THIS, PROPS_OTHER }; +enum { PROPS_SINGLEMODE = 0, PROPS_MULTIMODE }; typedef struct _propelem { @@ -41,8 +42,8 @@ struct _props }; /* Dictionary of properties, p_dict, meant to be nothing more, but an - optimalization detail, is handled implicitly, through its owning t_props. - This optimalization has to be enabled by passing a nonzero 'resolver' + optimization detail, is handled implicitly, through its owning t_props. + This optimization has to be enabled by passing a nonzero 'resolver' argument to props_new(). Since p_dict stores resolved strings, it is a secondary, `shallow' storage, which has to be synced to its master, p_buffer of atoms. @@ -109,18 +110,6 @@ static void props_dictadd(t_props *pp, t_symbol *s, int ac, t_atom *av) } } -static int props_atstart(t_props *pp, char *buf) -{ - if (*buf == pp->p_thisescape) - { - char c = buf[1]; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (pp->p_thisinitial && strchr(pp->p_thisinitial, c))) - return (PROPS_THIS); - } - return (PROPS_NONE); -} - static char *props_otherinitial(t_props *pp, char c) { t_props *pp1 = pp->p_otherprops; @@ -135,7 +124,7 @@ static char *props_otherinitial(t_props *pp, char c) return (0); } -static int props_atnext(t_props *pp, char *buf) +static int props_atstart(t_props *pp, int mode, char *buf) { char *otherinitial; if (*buf == pp->p_thisescape) @@ -145,7 +134,8 @@ static int props_atnext(t_props *pp, char *buf) || (pp->p_thisinitial && strchr(pp->p_thisinitial, c))) return (PROPS_THIS); } - else if (*pp->p_otherescapes && strchr(pp->p_otherescapes, *buf)) + else if (mode == PROPS_MULTIMODE && + *pp->p_otherescapes && strchr(pp->p_otherescapes, *buf)) { char c = buf[1]; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') @@ -158,13 +148,14 @@ static int props_atnext(t_props *pp, char *buf) /* Search for a property, replace its value if found, otherwise add. Assuming s is valid. Returning nafter - nbefore. */ -static int props_update(t_props *pp, t_symbol *s, int ac, t_atom *av, int doit) +static int props_update(t_props *pp, int mode, + t_symbol *s, int ac, t_atom *av, int doit) { int nadd, ndiff, ibeg, iend = 0; t_atom *ap; for (nadd = 0, ap = av; nadd < ac; nadd++, ap++) if (ap->a_type == A_SYMBOL - && props_atnext(pp, ap->a_w.w_symbol->s_name)) + && props_atstart(pp, mode, ap->a_w.w_symbol->s_name)) break; if (!nadd) { @@ -179,7 +170,8 @@ static int props_update(t_props *pp, t_symbol *s, int ac, t_atom *av, int doit) { for (iend = ibeg + 1, ap++; iend < pp->p_natoms; iend++, ap++) if (ap->a_type == A_SYMBOL - && props_atnext(pp, ap->a_w.w_symbol->s_name)) + && props_atstart(pp, PROPS_SINGLEMODE, + ap->a_w.w_symbol->s_name)) break; break; } @@ -228,23 +220,43 @@ static int props_update(t_props *pp, t_symbol *s, int ac, t_atom *av, int doit) return (ndiff); } -/* If there is an empty property, do not parse beyond. - Return the offending switch, if any. */ -t_symbol *props_add(t_props *pp, t_symbol *s, int ac, t_atom *av) +/* If in a single mode, ignore `other' properties (their switches are parsed + through as values). If there is an empty property, which is not to be + ignored, do not parse beyond. Return an offending switch, if any. */ +t_symbol *props_add(t_props *pp, int single, t_symbol *s, int ac, t_atom *av) { t_symbol *empty = 0; t_atom *av1, *ap; + int mode = (single ? PROPS_SINGLEMODE : PROPS_MULTIMODE); int ac1, i, ngrown = 0; - if (s && props_atstart(pp, s->s_name)) - ngrown += props_update(pp, s, ac, av, 0); + if (!s || !props_atstart(pp, PROPS_SINGLEMODE, s->s_name)) + { + s = 0; + while (ac) + { + s = (av->a_type == A_SYMBOL ? av->a_w.w_symbol : 0); + ac--; av++; + if (s && props_atstart(pp, PROPS_SINGLEMODE, s->s_name)) + break; + s = 0; + } + } + if (!s || !ac) + { + empty = s; + goto done; + } + ngrown += props_update(pp, mode, s, ac, av, 0); if (pp->p_badupdate) empty = s; else for (i = 0, ap = av; i < ac; i++, ap++) { if (ap->a_type == A_SYMBOL - && props_atstart(pp, ap->a_w.w_symbol->s_name)) + && props_atstart(pp, PROPS_SINGLEMODE, + ap->a_w.w_symbol->s_name)) { - ngrown += props_update(pp, ap->a_w.w_symbol, ac - i - 1, ap + 1, 0); + ngrown += props_update(pp, mode, ap->a_w.w_symbol, + ac - i - 1, ap + 1, 0); if (pp->p_badupdate) { empty = ap->a_w.w_symbol; @@ -263,24 +275,17 @@ t_symbol *props_add(t_props *pp, t_symbol *s, int ac, t_atom *av) if (nrequested != ngrown) goto done; } - ac1 = (s ? ac + 1 : ac); - if (!(av1 = getbytes(ac1 * sizeof(*av1)))) - goto done; - ap = av1; - if (s) - { - SETSYMBOL(ap, s); - ap++; - } - while (ac--) *ap++ = *av++; - ac = ac1; - av = av1; - for (i = 0, ap = av; i < ac; i++, ap++) + props_update(pp, mode, s, ac, av, 1); + if (pp->p_badupdate) + empty = s; + else for (i = 0, ap = av; i < ac; i++, ap++) { if (ap->a_type == A_SYMBOL - && props_atstart(pp, ap->a_w.w_symbol->s_name)) + && props_atstart(pp, PROPS_SINGLEMODE, + ap->a_w.w_symbol->s_name)) { - props_update(pp, ap->a_w.w_symbol, ac - i - 1, ap + 1, 1); + props_update(pp, mode, ap->a_w.w_symbol, + ac - i - 1, ap + 1, 1); if (pp->p_badupdate) { empty = ap->a_w.w_symbol; @@ -288,7 +293,6 @@ t_symbol *props_add(t_props *pp, t_symbol *s, int ac, t_atom *av) } } } - freebytes(av1, ac1 * sizeof(*av1)); done: return (empty); } @@ -328,11 +332,12 @@ void props_clone(t_props *to, t_props *from) while (ibeg < from->p_natoms) { if (ap->a_type == A_SYMBOL && - props_atstart(from, ap->a_w.w_symbol->s_name)) + props_atstart(from, PROPS_SINGLEMODE, ap->a_w.w_symbol->s_name)) { for (iend = ibeg + 1, ap++; iend < from->p_natoms; iend++, ap++) if (ap->a_type == A_SYMBOL - && props_atnext(from, ap->a_w.w_symbol->s_name)) + && props_atstart(from, PROPS_MULTIMODE, + ap->a_w.w_symbol->s_name)) break; props_dictadd(to, abeg->a_w.w_symbol, iend - ibeg - 1, abeg + 1); @@ -397,7 +402,7 @@ t_atom *props_getone(t_props *pp, t_symbol *s, int *npp) { int ibeg, iend = 0; t_atom *ap; - if (!(s && props_atstart(pp, s->s_name))) + if (!(s && props_atstart(pp, PROPS_SINGLEMODE, s->s_name))) return (0); for (ibeg = 0, ap = pp->p_buffer; ibeg < pp->p_natoms; ibeg++, ap++) { @@ -405,7 +410,8 @@ t_atom *props_getone(t_props *pp, t_symbol *s, int *npp) { for (iend = ibeg + 1, ap++; iend < pp->p_natoms; iend++, ap++) if (ap->a_type == A_SYMBOL - && props_atnext(pp, ap->a_w.w_symbol->s_name)) + && props_atstart(pp, PROPS_MULTIMODE, + ap->a_w.w_symbol->s_name)) break; break; } diff --git a/shared/common/props.h b/shared/common/props.h index 0eef345..8e3add6 100644 --- a/shared/common/props.h +++ b/shared/common/props.h @@ -10,7 +10,7 @@ EXTERN_STRUCT _props; typedef char *(*t_propsresolver)(t_pd *, int, t_atom *); -t_symbol *props_add(t_props *pp, t_symbol *s, int ac, t_atom *av); +t_symbol *props_add(t_props *pp, int single, t_symbol *s, int ac, t_atom *av); int props_remove(t_props *pp, t_symbol *s); void props_clone(t_props *to, t_props *from); char *props_getvalue(t_props *pp, char *key); diff --git a/shared/getridof.baddeps b/shared/getridof.baddeps new file mode 100644 index 0000000..37c56d5 --- /dev/null +++ b/shared/getridof.baddeps @@ -0,0 +1,16 @@ +This is the list of all dependencies among miXed/shared objects. +Some are inevitable, but others can, and should be removed. + +unstable/fringe -> unstable/forky +toxy/scriptlet -> common/loud, common/grow, common/props +sickle/sic -> common/loud +sickle/arsic -> common/loud, common/vefl, sickle/sic, unstable/fragile +hammer/file -> unstable/forky +common/hyphen -> common/dict +common/props -> common/grow +common/vefl -> common/loud, unstable/fragile +common/port -> common/loud, common/grow, common/binport, + unstable/forky, unstable/fragile, unstable/fringe +common/sofi -> common/bifi +common/mifi -> common/bifi common/sq +common/mfbb -> common/bifi, common/mifi, common/sq, common/squeal diff --git a/shared/toxy/scriptlet.c b/shared/toxy/scriptlet.c index 2592cee..e2f9883 100644 --- a/shared/toxy/scriptlet.c +++ b/shared/toxy/scriptlet.c @@ -277,6 +277,11 @@ static char *scriptlet_dedot(t_scriptlet *sp, char *ibuf, char *obuf, return (len ? ibuf + len : 0); } +int scriptlet_isempty(t_scriptlet *sp) +{ + return (!(sp->s_tail > sp->s_head && *sp->s_head)); +} + void scriptlet_reset(t_scriptlet *sp) { sp->s_cvstate = SCRIPTLET_CVUNKNOWN; @@ -395,6 +400,20 @@ void scriptlet_qpush(t_scriptlet *sp) } } +/* Non-expanding -- LATER think if this is likely to cause any confusion. + Especially, consider the widget_vis() vs. widget_update() case. */ +void scriptlet_vpush(t_scriptlet *sp, char *varname) +{ + if (scriptlet_ready(sp)) + { + char *tail = sp->s_tail; + strcpy(tail, "}\n"); + sys_vgui("set ::toxy::%s { ", varname); + sys_gui(sp->s_head); + *tail = 0; + } +} + int scriptlet_evaluate(t_scriptlet *insp, t_scriptlet *outsp, int visedonly, int ac, t_atom *av, t_props *argprops) { diff --git a/shared/toxy/scriptlet.h b/shared/toxy/scriptlet.h index 4b057b9..336d729 100644 --- a/shared/toxy/scriptlet.h +++ b/shared/toxy/scriptlet.h @@ -14,6 +14,7 @@ EXTERN_STRUCT _scriptlet; typedef t_canvas *(*t_scriptlet_cvfn)(t_pd *); typedef t_scriptlet *(*t_scriptlet_cmntfn)(t_pd *, char *, char, char *); +int scriptlet_isempty(t_scriptlet *sp); void scriptlet_reset(t_scriptlet *sp); void scriptlet_prealloc(t_scriptlet *sp, int sz, int mayshrink); int scriptlet_add(t_scriptlet *sp, @@ -25,6 +26,7 @@ int scriptlet_addfloat(t_scriptlet *sp, t_float f); void scriptlet_setseparator(t_scriptlet *sp, char c); void scriptlet_push(t_scriptlet *sp); void scriptlet_qpush(t_scriptlet *sp); +void scriptlet_vpush(t_scriptlet *sp, char *varname); int scriptlet_evaluate(t_scriptlet *insp, t_scriptlet *outsp, int visedonly, int ac, t_atom *av, t_props *argprops); char *scriptlet_nextword(char *buf); |