merentha_fluffos_v2/
merentha_fluffos_v2/bin/
merentha_fluffos_v2/fluffos-2.9-ds2.03/
merentha_fluffos_v2/fluffos-2.9-ds2.03/ChangeLog.old/
merentha_fluffos_v2/fluffos-2.9-ds2.03/Win32/
merentha_fluffos_v2/fluffos-2.9-ds2.03/compat/
merentha_fluffos_v2/fluffos-2.9-ds2.03/compat/simuls/
merentha_fluffos_v2/fluffos-2.9-ds2.03/include/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/clone/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/command/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/data/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/etc/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/include/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/inherit/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/inherit/master/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/log/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/single/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/single/tests/compiler/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/single/tests/efuns/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/single/tests/operators/
merentha_fluffos_v2/fluffos-2.9-ds2.03/testsuite/u/
merentha_fluffos_v2/fluffos-2.9-ds2.03/tmp/
merentha_fluffos_v2/fluffos-2.9-ds2.03/windows/
merentha_fluffos_v2/lib/cfg/
merentha_fluffos_v2/lib/cfg/races/
merentha_fluffos_v2/lib/cmds/abilities/
merentha_fluffos_v2/lib/cmds/actions/
merentha_fluffos_v2/lib/cmds/spells/
merentha_fluffos_v2/lib/daemon/include/
merentha_fluffos_v2/lib/daemon/services/
merentha_fluffos_v2/lib/doc/
merentha_fluffos_v2/lib/doc/building/
merentha_fluffos_v2/lib/doc/help/classes/
merentha_fluffos_v2/lib/doc/help/general/
merentha_fluffos_v2/lib/doc/help/races/
merentha_fluffos_v2/lib/doc/help/skills/
merentha_fluffos_v2/lib/doc/help/stats/
merentha_fluffos_v2/lib/doc/man/efuns/
merentha_fluffos_v2/lib/doc/man/lfuns/
merentha_fluffos_v2/lib/doc/news/
merentha_fluffos_v2/lib/doc/old/
merentha_fluffos_v2/lib/doc/old/concepts/
merentha_fluffos_v2/lib/doc/old/lpc/constructs/
merentha_fluffos_v2/lib/doc/old/lpc/types/
merentha_fluffos_v2/lib/domains/ROOMS/
merentha_fluffos_v2/lib/domains/obj/armour/
merentha_fluffos_v2/lib/domains/obj/monsters/
merentha_fluffos_v2/lib/domains/obj/other/
merentha_fluffos_v2/lib/domains/obj/weapons/
merentha_fluffos_v2/lib/realms/petrarch/
merentha_fluffos_v2/lib/save/daemons/
merentha_fluffos_v2/lib/save/rid/
merentha_fluffos_v2/lib/save/users/a/
merentha_fluffos_v2/lib/save/users/p/
merentha_fluffos_v2/lib/save/users/t/
merentha_fluffos_v2/lib/std/login/
merentha_fluffos_v2/lib/std/obj/
merentha_fluffos_v2/win32/
// Petrarch
// Merentha Lib 1.0
// <nickname>

string help() {
    return "\
Syntax: nickname                    - lists all nicknames\n\
        nickname <nick>             - shows what <nick> is aliased to\n\
        nickname add <nick> <long>  - creates nickname\n\
        nickname remove <nick>      - removes a nickname\n\
\n\
Nicknames are used to help you type in short hand.  You can create an nickname as follows:\n\
> nickname add petr Petrarch\n\
\n\
Now whenever you type 'say Hi petr' it is just like typing 'say Hi Petrarch'.\n\
\n\
See also: alias\
";
}

int display_aliases() {
    mapping aliases=([]);
    string *k, *ret=({});
    int i, max=0, lines;
    lines=(this_player()->getenv("SCREEN")?this_player()->getenv("SCREEN"):75);
    aliases=this_player()->query_nickname();
    if(!aliases) this_player()->init_nicknames();
    aliases=this_player()->query_nickname();
    if(!aliases) aliases=([]);
    i=sizeof(k=sort_array(keys(aliases),-1));
    while(i--) if(strlen(k[i])>max) max=strlen(k[i]);
    i=sizeof(k);
    while(i--) ret+=({"%^RED%^"+arrange_string(k[i],max)+": %^ORANGE%^"+aliases[k[i]]+" "});
    i=sizeof(ret);
    while(i--) if(strlen(strip_colours(ret[i]))>max) max=strlen(strip_colours(ret[i]));
    if(max) {
        max=lines/max;
        this_player()->more(border(format_page(ret,max,lines-4),"nickname",lines ));
    } else  
        message("command", "You have no nicknames set.", this_player());
    return 1;
}

varargs int command(string str) {
    string word, alias;
    if(!str) return display_aliases();
    if(sscanf(str, "add %s %s", word, alias)==2) {
        this_player()->add_nickname(word, alias);
        message("command", "Nickname added: "+word+" -> "+alias, this_player());
        return 1;
    } else {
        if(sscanf(str, "remove %s", word)==1) {
            this_player()->remove_nickname(word);
            message("command", "Nickname: "+word+" removed.", this_player());
            return 1;
        } else {
            alias=this_player()->query_nickname(str);
            if(!alias) message("command", "Nickname for "+str+" not found.", this_player());
            else message("command", "Nickname: "+str+" -> "+alias, this_player());
            return 1;
        }
    }
}