/
CDC-1.2b/
CDC-1.2b/src/
parent $thing
parent $text
parent $public
object $note

var $root dbref 'note
var $root child_index 26
var $root fertile 1
var $root manager $note
var $root owned [$note]
var $root owners [$note]
var $root writable []
var $root readable ['parameters, 'methods, 'code]
var $text text []
var $root inited 1
var $located location $nowhere
var $located obvious 1
var $messaged messages #[]
var $described prose #[]
var $has_verbs verbs #[["erase %this", ['erase_vrb, 'remote]], ["read|nread %this", ['read_vrb, 'remote]], ["write on %this", ['write_vrb, 'remote]], ["write at * on %this", ['write_at_vrb, 'remote]], ["write * on %this", ['write_str_vrb, 'remote]], ["copy from %this to *", ['copy_vrb, 'remote]], ["erase * on|from %this", ['erase_on_vrb, 'remote]]]
var $gendered gender $gender_neuter
var $named name ['uniq, "Generic Note"]
var $named name_aliases ["note"]
var $note seperator 0
var $public public []
var $root info ["Generic Note", "============", "", "For basic editing and saving of text.", "", "Descendant of $text", "", "Commands:", "", "  \"erase * on %this\"                    rmt 'erase_on_vrb", "  \"erase %this\"                         rmt 'erase_vrb", "  \"read|nread %this\"                    rmt 'read_vrb", "  \"write on %this\"                      rmt 'write_vrb", "  \"write at * on %this\"                 rmt 'write_at_vrb", "  \"write * on %this\"                    rmt 'write_str_vrb", "  \"copy from %this to *\"                rmt 'copy_vrb", "", "erase", "-----", "", "Erases all or part of the text.  \"erase %this\" and \"erase all on %this\" erases all text from the note.  \"erase <line(s)> on %this\" erases a line or lines from the note, example: \"erase 2-5 on %this\".", "", "read|nread", "----------", "", "Read the text.  \"nread\" will read the text and prepend each line with it's relative number.", "", "write", "-----", "", "Write on the note using this command.  \"write on %this\" will accept text after the command line and append it to the end.  \"write <line> on %this\" will add the line to the end of the note.  \"write at <line> on %this\" will accept text after the command line and place it in the text beginning at <line>.", "", "copy", "----", "", "Used to copy the text from the note to either another descendant of $note or if a method is specified it sends to that method instead.", "", "Maintenance", "===========", "", "As an owner of the note object you can set it as publicly writable or readable.  The Note is a child of the generic public object, so you can do this by using the \"@public\" command (Syntax: `@public on note <+|-[w?ritable|r?eadable]>`).  Writers following the system permissions scheme are also allowed to write on the note.", "", "The seperator can be changed using eval on the .set_seperator() method.  This is not a command as most people don't change it."]

method read_vrb
    arg vrb, [args];
    var who, text, prose;
    
    who = sender();
    if ((!(.is_publicly('readable))) && (!(.trusts(who))))
        return who.tell((.name('def)) + " is not publicly readable!");
    who.tell(.name('def));
    prose = .prose('literal);
    if (prose)
        who.tell((| prose['short] |) || []);
    who.tell(.seperator());
    text = .text();
    if ((vrb == "nread") && text)
        text = $list.numbered_text(text);
    who.tell(text ? text | ["", "(nothing)", ""]);
    who.tell(.seperator());
    who.tell(("You finish reading " + (.name('def))) + ".");
.

method write_vrb
    arg write, [args];
    var who, line;
    
    who = sender();
    if ((!(.is_publicly('writable))) && (!(.is_writable_by(who))))
        return who.tell((.namef()) + " is not publicly writable!");
    
    // because I'm odd lets do this all 1 one command.
    if (listlen(args) == 2) {
        line = "Now writing on " + (.name('def));
        line = line + ", enter \".\" to finish and \"@abort\" to abort.";
    
        //      who.tell(line);
        .add_text(who.read(line), who);
    } else {
        args = explode(args[1]);
        who.debug(args);
    }
.

method erase_on_vrb
    arg erase, str, prep, this;
    var line, nline, who, len, oldline;
    
    who = sender();
    if ((!(.is_publicly('writable))) && (!(.is_writable_by(who))))
        return who.tell((.namef()) + " is not publicly writable!");
    if (!str)
        return who.tell("You must erase either a line, line number, or all");
    catch any {
        if (match_begin("all", str)) {
            .del_text();
    
            // if erase is null, this method was called by an editor
            if (erase)
                who.tell(("All text cleared from " + (.name('def))) + ".");
        } else {
            if (listlen(explode(str)) > 1)
                nline = toint(explode(str)[2]);
            else
                nline = toint(str);
            oldline = (.text())[nline];
            .del_nline(nline);
            line = ("Line " + tostr(nline)) + " (\"";
            len = (who.linelen()) - (25 + strlen(.name('def)));
            line = line + ($string.chop(oldline, len));
            line = (line + "\") erased from ") + (.name('def));
            who.tell(line);
        }
    } with handler {
        switch (error()) {
            case ~range:
                who.tell("There are not that many lines in the text.");
            default:
                who.tell("Oops: " + ((traceback()[1])[2]));
        }
    }
.

method erase_vrb
    arg erase, this;
    var line, nline, len;
    
    if ((!(.is_publicly('writable))) && (!(.is_writable_by(sender()))))
        return sender().tell((.namef()) + " is not publicly writable!");
    .del_text();
    
    // if erase is null, this method was called by an editor originally.
    if (erase)
        sender().tell(("All text cleared from " + (.name('def))) + ".");
.

method add_text
    arg ntext, who, [args];
    
    // if at they should be an int defining where to insert.
    if (sender() != this()) {
        if ((!(.is_publicly('writable))) && (!(.is_writable_by(sender()))))
            throw(~perm, "Permission Denied.");
    }
    if (ntext) {
        if (ntext == 'aborted)
            return;
        if (args) {
            if (!(| .ins_lines(ntext, args[1]) |))
                who.tell(("There are not that many lines in " + (.name('ref))) + ".");
        } else {
            .set_text((.text()) + ntext);
        }
        who.tell(((("Line" + ((listlen(ntext) == 1) ? "" | "s")) + " added to ") + (.name('def))) + ".");
    } else {
        who.tell("Text not added.");
    }
.

method seperator
    return (type(seperator) == 'string) ? seperator | "---";
.

method write_str_vrb
    arg write, str, prep, this;
    var who, line;
    
    who = sender();
    if ((!(.is_publicly('writable))) && (!(.is_writable_by(who))))
        return who.tell((.namef()) + " is not publicly writable!");
    if (!str)
        return .tell(("Nothing to write on " + (.name('def))) + "!");
    .add_text([str], sender());
.

method write_at_vrb
    arg write, at, str, prep, this;
    var who, line, lines, syn;
    
    who = sender();
    if ((!(.is_publicly('writable))) && (!(.is_writable_by(who))))
        return who.tell((.namef()) + " is not publicly writable!");
    syn = ((("`" + write) + " at [line] <line number> on ") + this) + "`";
    str = explode(str);
    if ((str[1]) == "line")
        str = delete(str, 1);
    line = $string.is_numeric(str[1]);
    if (!at)
        $parse.tell_error(("Unknown line \"" + (str[1])) + "\".", syn, who);
    lines = listlen(.text());
    if (line > (lines + 1))
        $parse.tell_error(("There are only " + tostr(lines)) + " lines!", syn, who);
    .add_text(who.read(), who, line);
.

method copy_vrb
    arg com, from, this, prep, where;
    var obj, what;
    
    // this method is outdated, needs to be rewritten.
    // it probably doesn't even work.
    if ((!(.is_writable_by(sender()))) && (!(.is_publicly_readable())))
        return sender().tell(("You cannot read the text on " + (.namef('ref))) + ".");
    if ("." in where) {
        where = $parse.reference(where);
        what = 1;
    } else {
        where = $parse.reference(where, ",");
    }
    obj = sender().match_env_nice(where[1]);
    if (!(obj.is_writable_by(sender())))
        return .tell(("!  " + (obj.namef('ref))) + " is not owned by you.");
    if ((obj.has_ancestor($note)) && (!(where[2])))
        obj.add_text(text, sender());
    
    // they want a method ref
    if (where[2]) {
        catch any {
            where = tosym(where[2]);
            if (what) {
                obj.(where)(text, sender());
                sender().tell(((("Text copied to " + ($data.unparse(obj))) + ".") + tostr(where)) + "().");
            } else {
                if (!(where in (obj.parameters())))
                    return .tell(("!  parameter '" + tostr(where)) + " not found");
                obj.eval([(tostr(where) + " = ") + ($data.unparse(.text()))]);
            }
        } with handler {
            $brandon.tell_traceback(traceback());
            $parse.tell_error((traceback()[1])[2], ("`" + com) + " <obj>[.,<destination]`", sender());
        }
    }
    sender().tell("Text copied from " + (.namef()));
.

method init_note
    .perms(caller(), $root);
    .set_readable(['methods, 'code]);
.

method init_for_core
    .perms(caller(), $sys);
.

method set_seperator
    arg newsep;
    
    .perms(sender(), 'manager);
    seperator = newsep;
.