[CODE] Better argument processing

From: Sammy (samedi@DHC.NET)
Date: 09/19/97


Consider the following:

char *two_args(char *inp)
{
  char *p;

  for(p = inp; *p && *p != ' '; p++);

  if(*p)
    *(p++) = '\0';

  if(*p == ' ')
    for(;*p == ' '; p++);

  return p;
}

This is my idea of a better two_arguments() function.  It's meant to act
on the original "argument" paramter passed to all the ACMD functions, or
you can pass it a copy of argument for nondestructive processing (for
spec_procs).

Example function:

ACMD(add)
{
  int a, b;
  char *arg2 = two_args(argument);

  if(!*argument || !*arg2) {
    send_to_char("Add what to what?!\r\n", ch);
    return;
  }
  a = atoi(argument);
  b = atoi(arg2);
  sprintf(buf, "%d + %d = %d\r\n", a, b, a + b);
  send_to_char(buf, ch);
}

With a few more similar argument processing functions, you can
eliminate all the argX[MAX_INPUT_LENGTH] variables throughout the ACMD
functions.

I think someone (Daniel?) once posted code to handle all the argument
processing in command_interpreter.  This is slower but in my opinion
easier to implement.

BTW, this assumes the argument passed to ACMD functions already has
leading spaces stripped (can't remember if stock circle does this).

Sam
Reinventing the wheel is fun!


     +------------------------------------------------------------+
     | 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