[PD-cvs] pd/src desire.c,1.1.2.217.2.168,1.1.2.217.2.169
Mathieu Bouchard
matju at users.sourceforge.net
Thu Jul 19 10:14:41 CEST 2007
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11036
Modified Files:
Tag: desiredata
desire.c
Log Message:
cleanup; removed redundancy in error messages
Index: desire.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v
retrieving revision 1.1.2.217.2.168
retrieving revision 1.1.2.217.2.169
diff -C2 -d -r1.1.2.217.2.168 -r1.1.2.217.2.169
*** desire.c 19 Jul 2007 04:39:26 -0000 1.1.2.217.2.168
--- desire.c 19 Jul 2007 08:14:36 -0000 1.1.2.217.2.169
***************
*** 763,772 ****
canvas_pop(x, x->willvis);
t_pd *z = gensym("#X")->thing;
! if (!z) error("canvas_restore: out of context");
! else if (z->_class != canvas_class) error("canvas_restore: wasn't a canvas");
! else {
! x->owner = (t_canvas *)z;
! canvas_objfor((t_canvas *)z, x, argc, argv);
! }
}
--- 763,770 ----
canvas_pop(x, x->willvis);
t_pd *z = gensym("#X")->thing;
! if (!z) {error("out of context"); return;}
! else if (z->_class != canvas_class) {error("wasn't a canvas"); return;}
! x->owner = (t_canvas *)z;
! canvas_objfor((t_canvas *)z, x, argc, argv);
}
***************
*** 1457,1464 ****
int filestyle = (flags & 6)>>1;
int style = filestyle == 0 ? PLOTSTYLE_POLY : filestyle == 1 ? PLOTSTYLE_POINTS : filestyle;
! if (templateargsym != &s_float) {
! error("%s: only 'float' type understood", templateargsym->name);
! return 0;
! }
t_template *t = template_findbyname(templatesym);
TEMPLATE_CHECK(templatesym,0)
--- 1455,1459 ----
int filestyle = (flags & 6)>>1;
int style = filestyle == 0 ? PLOTSTYLE_POLY : filestyle == 1 ? PLOTSTYLE_POINTS : filestyle;
! if (templateargsym != &s_float) {error("%s: only 'float' type understood", templateargsym->name); return 0;}
t_template *t = template_findbyname(templatesym);
TEMPLATE_CHECK(templatesym,0)
***************
*** 1467,1479 ****
return 0;
}
! if (ztype != DT_ARRAY) {
! error("template %s, 'z' field is not an array", templatesym->name);
! return 0;
! }
t_template *ztemplate = template_findbyname(zarraytype);
! if (!ztemplate) {
! error("no template of type %s", zarraytype->name);
! return 0;
! }
saveit = (flags & 1) != 0;
t_garray *x = graph_scalar(gl, s, templatesym, saveit);
--- 1462,1468 ----
return 0;
}
! if (ztype != DT_ARRAY) {error("template %s, 'z' field is not an array", templatesym->name); return 0;}
t_template *ztemplate = template_findbyname(zarraytype);
! if (!ztemplate) {error("no template of type %s", zarraytype->name); return 0;}
saveit = (flags & 1) != 0;
t_garray *x = graph_scalar(gl, s, templatesym, saveit);
***************
*** 1528,1535 ****
t_template *scalartemplate;
if (!a) {error("can't find array"); return;}
! if (!(scalartemplate = template_findbyname(x->scalar->t))) {
! error("no template of type %s", x->scalar->t->name);
! return;
! }
if (argname != x->realname) {
if (x->listviewing) garray_arrayviewlist_close(x);
--- 1517,1521 ----
t_template *scalartemplate;
if (!a) {error("can't find array"); return;}
! if (!(scalartemplate = template_findbyname(x->scalar->t))) {error("no template of type %s", x->scalar->t->name); return;}
if (argname != x->realname) {
if (x->listviewing) garray_arrayviewlist_close(x);
***************
*** 1553,1585 ****
void garray_arrayviewlist_new(t_garray *x) {
int yonset=0, elemsize=0;
char cmdbuf[200];
t_array *a = garray_getarray_floatonly(x, &yonset, &elemsize);
! if (!a) { /* FIXME */ error("error in garray_arrayviewlist_new()");}
x->listviewing = 1;
! sprintf(cmdbuf, "pdtk_array_listview_new %%s %s %d\n", x->realname->name, 0);
for (int i=0; i < ARRAYPAGESIZE && i < a->n; i++) {
float yval = *(float *)(a->vec + elemsize*i + yonset);
! sys_vgui(".%sArrayWindow.lb insert %d {%d) %g}\n", x->realname->name, i, i, yval);
}
}
void garray_arrayviewlist_fillpage(t_garray *x, t_float page, t_float fTopItem) {
int yonset=0, elemsize=0, topItem=(int)fTopItem;
t_array *a = garray_getarray_floatonly(x, &yonset, &elemsize);
! if (!a) error("error in garray_arrayviewlist_new()");
if (page < 0) {
page = 0;
! sys_vgui("pdtk_array_listview_setpage %s %d\n", x->realname->name, (int)page);
} else if ((page * ARRAYPAGESIZE) >= a->n) {
page = (int)(((int)a->n - 1)/ (int)ARRAYPAGESIZE);
! sys_vgui("pdtk_array_listview_setpage %s %d\n", x->realname->name, (int)page);
}
! sys_vgui(".%sArrayWindow.lb delete 0 %d\n", x->realname->name, ARRAYPAGESIZE - 1);
for (int i = (int)page * ARRAYPAGESIZE; (i < (page+1)*ARRAYPAGESIZE && i < a->n); i++) {
float yval = *(float *)(a->vec + elemsize*i + yonset);
! sys_vgui(".%sArrayWindow.lb insert %d {%d) %g}\n", x->realname->name, i%ARRAYPAGESIZE, i, yval);
}
! sys_vgui(".%sArrayWindow.lb yview %d\n", x->realname->name, topItem);
}
--- 1539,1573 ----
void garray_arrayviewlist_new(t_garray *x) {
+ char *s = x->realname->name;
int yonset=0, elemsize=0;
char cmdbuf[200];
t_array *a = garray_getarray_floatonly(x, &yonset, &elemsize);
! if (!a) {error("garray_arrayviewlist_new()"); return;}
x->listviewing = 1;
! sprintf(cmdbuf, "pdtk_array_listview_new %%s %s %d\n",s,0);
for (int i=0; i < ARRAYPAGESIZE && i < a->n; i++) {
float yval = *(float *)(a->vec + elemsize*i + yonset);
! sys_vgui(".%sArrayWindow.lb insert %d {%d) %g}\n",s,i,i,yval);
}
}
void garray_arrayviewlist_fillpage(t_garray *x, t_float page, t_float fTopItem) {
+ char *s = x->realname->name;
int yonset=0, elemsize=0, topItem=(int)fTopItem;
t_array *a = garray_getarray_floatonly(x, &yonset, &elemsize);
! if (!a) {error("garray_arrayviewlist_fillpage()"); return;}
if (page < 0) {
page = 0;
! sys_vgui("pdtk_array_listview_setpage %s %d\n",s,(int)page);
} else if ((page * ARRAYPAGESIZE) >= a->n) {
page = (int)(((int)a->n - 1)/ (int)ARRAYPAGESIZE);
! sys_vgui("pdtk_array_listview_setpage %s %d\n",s,(int)page);
}
! sys_vgui(".%sArrayWindow.lb delete 0 %d\n",s,ARRAYPAGESIZE-1);
for (int i = (int)page * ARRAYPAGESIZE; (i < (page+1)*ARRAYPAGESIZE && i < a->n); i++) {
float yval = *(float *)(a->vec + elemsize*i + yonset);
! sys_vgui(".%sArrayWindow.lb insert %d {%d) %g}\n",s,i%ARRAYPAGESIZE,i,yval);
}
! sys_vgui(".%sArrayWindow.lb yview %d\n",s,topItem);
}
***************
*** 1824,1836 ****
t_array *array = garray_getarray(x);
t_template *scalartemplate;
! if (x->scalar->t != gensym("pd-_float_array")) {
! /* LATER "save" the scalar as such */
! error("can't save arrays of type %s yet", x->scalar->t->name);
! return;
! }
! if (!(scalartemplate = template_findbyname(x->scalar->t))) {
! error("no template of type %s", x->scalar->t->name);
! return;
! }
int style = (int)template_getfloat(scalartemplate, gensym("style"), x->scalar->v, 0);
int filestyle = (style == PLOTSTYLE_POINTS ? 1 : (style == PLOTSTYLE_POLY ? 0 : style));
--- 1812,1818 ----
t_array *array = garray_getarray(x);
t_template *scalartemplate;
! /* LATER "save" the scalar as such */
! if (x->scalar->t != gensym("pd-_float_array")) {error("can't save arrays of type %s yet", x->scalar->t->name); return;}
! if (!(scalartemplate = template_findbyname(x->scalar->t))) {error("no template of type %s", x->scalar->t->name); return;}
int style = (int)template_getfloat(scalartemplate, gensym("style"), x->scalar->v, 0);
int filestyle = (style == PLOTSTYLE_POINTS ? 1 : (style == PLOTSTYLE_POLY ? 0 : style));
***************
*** 1861,1868 ****
t_array *a = garray_getarray_floatonly(x, &yonset, &elemsize);
TEMPLATE_FLOATY(a,0)
! if (elemsize != sizeof(t_word)) {
! error("%s: has more than one field", x->realname);
! return 0;
! }
*size = garray_npoints(x);
*vec = (float *)garray_vec(x);
--- 1843,1847 ----
t_array *a = garray_getarray_floatonly(x, &yonset, &elemsize);
TEMPLATE_FLOATY(a,0)
! if (elemsize != sizeof(t_word)) {error("%s: has more than one field", x->realname); return 0;}
*size = garray_npoints(x);
*vec = (float *)garray_vec(x);
***************
*** 1905,1909 ****
static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv) {
! if (argc < 2) {error("sinesum: %s: need number of points and partial strengths", x->realname->name); return;}
t_float *svec = (t_float *)getbytes(sizeof(t_float) * argc);
int npoints = atom_getintarg(0,argc--,argv++);
--- 1884,1888 ----
static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv) {
! if (argc < 2) {error("%s: need number of points and partial strengths", x->realname->name); return;}
t_float *svec = (t_float *)getbytes(sizeof(t_float) * argc);
int npoints = atom_getintarg(0,argc--,argv++);
***************
*** 1914,1918 ****
}
static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv) {
! if (argc < 2) {error("cosinesum: %s: need number of points and partial strengths", x->realname->name); return;}
t_float *svec = (t_float *)getbytes(sizeof(t_float) * argc);
int npoints = atom_getintarg(0,argc--,argv++);
--- 1893,1897 ----
}
static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv) {
! if (argc < 2) {error("%s: need number of points and partial strengths", x->realname->name); return;}
t_float *svec = (t_float *)getbytes(sizeof(t_float) * argc);
int npoints = atom_getintarg(0,argc--,argv++);
***************
*** 2007,2015 ****
sys_bashfilename(buf, buf);
FILE *fd = fopen(buf, "w");
! if (!fd) {
! error("can't create file '%s'", buf);
! free(buf);
! return;
! }
free(buf);
for (int i=0; i < array->n; i++) {
--- 1986,1990 ----
sys_bashfilename(buf, buf);
FILE *fd = fopen(buf, "w");
! if (!fd) {error("can't create file '%s'", buf); free(buf); return;}
free(buf);
for (int i=0; i < array->n; i++) {
***************
*** 2537,2541 ****
*p_nextmsg = nextmsg + 1;
t_template *t = template_findbyname(ts);
! if (!t) {error("canvas_read: %s: no such template", ts->name); *p_nextmsg = natoms; return 0;}
t_scalar *sc = scalar_new(x, ts);
if (!sc) {error("couldn't create scalar \"%s\"", ts->name); *p_nextmsg = natoms; return 0;}
--- 2512,2516 ----
*p_nextmsg = nextmsg + 1;
t_template *t = template_findbyname(ts);
! if (!t) {error("%s: no such template", ts->name); *p_nextmsg = natoms; return 0;}
t_scalar *sc = scalar_new(x, ts);
if (!sc) {error("couldn't create scalar \"%s\"", ts->name); *p_nextmsg = natoms; return 0;}
***************
*** 2607,2611 ****
int wasvis = canvas_isvisible(canvas);
int cr = strcmp(format->name, "cr")==0;
! if (!cr && *format->name) error("canvas_read: unknown flag: %s", format->name);
/* flag 2 means eval continuously. this is required to autodetect the syntax */
if (binbuf_read_via_path(b, filename->name, canvas_getdir(canvas)->name, cr|2)) {
--- 2582,2586 ----
int wasvis = canvas_isvisible(canvas);
int cr = strcmp(format->name, "cr")==0;
! if (!cr && *format->name) error("unknown flag: %s", format->name);
/* flag 2 means eval continuously. this is required to autodetect the syntax */
if (binbuf_read_via_path(b, filename->name, canvas_getdir(canvas)->name, cr|2)) {
***************
*** 3627,3642 ****
else if (newtypesym == &s_list) newtype = DT_LIST;
else if (newtypesym == gensym("array")) {
! if (argc < 3 || argv[2].a_type != A_SYMBOL) {
! error("array lacks element template or name");
! goto bad;
! }
newarraytemplate = canvas_makebindsym(argv[2].a_symbol);
newtype = DT_ARRAY;
argc--;
argv++;
! } else {
! error("%s: no such type", newtypesym->name);
! goto bad;
! }
newn = (oldn = x->n) + 1;
x->vec = (t_dataslot *)realloc(x->vec, newn*sizeof(*x->vec));
--- 3602,3611 ----
else if (newtypesym == &s_list) newtype = DT_LIST;
else if (newtypesym == gensym("array")) {
! if (argc < 3 || argv[2].a_type != A_SYMBOL) {error("array lacks element template or name"); goto bad;}
newarraytemplate = canvas_makebindsym(argv[2].a_symbol);
newtype = DT_ARRAY;
argc--;
argv++;
! } else {error("%s: no such type", newtypesym->name); goto bad;}
newn = (oldn = x->n) + 1;
x->vec = (t_dataslot *)realloc(x->vec, newn*sizeof(*x->vec));
***************
*** 4057,4061 ****
return;
fail:
! post("parse error: %s", s->name);
fd->min = fd->scrmin = fd->max = fd->scrmax = fd->quantum = 0;
}
--- 4026,4030 ----
return;
fail:
! error("parse error: %s", s->name);
fd->min = fd->scrmin = fd->max = fd->scrmax = fd->quantum = 0;
}
***************
*** 4338,4349 ****
slot_setfloat_const(&x->scalarvis, 1);
while (1) {
! t_symbol *firstarg = atom_getsymbolarg(0, argc, argv);
! const char *f = firstarg->name;
! if (!strcmp(f, "curve") || !strcmp(f, "-c")) {defstyle = PLOTSTYLE_BEZ; argc--; argv++; }
! else if (!strcmp(f,"-v") &&argc>1) {slot_setfloatarg(&x->vis, 1,argv+1);argc-=2;argv+=2;}
! else if (!strcmp(f,"-vs")&&argc>1) {slot_setfloatarg(&x->scalarvis,1,argv+1);argc-=2;argv+=2;}
! else if (!strcmp(f,"-x") &&argc>1) {slot_setfloatarg(&x->xpoints, 1,argv+1);argc-=2;argv+=2;}
! else if (!strcmp(f,"-y") &&argc>1) {slot_setfloatarg(&x->ypoints, 1,argv+1);argc-=2;argv+=2;}
! else if (!strcmp(f,"-w") &&argc>1) {slot_setfloatarg(&x->wpoints, 1,argv+1);argc-=2;argv+=2;}
else break;
}
--- 4307,4318 ----
slot_setfloat_const(&x->scalarvis, 1);
while (1) {
! const char *f = atom_getsymbolarg(0, argc, argv)->name;
! argc--; argv++;
! if (!strcmp(f, "curve") || !strcmp(f, "-c")) defstyle = PLOTSTYLE_BEZ;
! else if (!strcmp(f,"-v") &&argc>0) {slot_setfloatarg(&x->vis, 1,argv+1);argc--;argv++;}
! else if (!strcmp(f,"-vs")&&argc>0) {slot_setfloatarg(&x->scalarvis,1,argv+1);argc--;argv++;}
! else if (!strcmp(f,"-x") &&argc>0) {slot_setfloatarg(&x->xpoints, 1,argv+1);argc--;argv++;}
! else if (!strcmp(f,"-y") &&argc>0) {slot_setfloatarg(&x->ypoints, 1,argv+1);argc--;argv++;}
! else if (!strcmp(f,"-w") &&argc>0) {slot_setfloatarg(&x->wpoints, 1,argv+1);argc--;argv++;}
else break;
}
***************
*** 4360,4367 ****
void plot_float(t_plot *x, t_floatarg f) {
int viswas;
! if (x->vis.type != A_FLOAT || x->vis.var) {
! error("global vis/invis for a template with variable visibility");
! return;
! }
viswas = x->vis.f!=0;
if ((f!=0 && viswas) || (f==0 && !viswas)) return;
--- 4329,4333 ----
void plot_float(t_plot *x, t_floatarg f) {
int viswas;
! if (x->vis.type != A_FLOAT || x->vis.var) {error("global vis/invis for a template with variable visibility"); return;}
viswas = x->vis.f!=0;
if ((f!=0 && viswas) || (f==0 && !viswas)) return;
***************
*** 4379,4394 ****
t_symbol *elemtemplatesym;
t_array *array;
! if (x->data.type != A_ARRAY || !x->data.var) {
! error("needs an array field");
! return -1;
! }
if (!template_find_field(ownertemplate, x->data.varsym, &arrayonset, &type, &elemtemplatesym)) {
error("%s: no such field", x->data.varsym->name);
return -1;
}
! if (type != DT_ARRAY) {
! error("%s: not an array", x->data.varsym->name);
! return -1;
! }
array = *(t_array **)(((char *)data) + arrayonset);
*linewidthp = slot_getfloat(&x->width, ownertemplate, data, 1);
--- 4345,4354 ----
t_symbol *elemtemplatesym;
t_array *array;
! if (x->data.type != A_ARRAY || !x->data.var) {error("needs an array field"); return -1;}
if (!template_find_field(ownertemplate, x->data.varsym, &arrayonset, &type, &elemtemplatesym)) {
error("%s: no such field", x->data.varsym->name);
return -1;
}
! if (type != DT_ARRAY) {error("%s: not an array", x->data.varsym->name); return -1;}
array = *(t_array **)(((char *)data) + arrayonset);
*linewidthp = slot_getfloat(&x->width, ownertemplate, data, 1);
***************
*** 4415,4422 ****
template_findbyname is hardwired to return a predefined template. */
t_template *elemtemplate = template_findbyname(elemtemplatesym);
! if (!elemtemplate) {
! error("%s: no such template", elemtemplatesym->name);
! return -1;
! }
if (!(elemtemplatesym==&s_float || (elemtemplatecanvas = template_findcanvas(elemtemplate)))) {
error("%s: no canvas for this template", elemtemplatesym->name);
--- 4375,4379 ----
template_findbyname is hardwired to return a predefined template. */
t_template *elemtemplate = template_findbyname(elemtemplatesym);
! if (!elemtemplate) {error("%s: no such template", elemtemplatesym->name); return -1;}
if (!(elemtemplatesym==&s_float || (elemtemplatecanvas = template_findcanvas(elemtemplate)))) {
error("%s: no canvas for this template", elemtemplatesym->name);
***************
*** 4638,4645 ****
void drawnumber_float(t_drawnumber *x, t_floatarg f) {
! if (x->vis.type != A_FLOAT || x->vis.var) {
! error("global vis/invis for a template with variable visibility");
! return;
! }
int viswas = x->vis.f!=0;
if ((f != 0 && viswas) || (f == 0 && !viswas)) return;
--- 4595,4599 ----
void drawnumber_float(t_drawnumber *x, t_floatarg f) {
! if (x->vis.type != A_FLOAT || x->vis.var) {error("global vis/invis for a template with variable visibility"); return;}
int viswas = x->vis.f!=0;
if ((f != 0 && viswas) || (f == 0 && !viswas)) return;
***************
*** 7269,7278 ****
char *nameptr;
int fd = open_via_path(dirname,filename,"",dirbuf,&nameptr,MAXPDSTRING,0);
! if (fd) {
! close(fd);
! glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
! } else {
! error("%s: can't open", filename);
! }
}
--- 7223,7229 ----
char *nameptr;
int fd = open_via_path(dirname,filename,"",dirbuf,&nameptr,MAXPDSTRING,0);
! if (!fd) {error("%s: can't open", filename); return;}
! close(fd);
! glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
}
More information about the Pd-cvs
mailing list