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/
/* _changelog.c
 * original author: wayfarer
 * date: 12/8/91
 * note: adds an entry into the ChangeLog file in the named domain
 * bugs: no error checking on non-existant domains
 * Modified for the TMI distribution mudlib by Buddha (1/9/92)
 * Changed to fit into the /cmds command structure, setting its
 * euid to the current user, then self-destructs to reduce memory use.
 * Also created a stack of active users, so that any number of people can
 * use this command at one time.
 * (93-03-20) Pallando changed a hardwired reference to the tmp dir.
 *  93-07-30  Grendel added logging to a central log, and turned about
 *                four write_file()s into one big one.
 *  93-09-16  Guardian added "changelog /some/path A quick comment".
 */

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

inherit DAEMON ;

private string *files, *coders, command_line_comment;

void changelog_done();

void create() { seteuid(ROOT_UID); coders = ({}); files = ({}); }

int get_ref() { 
	return member_array(geteuid(this_player()), coders);
}
void push_coder(string file) {
        string who;
        who = geteuid(this_player());
        coders += ({ who });
	files += ({ file });
}
void pop_coder(int ref) {
	coders -= ({ coders[ref] });
	files -= ({ files[ref] });
}
int cmd_changelog(string path) {
   string who, tmp, temp1, temp2;
   who = geteuid(this_player());
   if (!path)  path = (string)this_player()->query("cwd");

   if(sscanf(path, "%s %s", temp1, temp2) == 2) {
      path = resolv_path((string)this_player()->query("cwd"), temp1);
     if (file_size(path) != -2) {
         write("No such directory exists!\n");
         return 1;
      }
      if(!master()->valid_write(path+"/ChangeLog", this_player(), "write_file")) {
         write("You don't have permission to write there!\n");
         return 1;
      }
      command_line_comment = TMP_DIR+"changelog_"+who;
      write_file(command_line_comment, temp2+"\n");
      changelog_done();
      return 1;
   }

   path = resolv_path((string)this_player()->query("cwd"), path);
   if (file_size(path) != -2) {
      write("No such directory exists!\n");
      return 1;
   }
   if (!master()->valid_write(path + "/ChangeLog", this_player(),
      "write_file")) {
      write("You don't have permission to write there!\n");
      return 1;
   }
   push_coder(path + "/ChangeLog");
   write("Editing ChangeLog for " + path + "\n");
   this_player()->edit(TMP_DIR+"changelog_"+who,"changelog_done",
		this_object());
   return 1;
}

void changelog_done() {
   string old, msg, infile, clfile;
   string *lines, *newlines;
   string entry;
   int count, i, j;
   
   if(command_line_comment) {
      infile = command_line_comment;
      command_line_comment = (string) 0;
   } else infile = (string)this_player()->query_edit_filename();
   msg = read_file(infile);
   if (msg == "" || !msg) return;
   clfile = files[get_ref()];
   old = read_file(clfile);
   rm(clfile);
   entry = sprintf("%s   %s   (%s at %s)\n\n\t* ", ctime(time()),
      (string)this_player()->query_link()->query("real_name"),
      (string)this_player()->query("cap_name"),
      query_ip_name(this_player()));
   lines = explode(msg," ");
   if (lines)
      for (i = 0; i < sizeof(lines); i++) {
      newlines = explode(lines[i],"\n");
      if (!newlines) newlines = ({lines[i]});
      for (j = 0; j < sizeof(newlines); j++) {
         if (newlines[j] == 0)
            continue;
         if (count + strlen(newlines[j]) >= 65) {
            entry += "\n\t";
            count = 0;
           }
         entry += newlines[j] + " ";
         count += strlen(newlines[j]) + 1;
         }
   }
   entry += "\n\n";
   write_file(clfile,entry);
#ifdef MASTER_CHANGELOG
   log_file(MASTER_CHANGELOG,"---"+clfile+"---\n"+entry);
#endif
   if (old)
      write_file(clfile, old);
   rm(infile);
   write("Updated ChangeLog.\n");
   pop_coder(get_ref());
}

void abort() {
   write ("changelog aborted\n");
    rm(TMP_DIR+"changelog_"+getuid(this_player()));
   return;
}
string help() {
    return("Usage: changelog <directory>\n"+@HELP

  Updates the ChangeLog file in either the current directory (If no
directory is specified) or the specified directory.  This will put you
in an editor, like the one on the bulletin boards.  This is useful for
keeping a record of the changes that have been made in the directory in
question.
HELP
	);
}

void clean_up() {
    if (!sizeof(coders) && !sizeof(files))
        destruct(this_object());
}