ds2.10/bin/
ds2.10/extra/
ds2.10/extra/crat/
ds2.10/extra/creremote/
ds2.10/extra/mingw/
ds2.10/extra/wolfpaw/
ds2.10/fluffos-2.16-ds05/
ds2.10/fluffos-2.16-ds05/Win32/
ds2.10/fluffos-2.16-ds05/compat/
ds2.10/fluffos-2.16-ds05/compat/simuls/
ds2.10/fluffos-2.16-ds05/include/
ds2.10/fluffos-2.16-ds05/testsuite/
ds2.10/fluffos-2.16-ds05/testsuite/clone/
ds2.10/fluffos-2.16-ds05/testsuite/command/
ds2.10/fluffos-2.16-ds05/testsuite/data/
ds2.10/fluffos-2.16-ds05/testsuite/etc/
ds2.10/fluffos-2.16-ds05/testsuite/include/
ds2.10/fluffos-2.16-ds05/testsuite/inherit/
ds2.10/fluffos-2.16-ds05/testsuite/inherit/master/
ds2.10/fluffos-2.16-ds05/testsuite/log/
ds2.10/fluffos-2.16-ds05/testsuite/single/
ds2.10/fluffos-2.16-ds05/testsuite/single/tests/compiler/
ds2.10/fluffos-2.16-ds05/testsuite/single/tests/efuns/
ds2.10/fluffos-2.16-ds05/testsuite/single/tests/operators/
ds2.10/fluffos-2.16-ds05/testsuite/u/
ds2.10/lib/cmds/admins/
ds2.10/lib/cmds/common/
ds2.10/lib/cmds/creators/include/
ds2.10/lib/daemon/services/
ds2.10/lib/daemon/tmp/
ds2.10/lib/doc/
ds2.10/lib/doc/bguide/
ds2.10/lib/doc/efun/all/
ds2.10/lib/doc/efun/arrays/
ds2.10/lib/doc/efun/buffers/
ds2.10/lib/doc/efun/compile/
ds2.10/lib/doc/efun/floats/
ds2.10/lib/doc/efun/functions/
ds2.10/lib/doc/efun/general/
ds2.10/lib/doc/efun/mixed/
ds2.10/lib/doc/efun/numbers/
ds2.10/lib/doc/efun/parsing/
ds2.10/lib/doc/help/classes/
ds2.10/lib/doc/help/races/
ds2.10/lib/doc/lfun/
ds2.10/lib/doc/lfun/all/
ds2.10/lib/doc/lfun/lib/abilities/
ds2.10/lib/doc/lfun/lib/armor/
ds2.10/lib/doc/lfun/lib/bank/
ds2.10/lib/doc/lfun/lib/bot/
ds2.10/lib/doc/lfun/lib/clay/
ds2.10/lib/doc/lfun/lib/clean/
ds2.10/lib/doc/lfun/lib/clerk/
ds2.10/lib/doc/lfun/lib/client/
ds2.10/lib/doc/lfun/lib/combat/
ds2.10/lib/doc/lfun/lib/connect/
ds2.10/lib/doc/lfun/lib/container/
ds2.10/lib/doc/lfun/lib/corpse/
ds2.10/lib/doc/lfun/lib/creator/
ds2.10/lib/doc/lfun/lib/daemon/
ds2.10/lib/doc/lfun/lib/damage/
ds2.10/lib/doc/lfun/lib/deterioration/
ds2.10/lib/doc/lfun/lib/donate/
ds2.10/lib/doc/lfun/lib/door/
ds2.10/lib/doc/lfun/lib/equip/
ds2.10/lib/doc/lfun/lib/file/
ds2.10/lib/doc/lfun/lib/fish/
ds2.10/lib/doc/lfun/lib/fishing/
ds2.10/lib/doc/lfun/lib/flashlight/
ds2.10/lib/doc/lfun/lib/follow/
ds2.10/lib/doc/lfun/lib/ftp_client/
ds2.10/lib/doc/lfun/lib/ftp_data_connection/
ds2.10/lib/doc/lfun/lib/fuel/
ds2.10/lib/doc/lfun/lib/furnace/
ds2.10/lib/doc/lfun/lib/genetics/
ds2.10/lib/doc/lfun/lib/holder/
ds2.10/lib/doc/lfun/lib/id/
ds2.10/lib/doc/lfun/lib/interactive/
ds2.10/lib/doc/lfun/lib/lamp/
ds2.10/lib/doc/lfun/lib/leader/
ds2.10/lib/doc/lfun/lib/light/
ds2.10/lib/doc/lfun/lib/limb/
ds2.10/lib/doc/lfun/lib/living/
ds2.10/lib/doc/lfun/lib/load/
ds2.10/lib/doc/lfun/lib/look/
ds2.10/lib/doc/lfun/lib/manipulate/
ds2.10/lib/doc/lfun/lib/meal/
ds2.10/lib/doc/lfun/lib/messages/
ds2.10/lib/doc/lfun/lib/player/
ds2.10/lib/doc/lfun/lib/poison/
ds2.10/lib/doc/lfun/lib/position/
ds2.10/lib/doc/lfun/lib/post_office/
ds2.10/lib/doc/lfun/lib/potion/
ds2.10/lib/doc/lfun/lib/room/
ds2.10/lib/doc/lfun/lib/server/
ds2.10/lib/doc/lfun/lib/spell/
ds2.10/lib/doc/lfun/lib/torch/
ds2.10/lib/doc/lfun/lib/vendor/
ds2.10/lib/doc/lfun/lib/virt_sky/
ds2.10/lib/doc/lfun/lib/weapon/
ds2.10/lib/doc/lfun/lib/worn_storage/
ds2.10/lib/doc/lpc/constructs/
ds2.10/lib/doc/lpc/etc/
ds2.10/lib/doc/lpc/intermediate/
ds2.10/lib/doc/lpc/types/
ds2.10/lib/doc/misc/
ds2.10/lib/doc/old/
ds2.10/lib/doc/phints/
ds2.10/lib/domains/
ds2.10/lib/domains/Praxis/adm/
ds2.10/lib/domains/Praxis/attic/
ds2.10/lib/domains/Praxis/cemetery/mon/
ds2.10/lib/domains/Praxis/data/
ds2.10/lib/domains/Praxis/death/
ds2.10/lib/domains/Praxis/mountains/
ds2.10/lib/domains/Praxis/obj/armour/
ds2.10/lib/domains/Praxis/obj/magic/
ds2.10/lib/domains/Praxis/obj/weapon/
ds2.10/lib/domains/Praxis/orc_valley/
ds2.10/lib/domains/Ylsrim/
ds2.10/lib/domains/Ylsrim/adm/
ds2.10/lib/domains/Ylsrim/armor/
ds2.10/lib/domains/Ylsrim/broken/
ds2.10/lib/domains/Ylsrim/fish/
ds2.10/lib/domains/Ylsrim/meal/
ds2.10/lib/domains/Ylsrim/npc/
ds2.10/lib/domains/Ylsrim/obj/
ds2.10/lib/domains/Ylsrim/virtual/
ds2.10/lib/domains/Ylsrim/weapon/
ds2.10/lib/domains/alpha/room/
ds2.10/lib/domains/alpha/virtual/
ds2.10/lib/domains/campus/adm/
ds2.10/lib/domains/campus/etc/
ds2.10/lib/domains/campus/meals/
ds2.10/lib/domains/campus/txt/ai/charles/
ds2.10/lib/domains/campus/txt/ai/charles/bak2/
ds2.10/lib/domains/campus/txt/ai/charles/bak2/bak1/
ds2.10/lib/domains/campus/txt/ai/charly/
ds2.10/lib/domains/campus/txt/ai/charly/bak/
ds2.10/lib/domains/campus/txt/jenny/
ds2.10/lib/domains/cave/doors/
ds2.10/lib/domains/cave/etc/
ds2.10/lib/domains/cave/meals/
ds2.10/lib/domains/cave/weap/
ds2.10/lib/domains/default/chamber/
ds2.10/lib/domains/default/creator/
ds2.10/lib/domains/default/doors/
ds2.10/lib/domains/default/etc/
ds2.10/lib/domains/default/vehicle/
ds2.10/lib/domains/default/virtual/
ds2.10/lib/domains/town/save/
ds2.10/lib/domains/town/txt/shame/
ds2.10/lib/domains/town/virtual/
ds2.10/lib/domains/town/virtual/bottom/
ds2.10/lib/domains/town/virtual/space/
ds2.10/lib/estates/
ds2.10/lib/ftp/
ds2.10/lib/lib/comp/
ds2.10/lib/lib/daemons/
ds2.10/lib/lib/daemons/include/
ds2.10/lib/lib/lvs/
ds2.10/lib/lib/user/
ds2.10/lib/lib/virtual/
ds2.10/lib/log/
ds2.10/lib/log/adm/
ds2.10/lib/log/archive/
ds2.10/lib/log/chan/
ds2.10/lib/log/errors/
ds2.10/lib/log/law/adm/
ds2.10/lib/log/law/email/
ds2.10/lib/log/law/names/
ds2.10/lib/log/law/sites-misc/
ds2.10/lib/log/law/sites-register/
ds2.10/lib/log/law/sites-tempban/
ds2.10/lib/log/law/sites-watch/
ds2.10/lib/log/open/
ds2.10/lib/log/reports/
ds2.10/lib/log/router/
ds2.10/lib/log/secure/
ds2.10/lib/log/watch/
ds2.10/lib/obj/book_source/
ds2.10/lib/obj/include/
ds2.10/lib/powers/prayers/
ds2.10/lib/powers/spells/
ds2.10/lib/realms/template/
ds2.10/lib/realms/template/adm/
ds2.10/lib/realms/template/area/
ds2.10/lib/realms/template/area/armor/
ds2.10/lib/realms/template/area/npc/
ds2.10/lib/realms/template/area/obj/
ds2.10/lib/realms/template/area/room/
ds2.10/lib/realms/template/area/weap/
ds2.10/lib/realms/template/bak/
ds2.10/lib/realms/template/cmds/
ds2.10/lib/save/kills/o/
ds2.10/lib/secure/cfg/classes/
ds2.10/lib/secure/cmds/builders/
ds2.10/lib/secure/cmds/creators/include/
ds2.10/lib/secure/cmds/players/include/
ds2.10/lib/secure/daemon/imc2server/
ds2.10/lib/secure/daemon/include/
ds2.10/lib/secure/lib/
ds2.10/lib/secure/lib/include/
ds2.10/lib/secure/lib/net/include/
ds2.10/lib/secure/lib/std/
ds2.10/lib/secure/log/adm/
ds2.10/lib/secure/log/bak/
ds2.10/lib/secure/log/intermud/
ds2.10/lib/secure/log/network/
ds2.10/lib/secure/modules/
ds2.10/lib/secure/npc/
ds2.10/lib/secure/obj/include/
ds2.10/lib/secure/room/
ds2.10/lib/secure/save/
ds2.10/lib/secure/save/backup/
ds2.10/lib/secure/save/boards/
ds2.10/lib/secure/save/players/g/
ds2.10/lib/secure/tmp/
ds2.10/lib/secure/upgrades/files/
ds2.10/lib/secure/verbs/creators/
ds2.10/lib/std/board/
ds2.10/lib/std/lib/
ds2.10/lib/verbs/admins/include/
ds2.10/lib/verbs/builders/
ds2.10/lib/verbs/common/
ds2.10/lib/verbs/common/include/
ds2.10/lib/verbs/creators/
ds2.10/lib/verbs/creators/include/
ds2.10/lib/verbs/rooms/
ds2.10/lib/verbs/rooms/include/
ds2.10/lib/www/client/
ds2.10/lib/www/errors/
ds2.10/lib/www/images/
ds2.10/win32/
#define NOECHO 1
#ifndef CED_DISABLED
#define CED_DISABLED 0
#endif
#define CED_DEBUG 0

