getargs enhancement

Donald Beaudry (don@vicorp.com)
Tue, 8 Mar 94 09:16:52 EST

Occasionally I get annoyed when using getargs() because whenever I
extract an argument using "O", I then need to verify that the object
is really of the type I wanted. So, I added this case to the switch
statement in the do_arg() routine in modsupport.c.

case 'o': /* typed object */ {
typeobject *t = va_arg(va, typeobject *);
object **p = va_arg(va, object **);
if (arg->ob_type == t)
*p = arg;
else
return 0;
break;
}

This case works just like "O" but allows me to specify the type of the
object. If the type of the object does not match, getargs() will fail.

A common case is when I need a string argument but I want the string
object, not the character pointer associated with it. With this patch
in place, I can now use:

object *str;
int i;

if (!getarg(args, "(oi)", &Stringtype, &str, &i))
return NULL;

If all goes well, str points to a string object, if not the caller will
hear about it.

--Don

______ ______
\_\_\_\ /#/#/#/
\_\_\_\ ______
\_\_\_V#/#/#/ Donald Beaudry don@vicorp.com
\_\_/#/#/#/ V. I. Corporation uunet!vicorp!don
\_/#/#/#/ 47 Pleasant Street PHONE: (413) 586-4144
V#/#/#/ Northampton, MA 01060 FAX: (413) 586-3805