Commit fc58e58c authored by Guido van Rossum's avatar Guido van Rossum

Use getargs() function.

parent 521f81ca
...@@ -22,7 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -22,7 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/ ******************************************************************/
/* AL module -- interface to Mark Calows' Auido Library (AL). */ /* AL module -- interface to Mark Callows' Audio Library (AL). */
#include "audio.h" #include "audio.h"
...@@ -43,6 +43,10 @@ extern typeobject Configtype; /* Forward */ ...@@ -43,6 +43,10 @@ extern typeobject Configtype; /* Forward */
#define is_configobject(v) ((v)->ob_type == &Configtype) #define is_configobject(v) ((v)->ob_type == &Configtype)
/* Forward */
static int getconfigarg PROTO((object *, ALconfig *));
static int getstrstrconfigarg PROTO((object *, char **, char **, ALconfig *));
static object * static object *
setConfig (self, args, func) setConfig (self, args, func)
configobject *self; configobject *self;
...@@ -51,7 +55,7 @@ setConfig (self, args, func) ...@@ -51,7 +55,7 @@ setConfig (self, args, func)
{ {
long par; long par;
if (!getlongarg(args, &par)) return NULL; if (!getlongarg (args, &par)) return NULL;
(*func) (self-> ob_config, par); (*func) (self-> ob_config, par);
...@@ -67,7 +71,7 @@ getConfig (self, args, func) ...@@ -67,7 +71,7 @@ getConfig (self, args, func)
{ {
long par; long par;
if (!getnoarg(args)) return NULL; if (!getnoarg (args)) return NULL;
par = (*func) (self-> ob_config); par = (*func) (self-> ob_config);
...@@ -192,7 +196,7 @@ al_closeport (self, args) ...@@ -192,7 +196,7 @@ al_closeport (self, args)
portobject *self; portobject *self;
object *args; object *args;
{ {
if (!getnoarg(args)) return NULL; if (!getnoarg (args)) return NULL;
if (self->ob_port != NULL) { if (self->ob_port != NULL) {
ALcloseport (self-> ob_port); ALcloseport (self-> ob_port);
...@@ -211,7 +215,7 @@ al_getfd (self, args) ...@@ -211,7 +215,7 @@ al_getfd (self, args)
{ {
int fd; int fd;
if (!getnoarg(args)) return NULL; if (!getnoarg (args)) return NULL;
fd = ALgetfd (self-> ob_port); fd = ALgetfd (self-> ob_port);
...@@ -225,7 +229,7 @@ al_getfilled (self, args) ...@@ -225,7 +229,7 @@ al_getfilled (self, args)
{ {
long count; long count;
if (!getnoarg(args)) return NULL; if (!getnoarg (args)) return NULL;
count = ALgetfilled (self-> ob_port); count = ALgetfilled (self-> ob_port);
...@@ -239,7 +243,7 @@ al_getfillable (self, args) ...@@ -239,7 +243,7 @@ al_getfillable (self, args)
{ {
long count; long count;
if (!getnoarg(args)) return NULL; if (!getnoarg (args)) return NULL;
count = ALgetfillable (self-> ob_port); count = ALgetfillable (self-> ob_port);
...@@ -281,17 +285,16 @@ al_writesamps (self, args) ...@@ -281,17 +285,16 @@ al_writesamps (self, args)
object *args; object *args;
{ {
long count; long count;
object *v; char *buf;
int size, width;
ALconfig c; ALconfig c;
int width;
if (!getstrarg (args, &v)) return NULL; if (!getargs (args, "s#", &buf, &size)) return NULL;
c = ALgetconfig(self->ob_port); c = ALgetconfig(self->ob_port);
width = ALgetwidth(c); width = ALgetwidth(c);
ALfreeconfig(c); ALfreeconfig(c);
ALwritesamps (self-> ob_port, (void *) getstringvalue(v), ALwritesamps (self-> ob_port, (void *) buf, (long) size / width);
getstringsize(v) / width);
INCREF (None); INCREF (None);
return None; return None;
...@@ -304,7 +307,7 @@ al_getfillpoint (self, args) ...@@ -304,7 +307,7 @@ al_getfillpoint (self, args)
{ {
long count; long count;
if (!getnoarg(args)) return NULL; if (!getnoarg (args)) return NULL;
count = ALgetfillpoint (self-> ob_port); count = ALgetfillpoint (self-> ob_port);
...@@ -318,7 +321,7 @@ al_setfillpoint (self, args) ...@@ -318,7 +321,7 @@ al_setfillpoint (self, args)
{ {
long count; long count;
if (!getlongarg(args, &count)) return NULL; if (!getlongarg (args, &count)) return NULL;
ALsetfillpoint (self-> ob_port, count); ALsetfillpoint (self-> ob_port, count);
...@@ -333,7 +336,7 @@ al_setconfig (self, args) ...@@ -333,7 +336,7 @@ al_setconfig (self, args)
{ {
ALconfig config; ALconfig config;
if (!getconfigarg(args, &config)) return NULL; if (!getconfigarg (args, &config)) return NULL;
ALsetconfig (self-> ob_port, config); ALsetconfig (self-> ob_port, config);
...@@ -348,7 +351,7 @@ al_getconfig (self, args) ...@@ -348,7 +351,7 @@ al_getconfig (self, args)
{ {
ALconfig config; ALconfig config;
if (!getnoarg(args)) return NULL; if (!getnoarg (args)) return NULL;
config = ALgetconfig (self-> ob_port); config = ALgetconfig (self-> ob_port);
...@@ -420,13 +423,13 @@ static object * ...@@ -420,13 +423,13 @@ static object *
al_openport (self, args) al_openport (self, args)
object *self, *args; object *self, *args;
{ {
object *name, *dir; char *name, *dir;
ALport port; ALport port;
ALconfig config = NULL; ALconfig config = NULL;
int size; int size;
if (args == NULL || !is_tupleobject(args)) { if (args == NULL || !is_tupleobject(args)) {
err_badarg(); err_badarg ();
return NULL; return NULL;
} }
size = gettuplesize(args); size = gettuplesize(args);
...@@ -439,11 +442,11 @@ al_openport (self, args) ...@@ -439,11 +442,11 @@ al_openport (self, args)
return NULL; return NULL;
} }
else { else {
err_badarg(); err_badarg ();
return NULL; return NULL;
} }
port = ALopenport(getstringvalue(name), getstringvalue(dir), config); port = ALopenport(name, dir, config);
if (port == NULL) { if (port == NULL) {
err_errno(RuntimeError); err_errno(RuntimeError);
...@@ -481,7 +484,7 @@ al_queryparams(self, args) ...@@ -481,7 +484,7 @@ al_queryparams(self, args)
object *v; object *v;
object *w; object *w;
if (!getlongarg(args, &device)) if (!getlongarg (args, &device))
return NULL; return NULL;
length = ALqueryparams(device, PVdummy, 2L); length = ALqueryparams(device, PVdummy, 2L);
PVbuffer = NEW(long, length); PVbuffer = NEW(long, length);
...@@ -510,7 +513,7 @@ doParams(args, func, modified) ...@@ -510,7 +513,7 @@ doParams(args, func, modified)
long length; long length;
int i; int i;
if (!getlongobjectarg(args, &device, &list)) if (!getargs(args, "(lO)", &device, &list))
return NULL; return NULL;
if (!is_listobject(list)) { if (!is_listobject(list)) {
err_badarg(); err_badarg();
...@@ -572,31 +575,26 @@ inital() ...@@ -572,31 +575,26 @@ inital()
initmodule("al", al_methods); initmodule("al", al_methods);
} }
int static int
getconfigarg (o, conf) getconfigarg(o, conf)
configobject *o; object *o;
ALconfig *conf; ALconfig *conf;
{ {
if (o == NULL || !is_configobject(o)) if (o == NULL || !is_configobject(o))
return err_badarg (); return err_badarg ();
*conf = o-> ob_config; *conf = ((configobject *) o) -> ob_config;
return 1; return 1;
} }
int static int
getstrstrconfigarg(v, a, b, c) getstrstrconfigarg(v, a, b, c)
object *v; object *v;
object **a; char **a;
object **b; char **b;
ALconfig *c; ALconfig *c;
{ {
if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) { object *o;
return err_badarg(); return getargs(v, "(ssO)", a, b, &o) && getconfigarg(o, c);
}
return getstrarg(gettupleitem(v, 0), a) &&
getstrarg(gettupleitem(v, 1), b) &&
getconfigarg (gettupleitem (v, 2), c);
} }
...@@ -394,7 +394,7 @@ call_forms_INf (func, obj, args) ...@@ -394,7 +394,7 @@ call_forms_INf (func, obj, args)
{ {
float parameter; float parameter;
if (!getfloatarg (args, &parameter)) return NULL; if (!getargs(args, "f", &parameter)) return NULL;
(*func) (obj, parameter); (*func) (obj, parameter);
...@@ -411,7 +411,7 @@ call_forms_INfINf (func, obj, args) ...@@ -411,7 +411,7 @@ call_forms_INfINf (func, obj, args)
{ {
float par1, par2; float par1, par2;
if (!getfloatfloatarg (args, &par1, &par2)) return NULL; if (!getargs(args, "(ff)", &par1, &par2)) return NULL;
(*func) (obj, par1, par2); (*func) (obj, par1, par2);
...@@ -428,7 +428,7 @@ call_forms_INi (func, obj, args) ...@@ -428,7 +428,7 @@ call_forms_INi (func, obj, args)
{ {
int parameter; int parameter;
if (!getintarg (args, &parameter)) return NULL; if (!getintarg(args, &parameter)) return NULL;
(*func) (obj, parameter); (*func) (obj, parameter);
...@@ -443,11 +443,11 @@ call_forms_INc (func, obj, args) ...@@ -443,11 +443,11 @@ call_forms_INc (func, obj, args)
FL_OBJECT *obj; FL_OBJECT *obj;
object *args; object *args;
{ {
object *a; char *a;
if (!getstrarg (args, &a)) return NULL; if (!getstrarg(args, &a)) return NULL;
(*func) (obj, getstringvalue(a)[0]); (*func) (obj, a[0]);
INCREF(None); INCREF(None);
return None; return None;
...@@ -460,11 +460,11 @@ call_forms_INstr (func, obj, args) ...@@ -460,11 +460,11 @@ call_forms_INstr (func, obj, args)
FL_OBJECT *obj; FL_OBJECT *obj;
object *args; object *args;
{ {
object *a; char *a;
if (!getstrarg (args, &a)) return NULL; if (!getstrarg(args, &a)) return NULL;
(*func) (obj, getstringvalue (a)); (*func) (obj, a);
INCREF(None); INCREF(None);
return None; return None;
...@@ -478,12 +478,12 @@ call_forms_INiINstr (func, obj, args) ...@@ -478,12 +478,12 @@ call_forms_INiINstr (func, obj, args)
FL_OBJECT *obj; FL_OBJECT *obj;
object *args; object *args;
{ {
object *a; char *b;
int b; int a;
if (!getintstrarg (args, &b, &a)) return NULL; if (!getintstrarg(args, &a, &b)) return NULL;
(*func) (obj, b, getstringvalue (a)); (*func) (obj, a, b);
INCREF(None); INCREF(None);
return None; return None;
...@@ -499,7 +499,7 @@ call_forms_INiINi (func, obj, args) ...@@ -499,7 +499,7 @@ call_forms_INiINi (func, obj, args)
{ {
int par1, par2; int par1, par2;
if (!getintintarg (args, &par1, &par2)) return NULL; if (!getintintarg(args, &par1, &par2)) return NULL;
(*func) (obj, par1, par2); (*func) (obj, par1, par2);
...@@ -533,7 +533,7 @@ call_forms_Rstr (func, obj, args) ...@@ -533,7 +533,7 @@ call_forms_Rstr (func, obj, args)
{ {
char *str; char *str;
if (!getnoarg (args)) return NULL; if (!getnoarg(args)) return NULL;
str = (*func) (obj); str = (*func) (obj);
...@@ -1034,7 +1034,7 @@ set_dial (g, args) ...@@ -1034,7 +1034,7 @@ set_dial (g, args)
{ {
float f1, f2, f3; float f1, f2, f3;
if (!getfloatfloatfloatarg(args, &f1, &f2, &f3)) if (!getargs(args, "(fff)", &f1, &f2, &f3))
return NULL; return NULL;
fl_set_dial (g->ob_generic, f1, f2, f3); fl_set_dial (g->ob_generic, f1, f2, f3);
INCREF(None); INCREF(None);
...@@ -1192,7 +1192,7 @@ set_slider (g, args) ...@@ -1192,7 +1192,7 @@ set_slider (g, args)
{ {
float f1, f2, f3; float f1, f2, f3;
if (!getfloatfloatfloatarg(args, &f1, &f2, &f3)) if (!args(args, "(fff)", &f1, &f2, &f3))
return NULL; return NULL;
fl_set_slider (g->ob_generic, f1, f2, f3); fl_set_slider (g->ob_generic, f1, f2, f3);
INCREF(None); INCREF(None);
...@@ -1402,10 +1402,10 @@ form_show_form(f, args) ...@@ -1402,10 +1402,10 @@ form_show_form(f, args)
object *args; object *args;
{ {
int place, border; int place, border;
object *name; char *name;
if (!getintintstrarg(args, &place, &border, &name)) if (!getargs(args, "(iis)", &place, &border, &name))
return NULL; return NULL;
fl_show_form(f->ob_form, place, border, getstringvalue(name)); fl_show_form(f->ob_form, place, border, name);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -1489,15 +1489,15 @@ generic_add_object(f, args, func, internal_methods) ...@@ -1489,15 +1489,15 @@ generic_add_object(f, args, func, internal_methods)
{ {
int type; int type;
float x, y, w, h; float x, y, w, h;
object *name; char *name;
FL_OBJECT *obj; FL_OBJECT *obj;
if (!getintfloatfloatfloatfloatstrarg(args,&type,&x,&y,&w,&h,&name)) if (!getargs(args,"(iffffs)", &type,&x,&y,&w,&h,&name))
return NULL; return NULL;
fl_addto_form (f-> ob_form); fl_addto_form (f-> ob_form);
obj = (*func) (type, x, y, w, h, getstringvalue(name)); obj = (*func) (type, x, y, w, h, name);
fl_end_form(); fl_end_form();
...@@ -1671,10 +1671,10 @@ form_display_form(f, args) ...@@ -1671,10 +1671,10 @@ form_display_form(f, args)
object *args; object *args;
{ {
int place, border; int place, border;
object *name; char *name;
if (!getintintstrarg(args, &place, &border, &name)) if (!getargs(args, "(iis)", &place, &border, &name))
return NULL; return NULL;
fl_show_form(f->ob_form, place, border, getstringvalue(name)); fl_show_form(f->ob_form, place, border, name);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -1747,7 +1747,7 @@ forms_find_first_or_last(func, f, args) ...@@ -1747,7 +1747,7 @@ forms_find_first_or_last(func, f, args)
FL_OBJECT *generic; FL_OBJECT *generic;
genericobject *g; genericobject *g;
if (!getintfloatfloatarg(args, &type, &mx, &my)) return NULL; if (!getargs(args, "(iff)", &type, &mx, &my)) return NULL;
generic = (*func) (f-> ob_form, type, mx, my); generic = (*func) (f-> ob_form, type, mx, my);
...@@ -1921,7 +1921,7 @@ forms_make_form(dummy, args) ...@@ -1921,7 +1921,7 @@ forms_make_form(dummy, args)
int type; int type;
float w, h; float w, h;
FL_FORM *form; FL_FORM *form;
if (!getintfloatfloatarg(args, &type, &w, &h)) if (!getargs(args, "(iff)", &type, &w, &h))
return NULL; return NULL;
form = fl_bgn_form(type, w, h); form = fl_bgn_form(type, w, h);
if (form == NULL) { if (form == NULL) {
...@@ -2184,7 +2184,7 @@ forms_mapcolor(self, args) ...@@ -2184,7 +2184,7 @@ forms_mapcolor(self, args)
{ {
int arg0, arg1, arg2, arg3; int arg0, arg1, arg2, arg3;
if (!getintintintintarg(args, &arg0, &arg1, &arg2, &arg3)) if (!getargs(args, "(iiii)", &arg0, &arg1, &arg2, &arg3))
return NULL; return NULL;
fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3); fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3);
...@@ -2263,12 +2263,11 @@ forms_show_message(f, args) ...@@ -2263,12 +2263,11 @@ forms_show_message(f, args)
object *f; object *f;
object *args; object *args;
{ {
object *a, *b, *c; char *a, *b, *c;
if (!getstrstrstrarg(args, &a, &b, &c)) return NULL; if (!getargs(args, "(sss)", &a, &b, &c)) return NULL;
fl_show_message( fl_show_message(a, b, c);
getstringvalue(a), getstringvalue(b), getstringvalue(c));
INCREF(None); INCREF(None);
return None; return None;
...@@ -2280,12 +2279,11 @@ forms_show_question(f, args) ...@@ -2280,12 +2279,11 @@ forms_show_question(f, args)
object *args; object *args;
{ {
int ret; int ret;
object *a, *b, *c; char *a, *b, *c;
if (!getstrstrstrarg(args, &a, &b, &c)) return NULL; if (!getargs(args, "(sss)", &a, &b, &c)) return NULL;
ret = fl_show_question( ret = fl_show_question(a, b, c);
getstringvalue(a), getstringvalue(b), getstringvalue(c));
return newintobject((long) ret); return newintobject((long) ret);
} }
...@@ -2296,11 +2294,11 @@ forms_show_input(f, args) ...@@ -2296,11 +2294,11 @@ forms_show_input(f, args)
object *args; object *args;
{ {
char *str; char *str;
object *a, *b; char *a, *b;
if (!getstrstrarg(args, &a, &b)) return NULL; if (!getstrstrarg(args, &a, &b)) return NULL;
str = fl_show_input(getstringvalue(a), getstringvalue(b)); str = fl_show_input(a, b);
if (str == NULL) { if (str == NULL) {
INCREF(None); INCREF(None);
...@@ -2315,12 +2313,11 @@ forms_file_selector(f, args) ...@@ -2315,12 +2313,11 @@ forms_file_selector(f, args)
object *args; object *args;
{ {
char *str; char *str;
object *a, *b, *c, *d; char *a, *b, *c, *d;
if (!getstrstrstrstrarg(args, &a, &b, &c, &d)) return NULL; if (!getargs(args, "(ssss)", &a, &b, &c, &d)) return NULL;
str = fl_show_file_selector(getstringvalue(a), getstringvalue(b), str = fl_show_file_selector(a, b, c, d);
getstringvalue(c), getstringvalue(d));
if (str == NULL) { if (str == NULL) {
INCREF(None); INCREF(None);
...@@ -2420,143 +2417,3 @@ initfl() ...@@ -2420,143 +2417,3 @@ initfl()
fl_init(); fl_init();
#endif /* !FL_V15 */ #endif /* !FL_V15 */
} }
/* Support routines */
int
getintintstrarg(args, a, b, c)
object *args;
int *a, *b;
object **c;
{
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 3) {
err_badarg();
return NULL;
}
return getintarg(gettupleitem(args, 0), a) &&
getintarg(gettupleitem(args, 1), b) &&
getstrarg(gettupleitem(args, 2), c);
}
int
getintfloatfloatarg(args, a, b, c)
object *args;
int *a;
float *b, *c;
{
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 3) {
err_badarg();
return NULL;
}
return getintarg(gettupleitem(args, 0), a) &&
getfloatarg(gettupleitem(args, 1), b) &&
getfloatarg(gettupleitem(args, 2), c);
}
int
getintintintintarg(args, a, b, c, d)
object *args;
int *a, *b, *c, *d;
{
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 4) {
err_badarg();
return NULL;
}
return getintarg(gettupleitem(args, 0), a) &&
getintarg(gettupleitem(args, 1), b) &&
getintarg(gettupleitem(args, 2), c) &&
getintarg(gettupleitem(args, 3), d);
}
int
getfloatarg(args, a)
object *args;
float *a;
{
double x;
if (!getdoublearg(args, &x))
return 0;
*a = x;
return 1;
}
int
getintfloatfloatfloatfloatstrarg(args, type, x, y, w, h, name)
object *args;
int *type;
float *x, *y, *w, *h;
object **name;
{
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 6) {
err_badarg();
return NULL;
}
return getintarg(gettupleitem(args, 0), type) &&
getfloatarg(gettupleitem(args, 1), x) &&
getfloatarg(gettupleitem(args, 2), y) &&
getfloatarg(gettupleitem(args, 3), w) &&
getfloatarg(gettupleitem(args, 4), h) &&
getstrarg(gettupleitem(args, 5), name);
}
int
getfloatfloatfloatarg(args, f1, f2, f3)
object *args;
float *f1, *f2, *f3;
{
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 3) {
err_badarg();
return NULL;
}
return getfloatarg(gettupleitem(args, 0), f1) &&
getfloatarg(gettupleitem(args, 1), f2) &&
getfloatarg(gettupleitem(args, 2), f3);
}
int
getfloatfloatarg(args, f1, f2)
object *args;
float *f1, *f2;
{
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
err_badarg();
return NULL;
}
return getfloatarg(gettupleitem(args, 0), f1) &&
getfloatarg(gettupleitem(args, 1), f2);
}
int
getstrstrstrarg(v, a, b, c)
object *v;
object **a;
object **b;
object **c;
{
if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) {
return err_badarg();
}
return getstrarg(gettupleitem(v, 0), a) &&
getstrarg(gettupleitem(v, 1), b)&&
getstrarg(gettupleitem(v, 2), c);
}
int
getstrstrstrstrarg(v, a, b, c, d)
object *v;
object **a;
object **b;
object **c;
object **d;
{
if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 4) {
return err_badarg();
}
return getstrarg(gettupleitem(v, 0), a) &&
getstrarg(gettupleitem(v, 1), b)&&
getstrarg(gettupleitem(v, 2), c) &&
getstrarg(gettupleitem(v, 3),d);
}
...@@ -97,33 +97,18 @@ extern typeobject Menutype; /* Really static, forward */ ...@@ -97,33 +97,18 @@ extern typeobject Menutype; /* Really static, forward */
/* Strongly stdwin-specific argument handlers */ /* Strongly stdwin-specific argument handlers */
static int
getmousedetail(v, ep)
object *v;
EVENT *ep;
{
if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 4)
return err_badarg();
return getintintarg(gettupleitem(v, 0),
&ep->u.where.h, &ep->u.where.v) &&
getintarg(gettupleitem(v, 1), &ep->u.where.clicks) &&
getintarg(gettupleitem(v, 2), &ep->u.where.button) &&
getintarg(gettupleitem(v, 3), &ep->u.where.mask);
}
static int static int
getmenudetail(v, ep) getmenudetail(v, ep)
object *v; object *v;
EVENT *ep; EVENT *ep;
{ {
object *mp; menuobject *mp;
if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) if (!getargs(v, "(Oi)", &mp, &ep->u.m.item))
return err_badarg(); return 0;
mp = gettupleitem(v, 0); if (!is_menuobject(mp))
if (mp == NULL || !is_menuobject(mp))
return err_badarg(); return err_badarg();
ep->u.m.id = ((menuobject *)mp) -> m_id; ep->u.m.id = mp->m_id;
return getintarg(gettupleitem(v, 1), &ep->u.m.item); return 1;
} }
static int static int
...@@ -133,24 +118,22 @@ geteventarg(v, ep) ...@@ -133,24 +118,22 @@ geteventarg(v, ep)
{ {
object *wp, *detail; object *wp, *detail;
int a[4]; int a[4];
if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) if (!getargs(v, "(iOO)", &ep->type, &wp, &detail))
return err_badarg();
if (!getintarg(gettupleitem(v, 0), &ep->type))
return 0; return 0;
wp = gettupleitem(v, 1); if (is_windowobject(wp))
if (wp == None) ep->window = ((windowobject *)wp) -> w_win;
else if (wp == None)
ep->window = NULL; ep->window = NULL;
else if (wp == NULL || !is_windowobject(wp))
return err_badarg();
else else
ep->window = ((windowobject *)wp) -> w_win;
detail = gettupleitem(v, 2);
switch (ep->type) {
case WE_CHAR:
if (!is_stringobject(detail) || getstringsize(detail) != 1)
return err_badarg(); return err_badarg();
ep->u.character = getstringvalue(detail)[0]; switch (ep->type) {
case WE_CHAR: {
char c;
if (!getargs(detail, "c", &c))
return 0;
ep->u.character = c;
return 1; return 1;
}
case WE_COMMAND: case WE_COMMAND:
return getintarg(detail, &ep->u.command); return getintarg(detail, &ep->u.command);
case WE_DRAW: case WE_DRAW:
...@@ -164,7 +147,11 @@ geteventarg(v, ep) ...@@ -164,7 +147,11 @@ geteventarg(v, ep)
case WE_MOUSE_DOWN: case WE_MOUSE_DOWN:
case WE_MOUSE_UP: case WE_MOUSE_UP:
case WE_MOUSE_MOVE: case WE_MOUSE_MOVE:
return getmousedetail(detail, ep); return getargs(detail, "((ii)iii)",
&ep->u.where.h, &ep->u.where.v,
&ep->u.where.clicks,
&ep->u.where.button,
&ep->u.where.mask);
case WE_MENU: case WE_MENU:
return getmenudetail(detail, ep); return getmenudetail(detail, ep);
default: default:
...@@ -561,11 +548,11 @@ drawing_text(dp, args) ...@@ -561,11 +548,11 @@ drawing_text(dp, args)
drawingobject *dp; drawingobject *dp;
object *args; object *args;
{ {
int a[2]; int h, v, size;
object *s; char *text;
if (!getpointstrarg(args, a, &s)) if (!getargs(args, "((ii)s#)", &h, &v, &text, &size))
return NULL; return NULL;
wdrawtext(a[0], a[1], getstringvalue(s), (int)getstringsize(s)); wdrawtext(h, v, text, size);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -597,11 +584,11 @@ drawing_textwidth(dp, args) ...@@ -597,11 +584,11 @@ drawing_textwidth(dp, args)
drawingobject *dp; drawingobject *dp;
object *args; object *args;
{ {
object *s; char *text;
if (!getstrarg(args, &s)) int size;
if (!getargs(args, "s#", &text, &size))
return NULL; return NULL;
return newintobject( return newintobject((long)wtextwidth(text, size));
(long)wtextwidth(getstringvalue(s), (int)getstringsize(s)));
} }
static object * static object *
...@@ -609,12 +596,11 @@ drawing_textbreak(dp, args) ...@@ -609,12 +596,11 @@ drawing_textbreak(dp, args)
drawingobject *dp; drawingobject *dp;
object *args; object *args;
{ {
object *s; char *text;
int a; int size, width;
if (!getstrintarg(args, &s, &a)) if (!getargs(args, "(s#i)", &text, &size, &width))
return NULL; return NULL;
return newintobject( return newintobject((long)wtextbreak(text, size, width));
(long)wtextbreak(getstringvalue(s), (int)getstringsize(s), a));
} }
static object * static object *
...@@ -622,34 +608,30 @@ drawing_setfont(self, args) ...@@ -622,34 +608,30 @@ drawing_setfont(self, args)
drawingobject *self; drawingobject *self;
object *args; object *args;
{ {
object *font, *style; char *font;
int size; char style = '\0';
if (args == NULL) { int size = 0;
err_badarg(); if (args == NULL || !is_tupleobject(args)) {
if (!getargs(args, "z", font))
return NULL; return NULL;
} }
if (is_stringobject(args)) { else {
font = args;
style = NULL;
size = 0;
}
else if (is_tupleobject(args)) {
int n = gettuplesize(args); int n = gettuplesize(args);
if (n == 2) { if (n == 2) {
if (!getstrintarg(args, &font, &size)) if (!getargs(args, "(zi)", &font, &size))
return NULL; return NULL;
style = NULL;
} }
else if (!getstrstrintarg(args, &font, &style, &size)) else if (!getargs(args, "(zic)", &font, &size, &style)) {
err_clear();
if (!getargs(args, "(zci)", &font, &style, &size))
return NULL; return NULL;
} }
else {
err_badarg();
return NULL;
} }
wsetfont(getstringvalue(font)); if (font != NULL)
if (style != NULL) { wsetfont(font);
switch (*getstringvalue(style)) { if (size != 0)
wsetsize(size);
switch (style) {
case 'b': case 'b':
wsetbold(); wsetbold();
break; break;
...@@ -662,13 +644,10 @@ drawing_setfont(self, args) ...@@ -662,13 +644,10 @@ drawing_setfont(self, args)
case 'u': case 'u':
wsetunderline(); wsetunderline();
break; break;
default: case 'p':
wsetplain(); wsetplain();
break; break;
} }
}
if (size != 0)
wsetsize(size);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -990,10 +969,10 @@ text_replace(self, args) ...@@ -990,10 +969,10 @@ text_replace(self, args)
textobject *self; textobject *self;
object *args; object *args;
{ {
object *text; char *text;
if (!getstrarg(args, &text)) if (!getstrarg(args, &text))
return NULL; return NULL;
tereplace(self->t_text, getstringvalue(text)); tereplace(self->t_text, text);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -1029,16 +1008,15 @@ text_settext(self, args) ...@@ -1029,16 +1008,15 @@ text_settext(self, args)
textobject *self; textobject *self;
object *args; object *args;
{ {
object *text; char *text;
char *buf; char *buf;
int size; int size;
if (!getstrarg(args, &text)) if (!getargs(args, "s#", &text, &size))
return NULL; return NULL;
size = getstringsize(text);
if ((buf = NEW(char, size)) == NULL) { if ((buf = NEW(char, size)) == NULL) {
return err_nomem(); return err_nomem();
} }
memcpy(buf, getstringvalue(text), size); memcpy(buf, text, size);
tesetbuf(self->t_text, buf, size); /* Becomes owner of buffer */ tesetbuf(self->t_text, buf, size); /* Becomes owner of buffer */
INCREF(None); INCREF(None);
return None; return None;
...@@ -1143,9 +1121,10 @@ typeobject Texttype = { ...@@ -1143,9 +1121,10 @@ typeobject Texttype = {
#define MAXNMENU 200 /* Max #menus we allow */ #define MAXNMENU 200 /* Max #menus we allow */
static menuobject *menulist[MAXNMENU]; static menuobject *menulist[MAXNMENU];
static menuobject *newmenuobject PROTO((char *));
static menuobject * static menuobject *
newmenuobject(title) newmenuobject(title)
object *title; char *title;
{ {
int id; int id;
MENU *menu; MENU *menu;
...@@ -1158,7 +1137,7 @@ newmenuobject(title) ...@@ -1158,7 +1137,7 @@ newmenuobject(title)
err_setstr(StdwinError, "creating too many menus"); err_setstr(StdwinError, "creating too many menus");
return NULL; return NULL;
} }
menu = wmenucreate(id + IDOFFSET, getstringvalue(title)); menu = wmenucreate(id + IDOFFSET, title);
if (menu == NULL) if (menu == NULL)
return (menuobject *) err_nomem(); return (menuobject *) err_nomem();
mp = NEWOBJ(menuobject, &Menutype); mp = NEWOBJ(menuobject, &Menutype);
...@@ -1214,24 +1193,17 @@ menu_additem(self, args) ...@@ -1214,24 +1193,17 @@ menu_additem(self, args)
menuobject *self; menuobject *self;
object *args; object *args;
{ {
object *text; char *text;
int shortcut; int shortcut = -1;
if (is_tupleobject(args)) { if (is_tupleobject(args)) {
object *v; char c;
if (!getstrstrarg(args, &text, &v)) if (!getargs(args, "(sc)", &text, &c))
return NULL;
if (getstringsize(v) != 1) {
err_badarg();
return NULL; return NULL;
shortcut = c;
} }
shortcut = *getstringvalue(v) & 0xff; else if (!getstrarg(args, &text))
}
else {
if (!getstrarg(args, &text))
return NULL; return NULL;
shortcut = -1; wmenuadditem(self->m_menu, text, shortcut);
}
wmenuadditem(self->m_menu, getstringvalue(text), shortcut);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -1242,10 +1214,10 @@ menu_setitem(self, args) ...@@ -1242,10 +1214,10 @@ menu_setitem(self, args)
object *args; object *args;
{ {
int index; int index;
object *text; char *text;
if (!getintstrarg(args, &index, &text)) if (!getintstrarg(args, &index, &text))
return NULL; return NULL;
wmenusetitem(self->m_menu, index, getstringvalue(text)); wmenusetitem(self->m_menu, index, text);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -1506,18 +1478,6 @@ window_scroll(wp, args) ...@@ -1506,18 +1478,6 @@ window_scroll(wp, args)
return None; return None;
} }
static object *
window_setactive(wp, args)
windowobject *wp;
object *args;
{
if (!getnoarg(args))
return NULL;
wsetactive(wp->w_win);
INCREF(None);
return None;
}
static object * static object *
window_setdocsize(wp, args) window_setdocsize(wp, args)
windowobject *wp; windowobject *wp;
...@@ -1550,7 +1510,7 @@ window_settitle(wp, args) ...@@ -1550,7 +1510,7 @@ window_settitle(wp, args)
object *args; object *args;
{ {
object *title; object *title;
if (!getstrarg(args, &title)) if (!getStrarg(args, &title))
return NULL; return NULL;
DECREF(wp->w_title); DECREF(wp->w_title);
INCREF(title); INCREF(title);
...@@ -1592,7 +1552,7 @@ window_menucreate(self, args) ...@@ -1592,7 +1552,7 @@ window_menucreate(self, args)
object *args; object *args;
{ {
menuobject *mp; menuobject *mp;
object *title; char *title;
if (!getstrarg(args, &title)) if (!getstrarg(args, &title))
return NULL; return NULL;
wmenusetdeflocal(1); wmenusetdeflocal(1);
...@@ -1621,13 +1581,11 @@ window_setselection(self, args) ...@@ -1621,13 +1581,11 @@ window_setselection(self, args)
windowobject *self; windowobject *self;
object *args; object *args;
{ {
int sel; int sel, size, ok;
object *str; char *text;
int ok; if (!getargs(args, "(is#)", &sel, &text, &size))
if (!getintstrarg(args, &sel, &str))
return NULL; return NULL;
ok = wsetselection(self->w_win, sel, ok = wsetselection(self->w_win, sel, text, size);
getstringvalue(str), (int)getstringsize(str));
return newintobject(ok); return newintobject(ok);
} }
...@@ -1636,11 +1594,11 @@ window_setwincursor(self, args) ...@@ -1636,11 +1594,11 @@ window_setwincursor(self, args)
windowobject *self; windowobject *self;
object *args; object *args;
{ {
object *str; char *name;
CURSOR *c; CURSOR *c;
if (!getstrarg(args, &str)) if (!getstrarg(args, &name))
return NULL; return NULL;
c = wfetchcursor(getstringvalue(str)); c = wfetchcursor(name);
if (c == NULL) { if (c == NULL) {
err_setstr(StdwinError, "no such cursor"); err_setstr(StdwinError, "no such cursor");
return NULL; return NULL;
...@@ -1650,6 +1608,18 @@ window_setwincursor(self, args) ...@@ -1650,6 +1608,18 @@ window_setwincursor(self, args)
return None; return None;
} }
static object *
window_setactive(self, args)
windowobject *self;
object *args;
{
if (!getnoarg(args))
return NULL;
wsetactive(self->w_win);
INCREF(None);
return None;
}
#ifdef CWI_HACKS #ifdef CWI_HACKS
static object * static object *
window_getxwindowid(self, args) window_getxwindowid(self, args)
...@@ -1754,7 +1724,7 @@ stdwin_open(sw, args) ...@@ -1754,7 +1724,7 @@ stdwin_open(sw, args)
int tag; int tag;
object *title; object *title;
windowobject *wp; windowobject *wp;
if (!getstrarg(args, &title)) if (!getStrarg(args, &title))
return NULL; return NULL;
for (tag = 0; tag < MAXNWIN; tag++) { for (tag = 0; tag < MAXNWIN; tag++) {
if (windowlist[tag] == NULL) if (windowlist[tag] == NULL)
...@@ -1988,7 +1958,7 @@ stdwin_menucreate(self, args) ...@@ -1988,7 +1958,7 @@ stdwin_menucreate(self, args)
object *self; object *self;
object *args; object *args;
{ {
object *title; char *title;
if (!getstrarg(args, &title)) if (!getstrarg(args, &title))
return NULL; return NULL;
wmenusetdeflocal(0); wmenusetdeflocal(0);
...@@ -2000,14 +1970,14 @@ stdwin_askfile(self, args) ...@@ -2000,14 +1970,14 @@ stdwin_askfile(self, args)
object *self; object *self;
object *args; object *args;
{ {
object *prompt, *dflt; char *prompt, *dflt;
int new, ret; int new, ret;
char buf[256]; char buf[256];
if (!getstrstrintarg(args, &prompt, &dflt, &new)) if (!getstrstrintarg(args, &prompt, &dflt, &new))
return NULL; return NULL;
strncpy(buf, getstringvalue(dflt), sizeof buf); strncpy(buf, dflt, sizeof buf);
buf[sizeof buf - 1] = '\0'; buf[sizeof buf - 1] = '\0';
ret = waskfile(getstringvalue(prompt), buf, sizeof buf, new); ret = waskfile(prompt, buf, sizeof buf, new);
if (!ret) { if (!ret) {
err_set(KeyboardInterrupt); err_set(KeyboardInterrupt);
return NULL; return NULL;
...@@ -2020,11 +1990,11 @@ stdwin_askync(self, args) ...@@ -2020,11 +1990,11 @@ stdwin_askync(self, args)
object *self; object *self;
object *args; object *args;
{ {
object *prompt; char *prompt;
int new, ret; int new, ret;
if (!getstrintarg(args, &prompt, &new)) if (!getstrintarg(args, &prompt, &new))
return NULL; return NULL;
ret = waskync(getstringvalue(prompt), new); ret = waskync(prompt, new);
if (ret < 0) { if (ret < 0) {
err_set(KeyboardInterrupt); err_set(KeyboardInterrupt);
return NULL; return NULL;
...@@ -2037,14 +2007,14 @@ stdwin_askstr(self, args) ...@@ -2037,14 +2007,14 @@ stdwin_askstr(self, args)
object *self; object *self;
object *args; object *args;
{ {
object *prompt, *dflt; char *prompt, *dflt;
int ret; int ret;
char buf[256]; char buf[256];
if (!getstrstrarg(args, &prompt, &dflt)) if (!getstrstrarg(args, &prompt, &dflt))
return NULL; return NULL;
strncpy(buf, getstringvalue(dflt), sizeof buf); strncpy(buf, dflt, sizeof buf);
buf[sizeof buf - 1] = '\0'; buf[sizeof buf - 1] = '\0';
ret = waskstr(getstringvalue(prompt), buf, sizeof buf); ret = waskstr(prompt, buf, sizeof buf);
if (!ret) { if (!ret) {
err_set(KeyboardInterrupt); err_set(KeyboardInterrupt);
return NULL; return NULL;
...@@ -2057,10 +2027,10 @@ stdwin_message(self, args) ...@@ -2057,10 +2027,10 @@ stdwin_message(self, args)
object *self; object *self;
object *args; object *args;
{ {
object *msg; char *msg;
if (!getstrarg(args, &msg)) if (!getstrarg(args, &msg))
return NULL; return NULL;
wmessage(getstringvalue(msg)); wmessage(msg);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -2082,11 +2052,11 @@ stdwin_setcutbuffer(self, args) ...@@ -2082,11 +2052,11 @@ stdwin_setcutbuffer(self, args)
object *self; object *self;
object *args; object *args;
{ {
int i; int i, size;
object *str; char *str;
if (!getintstrarg(args, &i, &str)) if (!getargs(args, "(is#)", &i, &str, &size))
return NULL; return NULL;
wsetcutbuffer(i, getstringvalue(str), getstringsize(str)); wsetcutbuffer(i, str, size);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -2166,10 +2136,10 @@ stdwin_fetchcolor(self, args) ...@@ -2166,10 +2136,10 @@ stdwin_fetchcolor(self, args)
object *self; object *self;
object *args; object *args;
{ {
object *colorname; char *colorname;
if (!getstrarg(args, &colorname)) if (!getstrarg(args, &colorname))
return NULL; return NULL;
return newintobject((long)wfetchcolor(getstringvalue(colorname))); return newintobject((long)wfetchcolor(colorname));
} }
static object * static object *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment