/* Copyright (C) 1991, Marcus J. Ranum. All rights reserved. */ #ifndef lint static char RCSid[] = "$Header: /home/mjr/hacks/umud/CMD/RCS/use.c,v 1.1 92/02/09 22:59:29 mjr Exp $"; #endif #include "config.h" #include "mud.h" #include "match.h" #include "vars.h" static int stop_using(who,ud) char *who; char *ud; { if(ut_listadd(who,who,var_cont,ud)) return(UERR_FATAL); if(ut_unset(who,who,var_using)) return(UERR_FATAL); say(who,"You stop holding ",ut_name(ud),".\n",(char *)0); return(UERR_NONE); } /* ARGSUSED */ cmd_use(ac,av,who,aswho) int ac; char *av[]; char *who; char *aswho; { char *ud; ud = ut_getatt(who,0,typ_obj,var_using,(char *)0); /* no args stop using */ if(ac <= 1) { if(ud == (char *)0) { say(who,"You aren't holding anything.\n",(char *)0); return(UERR_NONE); } return(stop_using(who,ud)); } else if(ac == 2) { char ob[MAXOID]; int xx; if(ud != (char *)0 && (xx = stop_using(who,ud)) != UERR_NONE) return(xx); if(matchinv(who,av[1],0,MTCH_UNIQ|MTCH_QUIET,ob) && matchinv(who,av[1],0,MTCH_FRST|MTCH_QUIET,ob)) { if((xx = cmd_take(ac,av,who,aswho)) != UERR_NONE) return(xx); if(matchinv(who,av[1],0,MTCH_UNIQ|MTCH_QUIET,ob) && matchinv(who,av[1],0,MTCH_FRST|MTCH_QUIET,ob)) return(UERR_NOMATCH); } if(ut_listdel(who,who,var_cont,ob)) return(UERR_FATAL); if(ut_set(who,who,typ_obj,var_using,ob)) return(UERR_FATAL); say(who,"You are now holding ",ut_name(ob),".\n",(char *)0); return(UERR_NONE); } say(who,"You can only use one thing at a time.\n",(char *)0); return(UERR_NONE); }