Here is a correct version: sorry for the complete repost, but i wanted to give a fresh copy in cast alex wanted to snippet this. /* <stuff from the has discussion> Quote ------> n > o > r > t > h V e > a > s > t V s > o > u > t > h V w > e > s > t V a > t V V V d > v > a > n > c > e V V V l > i > a > s V V V s > s > i > t V V V V V k V V V u > t > o > e > x > i > t V e > a > t <------Quote n (index letter) -> (next in word ptr) -> o (index letter) | V (next in list ptr) | V e (index letter) so, what type of data structure would you us for this type of thing? something like this:? */ struct xCommandList { char cIndexLetter; /* (a,b,c,d) the actual letter you are checking */ struct xCommandList *pxNextInWord; /* the next letter in this command */ struct xCommandList *pxNextInList; /* the next command with this letter */ struct xCommandStruct *pxThisCommand; /*the struct for this command */ }; struct xCommandStruct { char *pztCommand; byte iMinPosition; void (*CommandPointer) (struct char_data *ch, char * argument, int cmd, int subcmd); sh_int iMinLevel; int iSubCmd; }; pxTempCmdLst=pxHeadOfList; /*a global pointer to the top of the tree */ iPosition =0; CheckCommand("test",NULL, pxTempCmdList, iPosition); /* this is where we check the command against the struct, we have already checked the SPEC */ int CheckCommand(char *pztCommand,struct xCommandStruct *pxCommand, struct xCommandList *pxCmdLst, int iPosition) { assert(pztCommand); assert(pztCommand[0]!='\0'); /* end of this chain, no match */ if(!pxCmdLst) return(FALSE); /* if item matches */ if(pztCommand[iPosition]==pxCmdList->cIndexLetter) { /* end of command string, we match */ if(pztCommand[iPosition+1]=='\0') { pxCommand=pxCmdLst->pxThisCommand; return(TRUE); } /* check the next letter */ if(pxCmdLst->pxNextInWord!=NULL)/* for the 'qui' 'quit' scenario */ { if(CheckCommand(pztCommand,pxCommand,pxCmdLst->pxNextInWord, iPosition++)==TRUE) { return(TRUE); } else { return(FALSE); } } else { if(CheckCommand(pztCommand,pxCommand,pxCmdLst->pxNextInList, iPosition++)==TRUE) { return(TRUE); } else { return(FALSE); } } }/* END: if(pztCommand[iPosition]==pxCmdList.cIndexLetter) */ /* else check the next item in the list */ if(CheckCommand(pztCommand,pxCommand,pxCmdLst->pxNextInList, iPosition++)==TRUE) { return(TRUE); } else { return(FALSE); } return(ERROR); /* SHOULD NEVER GET HERE */ } /* Should be able to build this list by reading in to cmd_info array and, using the array's order, construct the pointers. Probably some sort of recursive build. You will want to strip out all relation between cmd number and the dirs array. Use the SCMD_ instead for this. It is bad form to use the same variable for multiple purposes. Just look at all the problems getc causes by returning an int for errors, and a char for success. I personally prefer sending results through pointers, and errors through return values. Mileage may vary. */ +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST