tmi2_fluffos_v2/
tmi2_fluffos_v2/bin/
tmi2_fluffos_v2/etc/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/ChangeLog.old/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/Win32/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/compat/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/compat/simuls/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/include/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/clone/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/command/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/data/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/etc/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/include/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/inherit/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/inherit/master/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/log/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/compiler/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/efuns/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/operators/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/u/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/tmp/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/windows/
tmi2_fluffos_v2/lib/
tmi2_fluffos_v2/lib/adm/
tmi2_fluffos_v2/lib/adm/daemons/languages/
tmi2_fluffos_v2/lib/adm/daemons/network/I3/
tmi2_fluffos_v2/lib/adm/daemons/virtual/
tmi2_fluffos_v2/lib/adm/daemons/virtual/template/
tmi2_fluffos_v2/lib/adm/news/
tmi2_fluffos_v2/lib/adm/obj/
tmi2_fluffos_v2/lib/adm/obj/master/
tmi2_fluffos_v2/lib/adm/priv/
tmi2_fluffos_v2/lib/adm/shell/
tmi2_fluffos_v2/lib/adm/tmp/
tmi2_fluffos_v2/lib/cmds/
tmi2_fluffos_v2/lib/d/
tmi2_fluffos_v2/lib/d/Conf/
tmi2_fluffos_v2/lib/d/Conf/adm/
tmi2_fluffos_v2/lib/d/Conf/boards/
tmi2_fluffos_v2/lib/d/Conf/cmds/
tmi2_fluffos_v2/lib/d/Conf/data/
tmi2_fluffos_v2/lib/d/Conf/logs/
tmi2_fluffos_v2/lib/d/Conf/obj/
tmi2_fluffos_v2/lib/d/Conf/text/help/
tmi2_fluffos_v2/lib/d/Fooland/adm/
tmi2_fluffos_v2/lib/d/Fooland/data/
tmi2_fluffos_v2/lib/d/Fooland/data/attic/
tmi2_fluffos_v2/lib/d/Fooland/items/
tmi2_fluffos_v2/lib/d/TMI/
tmi2_fluffos_v2/lib/d/TMI/adm/
tmi2_fluffos_v2/lib/d/TMI/boards/
tmi2_fluffos_v2/lib/d/TMI/data/
tmi2_fluffos_v2/lib/d/TMI/rooms/
tmi2_fluffos_v2/lib/d/grid/
tmi2_fluffos_v2/lib/d/grid/adm/
tmi2_fluffos_v2/lib/d/grid/data/
tmi2_fluffos_v2/lib/d/std/
tmi2_fluffos_v2/lib/d/std/adm/
tmi2_fluffos_v2/lib/data/adm/
tmi2_fluffos_v2/lib/data/adm/daemons/
tmi2_fluffos_v2/lib/data/adm/daemons/doc_d/
tmi2_fluffos_v2/lib/data/adm/daemons/emoted/
tmi2_fluffos_v2/lib/data/adm/daemons/network/http/
tmi2_fluffos_v2/lib/data/adm/daemons/network/services/mail_q/
tmi2_fluffos_v2/lib/data/adm/daemons/network/smtp/
tmi2_fluffos_v2/lib/data/adm/daemons/news/archives/
tmi2_fluffos_v2/lib/data/attic/connection/
tmi2_fluffos_v2/lib/data/attic/user/
tmi2_fluffos_v2/lib/data/std/connection/b/
tmi2_fluffos_v2/lib/data/std/connection/l/
tmi2_fluffos_v2/lib/data/std/user/a/
tmi2_fluffos_v2/lib/data/std/user/b/
tmi2_fluffos_v2/lib/data/std/user/d/
tmi2_fluffos_v2/lib/data/std/user/f/
tmi2_fluffos_v2/lib/data/std/user/l/
tmi2_fluffos_v2/lib/data/std/user/x/
tmi2_fluffos_v2/lib/data/u/d/dm/working/doc_d/
tmi2_fluffos_v2/lib/data/u/l/leto/doc_d/
tmi2_fluffos_v2/lib/data/u/l/leto/smtp/
tmi2_fluffos_v2/lib/doc/
tmi2_fluffos_v2/lib/doc/driverdoc/applies/
tmi2_fluffos_v2/lib/doc/driverdoc/applies/interactive/
tmi2_fluffos_v2/lib/doc/driverdoc/concepts/
tmi2_fluffos_v2/lib/doc/driverdoc/driver/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/arrays/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/buffers/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/compile/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/ed/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/filesystem/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/floats/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/functions/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/general/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/mappings/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/numbers/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/parsing/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/constructs/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/preprocessor/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/types/
tmi2_fluffos_v2/lib/doc/driverdoc/platforms/
tmi2_fluffos_v2/lib/doc/mudlib/
tmi2_fluffos_v2/lib/ftp/
tmi2_fluffos_v2/lib/include/driver/
tmi2_fluffos_v2/lib/log/
tmi2_fluffos_v2/lib/log/driver/
tmi2_fluffos_v2/lib/obj/net/
tmi2_fluffos_v2/lib/obj/shells/
tmi2_fluffos_v2/lib/obj/tools/
tmi2_fluffos_v2/lib/std/adt/
tmi2_fluffos_v2/lib/std/board/
tmi2_fluffos_v2/lib/std/body/
tmi2_fluffos_v2/lib/std/fun/
tmi2_fluffos_v2/lib/std/living/
tmi2_fluffos_v2/lib/std/object/
tmi2_fluffos_v2/lib/std/shop/
tmi2_fluffos_v2/lib/std/socket/
tmi2_fluffos_v2/lib/std/user/
tmi2_fluffos_v2/lib/std/virtual/
tmi2_fluffos_v2/lib/student/
tmi2_fluffos_v2/lib/student/kalypso/
tmi2_fluffos_v2/lib/student/kalypso/armor/
tmi2_fluffos_v2/lib/student/kalypso/rooms/
tmi2_fluffos_v2/lib/student/kalypso/weapons/
tmi2_fluffos_v2/lib/u/l/leto/
tmi2_fluffos_v2/lib/u/l/leto/cmds/
tmi2_fluffos_v2/lib/www/errors/
tmi2_fluffos_v2/lib/www/gateways/
tmi2_fluffos_v2/lib/www/images/
tmi2_fluffos_v2/old/
tmi2_fluffos_v2/win32/
/*
// File     : cmd_d.c
// Purpose  : This file acts as an Application Program Interface for
//            command parsing.  It maintains a table of all available
//            commands and adds new elements when necessary.
// 92-02-25 : Written by Buddha@TMI based on the old cmd_d.c, by Sulam@TMI,
//            which did not deal with multiple "bin" directories.
//            This file is part of the TMI-2 mudlib distribution.
//            Please retain this header if you use any of this code.
// 92-03-08 : Truilkan@TMI added the ADM_CMDS dir
// 93-02-05 : Pallando@TMI-2 added the REF_CMDS and WIZF_CMDS dirs
// 93-07-22 : Pallando@TMI-2 added the WIZX_CMDS dir
// 93-08-25 : Pallando@TMI-2 changed REF_CMDS to OBJ_CMDS
//            I thought the point of defines was not having to change them? 8-)
// 93-10-02 : Pallando@Rift improved the efficiency of rehash()
*/


