nightmare3_fluffos_v2/
nightmare3_fluffos_v2/bin/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/ChangeLog.old/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/Win32/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/simuls/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/clone/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/command/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/data/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/etc/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/master/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/log/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/compiler/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/efuns/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/operators/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/u/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/tmp/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/windows/
nightmare3_fluffos_v2/lib/cmds/ambassador/
nightmare3_fluffos_v2/lib/cmds/database/
nightmare3_fluffos_v2/lib/cmds/hm/
nightmare3_fluffos_v2/lib/cmds/soul/
nightmare3_fluffos_v2/lib/daemon/cfg/
nightmare3_fluffos_v2/lib/daemon/cfg/mon_races/
nightmare3_fluffos_v2/lib/daemon/cfg/races/
nightmare3_fluffos_v2/lib/daemon/include/
nightmare3_fluffos_v2/lib/daemon/save/
nightmare3_fluffos_v2/lib/daemon/services/
nightmare3_fluffos_v2/lib/daemon/soul/
nightmare3_fluffos_v2/lib/doc/
nightmare3_fluffos_v2/lib/doc/TestPlans/
nightmare3_fluffos_v2/lib/doc/approval/
nightmare3_fluffos_v2/lib/doc/approval/QC/
nightmare3_fluffos_v2/lib/doc/approval/balance/
nightmare3_fluffos_v2/lib/doc/build/
nightmare3_fluffos_v2/lib/doc/build/armours/
nightmare3_fluffos_v2/lib/doc/build/economy/
nightmare3_fluffos_v2/lib/doc/build/etc/
nightmare3_fluffos_v2/lib/doc/build/monster/
nightmare3_fluffos_v2/lib/doc/build/room/
nightmare3_fluffos_v2/lib/doc/build/virtual/
nightmare3_fluffos_v2/lib/doc/build/weapon/
nightmare3_fluffos_v2/lib/doc/classes/
nightmare3_fluffos_v2/lib/doc/efun/
nightmare3_fluffos_v2/lib/doc/etc/
nightmare3_fluffos_v2/lib/doc/help/creator/
nightmare3_fluffos_v2/lib/doc/help/hm/
nightmare3_fluffos_v2/lib/doc/law/
nightmare3_fluffos_v2/lib/doc/lpc/basic/
nightmare3_fluffos_v2/lib/doc/lpc/data_types/
nightmare3_fluffos_v2/lib/doc/lpc/etc/
nightmare3_fluffos_v2/lib/doc/lpc/intermediate/
nightmare3_fluffos_v2/lib/doc/lpc/types/
nightmare3_fluffos_v2/lib/doc/mudlib/
nightmare3_fluffos_v2/lib/doc/mudlib/features/
nightmare3_fluffos_v2/lib/domains/Examples/etc/
nightmare3_fluffos_v2/lib/domains/Examples/room/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaA/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaB/
nightmare3_fluffos_v2/lib/domains/Examples/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/
nightmare3_fluffos_v2/lib/domains/Praxis/adm/
nightmare3_fluffos_v2/lib/domains/Praxis/attic/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/mon/
nightmare3_fluffos_v2/lib/domains/Praxis/data/
nightmare3_fluffos_v2/lib/domains/Praxis/death/
nightmare3_fluffos_v2/lib/domains/Praxis/mountains/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/armour/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/magic/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/orc_valley/
nightmare3_fluffos_v2/lib/domains/Praxis/quests/
nightmare3_fluffos_v2/lib/domains/Praxis/standardOld/
nightmare3_fluffos_v2/lib/include/
nightmare3_fluffos_v2/lib/log/
nightmare3_fluffos_v2/lib/log/errors/
nightmare3_fluffos_v2/lib/log/reports/
nightmare3_fluffos_v2/lib/log/watch/
nightmare3_fluffos_v2/lib/news/
nightmare3_fluffos_v2/lib/secure/cfg/
nightmare3_fluffos_v2/lib/secure/cmds/ambassador/
nightmare3_fluffos_v2/lib/secure/cmds/mortal/
nightmare3_fluffos_v2/lib/secure/save/users/d/
nightmare3_fluffos_v2/lib/secure/std/
nightmare3_fluffos_v2/lib/std/hm/
nightmare3_fluffos_v2/lib/std/living/
nightmare3_fluffos_v2/lib/std/room/
nightmare3_fluffos_v2/lib/std/user/
nightmare3_fluffos_v2/lib/std/virtual/
nightmare3_fluffos_v2/lib/www/
nightmare3_fluffos_v2/lib/www/errors/
nightmare3_fluffos_v2/lib/www/gateways/
nightmare3_fluffos_v2/win32/
/*    /std/user/editor.c
 *    from Nightmare IV
 *    an editor object for users
 *    created by Descartes of Borg 940715
 */

#include <dirs.h>
#include "editor.h"

