Method code for $command_cache.match_command()

[Turn off line numbering]
  1: arg str, cmd, args;
  2: var command, m, matched, templates, info, cdef, def, cmds, c, p;
  3: 
  4: templates = (matched = []);
  5: cmds = #[];
  6: if (dict_contains(commands, cmd))
  7:     cmds = #[[this(), commands[cmd]]];
  8: for def in (parents() + modules) {
  9:     if ((c = def.command_cache()) && dict_contains(c, cmd))
 10:         cmds = dict_add(cmds, def, c[cmd]);
 11: }
 12: if (!cmds)
 13:     return 0;
 14: for def in (cmds) {
 15:     if (def[1] in parents())
 16:         p = this();
 17:     else
 18:         p = def[1];
 19:     for command in (def[2]) {
 20:         if (!(info = command[2].command_info('local, command[1])))
 21:             continue;
 22:         for cdef in (info) {
 23:             if ((m = match_template(args, cdef[2])) != 0)
 24:                 matched += [[listlen(m), [str, cmd, @m], p, @sublist(cdef, 3)]];
 25:         }
 26:         templates = union(templates, info.slice(3));
 27:         refresh();
 28:     }
 29: }
 30: if (matched) {
 31:     info = [matched[1]];
 32:     matched = delete(matched, 1);
 33:     for m in (matched) {
 34:         if (m[1] > info[1][1])
 35:             info = [m];
 36:         else if (m[1] == info[1][1])
 37:             info += [m];
 38:     }
 39:     return ['command, info];
 40: }
 41: if (!templates)
 42:     return 0;
 43: return ['partial, templates];

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

Tlon