int name2sdb (char *name) /* Returns the sdb# of a named space object */ { register int i; for (i = MIN_SPACE_OBJECTS ; i <= max_space_objects ; ++i) if (sdb[i].structure.type) if (SpaceObj(sdb[i].object) && GoodObject(sdb[i].object)) if (local_wild_match(name, Name(sdb[i].object))) return i; return SENSOR_FAIL; }
/** The switch command. * \verbatim * For lack of better place the @switch code is here. * @switch expression=args * \endverbatim * \param executor the executor. * \param expression the expression to test against cases. * \param argv array of cases and actions. * \param enactor the object that caused this code to run. * \param first if 1, run only first matching case; if 0, run all matching cases. * \param notifyme if 1, perform a notify after executing matched cases. * \param regexp if 1, do regular expression matching; if 0, wildcard globbing. * \param queue_type the type of queue to run any new commands as * \param queue_entry the queue entry \@switch is being run in */ void do_switch(dbref executor, char *expression, char **argv, dbref enactor, int first, int notifyme, int regexp, int queue_type, MQUE *queue_entry) { int any = 0, a; char buff[BUFFER_LEN], *bp; char const *ap; char *tbuf1; PE_REGS *pe_regs; if (!argv[1]) return; /* now try a wild card match of buff with stuff in coms */ for (a = 1; !(first && any) && (a < (MAX_ARG - 1)) && argv[a] && argv[a + 1]; a += 2) { /* eval expression */ ap = argv[a]; bp = buff; if (process_expression(buff, &bp, &ap, executor, enactor, enactor, PE_DEFAULT, PT_DEFAULT, queue_entry->pe_info)) { return; } *bp = '\0'; /* check for a match */ pe_regs = pe_regs_create(PE_REGS_SWITCH | PE_REGS_CAPTURE, "do_switch"); pe_regs_set(pe_regs, PE_REGS_SWITCH, "t0", expression); if (regexp ? regexp_match_case_r(buff, expression, 0, NULL, 0, NULL, 0, pe_regs, 0) : local_wild_match(buff, expression, pe_regs)) { tbuf1 = replace_string("#$", expression, argv[a + 1]); if (!any) { /* Add the new switch context to the parent queue... */ any = 1; } if (queue_type & QUEUE_INPLACE) { new_queue_actionlist(executor, enactor, enactor, tbuf1, queue_entry, PE_INFO_SHARE, queue_type, pe_regs); } else { new_queue_actionlist(executor, enactor, enactor, tbuf1, queue_entry, PE_INFO_CLONE, queue_type, pe_regs); } mush_free(tbuf1, "replace_string.buff"); } } /* do default if nothing has been matched */ if ((a < MAX_ARG) && !any && argv[a]) { tbuf1 = replace_string("#$", expression, argv[a]); pe_regs = pe_regs_create(PE_REGS_SWITCH | PE_REGS_CAPTURE, "do_switch"); pe_regs_set(pe_regs, PE_REGS_SWITCH, "t0", expression); if (queue_type & QUEUE_INPLACE) { new_queue_actionlist(executor, enactor, enactor, tbuf1, queue_entry, PE_INFO_SHARE, queue_type, pe_regs); } else { new_queue_actionlist(executor, enactor, enactor, tbuf1, queue_entry, PE_INFO_CLONE, queue_type, pe_regs); } mush_free(tbuf1, "replace_string.buff"); } if (!(queue_type & QUEUE_INPLACE) && notifyme) { parse_que(executor, enactor, "@notify me", NULL); } }