private static mapping FileData = ([]);
private static mapping ScreenData = ([]);

static int *GetScreen(){ return ({ 79, 24 }); }
private static int ReceiveChars(string c);

void create(){
    mixed tmp = GetScreen();
    if(!sizeof(ScreenData)){
        ScreenData = ([]);
    }
    if(sizeof(tmp)){
        ScreenData["maxcol"] = tmp[0];
        ScreenData["row"] = tmp[1] - 1;
    }
    else {
        ScreenData["maxcol"] = 79;
        ScreenData["row"] = 24;
    }
    ScreenData["maxrow"] = ScreenData["row"];
    ScreenData["col"] = 1;
    ScreenData["charbuffer"] = "";
    ScreenData["sessionbuffer"] = "   ";
    ScreenData["insert"] = 1;
    ScreenData["cedmode"] = 0;
}

int ClearBuffers(){
    ScreenData["charbuffer"] = "";
    ScreenData["sessionbuffer"] = "";
    this_object()->SetCharbuffer("");
}

varargs int StatReport(string str){
    receive("\r\e["+(ScreenData["maxrow"])+";1H"); /* put cursor at bottom */
    receive("\r\e[2K"); /* Erase the entire bottom row */
    if(!str && sizeof(ScreenData["report"])){
        str = ScreenData["report"];
        ScreenData["report"] = "";
    }
    if(!str){
#if CED_DEBUG
        str = "screen: "+ScreenData["row"]+","+ScreenData["col"]+
                " file: "+((FileData["topline"]+ScreenData["row"])-1)+
                ","+ScreenData["col"]+", topline: "+FileData["topline"];
#else 
        str = "line: "+((FileData["topline"]+ScreenData["row"])-1)+
                " col: "+ScreenData["col"]+" file: "+ FileData["file"];
#endif
    }
    receive(str);
    /* now return cursor to prev pos */
    receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H");
    return 1;
}

