Hi,

Sorry if this is a dumb question, or if the answer is painfully obvious on some site.  It may be, but I couldn't find it.

I'm trying to add a better aliasing to Melville.  What I've done is added an alias mapping to shell.c in melville.  My code then checks this mapping & if the first word of a command matches a key in the alias mapping, it replaces that word with the associated value.  This works fine as long as the mapping is static, but when I try to make it non-static, so that it will be saved, I get an "Index on bad type" error whenever the process_alias() function is called.

Here's a snippet of the offending code (I hope you don't mind, but it's pretty short):

----- shell.c -----

mapping aliases;
static string *last_commands ;
static int last_command ;
static int num_commands ;

/* This is called from create() in player.c, and preps the user's
   history stuff. */

static void initialize_shell() {
    num_commands=0 ;
    last_command=HISTORY_SIZE-1 ;
    last_commands = allocate(HISTORY_SIZE) ;

    /* create a few initial aliases */
    aliases = ([ "n" : "go north",
		 "s" : "go south",
		 "e" : "go east",
		 "w" : "go west",
		 "l" : "look" ]);
  }

/* Called by command() in player.c.
   Should process_history (see below) be called first, or second? */

string process_alias (string command) {
  /* get the first word, which will be the alias. */
  string alias, rest;
  
  if (sscanf(command, "%s %s", alias, rest) == 0 && sscanf(command, "%s", alias) == 0) {
    /* couldn't get any words, so just return */
    return command;
  }

  /* check to see if the first word is an alias */
  if (aliases[alias] == nil) {
    /* no, so return the entire command */
    return command ;
  } else {
    /* yes, so expand the alias & return */
    if (rest != nil) {
      return aliases[alias] + " " + rest;
    } else {
      return aliases[alias];
    }
  }
}

/* Adds an alias to the list of aliases */
int add_alias (string alias, string expand) {
  aliases[alias] = expand;
  /* return true if the alias was added successfully, false otherwise*/
  return (aliases[alias] != nil);
}

/* removes an alias from the list of aliases */
void remove_alias(string alias) {
  aliases[alias] = nil;
}

---- end of shell.c -----


Thanks,

-- Keith

P.S. This behaviour appears in both 1.2p1 and 1.2.37


Find the best deals on the web at AltaVista Shopping!
http://www.shopping.altavista.com
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd

