dsI/bin/
dsI/extra/creremote/
dsI/extra/mingw/
dsI/extra/wolfpaw/
dsI/fluffos-2.7-ds2.018/
dsI/fluffos-2.7-ds2.018/ChangeLog.old/
dsI/fluffos-2.7-ds2.018/Win32/
dsI/fluffos-2.7-ds2.018/compat/
dsI/fluffos-2.7-ds2.018/compat/simuls/
dsI/fluffos-2.7-ds2.018/testsuite/
dsI/fluffos-2.7-ds2.018/testsuite/clone/
dsI/fluffos-2.7-ds2.018/testsuite/command/
dsI/fluffos-2.7-ds2.018/testsuite/data/
dsI/fluffos-2.7-ds2.018/testsuite/etc/
dsI/fluffos-2.7-ds2.018/testsuite/include/
dsI/fluffos-2.7-ds2.018/testsuite/inherit/
dsI/fluffos-2.7-ds2.018/testsuite/inherit/master/
dsI/fluffos-2.7-ds2.018/testsuite/log/
dsI/fluffos-2.7-ds2.018/testsuite/single/
dsI/fluffos-2.7-ds2.018/testsuite/single/tests/compiler/
dsI/fluffos-2.7-ds2.018/testsuite/single/tests/efuns/
dsI/fluffos-2.7-ds2.018/testsuite/single/tests/operators/
dsI/fluffos-2.7-ds2.018/testsuite/u/
dsI/fluffos-2.7-ds2.018/tmp/
dsI/lib/cfg/
dsI/lib/cmds/common/
dsI/lib/cmds/creators/include/
dsI/lib/cmds/creators/include/SCCS/
dsI/lib/daemon/services/
dsI/lib/doc/
dsI/lib/domains/Ylsrim/
dsI/lib/domains/Ylsrim/adm/
dsI/lib/domains/Ylsrim/armour/
dsI/lib/domains/Ylsrim/broken/
dsI/lib/domains/Ylsrim/fish/
dsI/lib/domains/Ylsrim/meal/
dsI/lib/domains/Ylsrim/npc/
dsI/lib/domains/Ylsrim/virtual/
dsI/lib/domains/Ylsrim/weapon/
dsI/lib/domains/default/creator/
dsI/lib/domains/default/etc/
dsI/lib/domains/default/room/
dsI/lib/lib/comp/
dsI/lib/lib/lvs/
dsI/lib/lib/user/
dsI/lib/lib/virtual/
dsI/lib/obj/
dsI/lib/obj/include/
dsI/lib/realms/
dsI/lib/save/kills/a/
dsI/lib/save/kills/b/
dsI/lib/save/kills/f/
dsI/lib/save/kills/m/
dsI/lib/save/kills/q/
dsI/lib/save/kills/r/
dsI/lib/secure/cfg/
dsI/lib/secure/cfg/classes/
dsI/lib/secure/cfg/races/SCCS/
dsI/lib/secure/cmds/creators/include/
dsI/lib/secure/cmds/players/
dsI/lib/secure/cmds/players/include/
dsI/lib/secure/daemon/include/
dsI/lib/secure/lib/
dsI/lib/secure/lib/include/
dsI/lib/secure/lib/net/
dsI/lib/secure/lib/net/include/
dsI/lib/secure/lib/std/
dsI/lib/secure/obj/
dsI/lib/secure/obj/include/
dsI/lib/secure/save/
dsI/lib/spells/
dsI/lib/verbs/admins/include/
dsI/lib/verbs/common/
dsI/lib/verbs/common/include/
dsI/lib/verbs/creators/
dsI/lib/verbs/creators/include/
dsI/lib/verbs/players/include/SCCS/
dsI/lib/verbs/rooms/
dsI/lib/verbs/rooms/include/
dsI/lib/www/
dsI/v22.2b14/
dsI/win32/
/*
// This file is a part of the TMI distribution mudlib.
// Please retain this header if you use this code.
// Coded by Grog (10/15/91 - 11/03/91)
// Added to the /bin structure by Buddha  (1/18/91) 
// Help added by Brian (1/28/92)
// Single arg cp added by Scythe@Dead Souls (1/25/93)
// Bug in single arg cp fixed by Pallando (5/26/93)
*/

#include <lib.h>
inherit LIB_DAEMON;

int help();

int
cmd(string str) {
    string line;
    string file1;
    string file2;
    int localdest;
    if(this_player()->GetForced()) {
        write("Someone has tried forcing you to cp " + str);
        return 1;
    }
    localdest = 0;    /* Assume it's not a local destination */
    if (!str || sscanf(str, "%s %s", file1, file2) != 2) {
       if (str && sscanf(str, "%s", file1)) {
          file2 = "";     // Check to see if it's a one arg
          localdest = 1;  // cp function.  Assume localdest.
       } else {
          help();
          return 1;
       }
    }
    /* check for last parameter == "." */
    if (file2 == ".") {
        localdest = 1;     /* It's a local destination */
        file2 = "";
    }
    /* Given the player's current working directory and the path(s)
       for the file, construct the new full path for both files */
    file1 = absolute_path(this_player()->query_cwd(), file1);
    file2 = absolute_path(this_player()->query_cwd(), file2);

    /* This used to give and lstat error, fixed 930208 by Plura */
   if(file_size(file1) < 1)
   {
      notify_fail("cp: couldn't find "+file1+"\n");
      return 0;
   }

  /* Check if the destination is a directory */
  if (!localdest) {
    if (file_size(file2) == -2)
      localdest = 1;
  }
  if (localdest) {
    /* Extract the root file name from the source and use
       it for the destination.  file2 should be just a
       directory path at this point so that the rootname can
       be appended. */
    string newroot;
    string path;
    string rootname;
    rootname = file1;
    while(sscanf(rootname, "%s/%s", path, newroot) == 2) {
      rootname = newroot;
    }
    file2 = file2 + "/" + rootname;
  }
   if(file_size(file1) == -2)   /*Plura 930120*/
   {
      notify_fail("cp: "+file1+" is a directory.\n");
      return 0;
   }
#if 0
   if(file_size(file2) > 0)  /* Plura 930120 */
  {
      notify_fail("cp: "+file2+" already exists.\n");
      return 0;
   }
#endif
  if (file1 == file2) {
    notify_fail("cp: can not copy a file on top of itself!\n");
    return 0;
  }
   if(!master()->valid_read(file1, this_player(), "cp"))
    {
    notify_fail(file1 + ": Permission denied.\n");
    return 0;
  }
    if(!master()->valid_write(file2, this_player(), "cp"))
    {
    notify_fail(file2 + ": Permission denied.\n");
    return 0;
  }
  line = read_file(file1);
  if (line == 0) {
    /* Uhoh.  Can't read source file. */
    notify_fail("cp: file not found: " + file1 + "\n");
    return 0;
  }
  if (file_size(file2) == -2)
    {
    notify_fail("Tried to overwrite the directory "+ file2 + "\n");
    return 0;
  }
  rm(file2);
  write_file(file2, line);
  message("system", "Copied: " + file1 + " to " + file2, this_player());
  return 1;
}

int 
help() {
  message("help", "Command: cp\nSyntax: cp <oldfile> [pathname]<newfile>\n"
	  "This command makes a copy of the file using the new name "
	  "and location passed.  If a new pathname is not specified "
	  "then the copy is put into the present working directory.", 
	  this_player());
  return 1;
}

/* EOF */