varargs int RedrawScreen(int topline){
    int lastline = sizeof(FileData["map"]);
    int line = 1;
    mixed tmp = GetScreen();

    if(sizeof(tmp)){
        ScreenData["maxcol"] = tmp[0];
        ScreenData["maxrow"] = tmp[1];
    }
    else {
        ScreenData["maxcol"] = 79;
        ScreenData["maxrow"] = 24;
    }

    if(!topline) topline = FileData["topline"];
    topline--;
    if(topline > lastline) return 0;
    receive("\r\e[1;1H");
    receive("\r\e[2K");
    while(line < (ScreenData["maxrow"] )){
        string trunky; // patches for linewrapping are welcome
        int extra;
        receive("\r\e["+line+";1H");
        receive("\e[2K");
        if(FileData["map"][(line+topline)]){
            trunky = FileData["map"][(line+topline)];
            extra = sizeof(trunky) - ScreenData["maxcol"];
            if(extra > 0) trunky = truncate(trunky, extra);
            receive("\r\e[7l"+trunky+"\n");
        }
        line++;
    }
    receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H");
    ScreenData["charbuffer"] = "";
    return 1;
}

static int UpdateScreen(){
    if(ScreenData["row"] > (ScreenData["maxrow"] - 1)){ 
        if(!ScreenData["goto"] && !ScreenData["searching"])
            ScreenData["row"] = (ScreenData["maxrow"] - 1);
        if(FileData["topline"] < sizeof(FileData["map"])){
            FileData["topline"]++;
            RedrawScreen(FileData["topline"]);
        }
    }
    if(ScreenData["row"] < 1){ 
        ScreenData["row"] = 1;
        FileData["topline"]--;
        if(FileData["topline"] < 1){
            FileData["topline"] = 1;
        }
        RedrawScreen(FileData["topline"]);
    }
    if(ScreenData["col"] > ScreenData["maxcol"]) 
        ScreenData["col"] = ScreenData["maxcol"];
    if(ScreenData["col"] < 1) 
        ScreenData["col"] = 1;
    if(ScreenData["col"] > sizeof(FileData["map"][(ScreenData["row"] +
                    FileData["topline"]) - 1])){
        ScreenData["col"] = sizeof(FileData["map"][(ScreenData["row"] +
                    FileData["topline"]) - 1])+1; /* lol */
        if(ScreenData["col"] < 1) ScreenData["col"] = 1;
    }
    receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H"); 
    StatReport();
}