#define EDITOR_HELP DIR_USER_HELP + "/editor"
static private int __Time;
static private string __FileName;
static private function __Callback, __Abort;
static private mixed __Arguments;

void create() {
    clear_editor();
  }

varargs int edit(string nom, function f, function abort, mixed args) {
    string tmp;

    if(!stringp(nom)) error("Bad argument 1 to edit().\n");
    if(!write_file(nom, "")) {
        message("system", "Permission denied.", this_object());
        return 0;
      }
    __FileName = nom;
    if(!functionp(f)) error("Bad argument 2 to edit().\n");
    else __Callback = f;
    if(!abort) abort = (: previous_object(), "abort" :);
    else if(!functionp(abort)) error("Bad argument 2 to edit().\n");
    __Abort = abort;
    if(args) __Arguments = args;
    tmp = read_file(__FileName);
    if(creatorp(this_object()) && getenv("EDITOR") == "ed") {
        __Time = stat(__FileName, -1)[1];
        ed(__FileName, "end_edit", !creatorp(this_object()));
        return 1;
      }
    message("system", "Nightmare IV Mudlib System Editor", this_object());
    message("system", sprintf("On a line by itself, type \".\" to end "
      "editing and \"%sq\" to abort.\nTo get help, type \"%sh\".",
      query_escape(), query_escape()), this_object());
    message("system", "____________________________________________________________________________", this_object());
    if(tmp) message("system", tmp, this_object());
    input_to("enter_line");
    return 1;
  }

nomask static void enter_line(string str) {
    string tmp;

    if(str == ".") {
        if(!((int)master()->valid_function(__Callback)))
          error("Illegal function pointer.\n");
        else (*__Callback)(__Arguments);
        return;
        clear_editor();
      }
    if(strlen(str) == 2 && str[0] == (query_escape())[0]) {
        switch(str[1]) {
	case 'h':
            this_object()->more(EDITOR_HELP, "help", (: "return_to_edit" :));
            return;
        case 'e': ed(__FileName, "end_edit", !creatorp(this_object())); return;
        case 'q':
            message("system", "Edit aborted.", this_object());
            if(!((int)master()->valid_function(__Abort)))
              error("Illegal function pointer.\n");
            else (*__Abort)();
            clear_editor();
            return;
	case 'l': 
            edit(__FileName, __Callback, __Abort, __Arguments);
            return;
        case 'r': case 'w':
            if(!creatorp(this_object()))
              message("system", "Function not available to mortals.",
                this_object());
            else message("system", "You must specify a file.", this_object());
            input_to("enter_line");
            return;
        }
      }
    else if(str[0..0] == query_escape()) {
        if(str == sprintf("%shelp", query_escape())) {
            enter_line(str[0..1]);
            return;
	  }
        else if(strlen(str) > 3) {
            if(str[1] == 'r') {
                if(!creatorp(this_object())) {
                    message("system", "Function not available to mortals.",
                      this_object());
                    input_to("enter_line");
                    return;
		  }
                if(!(tmp = read_file(absolute_path(query_cwd(),
                  str[3..strlen(str)-1])))) {
                    message("system", "File not found.", this_object());
                    input_to("enter_line");
                    return;
		  }
                write_file(__FileName, sprintf("%s\n", tmp));
                input_to("enter_line");
                return;
	      }
            else if(str[1] == 'w') {
                if(!creatorp(this_object())) {
                    message("system", "Function not available to mortals.",
                      this_object());
                    input_to("enter_line");
                    return;
		  }
                else if(!write_file(absolute_path(query_cwd(), 
                  str[3..strlen(str)-1]), read_file(__FileName))) {
                    message("system", "Permission denied.", this_object());
                    input_to("enter_line");
                    return;
		  }
                input_to("enter_line");
                return;
	      }
	  }
      }
    write_file(__FileName, sprintf("%s\n", str));
    input_to("enter_line");
    return;
  }

nomask void end_edit() {
    if(__Time == stat(__FileName, -1)[1]) {
        message("system", "Edit aborted.", this_object());
        if(!((int)master()->valid_function(__Abort)))
          error("Illegal function pointer.\n");
        else (*__Abort)();
        clear_editor();
        return;
      }
    if(!((int)master()->valid_function(__Callback)))
      error("Illegal function pointer.\n");
    else (*__Callback)(__Arguments);
    clear_editor();
    return;
  }

nomask static private void clear_editor() {
    __FileName = 0;
    __Time = 0;
    __Callback = 0;
    __Abort = 0;
    __Arguments = 0;
  }

nomask void return_to_edit() {
    input_to("enter_line");
    return;
}

nomask string query_edit_file() { return __FileName; }

string query_escape() {
    string tmp;

    if(!(tmp = getenv("ESCAPE"))) return "~";
    if(!stringp(tmp)) return "~";
    else return tmp;
  }

string getenv(string key) { return 0; }

string query_cwd() { return DIR_TMP; }

string query_edit_filename() { return __FileName; }