#include <uid.h>
#include <config.h>

mapping cmd_table;

void	create();
int	rehash(string path);
string 	find_cmd(string cmd, string *path);

void create() {
	seteuid(ROOT_UID);
	cmd_table = ([ ]);
	rehash(USER_CMDS);
	rehash(WIZ_CMDS);
	rehash(ADM_CMDS);
        rehash(WIZX_CMDS);
        rehash(WIZF_CMDS);
        rehash(OBJ_CMDS);
}

// Function: 	find_cmd
// Purpose:	looks up the command entered in the mapping, and loads the
//		entry for its directory if not loaded.
// Arguements:	the command typed, and the path to be searched for it
// Returns:	the full path (minus the .c) for the command.
// Other:	may cause errors if there are files other than "bin" files
//		in the directory.  This should be tested.
string find_cmd(string cmd, string *path) {
	int i;

	for (i=0;i<sizeof(path);i++) {
		/* first check for invalid path */
		if(!cmd_table[path[i]] && !rehash(path[i])) continue;
		/* then see if the command is there */
		if(member_array(cmd, cmd_table[path[i]]) > -1)
			return path[i] + "/_" + cmd;
	}
	return 0;
}

// Function:	rehash
// Purpose:	updates the mapping for the directory specified, when
//		new commands are added or old ones are removed.
// Arguements:	the path of the directory to be updated
// Returns:	1 if success, 0 if there is no such directory
// Other:	There should a function to update all the directories
//		stored.  Perhaps this file should save itself and restore
//		itself so as to further minimize disk usage.
int rehash(string path) {
	string *bin_ls, *result, tmp;
	int i, s;
        if(!stringp(path)) { write("Badness! Invalid path!\n"); return 0; }

	if(file_size(path) != -2) return 0;
	bin_ls = get_dir(path + "/");
        s = sizeof( bin_ls );
        result = allocate( s );
	for( i = 0 ; i < s ; i++ ) {
            if(sscanf(bin_ls[i], "_%s.c", tmp) == 1)
		result[i] = tmp;
        }
        result -= ({ 0 });
	cmd_table[path] = result;
	return 1;
}

string *list_cmds(string path) {
	if (!cmd_table[path]) rehash(path);
	return cmd_table[path];
}
	
void qq() {
        save_object("/tmp/cmd_d");
}


/* I don't think the printing of a table should be done by the daemon,
   but since it's older than I am, I'll leave it that way.  */

string show_cmds(string arg) {
	string *tt;
	int i;
	int c;
	string *ttt;
	int j;
   string * output;
  string line;

  output = ({});
	tt=keys(cmd_table);
	for (i=0;i<sizeof(tt);i++) {
output += ({"COMMAND PATH: "+tt[i]});
	c=0;
	line = "";
		ttt=cmd_table[tt[i]];
		for (j=0;j<sizeof(ttt);j++)
		{
  if (!(c%4)) 
  {
	output += ({line});
	line = "";
  }
		c++;
		line += sprintf("%-19s",ttt[j]);
		}
  output += ({line,""});

	}
  this_player()->more( output );
	return "Ok.\n";
}