void clear_allq(NEW_PE_INFO *pe_info) { PE_REGS *pe_regs; PE_REG_VAL *pe_val; pe_regs = pe_info->regvals; while (pe_regs) { if (pe_regs->flags & PE_REGS_Q) { /* Do this for everything up to the lowest level q-reg that _isn't_ a * letq() */ for (pe_val = pe_regs->vals; pe_val; pe_val = pe_val->next) { if (pe_val->type & PE_REGS_Q) { if (pe_val->type & PE_REGS_STR) { /* Quick and dirty: Set it to "". */ pe_regs_set(pe_regs, pe_val->type, pe_val->name, ""); } else { pe_val->val.ival = 0; } } } } if ((pe_regs->flags & (PE_REGS_LET | PE_REGS_LOCALIZED))) { /* This was created by localize(), letq(), or something similar, * so we can't change anything above it. * Instead, just set PE_REGS_QSTOP so we don't look at anything above it. * This effectively clears everything above while this pe_regs exists, * magically bringing it back when this localized pe_regs goes away */ pe_regs->flags |= PE_REGS_QSTOP; return; } pe_regs = pe_regs->prev; } }
/** 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); } }