Method code for $command_cache.match_command()

[Turn on line numbering]
arg str, cmd, args;
var command, m, matched, templates, info, cdef, def, cmds, c, p;

templates = (matched = []);
cmds = #[];
if (dict_contains(commands, cmd))
    cmds = #[[this(), commands[cmd]]];
for def in (parents() + modules) {
    if ((c = def.command_cache()) && dict_contains(c, cmd))
        cmds = dict_add(cmds, def, c[cmd]);
}
if (!cmds)
    return 0;
for def in (cmds) {
    if (def[1] in parents())
        p = this();
    else
        p = def[1];
    for command in (def[2]) {
        if (!(info = command[2].command_info('local, command[1])))
            continue;
        for cdef in (info) {
            if ((m = match_template(args, cdef[2])) != 0)
                matched += [[listlen(m), [str, cmd, @m], p, @sublist(cdef, 3)]];
        }
        templates = union(templates, info.slice(3));
        refresh();
    }
}
if (matched) {
    info = [matched[1]];
    matched = delete(matched, 1);
    for m in (matched) {
        if (m[1] > info[1][1])
            info = [m];
        else if (m[1] == info[1][1])
            info += [m];
    }
    return ['command, info];
}
if (!templates)
    return 0;
return ['partial, templates];

// $#Edited: 18 Jul 99 14:09 $brandon

["// Created 18-Sep-1997 as a part of ColdCore, see: @help Credit"]

the Cold Dark