static varargs int CeditCollate(int x){ /* when lines need to be resorted */
    int i; 
    string tmp = "";
    string *lns = sort_array(keys(FileData["map"]), 1);
    if(!sizeof(lns)) return 0;
    FileData["contents"] = "";
    foreach(int l in lns){
        if(!undefinedp(x) && !(l + x)) continue; /* remove a line */
        tmp += FileData["map"][l]+"\n";
        if(l == x) tmp += "\n"; /* add a line */
    }
    foreach(mixed key, mixed val in FileData["map"]){
    }
    tmp = replace_string(tmp,"\n","\n"+sprintf("%c",17));
    i = 1;
    foreach(mixed ln in explode(tmp,sprintf("%c",17))){
        FileData["map"][i] = replace_string(ln,"\n","");
        i++;
    }
    return i;
}

static varargs int CeditSave(string file){
    string ret = "";
    int i;
    string *lns = sort_array(keys(FileData["map"]), 1);
    if(!sizeof(lns)) return 0;
    foreach(int l in lns){
        ret += FileData["map"][l]+"\n";
    }
    foreach(mixed key, mixed val in FileData["map"]){
    }
#if CED_DISABLED
    StatReport("This alpha editor is not yet in shape to save files.");
#else
    i = write_file(FileData["file"],ret,1); 
#endif
    return i;
}

