struct searchNode *modes_parse(searchCtx *ctx, int argc, char **argv) {
struct modes_localdata *localdata;
- struct searchNode *thenode;
+ struct searchNode *thenode, *modestring;
const flag *flaglist;
-
+ char *p;
+
if (argc!=1) {
parseError="modes: usage: modes (mode string)";
return NULL;
}
- switch (ctx->type) {
- case SEARCHTYPE_CHANNEL:
+ if (ctx->searchcmd == reg_chansearch) {
flaglist=cmodeflags;
- break;
-
- case SEARCHTYPE_NICK:
+ } else {
flaglist=umodeflags;
- break;
-
- default:
- parseError="modes: unsupported search type";
- return NULL;
}
if (!(localdata=(struct modes_localdata *)malloc(sizeof(struct modes_localdata)))) {
localdata->setmodes=0;
localdata->clearmodes = ~0;
- setflags(&(localdata->setmodes), 0xFFFF, argv[0], flaglist, REJECT_NONE);
- setflags(&(localdata->clearmodes), 0xFFFF, argv[0], flaglist, REJECT_NONE);
-
+ if (!(modestring=argtoconststr("modes", ctx, argv[0], &p))) {
+ free(localdata);
+ return NULL;
+ }
+
+ setflags(&(localdata->setmodes), 0xFFFF, p, flaglist, REJECT_NONE);
+ setflags(&(localdata->clearmodes), 0xFFFF, p, flaglist, REJECT_NONE);
+ (modestring->free)(ctx, modestring);
+
localdata->clearmodes = ~(localdata->clearmodes);
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
localdata = (struct modes_localdata *)thenode->localdata;
- switch (ctx->type) {
- case SEARCHTYPE_CHANNEL:
+ if (ctx->searchcmd == reg_chansearch) {
cip=(chanindex *)value;
if (!cip->channel)
return NULL;
flags=cip->channel->flags;
- break;
-
- case SEARCHTYPE_NICK:
+ } else {
np=(nick *)value;
flags=np->umodes;
- break;
-
- default:
- return NULL;
}
if (~flags & (localdata->setmodes))