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/
/*
*  Author and date unknown ??
*  help() added 1/27/92   Brian@TMI
*  revised for greater speed by Buddha (8/23/92)
*/

#include <config.h>
#include <mudlib.h>

inherit DAEMON ;

// process_choice() and file_completion() were lifted almost verbatim from
// Watcher's shell code by Ed Murphy (Guardian@TMI-2) on 16 Sep 93 and
// slapped into the _cd.c code, in response to a suggestion that it allow
// wildcards.
//
// Maybe a user property should turn this file-completion attempt on/off, like
// the shell originally had it.

//	The function does the directory searches in an attempt
//	to complete the requested command's file path.
 
static mixed *process_choice(string str) {
   mixed *dir, *tmp, *hold;
   string file, where, patt, dump;
   int loop;
 
   //	Obtain user's present active directory
 
   file = resolv_path("cwd", str);
 
   //	Obtain the requested file's root path
 
   tmp = explode(file, "/");
   where = "/" + implode(tmp[0..(sizeof(tmp)-2)], "/") + "/";
 
   //	Form file search pattern
 
   if(sscanf(tmp[sizeof(tmp)-1],"%s\\*",patt) == 1) patt += "%s";
 
   //	Get requested directory contents
 
   dir = get_dir(where);
 
   //	Get all possible filenames that would match requested pattern
 
   for(hold = ({}),loop=0; loop<sizeof(dir); loop++)
   if(sscanf(dir[loop], patt, dump) == 1)
   hold += ({ (where + dir[loop]) });
 
return hold; }

//      This function allows file path completion of sorts.
//	If the last character in the file path is a *, then the
//	shell will try to complete the path as best it can.
 
static int file_completion(string str) {
   mixed *tmp, *result;
   string command;
 
   //   If last char isn't a *, then ignore
 
   if(str[strlen(str)-1] != '*') return 0;
 
   //	Break command into its word subsets and process last word
 
   tmp = explode(str, " ");
   result = process_choice(tmp[sizeof(tmp)-1]);
 
   //	Indicate ability to complete the file path
 
   if(!result || !sizeof(result))
   write("Unable to complete designated filename [" + 
	 tmp[sizeof(tmp)-1] + "]\n");
   else if(sizeof(result) > 1)
   write("Multiple possible filename completions [" +
	 tmp[sizeof(tmp)-1] + "]\n");
 
   //	Otherwise complete and initiate the command
 
   else { 
   tmp[sizeof(tmp)-1] = result[0];
   command = implode(tmp, " ");
   this_player()->force_me(command);  }
 
return 1; }

int
cmd_cd(string str) {
   int size;
   string name, path, hdir;
 
   path = this_player()->query("cwd");
   name = geteuid(this_player());
   seteuid(getuid());
 
   if(!str) {
      str = user_path(name);
 
      hdir = (string)this_player()->query("home_dir");
      if(hdir)  str = hdir;

      if(str[strlen(str)-1] == '/')  str = str[0..strlen(str)-2];
      if(!str || !directory_exists(str))  str = "/doc";
      this_player()->set("cwd", str);
      printf("%s\n", str);
      return 1;
   }
// Guardian's hack to access the wildcard code stolen from shsh.c
   if(file_completion(str)) return 1;

   str = resolv_path(path, str);
   replace_string("//", "/", str);
   if ((int)master()->valid_read(str, this_player()) == 0) {
      notify_fail(sprintf("%s:  permission denied\n", str));
      return 0;
   }
   size = file_size(str);
   if (size > -1) {
      notify_fail(sprintf("%s:  not a directory\n", str));
      return 0;
   }
   if (size == -1) {
      notify_fail(sprintf("%s:  no such file or directory\n", str));
      return 0;
   }
   this_player()->set("cwd", str);
    printf("%s\n", str);
   return 1;
}

string help() {
   return("Command: cd\nSyntax: cd <directory>\n"+
      "This command changes your current directory to the\n"+
      "one you specify.  If directory begins with a / then\n"+
      "the command will look from the root, otherwise it\n"+
      "will look in the child directories of your current\n"+
      "directory.  .. will back up to the parent of your\n"+
      "current directory.  Thus cd ../obj will attempt to\n"+
      "move to the directory obj which is a child of your\n"+
      "current parent directory.\n"+
      "cd with no arguments will move you to your home dir-\n"+
      "ectory if you are a student, or the /doc directory if\n"+
      "not.\n");
}