static int rBackspace(){
    int col, row;
    string begin, end;
    col = ScreenData["col"];
    row = (ScreenData["row"] + FileData["topline"]) - 1;
    if(FileData["map"][row]){
        begin = FileData["map"][row][0..(col-3)];
        end = FileData["map"][row][(col-1)..];
        FileData["map"][row]=begin+end;
        receive("\r\e[2K");
        receive(FileData["map"][row]);
        ScreenData["col"]--;
        if((ScreenData["maxrow"] - 1) != ScreenData["row"] &&
          FileData["map"][row+1]){
            receive("\r\e["+(ScreenData["row"]+1)+";"+ScreenData["col"]+"H");
            receive("\r\e[2K");
            receive(FileData["map"][row+1]);
        }
        receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H");
    }
    ScreenData["charbuffer"] = "";
    ScreenData["backspace"] = 0;
} 

static int rEnter(){
    if(!ScreenData["sessionbuffer"]) ScreenData["sessionbuffer"] = "";
    if(ScreenData["searching"]){
        int end, i, start = ScreenData["pregoto"][0];
        end = sort_array(keys(FileData["map"]), 1)[<1];
        ScreenData["searching"] = 0;
        if(sizeof(ScreenData["search"])){
            ScreenData["oldsearch"] = ScreenData["search"];
            ScreenData["searchhit"] = 0;
        }
        else {
            ScreenData["search"] = ScreenData["oldsearch"];
            start = ScreenData["searchhit"] + 1;
        }
        i = start;
        while(i <= end){
            if(FileData["map"][i] && grepp(FileData["map"][i],
              ScreenData["search"])){
                ScreenData["goto"] = 1;
                ScreenData["search"] = 0;
                ScreenData["searchhit"] = i;
                ScreenData["charbuffer"] = itoa(i);
                break;
            }
            i++;
        }
#if CED_DEBUG
        debug_message("ScreenData[\"search\"]: "+ScreenData["search"]);
        debug_message("ScreenData[\"goto\"]: "+ScreenData["goto"]);
        debug_message("ScreenData[\"charbuffer\"]: "+ScreenData["charbuffer"]);
        debug_message("ScreenData[\"oldsearch\"]: "+ScreenData["oldsearch"]);
#endif
        if(!ScreenData["goto"]){
            ScreenData["report"] = "String not found searching from line "+
              start;
        }
    }
    if(ScreenData["goto"]){
        int top;
        int line = atoi(ScreenData["charbuffer"]);
        if(line && FileData["map"][line]){
            ScreenData["report"] = "Going to "+ScreenData["charbuffer"];
            top = line - ScreenData["pregoto"][0]; 
            if(top < 1) top = 1;
            FileData["topline"] = top;
            ScreenData["row"] = (ScreenData["pregoto"][0]) + 1;
            ScreenData["col"] = 1;
        }
        else {
            ScreenData["report"] = "No such line!";
            ScreenData["row"] = ScreenData["pregoto"][0];
            ScreenData["col"] = ScreenData["pregoto"][1];
        }
        ScreenData["charbuffer"] = "";
        ScreenData["goto"] = 0;
        ScreenData["pregoto"] = 0;
        this_object()->SetNoEcho(1);
    }
    else {
        ScreenData["charbuffer"] = "\n";
        ScreenData["sessionbuffer"] += sprintf("%c", 13);
        CeditCollate((FileData["topline"]+ScreenData["row"])-1);
    }
    UpdateScreen();
    RedrawScreen();
    return 1;
}

