Re: Newbie? Parsing casting syntax

From: Patrick Dughi (dughi@IMAXX.NET)
Date: 08/18/98

> Ok. I want to parse the casting syntax from:
>    cast 'spell' target
> into:
>    cast spell at target with arguments
> I'm not really sure how to break it up, considering strtok uses only 1
> character, not words ... Thanx.
        Mental exercise:

      cast     spell       at      target    <argument>
    command    name     seperator   vict  optional arguments
    [_CMD_]    [_____________arg________________________]

        first we look for a spell name... we could have two, or more word
spells. Since we dont' have a delimiter (like double quotes), we can't use
the built in function 'one_word', instead we have to assume much trouble,
and use at.
--random mailer code --

char *at,*scratch,*dup;
char *spell_name, *vict_string, *opt_string;
int spell_number;

  /* make a duplicate of arg since strtok alters string just in case */

  if(at=strstr(dup,"at")) { /* good we found an at */
    spell_name = strtok(dup," ");

    while(dup != at && *spell_name && *dup &&
          ((spell_number=find_skill_num(spell_name)) > 1  &&
           find_skill_num(spell_name) < MAX_SPELLS)) {
      scratch=strtok(NULL," ");
  } else {
    send_to_char("Syntax is : cast <spellname> <target> [options]\r\n",ch);

  if(spell_number < 1 || spell_number > MAX_SPELLS) {
    send_to_char("Syntax is : cast <spellname> <target> [options]\r\n",ch);

  /* great, we have the spell number, now for the victim (remove at first) */

  strtok(NULL," "); /* throw out 'at' */
  vict_string=strtok(NULL," "); /* grab the vict_string */
  opt_string=strtok(NULL," ");  /* grab the options string */

 /* put in the normal rest of cast i'd suppose */

                Now, this may be wrong, cause i'm tired, and can't figure
out how to get a car to the auto shop this early in the morning, without
transportation back.  I'm sure theres errors, or even an easier way to do
it, but this is pretty dry.


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/15/00 PST