% % The registry is here to support drop-in scripts. % It's actually pretty simple. % Any script should be able to register it's actions from here, so that % a wordkicking script can simply register it's desire to observe all says, % for example. % To handle (additionally) a server response (eg TOPIC), register it with % register_action("TOPIC", &myfunction); % To handle (additionally) a command, eg JOIN, register it with % register_cmd_action("JOIN", &myotherfunction); % myotherfunction will have the commands parameter as a string in action_param. % The Rpms[] array is filled as usual for the server response functions. % typedef struct {key,act} Registry_Type; private variable text_registry = make_list(); % string,string private variable int_registry = make_list(); % int,string private variable command_registry = make_list(); % string,strings variable action_param = ""; private define NRi_cmp(v,key) { return (v.key == key); } private define register_list_action(list, key, action) { variable v = @Registry_Type; v.key = key; % key may be Integer_Type or String_Type v.act = action; () = s_putlast(list, v); } define register_action(text, action) { if(is_digits(text)) register_list_action(int_registry, integer(text), action); else register_list_action(text_registry, strup(text), action); } define register_cmd_action(text, action) { register_list_action(command_registry, strup(text), action); } private define perform_list_actions(list, key) { variable p, p0, i, r = -1; p0 = list.f; if (p0 == NULL) return r; p = p0; do { p = s_find_n1(p, &NRi_cmp, key); if(p == NULL) break; i = @p.v.act; % do the action if (r < i) r = i; p = p.n; } while(p != p0); return r; } define perform_Aactions(text) { perform_list_actions(text_registry, strup(text)); } define perform_Nactions(text) { perform_list_actions(int_registry, integer(text)); } define perform_cmd_actions(text) { perform_list_actions(command_registry, strup(text)); }