static int rAscii(string c){
    string tmp = c;
    int row, col, arrowed;
    if(!ScreenData["charbuffer"]) ScreenData["charbuffer"] = "";
    if(!ScreenData["sessionbuffer"]) ScreenData["sessionbuffer"] = "";
    if(ScreenData["searching"]){
        if(!ScreenData["search"]) ScreenData["search"] = "";
        ScreenData["charbuffer"] += c;
        ScreenData["search"] += c;
        return 1;
    }
    else if(ScreenData["goto"]){
        ScreenData["charbuffer"] += c;
        return 1;
    }
    else {
        ScreenData["charbuffer"] += c;
        ScreenData["sessionbuffer"] += c;
    }
    if(sizeof(ScreenData["sessionbuffer"]) > 1024){
        ScreenData["sessionbuffer"] = ScreenData["sessionbuffer"][1..];
    }
    if(sizeof(tmp) && tmp[0] != 30 && !ScreenData["sentinel"]){
        receive(tmp);
        if(tmp[0] == 91){
        }
        if(sizeof(ScreenData["sessionbuffer"]) > 2){
            if(ScreenData["sessionbuffer"][<1] == 91){
            }
        }
        if(ScreenData["insert"]){
            string begin;
            string end;
            col = ScreenData["col"];
            row = (ScreenData["row"] + FileData["topline"]) - 1;
            if(FileData["map"][row]){
                begin = FileData["map"][row][0..(col-2)];
                end = FileData["map"][row][(col-1)..];
                FileData["map"][row]=begin+ScreenData["charbuffer"]+end;
            }
        }
        else {
            col = ScreenData["col"];
            row = (ScreenData["row"] + FileData["topline"]) - 1;
            if(FileData["map"][row]){
                if(sizeof(FileData["map"][row]) >= col){
                    FileData["map"][row][col-1] = ScreenData["charbuffer"][0];
                }
                else {
                    FileData["map"][row] += ScreenData["charbuffer"];
                }
            }
        }
        if(ScreenData["charbuffer"] == "\n"){
            CeditCollate();
            RedrawScreen();
        }
        receive("\r\e[2K");
        if(FileData["map"][row]) receive(FileData["map"][row]);
        ScreenData["col"]++;
        receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H"); 
        ScreenData["charbuffer"] = "";
    }
    return 1;
}

static int rDel(){
    string begin, end;
    int col, row;
    col = ScreenData["col"];
    row = (ScreenData["row"] + FileData["topline"]) - 1;
    if(FileData["map"][row]){
        begin = FileData["map"][row][0..(col-2)];
        end = FileData["map"][row][(col)..];
        FileData["map"][row]=begin+end;
        receive("\r\e[2K");
        receive(FileData["map"][row]);
        if((ScreenData["maxrow"] - 1) != ScreenData["row"] &&
          FileData["map"][row+1]){
            receive("\r\e["+(ScreenData["row"]+1)+";"+ScreenData["col"]+"H");
            receive("\r\e[2K");
            receive(FileData["map"][row+1]);
        }
        receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H");
    }
    ScreenData["charbuffer"] = "";
    ScreenData["delete"] = 0;
    return 1;
}

int rCtrl(string c){
    string tmp;
    int row, col, arrowed;
    if(!ScreenData["charbuffer"]){
        ScreenData["charbuffer"] = this_object()->GetCharbuffer();
    }

    /* special chars */
    if(c == "q"){ /* Ctrl-Q for quitting without saving */
        write("Cancelling cedit!");
        ScreenData["cedmode"] = 0;
        FileData = ([ "file" : "", "map" : ([]) ]);
        ClearBuffers();
    }
    else if(c == "g"){ /* Ctrl-G for going to a line */
        string tmpstr = "Please type the line number then press enter.";
        int where = sizeof(tmpstr);
        ScreenData["report"] = tmpstr;
        ScreenData["pregoto"] = ({ ScreenData["row"], ScreenData["col"] });
        ScreenData["row"] = (ScreenData["maxrow"]);
        ScreenData["col"] = (where + 1);
        receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H");
        ScreenData["charbuffer"] = "";
        ScreenData["goto"] = 1;
        this_object()->SetNoEcho(0);
    }
    else if(c == "f"){ /* Ctrl-F */
        int targettopline, targetline, maxlines, lasty;
        lasty = sort_array(keys(FileData["map"]), 1)[<1];
        targettopline = FileData["topline"] + (ScreenData["maxrow"] - 1);
        if(targettopline > (lasty - ScreenData["maxrow"]) + 1){
            targettopline = (lasty - ScreenData["maxrow"]) + 1;
        }
        targetline = targettopline + ScreenData["row"];
        maxlines = sizeof(FileData["map"]);
        if(targettopline > maxlines) targettopline = maxlines;
        if(targetline > maxlines) targetline = maxlines;
        FileData["topline"] = targettopline;
        ScreenData["row"] = targetline;
        RedrawScreen(FileData["topline"]);
    }
    else if(c == "b"){ /* Ctrl-B */
        int targettopline = FileData["topline"] - (ScreenData["maxrow"] - 1);
        int targetline = targettopline - ScreenData["row"];
        if(targettopline < 1) targettopline = 1;
        if(targetline < 1) targetline = 1;
        FileData["topline"] = targettopline;
        ScreenData["row"] = targetline;
        RedrawScreen(FileData["topline"]);
    }
    else if(c == "l"){ /* Ctrl-L */
        RedrawScreen(FileData["topline"]);
        ScreenData["charbuffer"] = "";
    }
    else if(c == "d"){ /* Ctrl-D */
        row = (ScreenData["row"] + FileData["topline"]) - 1;
        if(FileData["map"][row]){
            CeditCollate(-((FileData["topline"]+ScreenData["row"])-1));
            RedrawScreen();
        }
        ScreenData["charbuffer"] = "";
        ScreenData["linedel"] = 0;
    }
    else if(c == "i"){ /* Ctrl-I */
        if(!ScreenData["insert"]){
            ScreenData["insert"] = 1;
            ScreenData["report"] = "Insert mode enabled";
        }
    }
    else if(c == "o"){ /* Ctrl-O */
        if(ScreenData["insert"]){
            ScreenData["insert"] = 0;
            ScreenData["report"] = "Overstrike mode enabled";
        }
    }
    else if(c == "x"){ /* Ctrl-X */
        int ret;
#if CED_DISABLED
        ScreenData["report"] = "This alpha editor is not yet in shape to "+
          "save files.";
#else
        if(sizeof(FileData["file"]) && sizeof(FileData["map"])){
            ret = CeditSave();
            if(ret){
                ScreenData["report"] = FileData["file"]+" saved.";
                write("Exiting screen editor.\n");
                ScreenData["cedmode"] = 0;
                FileData = ([ "file" : "", "map" : ([]) ]);
                ClearBuffers();
            }
            else ScreenData["report"] = FileData["file"]+" save FAILED.";
        }
#endif
    }
    else if(c == "s"){ /* Ctrl-S */
        int ret;
#if CED_DISABLED
        ScreenData["report"] = "This alpha editor is not yet in shape "+
          "to save files.";
#else
        if(sizeof(FileData["file"]) && sizeof(FileData["map"])){
            ret = CeditSave();
            if(ret) ScreenData["report"] = FileData["file"]+" saved.";
            else ScreenData["report"] = FileData["file"]+" save FAILED.";
        }
#endif
    }
    else if(c == "c"){ /* Ctrl-C */
        ClearBuffers();
    }
    else if(c == "31"){ /* Ctrl-/ for a search */
        string tmpstr = "Please type the word to search for: ";
        int where = sizeof(tmpstr);
        ScreenData["report"] = tmpstr;
        ScreenData["pregoto"] = ({ ScreenData["row"], ScreenData["col"] });
        ScreenData["row"] = (ScreenData["maxrow"]);
        ScreenData["col"] = (where + 1);
        receive("\r\e["+ScreenData["row"]+";"+ScreenData["col"]+"H");
        ScreenData["charbuffer"] = "";
        ScreenData["searching"] = 1;
        this_object()->SetNoEcho(0);
    }
    else if(c == "28"){ /* Ctrl-\ */
        ScreenData["report"] = "esc-28 received";
    }
    if(ScreenData["cedmode"]) UpdateScreen();
    else {
        this_object()->SetCharmode(1);
        this_object()->erase_prompt();
        this_object()->write_prompt();
    }
    return 1;
}

static int rArrow(string str){
    switch(str){
        int lasty;
        case "up" : ScreenData["row"]--; break;
        case "down" : 
            if((ScreenData["row"] > (ScreenData["maxrow"] - 2) )){
                lasty = sort_array(keys(FileData["map"]), 1)[<1];
                if((FileData["topline"] > (lasty - ScreenData["maxrow"]) + 1)){
                    break;
                }
            }
            ScreenData["row"]++; 
            break;
        case "left" : ScreenData["col"]--; break;
        case "right" : ScreenData["col"]++; break;
    }
    ScreenData["charbuffer"] = "";
    UpdateScreen();
    return 1;
}

varargs int SetCedmode(int x, string file){
    int num;
    mixed tmp, lines;
#ifndef __DSLIB__
    return 0;
#else
    FileData = ([ "file" : "", "map" : ([]) ]);
    if(!this_player() || this_player() != this_object()) return 0;
    if(!sizeof(file)) file = "";
    if(x){
        ClearBuffers();
        ScreenData["cedmode"] = x;
        ScreenData["insert"] = 1;
        FileData["topline"] = 1;
        if(!FileData["map"]) FileData["map"] = ([]);
        if(true()){
            FileData["file"] = file;
            tmp = read_file(FileData["file"]);
            if(!tmp){
                string line = repeat_string(" ", ScreenData["maxcol"])+"\n";
                lines = ScreenData["maxrow"];
                FileData["contents"] = "";
                while(lines){
                    lines--;
                    FileData["contents"] += line;
                }
            }
            tmp = replace_string(tmp,"\n","\n"+sprintf("%c",17));
            tmp = replace_string(tmp,"\t","    ");
            lines = 1;
            foreach(mixed ln in explode(tmp,sprintf("%c",17))){
                FileData["map"][lines] = replace_string(ln,"\n","");
                lines++;
            }
        }
        receive("\r\e[2J"); /* cls */
        receive("\r\e[7l"); /* no wrapping */
        ScreenData["row"] = 1;
        ScreenData["col"] = 1;
        ScreenData["report"] = "Editing "+FileData["file"];
        RedrawScreen(FileData["topline"]);
    }
    else {
        ScreenData["cedmode"] = 0;
    }
    return ScreenData["cedmode"];
#endif
}

int GetCedmode(){
    return ScreenData["cedmode"];
}

static int rAnsi(string str){
    return 1;
}