1 
2 /*
3  * Routines within this files are Copyright Colten Edwards 1996
4  * Aka panasync on irc.
5  * Thanks to Shiek and Flier for helpful hints and suggestions. As well
6  * as code in some cases.
7  */
8 
9 #define __modules_c
10 
11 #include "irc.h"
12 static char cvsrevision[] = "$Id: modules.c 87 2010-06-26 08:18:34Z keaston $";
13 CVS_REVISION(modules_c)
14 #include "struct.h"
15 #include "alias.h"
16 #include "encrypt.h"
17 #include "commands.h"
18 #include "dcc.h"
19 #include "input.h"
20 #include "ircaux.h"
21 #include "flood.h"
22 #include "hook.h"
23 #include "list.h"
24 #include "output.h"
25 #include "log.h"
26 #include "ctcp.h"
27 #include "cdcc.h"
28 #include "misc.h"
29 #include "module.h"
30 #include "names.h"
31 #include "hash2.h"
32 #include "vars.h"
33 #include "screen.h"
34 #include "parse.h"
35 #include "server.h"
36 #include "timer.h"
37 #include "status.h"
38 #include "window.h"
39 #include "tcl_bx.h"
40 #include "ircterm.h"
41 #define MAIN_SOURCE
42 #include "modval.h"
43 
44 IrcVariableDll *dll_variable = NULL;
45 extern void *default_output_function;
46 extern DCC_dllcommands dcc_dllcommands;
47 extern void *default_status_output_function;
48 
49 Function_ptr global_table[NUMBER_OF_GLOBAL_FUNCTIONS] = { NULL };
50 Function_ptr *global = global_table;
51 char *_modname_ = NULL;
52 
53 #ifdef WANT_DLL
54 
55 #ifdef NO_DLFCN_H
56 #   include "../include/dlfcn.h"
57 #else
58 #if defined(HPUX)
59 #include <dl.h>
60 #else
61 #   include <dlfcn.h>
62 #endif
63 #endif
64 
65 #ifndef RTLD_NOW
66 #   define RTLD_NOW 1
67 #endif
68 
69 #ifndef RTLD_GLOBAL
70 #   define RTLD_GLOBAL 0
71 #endif
72 
73 
74 Packages *install_pack = NULL;
75 #endif /* WANT_DLL */
76 
77 extern int BX_read_sockets();
78 extern int identd;
79 extern int doing_notice;
80 
81 extern int (*dcc_open_func) (int, int, unsigned long, int);
82 extern int (*dcc_output_func) (int, int, char *, int);
83 extern int (*dcc_input_func)  (int, int, char *, int, int);
84 extern int (*dcc_close_func) (int, unsigned long, int);
85 
86 extern int (*serv_open_func) (int, unsigned long, int);
87 extern int (*serv_output_func) (int, int, char *, int);
88 extern int (*serv_input_func)  (int, char *, int, int, int);
89 extern int (*serv_close_func) (int, unsigned long, int);
90 extern int (*check_ext_mail_status)(void);
91 extern char *(*check_ext_mail)(void);
92 
93 int BX_check_module_version(unsigned long);
94 
95 #ifdef GUI
96 extern char *lastclicklinedata;
97 extern int contextx, contexty;
98 extern int guiipc[2];
99 #endif
100 
null_function(void)101 void null_function(void)
102 {
103 }
104 
init_global_functions(void)105 void init_global_functions(void)
106 {
107 static int already_done = 0;
108 
109 	if (already_done)
110 		return;
111 	already_done++;
112 
113 /* ircaux.c */
114 	global_table[MODULE_VERSION_CHECK]	= (Function_ptr) BX_check_module_version;
115 	global_table[VSNPRINTF]			= (Function_ptr) vsnprintf;
116 	global_table[SNPRINTF]			= (Function_ptr) snprintf;
117 	global_table[NEW_MALLOC] 		= (Function_ptr) n_malloc;
118 	global_table[NEW_FREE]			= (Function_ptr) n_free;
119 	global_table[NEW_REALLOC] 		= (Function_ptr) n_realloc;
120 	global_table[MALLOC_STRCPY] 		= (Function_ptr) n_malloc_strcpy;
121 	global_table[MALLOC_STR2CPY] 		= (Function_ptr) BX_malloc_str2cpy;
122 	global_table[M_3DUP]	 		= (Function_ptr) BX_m_3dup;
123 	global_table[M_OPENDUP]	 		= (Function_ptr) BX_m_opendup;
124 	global_table[M_S3CAT]	 		= (Function_ptr) BX_m_s3cat;
125 	global_table[M_S3CAT_S]	 		= (Function_ptr) BX_m_s3cat_s;
126 	global_table[M_3CAT]	 		= (Function_ptr) BX_m_3cat;
127 	global_table[UPPER]	 		= (Function_ptr) BX_upper;
128 	global_table[LOWER]	 		= (Function_ptr) BX_lower;
129 	global_table[STRISTR]	 		= (Function_ptr) BX_stristr;
130 	global_table[RSTRISTR]	 		= (Function_ptr) BX_rstristr;
131 	global_table[WORD_COUNT]	 	= (Function_ptr) BX_word_count;
132 	global_table[REMOVE_TRAILING_SPACES] 	= (Function_ptr) BX_remove_trailing_spaces;
133 
134 	global_table[MY_STRICMP]		= (Function_ptr) BX_my_stricmp;
135 	global_table[MY_STRNICMP]		= (Function_ptr) BX_my_strnicmp;
136 
137 	global_table[MY_STRNSTR]		= (Function_ptr) BX_my_strnstr;
138 	global_table[CHOP]			= (Function_ptr) BX_chop;
139 	global_table[STRMCPY]			= (Function_ptr) BX_strmcpy;
140 	global_table[STRMCAT]			= (Function_ptr) BX_strmcat;
141 	global_table[SCANSTR]			= (Function_ptr) BX_scanstr;
142 	global_table[EXPAND_TWIDDLE]		= (Function_ptr) BX_expand_twiddle;
143 	global_table[CHECK_NICKNAME]		= (Function_ptr) BX_check_nickname;
144 	global_table[SINDEX]			= (Function_ptr) BX_sindex;
145 	global_table[RSINDEX]			= (Function_ptr) BX_rsindex;
146 	global_table[ISNUMBER]			= (Function_ptr) BX_is_number;
147 	global_table[RFGETS]			= (Function_ptr) BX_rfgets;
148 	global_table[PATH_SEARCH]		= (Function_ptr) BX_path_search;
149 	global_table[DOUBLE_QUOTE]		= (Function_ptr) BX_double_quote;
150 	global_table[IRCPANIC]			= (Function_ptr) BX_ircpanic;
151 	global_table[END_STRCMP]		= (Function_ptr) BX_end_strcmp;
152 	global_table[BEEP_EM]			= (Function_ptr) BX_beep_em;
153 	global_table[UZFOPEN]			= (Function_ptr) BX_uzfopen;
154 	global_table[FUNC_GET_TIME]		= (Function_ptr) BX_get_time;
155 	global_table[TIME_DIFF]			= (Function_ptr) BX_time_diff;
156 	global_table[TIME_TO_NEXT_MINUTE]	= (Function_ptr) BX_time_to_next_minute;
157 	global_table[PLURAL]			= (Function_ptr) BX_plural;
158 	global_table[MY_CTIME]			= (Function_ptr) BX_my_ctime;
159 	global_table[LTOA]			= (Function_ptr) BX_my_ltoa;
160 	global_table[STRFORMAT]			= (Function_ptr) BX_strformat;
161 	global_table[MATCHINGBRACKET]		= (Function_ptr) BX_MatchingBracket;
162 	global_table[PARSE_NUMBER]		= (Function_ptr) BX_parse_number;
163 	global_table[SPLITW]			= (Function_ptr) BX_splitw;
164 	global_table[UNSPLITW]			= (Function_ptr) BX_unsplitw;
165 	global_table[M_2DUP]			= (Function_ptr) BX_m_2dup;
166 	global_table[M_E3CAT]			= (Function_ptr) BX_m_e3cat;
167 	global_table[CHECK_VAL]			= (Function_ptr) BX_check_val;
168 	global_table[ON_OFF]			= (Function_ptr) BX_on_off;
169 	global_table[STREXTEND]			= (Function_ptr) BX_strextend;
170 	global_table[STRFILL]			= (Function_ptr) BX_strfill;
171 	global_table[EMPTY_FUNC]		= (Function_ptr) BX_empty;
172 	global_table[REMOVE_BRACKETS]		= (Function_ptr) BX_remove_brackets;
173 	global_table[MY_ATOL]			= (Function_ptr) BX_my_atol;
174 	global_table[M_DUPCHAR]			= (Function_ptr) BX_m_dupchar;
175 	global_table[STREQ]			= (Function_ptr) BX_streq;
176 	global_table[STRIEQ]			= (Function_ptr) BX_strieq;
177 	global_table[STRMOPENCAT]		= (Function_ptr) BX_strmopencat;
178 	global_table[OV_STRCPY]			= (Function_ptr) BX_ov_strcpy;
179 	global_table[STRIP_CONTROL]		= (Function_ptr) BX_strip_control;
180 	global_table[FIGURE_OUT_ADDRESS]	= (Function_ptr) BX_figure_out_address;
181 	global_table[STRNRCHR]			= (Function_ptr) BX_strnrchr;
182 	global_table[MASK_DIGITS]		= (Function_ptr) BX_mask_digits;
183 	global_table[CCSPAN]			= (Function_ptr) BX_ccspan;
184 	global_table[CHARCOUNT]			= (Function_ptr) BX_charcount;
185 	global_table[STRPCAT]			= (Function_ptr) BX_strpcat;
186 	global_table[STRCPY_NOCOLORCODES]	= (Function_ptr) BX_strcpy_nocolorcodes;
187 	global_table[CRYPTIT]			= (Function_ptr) BX_cryptit;
188 	global_table[STRIPDEV]			= (Function_ptr) BX_stripdev;
189 	global_table[MANGLE_LINE]		= (Function_ptr) BX_mangle_line;
190 	global_table[MALLOC_STRCAT] 		= (Function_ptr) n_malloc_strcat;
191 	global_table[M_STRDUP] 			= (Function_ptr) n_m_strdup;
192 	global_table[M_STRCAT_UES] 		= (Function_ptr) n_m_strcat_ues;
193 	global_table[M_STRNDUP] 		= (Function_ptr) n_m_strndup;
194 	global_table[MALLOC_SPRINTF] 		= (Function_ptr) BX_malloc_sprintf;
195 	global_table[M_SPRINTF] 		= (Function_ptr) BX_m_sprintf;
196 	global_table[NEXT_ARG] 			= (Function_ptr) BX_next_arg;
197 	global_table[NEW_NEXT_ARG] 		= (Function_ptr) BX_new_next_arg;
198 	global_table[NEW_NEW_NEXT_ARG] 		= (Function_ptr) BX_new_new_next_arg;
199 	global_table[LAST_ARG] 			= (Function_ptr) BX_last_arg;
200 	global_table[NEXT_IN_COMMA_LIST]	= (Function_ptr) BX_next_in_comma_list;
201 	global_table[RANDOM_NUMBER]		= (Function_ptr) BX_random_number;
202 
203 /* words.c reg.c */
204 	global_table[STRSEARCH]			= (Function_ptr) BX_strsearch;
205 	global_table[MOVE_TO_ABS_WORD]		= (Function_ptr) BX_move_to_abs_word;
206 	global_table[MOVE_WORD_REL]		= (Function_ptr) BX_move_word_rel;
207 	global_table[EXTRACT]			= (Function_ptr) BX_extract;
208 	global_table[EXTRACT2]			= (Function_ptr) BX_extract2;
209 	global_table[WILD_MATCH]		= (Function_ptr) BX_wild_match;
210 
211 
212 /* list.c */
213 	global_table[ADD_TO_LIST] 		= (Function_ptr) BX_add_to_list;
214 	global_table[ADD_TO_LIST_EXT] 		= (Function_ptr) BX_add_to_list_ext;
215 	global_table[FIND_IN_LIST] 		= (Function_ptr) BX_find_in_list;
216 	global_table[FIND_IN_LIST_EXT] 		= (Function_ptr) BX_find_in_list_ext;
217 	global_table[REMOVE_FROM_LIST_]		= (Function_ptr) BX_remove_from_list;
218 	global_table[REMOVE_FROM_LIST_EXT]	= (Function_ptr) BX_remove_from_list_ext;
219 	global_table[REMOVEWILD_FROM_LIST]	= (Function_ptr) BX_removewild_from_list;
220 	global_table[LIST_LOOKUP] 		= (Function_ptr) BX_list_lookup;
221 	global_table[LIST_LOOKUP_EXT] 		= (Function_ptr) BX_list_lookup_ext;
222 
223 /* alist.c */
224 	global_table[ADD_TO_ARRAY]		= (Function_ptr) BX_add_to_array;
225 	global_table[REMOVE_FROM_ARRAY]		= (Function_ptr) BX_remove_from_array;
226 	global_table[ARRAY_POP]			= (Function_ptr) BX_array_pop;
227 	global_table[REMOVE_ALL_FROM_ARRAY]	= (Function_ptr) BX_remove_all_from_array;
228 	global_table[ARRAY_LOOKUP]		= (Function_ptr) BX_array_lookup;
229 	global_table[FIND_ARRAY_ITEM]		= (Function_ptr) BX_find_array_item;
230 	global_table[FIND_FIXED_ARRAY_ITEM]	= (Function_ptr) BX_find_fixed_array_item;
231 
232 
233 /* server.c */
234 	global_table[SEND_TO_SERVER]		= (Function_ptr) BX_send_to_server;
235 	global_table[QUEUE_SEND_TO_SERVER]	= (Function_ptr) BX_queue_send_to_server;
236 	global_table[MY_SEND_TO_SERVER]		= (Function_ptr) BX_my_send_to_server;
237 
238 /* connecting to the server */
239 	global_table[GET_CONNECTED]		= (Function_ptr) BX_get_connected;
240 	global_table[CONNECT_TO_SERVER_BY_REFNUM]=(Function_ptr) BX_connect_to_server_by_refnum;
241 	global_table[CLOSE_SERVER]		= (Function_ptr) BX_close_server;
242 	global_table[IS_SERVER_CONNECTED]	= (Function_ptr) BX_is_server_connected;
243 	global_table[FLUSH_SERVER]		= (Function_ptr) BX_flush_server;
244 	global_table[SERVER_IS_CONNECTED]	= (Function_ptr) BX_server_is_connected;
245 	global_table[IS_SERVER_OPEN]		= (Function_ptr) BX_is_server_open;
246 	global_table[CLOSE_ALL_SERVER]		= (Function_ptr) BX_close_all_server;
247 /* server file reading */
248 	global_table[READ_SERVER_FILE]		= (Function_ptr) BX_read_server_file;
249 	global_table[ADD_TO_SERVER_LIST]	= (Function_ptr) BX_add_to_server_list;
250 	global_table[BUILD_SERVER_LIST]		= (Function_ptr) BX_build_server_list;
251 	global_table[DISPLAY_SERVER_LIST]	= (Function_ptr) BX_display_server_list;
252 	global_table[CREATE_SERVER_LIST]	= (Function_ptr) BX_create_server_list;
253 	global_table[PARSE_SERVER_INFO]		= (Function_ptr) BX_parse_server_info;
254 	global_table[SERVER_LIST_SIZE]		= (Function_ptr) BX_server_list_size;
255 /* misc server/nickname functions */
256 	global_table[FIND_SERVER_REFNUM]	= (Function_ptr) BX_find_server_refnum;
257 	global_table[FIND_IN_SERVER_LIST]	= (Function_ptr) BX_find_in_server_list;
258 	global_table[PARSE_SERVER_INDEX]	= (Function_ptr) BX_parse_server_index;
259 	global_table[GET_SERVER_REDIRECT]	= (Function_ptr) BX_get_server_redirect;
260 	global_table[SET_SERVER_REDIRECT]	= (Function_ptr) BX_set_server_redirect;
261 	global_table[CHECK_SERVER_REDIRECT]	= (Function_ptr) BX_check_server_redirect;
262 	global_table[FUDGE_NICKNAME]		= (Function_ptr) BX_fudge_nickname;
263 	global_table[RESET_NICKNAME]		= (Function_ptr) BX_reset_nickname;
264 /* various set server struct functions */
265 	global_table[SET_SERVER_COOKIE]		= (Function_ptr) BX_set_server_cookie;
266 	global_table[SET_SERVER_FLAG]		= (Function_ptr) BX_set_server_flag;
267 	global_table[SET_SERVER_MOTD]		= (Function_ptr) BX_set_server_motd;
268 	global_table[SET_SERVER_OPERATOR]	= (Function_ptr) BX_set_server_operator;
269 	global_table[SET_SERVER_ITSNAME]	= (Function_ptr) BX_set_server_itsname;
270 	global_table[SET_SERVER_VERSION]	= (Function_ptr) BX_set_server_version;
271 	global_table[SET_SERVER_LAG]		= (Function_ptr) BX_set_server_lag;
272 	global_table[SET_SERVER_PASSWORD]	= (Function_ptr) BX_set_server_password;
273 	global_table[SET_SERVER_NICKNAME]	= (Function_ptr) BX_set_server_nickname;
274 	global_table[SET_SERVER2_8]		= (Function_ptr) BX_set_server2_8;
275 	global_table[SET_SERVER_AWAY]		= (Function_ptr) BX_set_server_away;
276 
277 /* various get server struct functions */
278 	global_table[GET_SERVER_COOKIE]		= (Function_ptr) BX_get_server_cookie;
279 	global_table[GET_SERVER_NICKNAME]	= (Function_ptr) BX_get_server_nickname;
280 	global_table[GET_SERVER_NAME]		= (Function_ptr) BX_get_server_name;
281 	global_table[GET_SERVER_ITSNAME]	= (Function_ptr) BX_get_server_itsname;
282 	global_table[GET_SERVER_MOTD]		= (Function_ptr) BX_get_server_motd;
283 	global_table[GET_SERVER_OPERATOR]	= (Function_ptr) BX_get_server_operator;
284 	global_table[GET_SERVER_VERSION]	= (Function_ptr) BX_get_server_version;
285 	global_table[GET_SERVER_FLAG]		= (Function_ptr) BX_get_server_flag;
286 	global_table[GET_POSSIBLE_UMODES]	= (Function_ptr) BX_get_possible_umodes;
287 	global_table[GET_SERVER_PORT]		= (Function_ptr) BX_get_server_port;
288 	global_table[GET_SERVER_LAG]		= (Function_ptr) BX_get_server_lag;
289 	global_table[GET_SERVER2_8]		= (Function_ptr) BX_get_server2_8;
290 	global_table[GET_UMODE]			= (Function_ptr) BX_get_umode;
291 	global_table[GET_SERVER_AWAY]		= (Function_ptr) BX_get_server_away;
292 	global_table[GET_SERVER_NETWORK]	= (Function_ptr) BX_get_server_network;
293 	global_table[GET_PENDING_NICKNAME]	= (Function_ptr) BX_get_pending_nickname;
294 	global_table[SERVER_DISCONNECT]		= (Function_ptr) BX_server_disconnect;
295 
296 	global_table[GET_SERVER_LIST]		= (Function_ptr) BX_get_server_list;
297 	global_table[GET_SERVER_CHANNELS]	= (Function_ptr) BX_get_server_channels;
298 	global_table[SET_SERVER_LAST_CTCP_TIME]	= (Function_ptr) BX_set_server_last_ctcp_time;
299 	global_table[GET_SERVER_LAST_CTCP_TIME]	= (Function_ptr) BX_get_server_last_ctcp_time;
300 	global_table[SET_SERVER_TRACE_FLAG]	= (Function_ptr) BX_set_server_trace_flag;
301 	global_table[GET_SERVER_TRACE_FLAG]	= (Function_ptr) BX_get_server_trace_flag;
302 	global_table[SET_SERVER_STAT_FLAG]	= (Function_ptr) BX_set_server_stat_flag;
303 	global_table[GET_SERVER_STAT_FLAG]	= (Function_ptr) BX_get_server_stat_flag;
304 	global_table[GET_SERVER_READ]		= (Function_ptr) BX_get_server_read;
305 	global_table[GET_SERVER_LINKLOOK]	= (Function_ptr) BX_get_server_linklook;
306 	global_table[SET_SERVER_LINKLOOK]	= (Function_ptr) BX_set_server_linklook;
307 	global_table[GET_SERVER_LINKLOOK_TIME]	= (Function_ptr) BX_get_server_linklook_time;
308 	global_table[SET_SERVER_LINKLOOK_TIME]	= (Function_ptr) BX_set_server_linklook_time;
309 	global_table[GET_SERVER_TRACE_KILL]	= (Function_ptr) BX_get_server_trace_kill;
310 	global_table[SET_SERVER_TRACE_KILL]	= (Function_ptr) BX_set_server_trace_kill;
311 	global_table[ADD_SERVER_CHANNELS]	= (Function_ptr) BX_add_server_channels;
312 	global_table[SET_SERVER_CHANNELS]	= (Function_ptr) BX_set_server_channels;
313 	global_table[SEND_MSG_TO_CHANNELS]	= (Function_ptr) BX_send_msg_to_channels;
314 	global_table[SEND_MSG_TO_NICKS]		= (Function_ptr) BX_send_msg_to_nicks;
315 	global_table[IS_SERVER_QUEUE]		= (Function_ptr) BX_is_server_queue;
316 
317 /* glob.c */
318 	global_table[BSD_GLOB]			= (Function_ptr) BX_bsd_glob;
319 	global_table[BSD_GLOBFREE]		= (Function_ptr) BX_bsd_globfree;
320 
321 /* output.c */
322 	global_table[PUT_IT] 			= (Function_ptr) BX_put_it;
323 	global_table[BITCHSAY]			= (Function_ptr) BX_bitchsay;
324 	global_table[YELL]			= (Function_ptr) BX_yell;
325 
326 /* screen.c */
327 	global_table[ADD_TO_SCREEN]		= (Function_ptr) BX_add_to_screen;
328 	global_table[XTERM_SETTITLE]		= (Function_ptr) BX_xterm_settitle;
329 	global_table[PREPARE_DISPLAY]		= (Function_ptr) BX_prepare_display;
330 	global_table[ADD_TO_WINDOW]		= (Function_ptr) BX_add_to_window;
331 	global_table[SKIP_INCOMING_MIRC]	= (Function_ptr) BX_skip_incoming_mirc;
332 	global_table[SPLIT_UP_LINE]		= (Function_ptr) BX_split_up_line;
333 	global_table[OUTPUT_LINE]		= (Function_ptr) BX_output_line;
334 	global_table[OUTPUT_WITH_COUNT]		= (Function_ptr) BX_output_with_count;
335 	global_table[SCROLL_WINDOW]		= (Function_ptr) BX_scroll_window;
336 	global_table[CURSOR_NOT_IN_DISPLAY]	= (Function_ptr) BX_cursor_not_in_display;
337 	global_table[CURSOR_IN_DISPLAY]		= (Function_ptr) BX_cursor_in_display;
338 	global_table[IS_CURSOR_IN_DISPLAY]	= (Function_ptr) BX_is_cursor_in_display;
339 	global_table[REPAINT_WINDOW]		= (Function_ptr) BX_repaint_window;
340 	global_table[CREATE_NEW_SCREEN]		= (Function_ptr) BX_create_new_screen;
341 #ifdef WINDOW_CREATE
342 	global_table[CREATE_ADDITIONAL_SCREEN]	= (Function_ptr) BX_create_additional_screen;
343 	global_table[KILL_SCREEN]		= (Function_ptr) BX_kill_screen;
344 #endif
345 	global_table[ADD_WAIT_PROMPT]		= (Function_ptr) BX_add_wait_prompt;
346 	global_table[SKIP_CTL_C_SEQ]		= (Function_ptr) BX_skip_ctl_c_seq;
347 	global_table[STRIP_ANSI]		= (Function_ptr) BX_strip_ansi;
348 
349 /* status.c */
350 	global_table[BUILD_STATUS]		= (Function_ptr) BX_build_status;
351 
352 /* window.c */
353 	global_table[GET_WINDOW_BY_NAME]	= (Function_ptr) BX_get_window_by_name;
354 	global_table[GET_CURRENT_CHANNEL_BY_REFNUM]=(Function_ptr) BX_get_current_channel_by_refnum;
355 	global_table[NEW_WINDOW]		= (Function_ptr) BX_new_window;
356 	global_table[GET_WINDOW_SERVER]		= (Function_ptr) BX_get_window_server;
357 	global_table[RESIZE_WINDOW]		= (Function_ptr) BX_resize_window;
358 	global_table[UPDATE_ALL_WINDOWS]	= (Function_ptr) BX_update_all_windows;
359 	global_table[SET_SCREENS_CURRENT_WINDOW]= (Function_ptr) BX_set_screens_current_window;
360 	global_table[DELETE_WINDOW]		= (Function_ptr) BX_delete_window;
361 	global_table[FREE_FORMATS]		= (Function_ptr) BX_free_formats;
362 	global_table[REMOVE_WINDOW_FROM_SCREEN]	= (Function_ptr) BX_remove_window_from_screen;
363 	global_table[TRAVERSE_ALL_WINDOWS]	= (Function_ptr) BX_traverse_all_windows;
364 	global_table[ADD_TO_INVISIBLE_LIST]	= (Function_ptr) BX_add_to_invisible_list;
365 	global_table[ADD_TO_WINDOW_LIST]	= (Function_ptr) BX_add_to_window_list;
366 	global_table[RECALCULATE_WINDOW_POSITIONS]= (Function_ptr) BX_recalculate_window_positions;
367 	global_table[MOVE_WINDOW]		= (Function_ptr) BX_move_window;
368 	global_table[REDRAW_ALL_WINDOWS]	= (Function_ptr) BX_redraw_all_windows;
369 	global_table[REBALANCE_WINDOWS]		= (Function_ptr) BX_rebalance_windows;
370 	global_table[RECALCULATE_WINDOWS]	= (Function_ptr) BX_recalculate_windows;
371 	global_table[GOTO_WINDOW]		= (Function_ptr) BX_goto_window;
372 	global_table[HIDE_BX_WINDOW]		= (Function_ptr) BX_hide_window;
373 	global_table[FUNC_SWAP_LAST_WINDOW]	= (Function_ptr) BX_swap_last_window;
374 	global_table[FUNC_SWAP_NEXT_WINDOW]	= (Function_ptr) BX_swap_next_window;
375 	global_table[FUNC_SWAP_PREVIOUS_WINDOW]	= (Function_ptr) BX_swap_previous_window;
376 	global_table[SHOW_WINDOW]		= (Function_ptr) BX_show_window;
377 	global_table[GET_STATUS_BY_REFNUM]	= (Function_ptr) BX_get_status_by_refnum;
378 	global_table[GET_WINDOW_BY_DESC]	= (Function_ptr) BX_get_window_by_desc;
379 	global_table[GET_WINDOW_BY_REFNUM]	= (Function_ptr) BX_get_window_by_refnum;
380 	global_table[GET_VISIBLE_BY_REFNUM]	= (Function_ptr) BX_get_visible_by_refnum;
381 	global_table[FUNC_NEXT_WINDOW]		= (Function_ptr) BX_next_window;
382 	global_table[FUNC_PREVIOUS_WINDOW]	= (Function_ptr) BX_previous_window;
383 	global_table[UPDATE_WINDOW_STATUS]	= (Function_ptr) BX_update_window_status;
384 	global_table[UPDATE_ALL_STATUS]		= (Function_ptr) BX_update_all_status;
385 	global_table[UPDATE_WINDOW_STATUS_ALL]	= (Function_ptr) BX_update_window_status_all;
386 	global_table[STATUS_UPDATE]		= (Function_ptr) BX_status_update;
387 	global_table[SET_PROMPT_BY_REFNUM]	= (Function_ptr) BX_set_prompt_by_refnum;
388 	global_table[GET_PROMPT_BY_REFNUM]	= (Function_ptr) BX_get_prompt_by_refnum;
389 	global_table[QUERY_NICK]		= (Function_ptr) null_function; /* DEFUNCT */
390 	global_table[QUERY_HOST]		= (Function_ptr) null_function; /* DEFUNCT */
391 	global_table[QUERY_CMD]			= (Function_ptr) null_function; /* DEFUNCT */
392 	global_table[GET_TARGET_BY_REFNUM]	= (Function_ptr) BX_get_target_by_refnum;
393 	global_table[GET_TARGET_CMD_BY_REFNUM]	= (Function_ptr) BX_get_target_cmd_by_refnum;
394 	global_table[GET_WINDOW_TARGET_BY_DESC]	= (Function_ptr) BX_get_window_target_by_desc;
395 	global_table[IS_CURRENT_CHANNEL]	= (Function_ptr) BX_is_current_channel;
396 	global_table[SET_CURRENT_CHANNEL_BY_REFNUM]= (Function_ptr) BX_set_current_channel_by_refnum;
397 	global_table[GET_REFNUM_BY_WINDOW]	= (Function_ptr) BX_get_refnum_by_window;
398 	global_table[IS_BOUND_TO_WINDOW]	= (Function_ptr) BX_is_bound_to_window;
399 	global_table[GET_WINDOW_BOUND_CHANNEL]	= (Function_ptr) BX_get_window_bound_channel;
400 	global_table[IS_BOUND_ANYWHERE]		= (Function_ptr) BX_is_bound_anywhere;
401 	global_table[IS_BOUND]			= (Function_ptr) BX_is_bound;
402 	global_table[UNBIND_CHANNEL]		= (Function_ptr) BX_unbind_channel;
403 	global_table[GET_BOUND_CHANNEL]		= (Function_ptr) BX_get_bound_channel;
404 	global_table[SET_WINDOW_SERVER]		= (Function_ptr) BX_set_window_server;
405 	global_table[WINDOW_CHECK_SERVERS]	= (Function_ptr) BX_window_check_servers;
406 	global_table[CHANGE_WINDOW_SERVER]	= (Function_ptr) BX_change_window_server;
407 	global_table[SET_LEVEL_BY_REFNUM]	= (Function_ptr) BX_set_level_by_refnum;
408 	global_table[MESSAGE_TO]		= (Function_ptr) BX_message_to;
409 	global_table[CLEAR_WINDOW]		= (Function_ptr) BX_clear_window;
410 	global_table[CLEAR_ALL_WINDOWS]		= (Function_ptr) BX_clear_all_windows;
411 	global_table[CLEAR_WINDOW_BY_REFNUM]	= (Function_ptr) BX_clear_window_by_refnum;
412 	global_table[UNCLEAR_WINDOW_BY_REFNUM]	= (Function_ptr) BX_unclear_window_by_refnum;
413 	global_table[SET_SCROLL_LINES]		= (Function_ptr) BX_set_scroll_lines;
414 	global_table[SET_CONTINUED_LINES]	= (Function_ptr) BX_set_continued_lines;
415 	global_table[CURRENT_REFNUM]		= (Function_ptr) BX_current_refnum;
416 	global_table[NUMBER_OF_WINDOWS_ON_SCREEN]= (Function_ptr) BX_number_of_windows_on_screen;
417 	global_table[SET_SCROLLBACK_SIZE]	= (Function_ptr) BX_set_scrollback_size;
418 	global_table[IS_WINDOW_NAME_UNIQUE]	= (Function_ptr) BX_is_window_name_unique;
419 	global_table[GET_NICKLIST_BY_WINDOW]	= (Function_ptr) BX_get_nicklist_by_window;
420 	global_table[SCROLLBACK_BACKWARDS_LINES]= (Function_ptr) BX_scrollback_backwards_lines;
421 	global_table[SCROLLBACK_FORWARDS_LINES]	= (Function_ptr) BX_scrollback_forwards_lines;
422 	global_table[SCROLLBACK_FORWARDS]	= (Function_ptr) BX_scrollback_forwards;
423 	global_table[SCROLLBACK_BACKWARDS]	= (Function_ptr) BX_scrollback_backwards;
424 	global_table[SCROLLBACK_END]		= (Function_ptr) BX_scrollback_end;
425 	global_table[SCROLLBACK_START]		= (Function_ptr) BX_scrollback_start;
426 	global_table[SET_HOLD_MODE]		= (Function_ptr) BX_set_hold_mode;
427 	global_table[UNHOLD_WINDOWS]		= (Function_ptr) BX_unhold_windows;
428 	global_table[FUNC_UNSTOP_ALL_WINDOWS]	= (Function_ptr) BX_unstop_all_windows;
429 	global_table[RESET_LINE_CNT]		= (Function_ptr) BX_reset_line_cnt;
430 	global_table[FUNC_TOGGLE_STOP_SCREEN]	= (Function_ptr) BX_toggle_stop_screen;
431 	global_table[FLUSH_EVERYTHING_BEING_HELD]= (Function_ptr) BX_flush_everything_being_held;
432 	global_table[UNHOLD_A_WINDOW]		= (Function_ptr) BX_unhold_a_window;
433 	global_table[RECALCULATE_WINDOW_CURSOR]	= (Function_ptr) BX_recalculate_window_cursor;
434 	global_table[MAKE_WINDOW_CURRENT]	= (Function_ptr) BX_make_window_current;
435 	global_table[CLEAR_SCROLLBACK]		= (Function_ptr) BX_clear_scrollback;
436 
437 	global_table[RESET_DISPLAY_TARGET]	= (Function_ptr) BX_reset_display_target;
438 	global_table[SET_DISPLAY_TARGET]	= (Function_ptr) BX_set_display_target;
439 	global_table[SAVE_DISPLAY_TARGET]	= (Function_ptr) BX_save_display_target;
440 	global_table[RESTORE_DISPLAY_TARGET]	= (Function_ptr) BX_restore_display_target;
441 
442 	global_table[MY_ENCRYPT]		= (Function_ptr) BX_my_encrypt;
443 	global_table[MY_DECRYPT]		= (Function_ptr) BX_my_decrypt;
444 	global_table[PREPARE_COMMAND] 		= (Function_ptr) BX_prepare_command;
445 	global_table[CONVERT_OUTPUT_FORMAT] 	= (Function_ptr) BX_convert_output_format;
446 	global_table[BREAKARGS]			= (Function_ptr) BX_BreakArgs;
447 	global_table[PASTEARGS]			= (Function_ptr) BX_PasteArgs;
448 	global_table[USERAGE]			= (Function_ptr) BX_userage;
449 	global_table[SEND_TEXT]			= (Function_ptr) BX_send_text;
450 	global_table[SPLIT_CTCP]		= (Function_ptr) BX_split_CTCP;
451 	global_table[RANDOM_STR]		= (Function_ptr) BX_random_str;
452 	global_table[DCC_PRINTF]		= (Function_ptr) BX_dcc_printf;
453 	global_table[ADD_TO_LOG]		= (Function_ptr) BX_add_to_log;
454 	global_table[SET_LASTLOG_MSG_LEVEL]	= (Function_ptr) BX_set_lastlog_msg_level;
455 
456 
457 /* module.c */
458 #ifdef WANT_DLL
459 	global_table[REMOVE_MODULE_PROC]	= (Function_ptr) BX_remove_module_proc;
460 	global_table[ADD_MODULE_PROC] 		= (Function_ptr) BX_add_module_proc;
461 #else
462 	global_table[REMOVE_MODULE_PROC]	= (Function_ptr) null_function;
463 	global_table[ADD_MODULE_PROC] 		= (Function_ptr) null_function;
464 #endif
465 
466 /* this one should be differant. */
467 	global_table[FUNC_LOAD]			= (Function_ptr) BX_load;
468 
469 	global_table[HOOK]			= (Function_ptr) BX_do_hook;
470 
471 /* irc.c */
472 	global_table[UPDATE_CLOCK] 		= (Function_ptr) BX_update_clock;
473 	global_table[IRC_IO_FUNC]		= (Function_ptr) BX_io;
474 	global_table[IRC_EXIT_FUNC]		= (Function_ptr) BX_irc_exit;
475 
476 /* alias.c */
477 	global_table[LOCK_STACK_FRAME]		= (Function_ptr) BX_lock_stack_frame;
478 	global_table[UNLOCK_STACK_FRAME]	= (Function_ptr) BX_unlock_stack_frame;
479 
480 /* input.c */
481 	global_table[FUNC_UPDATE_INPUT]		= (Function_ptr) BX_update_input;
482 	global_table[CURSOR_TO_INPUT]		= (Function_ptr) BX_cursor_to_input;
483 	global_table[SET_INPUT]			= (Function_ptr) BX_set_input;
484 	global_table[GET_INPUT]			= (Function_ptr) BX_get_input;
485 	global_table[SET_INPUT_PROMPT]		= (Function_ptr) BX_set_input_prompt;
486 	global_table[GET_INPUT_PROMPT]		= (Function_ptr) BX_get_input_prompt;
487 	global_table[ADDTABKEY]			= (Function_ptr) BX_addtabkey;
488 	global_table[GETTABKEY]			= (Function_ptr) BX_gettabkey;
489 	global_table[GETNEXTNICK]		= (Function_ptr) BX_getnextnick;
490 	global_table[GETCHANNICK]		= (Function_ptr) BX_getchannick;
491 	global_table[LOOKUP_NICKCOMPLETION]	= (Function_ptr) BX_lookup_nickcompletion;
492 	global_table[ADD_COMPLETION_TYPE]	= (Function_ptr) BX_add_completion_type;
493 
494 /* names.c */
495 	global_table[IS_CHANOP]			= (Function_ptr) BX_is_chanop;
496 	global_table[IS_HALFOP]			= (Function_ptr) BX_is_halfop;
497 	global_table[IS_CHANNEL]		= (Function_ptr) BX_is_channel;
498 	global_table[MAKE_CHANNEL]		= (Function_ptr) BX_make_channel; /* this is really in misc.c */
499 	global_table[IM_ON_CHANNEL]		= (Function_ptr) BX_im_on_channel;
500 	global_table[IS_ON_CHANNEL]		= (Function_ptr) BX_is_on_channel;
501 	global_table[ADD_CHANNEL]		= (Function_ptr) BX_add_channel;
502 	global_table[ADD_TO_CHANNEL]		= (Function_ptr) BX_add_to_channel;
503 	global_table[GET_CHANNEL_KEY]		= (Function_ptr) BX_get_channel_key;
504 	global_table[FUNC_RECREATE_MODE]	= (Function_ptr) BX_recreate_mode;
505 #ifdef COMPRESS_MODES
506 	global_table[FUNC_COMPRESS_MODES]	= (Function_ptr) BX_do_compress_modes;
507 #endif
508 	global_table[FUNC_GOT_OPS]		= (Function_ptr) BX_got_ops;
509 	global_table[GET_CHANNEL_BANS]		= (Function_ptr) BX_get_channel_bans;
510 	global_table[GET_CHANNEL_MODE]		= (Function_ptr) BX_get_channel_mode;
511 	global_table[CLEAR_BANS]		= (Function_ptr) BX_clear_bans;
512 	global_table[REMOVE_CHANNEL]		= (Function_ptr) BX_remove_channel;
513 	global_table[REMOVE_FROM_CHANNEL]	= (Function_ptr) BX_remove_from_channel;
514 	global_table[RENAME_NICK]		= (Function_ptr) BX_rename_nick;
515 	global_table[GET_CHANNEL_OPER]		= (Function_ptr) BX_get_channel_oper;
516 	global_table[GET_CHANNEL_HALFOP]	= (Function_ptr) BX_get_channel_halfop;
517 	global_table[FETCH_USERHOST]		= (Function_ptr) BX_fetch_userhost;
518 	global_table[GET_CHANNEL_VOICE]		= (Function_ptr) BX_get_channel_voice;
519 	global_table[CREATE_CHANNEL_LIST]	= (Function_ptr) BX_create_channel_list;
520 	global_table[FLUSH_CHANNEL_STATS]	= (Function_ptr) BX_flush_channel_stats;
521 	global_table[LOOKUP_CHANNEL]		= (Function_ptr) BX_lookup_channel;
522 
523 /* hash.c */
524 	global_table[FIND_NICKLIST_IN_CHANNELLIST]= (Function_ptr) BX_find_nicklist_in_channellist;
525 	global_table[ADD_NICKLIST_TO_CHANNELLIST]= (Function_ptr) BX_add_nicklist_to_channellist;
526 	global_table[NEXT_NICKLIST] 		= (Function_ptr) BX_next_nicklist;
527 	global_table[NEXT_NAMELIST]		= (Function_ptr) BX_next_namelist;
528 	global_table[ADD_NAME_TO_GENERICLIST]	= (Function_ptr) BX_add_name_to_genericlist;
529 	global_table[FIND_NAME_IN_GENERICLIST]	= (Function_ptr) BX_find_name_in_genericlist;
530 	global_table[ADD_WHOWAS_USERHOST_CHANNEL]=(Function_ptr) BX_add_whowas_userhost_channel;
531 	global_table[FIND_USERHOST_CHANNEL]	= (Function_ptr) BX_find_userhost_channel;
532 	global_table[NEXT_USERHOST]		= (Function_ptr) BX_next_userhost;
533 	global_table[SORTED_NICKLIST]		= (Function_ptr) BX_sorted_nicklist;
534 	global_table[CLEAR_SORTED_NICKLIST] 	= (Function_ptr) BX_clear_sorted_nicklist;
535 	global_table[ADD_NAME_TO_FLOODLIST]	= (Function_ptr) BX_add_name_to_floodlist;
536 	global_table[FIND_NAME_IN_FLOODLIST]	= (Function_ptr) BX_find_name_in_floodlist;
537 	global_table[REMOVE_OLDEST_WHOWAS_HASHLIST]=(Function_ptr) BX_remove_oldest_whowas_hashlist;
538 
539 /* vars.h cset.c fset.c */
540 	global_table[FGET_STRING_VAR]		= (Function_ptr) BX_fget_string_var;
541 	global_table[FSET_STRING_VAR]		= (Function_ptr) BX_fset_string_var;
542 	global_table[GET_WSET_STRING_VAR]	= (Function_ptr) BX_get_wset_string_var;
543 	global_table[SET_WSET_STRING_VAR]	= (Function_ptr) BX_set_wset_string_var;
544 	global_table[SET_CSET_INT_VAR]		= (Function_ptr) BX_set_cset_int_var;
545 	global_table[GET_CSET_INT_VAR]		= (Function_ptr) BX_get_cset_int_var;
546 	global_table[SET_CSET_STR_VAR]		= (Function_ptr) BX_set_cset_str_var;
547 	global_table[GET_CSET_STR_VAR]		= (Function_ptr) BX_get_cset_str_var;
548 #ifdef WANT_DLL
549 	global_table[GET_DLLINT_VAR]		= (Function_ptr) BX_get_dllint_var;
550 	global_table[SET_DLLINT_VAR]		= (Function_ptr) BX_set_dllint_var;
551 	global_table[GET_DLLSTRING_VAR]		= (Function_ptr) BX_get_dllstring_var;
552 	global_table[SET_DLLSTRING_VAR]		= (Function_ptr) BX_set_dllstring_var;
553 #else
554 	global_table[GET_DLLINT_VAR]		= (Function_ptr) null_function;
555 	global_table[SET_DLLINT_VAR]		= (Function_ptr) null_function;
556 	global_table[GET_DLLSTRING_VAR]		= (Function_ptr) null_function;
557 	global_table[SET_DLLSTRING_VAR]		= (Function_ptr) null_function;
558 #endif
559 	global_table[GET_INT_VAR]		= (Function_ptr) BX_get_int_var;
560 	global_table[SET_INT_VAR]		= (Function_ptr) BX_set_int_var;
561 	global_table[GET_STRING_VAR]		= (Function_ptr) BX_get_string_var;
562 	global_table[SET_STRING_VAR]		= (Function_ptr) BX_set_string_var;
563 
564 /* timer.c */
565 	global_table[ADD_TIMER]			= (Function_ptr) BX_add_timer;
566 	global_table[DELETE_TIMER]		= (Function_ptr) BX_delete_timer;
567 	global_table[DELETE_ALL_TIMERS]		= (Function_ptr) BX_delete_all_timers;
568 
569 /* socket functions */
570 	global_table[ADD_SOCKETREAD]		= (Function_ptr) BX_add_socketread;
571 	global_table[ADD_SOCKETTIMEOUT]		= (Function_ptr) BX_add_sockettimeout;
572 	global_table[CLOSE_SOCKETREAD]		= (Function_ptr) BX_close_socketread;
573 	global_table[GET_SOCKET]		= (Function_ptr) BX_get_socket;
574 	global_table[SET_SOCKETFLAGS]		= (Function_ptr) BX_set_socketflags;
575 	global_table[GET_SOCKETFLAGS]		= (Function_ptr) BX_get_socketflags;
576 	global_table[GET_SOCKETINFO]		= (Function_ptr) BX_get_socketinfo;
577 	global_table[SET_SOCKETINFO]		= (Function_ptr) BX_set_socketinfo;
578 	global_table[SET_SOCKETWRITE]		= (Function_ptr) BX_set_socketwrite;
579 	global_table[CHECK_SOCKET]		= (Function_ptr) BX_check_socket;
580 	global_table[READ_SOCKETS]		= (Function_ptr) BX_read_sockets;
581 	global_table[WRITE_SOCKETS]		= (Function_ptr) BX_write_sockets;
582 	global_table[GET_MAX_FD]		= (Function_ptr) BX_get_max_fd;
583 	global_table[NEW_CLOSE]			= (Function_ptr) BX_new_close;
584 	global_table[NEW_OPEN]			= (Function_ptr) BX_new_open;
585 	global_table[DGETS]			= (Function_ptr) BX_dgets;
586 
587 /* network.c */
588 	global_table[CONNECT_BY_NUMBER]		= (Function_ptr) BX_connect_by_number;
589 	global_table[RESOLV]			= (Function_ptr) BX_lookup_host;
590 	global_table[LOOKUP_HOST]		= (Function_ptr) BX_lookup_host;
591 	global_table[LOOKUP_IP]			= (Function_ptr) BX_host_to_ip;
592 	global_table[HOST_TO_IP]		= (Function_ptr) BX_host_to_ip;
593 	global_table[IP_TO_HOST]		= (Function_ptr) BX_ip_to_host;
594 	global_table[ONE_TO_ANOTHER]		= (Function_ptr) BX_one_to_another;
595 	global_table[SET_BLOCKING]		= (Function_ptr) BX_set_blocking;
596 	global_table[SET_NON_BLOCKING]		= (Function_ptr) BX_set_non_blocking;
597 
598 /* flood.c */
599 	global_table[IS_OTHER_FLOOD]		= (Function_ptr) BX_is_other_flood;
600 	global_table[CHECK_FLOODING]		= (Function_ptr) BX_check_flooding;
601 	global_table[FLOOD_PROT]		= (Function_ptr) BX_flood_prot;
602 
603 /* alias.c */
604 	global_table[NEXT_UNIT]			= (Function_ptr) BX_next_unit;
605 	global_table[EXPAND_ALIAS]		= (Function_ptr) BX_expand_alias;
606 	global_table[PARSE_INLINE]		= (Function_ptr) BX_parse_inline;
607 	global_table[ALIAS_SPECIAL_CHAR]	= (Function_ptr) BX_alias_special_char;
608 	global_table[PARSE_LINE]		= (Function_ptr) BX_parse_line;
609 	global_table[PARSE_COMMAND_FUNC]	= (Function_ptr) BX_parse_command;
610 	global_table[MAKE_LOCAL_STACK]		= (Function_ptr) BX_make_local_stack;
611 	global_table[DESTROY_LOCAL_STACK]	= (Function_ptr) BX_destroy_local_stack;
612 
613 /* dcc.c */
614 	global_table[DCC_CREATE_FUNC]		= (Function_ptr) BX_dcc_create;
615 	global_table[FIND_DCC_FUNC]		= (Function_ptr) BX_find_dcc;
616 	global_table[ERASE_DCC_INFO]		= (Function_ptr) BX_erase_dcc_info;
617 	global_table[ADD_DCC_BIND]		= (Function_ptr) BX_add_dcc_bind;
618 	global_table[REMOVE_DCC_BIND]		= (Function_ptr) BX_remove_dcc_bind;
619 	global_table[REMOVE_ALL_DCC_BINDS]	= (Function_ptr) BX_remove_all_dcc_binds;
620 	global_table[GET_ACTIVE_COUNT]		= (Function_ptr) BX_get_active_count;
621 	global_table[DCC_FILESEND]		= (Function_ptr) BX_dcc_filesend;
622 	global_table[DCC_RESEND]		= (Function_ptr) BX_dcc_resend;
623 
624 /* cdcc.c */
625 	global_table[GET_NUM_QUEUE]		= (Function_ptr) BX_get_num_queue;
626 	global_table[ADD_TO_QUEUE]		= (Function_ptr) BX_add_to_queue;
627 
628 /* who.c */
629 	global_table[WHOBASE]			= (Function_ptr) BX_whobase;
630 	global_table[ISONBASE]			= (Function_ptr) BX_isonbase;
631 	global_table[USERHOSTBASE]		= (Function_ptr) BX_userhostbase;
632 
633 
634 	global_table[SERV_OPEN_FUNC]		= (Function_ptr) &serv_open_func;
635 	global_table[SERV_OUTPUT_FUNC]		= (Function_ptr) &serv_output_func;
636 	global_table[SERV_INPUT_FUNC]		= (Function_ptr) &serv_input_func;
637 	global_table[SERV_CLOSE_FUNC]		= (Function_ptr) &serv_close_func;
638 	global_table[DEFAULT_OUTPUT_FUNCTION]	= (Function_ptr) &default_output_function;
639 	global_table[DEFAULT_STATUS_OUTPUT_FUNCTION]=(Function_ptr) &default_status_output_function;
640 
641 
642 /* important variables */
643 	global_table[NICKNAME]			= (Function_ptr) &nickname;
644 	global_table[IRC_VERSION]		= (Function_ptr) &irc_version;
645 	global_table[FROM_SERVER]		= (Function_ptr) &from_server;
646 	global_table[CONNECTED_TO_SERVER]	= (Function_ptr) &connected_to_server;
647 	global_table[PRIMARY_SERVER]		= (Function_ptr) &primary_server;
648 	global_table[PARSING_SERVER_INDEX]	= (Function_ptr) &parsing_server_index;
649 	global_table[NOW]			= (Function_ptr) &now;
650 	global_table[START_TIME]		= (Function_ptr) &start_time;
651 	global_table[IDLE_TIME]			= (Function_ptr) &idle_time;
652 
653 	global_table[LOADING_GLOBAL]		= (Function_ptr) &loading_global;
654 
655 	global_table[TARGET_WINDOW]		= (Function_ptr) &target_window;
656 	global_table[CURRENT_WINDOW]		= (Function_ptr) &current_window;
657 	global_table[INVISIBLE_LIST]		= (Function_ptr) &invisible_list;
658 	global_table[MAIN_SCREEN]		= (Function_ptr) &main_screen;
659 	global_table[LAST_INPUT_SCREEN]		= (Function_ptr) &last_input_screen;
660 	global_table[OUTPUT_SCREEN]		= (Function_ptr) &output_screen;
661 	global_table[SCREEN_LIST]		= (Function_ptr) &screen_list;
662 	global_table[DOING_NOTICE]      = (Function_ptr) &doing_notice;
663 	global_table[SENT_NICK]         = 0;	/* No longer used */
664 	global_table[LAST_SENT_MSG_BODY]    = 0;	/* No longer used */
665 
666 	global_table[IRCLOG_FP]			= (Function_ptr) &irclog_fp;
667 #ifdef WANT_DLL
668 	global_table[DLL_FUNCTIONS]		= (Function_ptr) &dll_functions;
669 	global_table[DLL_NUMERIC]		= (Function_ptr) &dll_numeric_list;
670 	global_table[DLL_COMMANDS]		= (Function_ptr) &dll_commands;
671 	global_table[DLL_WINDOW]		= (Function_ptr) &dll_window;
672 	global_table[DLL_VARIABLE]		= (Function_ptr) &dll_variable;
673 	global_table[DLL_CTCP]			= (Function_ptr) &dll_ctcp;
674 #endif
675 	global_table[WINDOW_DISPLAY]		= (Function_ptr) &window_display;
676 	global_table[STATUS_UPDATE_FLAG]	= (Function_ptr) &status_update_flag;
677 	global_table[TABKEY_ARRAY]		= (Function_ptr) &tabkey_array;
678 	global_table[AUTOREPLY_ARRAY]		= (Function_ptr) &autoreply_array;
679 	global_table[IDENTD_SOCKET]		= (Function_ptr) &identd;
680 
681 #ifdef WANT_TCL
682 	global_table[VAR_TCL_INTERP]		= (Function_ptr) tcl_interp;
683 #endif
684 
685 #ifdef GUI
686 	global_table[LASTCLICKLINEDATA]         = (Function_ptr) &lastclicklinedata;
687 	global_table[CONTEXTX]                  = (Function_ptr) &contextx;
688 	global_table[CONTEXTY]                  = (Function_ptr) &contexty;
689 	global_table[GUIIPC]                    = (Function_ptr) &(guiipc[1]);
690 	global_table[GUI_MUTEX_LOCK]		= (Function_ptr) BX_gui_mutex_lock;
691 	global_table[GUI_MUTEX_UNLOCK]		= (Function_ptr) BX_gui_mutex_unlock;
692 #else
693 	global_table[GUI_MUTEX_LOCK]		= (Function_ptr) null_function;
694 	global_table[GUI_MUTEX_UNLOCK]		= (Function_ptr) null_function;
695 #endif
696 /* commands.c */
697 	global_table[FIND_COMMAND_FUNC]		= (Function_ptr) BX_find_command;
698 
699 #ifdef MEM_DEBUG
700 	{
701 		int i;
702 		for (i = 0; i < NUMBER_OF_GLOBAL_FUNCTIONS; i++)
703 			if (global_table[i] == NULL)
704 				put_it("global table %d is NULL", i);
705 	}
706 #endif
707 }
708 
709 
710 
BX_check_module_version(unsigned long number)711 int BX_check_module_version(unsigned long number)
712 {
713 	if (number != MODULE_VERSION)
714 		return 0;
715 	return 1;
716 }
717 
718 #ifdef WANT_DLL
BX_get_dllstring_var(char * typestr)719 char *BX_get_dllstring_var(char *typestr)
720 {
721 IrcVariableDll *dll = NULL;
722 	if (typestr)
723 		dll = (IrcVariableDll *) find_in_list((List **)&dll_variable, typestr, 0);
724 	return (dll?dll->string:NULL);
725 }
726 
727 
BX_get_dllint_var(char * typestr)728 int BX_get_dllint_var(char *typestr)
729 {
730 IrcVariableDll *dll = NULL;
731 	if (typestr)
732 		dll = (IrcVariableDll *) find_in_list((List **)&dll_variable, typestr, 0);
733 	return (dll?dll->integer:-1);
734 }
735 
BX_set_dllstring_var(char * typestr,char * string)736 void BX_set_dllstring_var(char *typestr, char *string)
737 {
738 	if (typestr)
739 	{
740 		IrcVariableDll *dll = NULL;
741 		if (typestr)
742 			dll = (IrcVariableDll *) find_in_list((List **)&dll_variable, typestr, 0);
743 		if (!dll)
744 			return;
745 		if (string)
746 			malloc_strcpy(&dll->string, string);
747 		else
748 			new_free(&dll->string);
749 	}
750 }
751 
BX_set_dllint_var(char * typestr,unsigned int value)752 void BX_set_dllint_var(char *typestr, unsigned int value)
753 {
754 	if (typestr)
755 	{
756 		IrcVariableDll *dll = NULL;
757 		if (typestr)
758 			dll = (IrcVariableDll *) find_in_list((List **)&dll_variable, typestr, 0);
759 		if (!dll)
760 			return;
761 		dll->integer = value;
762 	}
763 }
764 
BUILT_IN_COMMAND(dll_load)765 BUILT_IN_COMMAND(dll_load)
766 {
767 #if defined(HPUX)  /* 	HP machines */
768 	shl_t handle = NULL;
769 #elif defined(__EMX__)
770 	ULONG ulerror;
771 	HMODULE handle;
772 #elif defined(WINNT)
773 	HINSTANCE handle;
774 #else		     /*		linux SunOS AIX etc */
775 	void *handle = NULL;
776 #endif
777 
778 char *filename = NULL;
779 Irc_PackageInitProc *proc1Ptr;
780 Irc_PackageVersionProc *proc2Ptr;
781 char *f, *p, *procname = NULL;
782 int code = 0;
783 
784 	if (command)
785 	{
786 		if (install_pack)
787 		{
788 			Packages *pkg = install_pack;
789 			List *pk;
790 			for ( ; pkg; pkg = pkg->next)
791 				put_it("DLL [%s%s%s] installed", pkg->name, pkg->version?space:empty_string, pkg->version?pkg->version:empty_string);
792 			for (pk = (List *)dll_commands; pk; pk = pk->next)
793 				put_it("\t%10s\t%s", "Command", pk->name);
794 			for (pk = (List *)dll_functions; pk; pk = pk->next)
795 				put_it("\t%10s\t%s", "Alias", pk->name);
796 			for (pk = (List *)dll_ctcp; pk; pk = pk->next)
797 				put_it("\t%10s\t%s", "Ctcp", pk->name);
798 			for (pk = (List *)dll_variable; pk; pk = pk->next)
799 				put_it("\t%10s\t%s", "Variable", pk->name);
800 			for (pk = (List *)dll_window; pk; pk = pk->next)
801 				put_it("\t%10s\t %s", "Window", pk->name);
802 		}
803 		else
804 			bitchsay("No modules loaded");
805 		return;
806 	}
807 	if (!args || !*args)
808 		return;
809 
810 	filename = next_arg(args, &args);
811 	f = expand_twiddle(filename);
812 
813 	if ((p = strrchr(filename, '/')))
814 		p++;
815 	else
816 	{
817 		new_free(&f);
818 		if (!(p = path_search(filename, PLUGINDIR)))
819 			if (!(p = path_search(filename, get_string_var(LOAD_PATH_VAR))))
820 			{
821 				char file_buf[BIG_BUFFER_SIZE];
822 				strcpy(file_buf, filename);
823 				strcat(file_buf, SHLIB_SUFFIX);
824 				if (!(p = path_search(file_buf, get_string_var(LOAD_PATH_VAR))))
825 					if (!(p = path_search(file_buf, PLUGINDIR)))
826 						p = filename;
827 			}
828 		f = expand_twiddle(p);
829 		p = filename;
830 
831 	}
832 
833 	procname  = m_strdup(p);
834 	if ((p = strchr(procname, '.')))
835 		*p = 0;
836 
837 	p = procname;
838 	*p = toupper(*p);
839 	p++;
840 	while (p && *p)
841 	{
842 		*p = tolower(*p);
843 		p++;
844 	}
845 
846 	if (!procname || find_in_list((List **)&install_pack, procname, 0))
847 	{
848 		if (procname)
849 			bitchsay("Module [%s] Already installed", procname);
850 		new_free(&f);
851 		new_free(&procname);
852 		return;
853 	}
854 	malloc_strcat(&procname, "_Init");
855 
856 #if defined(HPUX)
857 	handle = shl_load(f, BIND_IMMEDIATE, 0L);
858 #elif defined(__osf1__)
859 	handle = dlopen(f, RTLD_NOW);
860 #elif defined(__EMX__)
861         malloc_strcat(&f, ".dll");
862         convert_dos(f);
863 	ulerror = DosLoadModule(NULL, 0, f, &handle);
864 #elif defined(WINNT)
865         malloc_strcat(&f, ".dll");
866 	convert_dos(f);
867 	handle = LoadLibrary(f);
868 #else
869 	handle = dlopen(f, RTLD_NOW | RTLD_GLOBAL);
870 #endif
871 #if defined(__EMX__)
872 	if (ulerror)
873 #else
874 	if (handle == NULL)
875 #endif
876 	{
877 #if defined(__EMX__)
878 		bitchsay("couldn't load file: DosLoadModule() failed %d", ulerror);
879 #elif defined(WINNT)
880 		bitchsay("could't load file %s", f);
881 #else
882 		bitchsay("couldn't load file: %s", dlerror());
883 #endif
884 		new_free(&procname);
885 		new_free(&f);
886 		return;
887 	}
888 
889 #if defined(HPUX)
890 	if (!shl_findsym(&handle, procname, (short) TYPE_PROCEDURE, (void *) proc1Ptr))
891 #elif defined(__EMX__)
892 	if(DosQueryProcAddr(handle, 0, procname, (PFN *) &proc1Ptr))
893 #elif defined(WINNT)
894 	if (!(proc1Ptr = (Irc_PackageInitProc *) GetProcAddress(handle, procname)))
895 #else
896 	if (!(proc1Ptr = (Irc_PackageInitProc *) dlsym(handle, (char *) procname)))
897 #endif
898 		bitchsay("UnSuccessful module load");
899 	else
900 		code = (proc1Ptr)(&dll_commands, global_table);
901 
902 	if (!code && proc1Ptr)
903 	{
904 		Packages *new;
905 		new = (Packages *) new_malloc(sizeof(Packages));
906 		new->name = m_strdup(procname);
907 		new->handle = handle;
908 		new->major = bitchx_numver / 10000;
909 		new->minor = (bitchx_numver / 100) % 100;
910 
911 		if ((p = strrchr(new->name, '_')))
912 			*p = 0;
913 		p = m_sprintf("%s_Version", new->name);
914 #if defined(__EMX__)
915 		if (!DosQueryProcAddr(handle, 0, p, (PFN *) &proc2Ptr))
916 #elif defined(WINNT)
917 		if ((proc2Ptr = (Irc_PackageVersionProc *) GetProcAddress(handle, p)))
918 #elif defined(HPUX)
919                if (shl_findsym(&handle, p, (short) TYPE_PROCEDURE, (void *)proc2Ptr))
920 #else
921 		if ((proc2Ptr = (Irc_PackageVersionProc *) dlsym(handle, p)))
922 #endif
923 			new->version = m_strdup(((proc2Ptr)(&dll_commands)));
924 		new_free(&p);
925 
926 		if ((p = strrchr(new->name, '_')))
927 			*p = 0;
928 		p = m_sprintf("%s_Cleanup", new->name);
929 #if defined(__EMX__)
930 		if(!DosQueryProcAddr(handle, 0, p, (PFN *) &proc1Ptr))
931 #elif defined(WINNT)
932 		if ((proc1Ptr = (Irc_PackageInitProc *) GetProcAddress(handle, p)))
933 #elif defined(HPUX)
934 		if (shl_findsym(&handle, p, (short) TYPE_PROCEDURE, (void *)proc1Ptr))
935 #else
936 		if ((proc1Ptr = (Irc_PackageInitProc *) dlsym(handle, p)))
937 #endif
938 			new->cleanup = proc1Ptr;
939 
940 		new_free(&p);
941 		if ((p = strrchr(new->name, '_')))
942 			*p = 0;
943 		p = m_sprintf("%s_Lock", new->name);
944 #if defined(__EMX__)
945 		if(!DosQueryProcAddr(handle, 0, p, (PFN *) &proc1Ptr))
946 #elif defined(WINNT)
947 		if ((proc1Ptr = (Irc_PackageInitProc *) GetProcAddress(handle, p)))
948 #elif defined(HPUX)
949 		if (shl_findsym(&handle, p, (short) TYPE_PROCEDURE, (void *)proc1Ptr))
950 #else
951 		if ((proc1Ptr = (Irc_PackageInitProc *) dlsym(handle, p)))
952 #endif
953 			new->lock = 1;
954 		new_free(&p);
955 		add_to_list((List **)&install_pack, (List *)new);
956 	}
957 	else
958 	{
959 		if (code == INVALID_MODVERSION)
960 			bitchsay("Error module version is wrong for [%s]", procname);
961 		else
962 			bitchsay("Error initiliziing module [%s:%d]", procname, code);
963 		if (handle)
964 #if defined(__EMX__)
965 			DosFreeModule(handle);
966 #elif defined(WINNT)
967 			FreeLibrary(handle);
968 #elif defined(HPUX)
969 			shl_unload(handle);
970 #else
971 			dlclose(handle);
972 #endif
973 	}
974 	new_free(&procname);
975 	new_free(&f);
976 }
977 
find_module(char * name)978 Packages *find_module(char *name)
979 {
980 Packages *new = NULL;
981 	if (name)
982 		new = (Packages *)find_in_list((List **)&install_pack, name, 0);
983 	return new;
984 }
985 
986 #define RAWHASH_SIZE 20
987 
988 HashEntry RawHash[RAWHASH_SIZE] = {{ NULL, 0, 0 }};
989 
find_raw_proc(char * comm,char ** ArgList)990 RawDll *find_raw_proc(char *comm, char **ArgList)
991 {
992 	RawDll *tmp = NULL;
993 	if ((tmp = (RawDll *)find_name_in_genericlist(comm, RawHash, RAWHASH_SIZE, 0)))
994 		return tmp;
995 	return NULL;
996 }
997 
998 
999 
1000 
BX_add_module_proc(unsigned int mod_type,char * modname,char * procname,char * desc,int id,int flag,void * func1,void * func2)1001 int BX_add_module_proc(unsigned int mod_type, char *modname, char *procname, char *desc, int id, int flag, void *func1, void *func2)
1002 {
1003 	switch(mod_type)
1004 	{
1005 		case COMMAND_PROC:
1006 		{
1007 			IrcCommandDll *new;
1008 			new = (IrcCommandDll *) new_malloc(sizeof(IrcCommandDll));
1009 			new->name = m_strdup(procname);
1010 			if (desc)
1011 				new->server_func = m_strdup(desc);
1012 			new->func = func1;
1013 			if (func2)
1014 				new->help = m_strdup((char *)func2);
1015 			new->module = m_strdup(modname);
1016 			add_to_list((List **)&dll_commands, (List *)new);
1017 			break;
1018 		}
1019 		case WINDOW_PROC:
1020 		{
1021 			WindowDll *new;
1022 			new = (WindowDll *) new_malloc(sizeof(WindowDll));
1023 			new->name = m_strdup(procname);
1024 			if (desc)
1025 				new->help = m_strdup(desc);
1026 			new->func = func1;
1027 			new->module = m_strdup(modname);
1028 			add_to_list((List **)&dll_window, (List *)new);
1029 			break;
1030 		}
1031 		case OUTPUT_PROC:
1032 		{
1033 			Screen *screen;
1034 			Window *window;
1035 			if (func1)
1036 			{
1037 				default_output_function = func1;
1038 				for (screen = screen_list; screen; screen = screen->next)
1039 				{
1040 					for (window = screen->window_list; window; window = window->next)
1041 						window->output_func = func1;
1042 				}
1043 			}
1044 			if (func2)
1045 			{
1046 				default_status_output_function = func2;
1047 				for (screen = screen_list; screen; screen = screen->next)
1048 				{
1049 					for (window = screen->window_list; window; window = window->next)
1050 						window->status_output_func = func2;
1051 				}
1052 			}
1053 			break;
1054 		}
1055 		case ALIAS_PROC:
1056 		{
1057 			BuiltInDllFunctions *new = NULL;
1058 			new = (BuiltInDllFunctions *) new_malloc(sizeof(BuiltInDllFunctions));
1059 			new->name = m_strdup(procname);
1060 			new->func = func1;
1061 			new->module = m_strdup(modname);
1062 			add_to_list((List **)&dll_functions, (List *)new);
1063 			break;
1064 		}
1065 		case CTCP_PROC:
1066 		{
1067 			CtcpEntryDll *new = NULL;
1068 			new = (CtcpEntryDll *) new_malloc(sizeof(CtcpEntryDll));
1069 			new->name = m_strdup(procname);
1070 			new->desc = m_strdup(desc);
1071 			new->id = id;
1072 			new->flag = flag;
1073 			new->func = func1;
1074 			new->repl = func2;
1075 			new->module = m_strdup(modname);
1076 			add_to_list((List **)&dll_ctcp, (List *)new);
1077 			break;
1078 		}
1079 		case VAR_PROC:
1080 		{
1081 			IrcVariableDll *new = NULL;
1082 			new = (IrcVariableDll *) new_malloc(sizeof(IrcVariableDll));
1083 			new->type = id;
1084 			new->integer = flag;
1085 			new->name = m_strdup(procname);
1086 			if (desc)
1087 				new->string = m_strdup(desc);
1088 			new->module = m_strdup(modname);
1089 			new->func = func1;
1090 			add_to_list((List **)&dll_variable, (List *)new);
1091 			break;
1092 		}
1093 		case RAW_PROC:
1094 		{
1095 			RawDll *raw;
1096 			unsigned long hvalue = hash_nickname(procname, RAWHASH_SIZE);
1097 			raw = (RawDll *)new_malloc(sizeof(RawDll));
1098 			raw->next = (RawDll *)RawHash[hvalue].list;
1099 			RawHash[hvalue].list = (void *)raw;
1100 			RawHash[hvalue].links++;
1101 			RawHash[hvalue].hits++;
1102 			raw->name = m_strdup(procname);
1103 			raw->module = m_strdup(modname);
1104 			raw->func = func1;
1105 			break;
1106 		}
1107 		case HOOK_PROC:
1108 		{
1109 extern void add_dll_hook(int , int, char *, char *, int (*func1)(int, char *, char **),int (*func2)(char *, char *, char **));
1110 			add_dll_hook(id, flag, desc? desc : "*", modname, func1, func2);
1111 			break;
1112 		}
1113 		case DCC_PROC:
1114 		{
1115 			DCC_dllcommands *new = NULL;
1116 			new = (DCC_dllcommands *) new_malloc(sizeof(DCC_dllcommands));
1117 			new->name = m_strdup(procname);
1118 			new->help = m_strdup(desc);
1119 			new->module = m_strdup(modname);
1120 			new->function = func1;
1121 			add_to_list((List **)&dcc_dllcommands, (List *)new);
1122 			break;
1123 		}
1124 		default:
1125 		{
1126 			if ((mod_type & ~TABLE_PROC) > 0 && (mod_type & ~TABLE_PROC) < NUMBER_OF_GLOBAL_FUNCTIONS)
1127 				global_table[mod_type & ~TABLE_PROC] = func1;
1128 		}
1129 	}
1130 	return 0;
1131 }
1132 
1133 typedef struct _list2
1134 {
1135 	struct _list2 *next;
1136 	char	*command;
1137 	char	*name;
1138 } List2;
1139 
remove_module(List2 ** list,char * name)1140 static List2	*remove_module(List2 **list, char *name)
1141 {
1142 register	List2	*tmp;
1143 		List2 	*last;
1144 
1145 	last = NULL;
1146 	for (tmp = *list; tmp; tmp = tmp->next)
1147 	{
1148 		if (tmp->name && !strcasecmp(tmp->name, name))
1149 		{
1150 			if (last)
1151 				last->next = tmp->next;
1152 			else
1153 				*list = tmp->next;
1154 			return (tmp);
1155 		}
1156 		last = tmp;
1157 	}
1158 	return NULL;
1159 }
1160 
1161 
BX_remove_module_proc(unsigned int mod_type,char * modname,char * procname,char * desc)1162 int BX_remove_module_proc(unsigned int mod_type, char *modname, char *procname, char *desc)
1163 {
1164 int count = 0;
1165 	switch(mod_type)
1166 	{
1167 		case COMMAND_PROC:
1168 		{
1169 			IrcCommandDll *ptr;
1170 			while ((ptr = (IrcCommandDll *)remove_module((List2 **)&dll_commands, modname)))
1171 			{
1172 				new_free(&ptr->name);
1173 				new_free(&ptr->module);
1174 				new_free(&ptr->server_func);
1175 				new_free(&ptr->result);
1176 				new_free(&ptr->help);
1177 				new_free((char **)&ptr);
1178 				count++;
1179 			}
1180 			break;
1181 		}
1182 		case WINDOW_PROC:
1183 		{
1184 			WindowDll *ptr;
1185 			while ((ptr = (WindowDll *)remove_module((List2 **)&dll_window, modname)))
1186 			{
1187 				new_free(&ptr->name);
1188 				new_free(&ptr->module);
1189 				new_free(&ptr->help);
1190 				new_free((char **)&ptr);
1191 				count++;
1192 			}
1193 			break;
1194 		}
1195 		case OUTPUT_PROC:
1196 		{
1197 			Screen *screen;
1198 			Window *window;
1199 			default_output_function = BX_add_to_window;
1200 			for (screen = screen_list; screen; screen = screen->next)
1201 			{
1202 				for (window = screen->window_list; window; window = window->next)
1203 					window->output_func = BX_add_to_window;
1204 			}
1205 			default_status_output_function = make_status;
1206 			for (screen = screen_list; screen; screen = screen->next)
1207 			{
1208 				for (window = screen->window_list; window; window = window->next)
1209 					window->status_output_func = make_status;
1210 			}
1211 			count++;
1212 			break;
1213 		}
1214 		case ALIAS_PROC:
1215 		{
1216 			BuiltInDllFunctions *ptr;
1217 			while ((ptr = (BuiltInDllFunctions *)remove_module((List2 **)&dll_functions, modname)))
1218 			{
1219 				new_free(&ptr->name);
1220 				new_free(&ptr->module);
1221 				new_free((char **)&ptr);
1222 				count++;
1223 			}
1224 			break;
1225 		}
1226 		case CTCP_PROC:
1227 		{
1228 			CtcpEntryDll *ptr;
1229 			while ((ptr = (CtcpEntryDll *)remove_module((List2 **)&dll_ctcp, modname)))
1230 			{
1231 				new_free(&ptr->name);
1232 				new_free(&ptr->module);
1233 				new_free(&ptr->desc);
1234 				new_free((char **)&ptr);
1235 				count++;
1236 			}
1237 			break;
1238 		}
1239 		case VAR_PROC:
1240 		{
1241 			IrcVariableDll *ptr;
1242 			while ((ptr = (IrcVariableDll *)remove_module((List2 **)&dll_variable, modname)))
1243 			{
1244 				new_free(&ptr->name);
1245 				new_free(&ptr->module);
1246 				new_free(&ptr->string);
1247 				new_free((char **)&ptr);
1248 				count++;
1249 			}
1250 			break;
1251 		}
1252 		case RAW_PROC:
1253 		{
1254 			int i;
1255 			RawDll *ptr = NULL;
1256 			for (i = 0; i < RAWHASH_SIZE; i++)
1257 			{
1258 				while ((ptr = (RawDll *)remove_module((List2 **)&(RawHash[i].list), modname)))
1259 				{
1260 					new_free(&ptr->module);
1261 					new_free(&ptr->name);
1262 					new_free((char **)&ptr);
1263 					count++;
1264 				}
1265 			}
1266 			break;
1267 		}
1268 		case HOOK_PROC:
1269 		{
1270 			extern int remove_dll_hook(char *);
1271 			count = remove_dll_hook(modname);
1272 			break;
1273 		}
1274 		case DCC_PROC:
1275 		{
1276 			DCC_dllcommands *ptr;
1277 			while ((ptr = (DCC_dllcommands *)remove_module((List2 **)&dcc_dllcommands, modname)))
1278 			{
1279 				new_free(&ptr->name);
1280 				new_free(&ptr->module);
1281 				new_free(&ptr->help);
1282 				new_free((char **)&ptr);
1283 				count++;
1284 			}
1285 			break;
1286 		}
1287 		default:
1288 		{
1289 			if ((mod_type & ~TABLE_PROC) > 0 && (mod_type & ~TABLE_PROC)< NUMBER_OF_GLOBAL_FUNCTIONS)
1290 			{
1291 				global_table[mod_type & ~TABLE_PROC] = NULL;
1292 				count++;
1293 			}
1294 		}
1295 	}
1296 	return count;
1297 }
1298 
remove_package(char * name)1299 int remove_package(char *name)
1300 {
1301 Packages *new = NULL;
1302 	if ((new = (Packages *) remove_from_list((List **)&install_pack, name)))
1303 	{
1304 #if defined(__EMX__)
1305 		DosFreeModule(new->handle);
1306 #elif defined(WINNT)
1307 		FreeLibrary(new->handle);
1308 #elif defined(HPUX)
1309 		shl_unload(new->handle);
1310 #else
1311 		dlclose(new->handle);
1312 #endif
1313 		new_free(&new->name);
1314 		new_free(&new->version);
1315 		new_free((char **)&new);
1316 		return 1;
1317 	}
1318 	return  0;
1319 }
1320 
check_version(unsigned long required)1321 int check_version(unsigned long required)
1322 {
1323 unsigned long major, minor, need_major, need_minor;
1324 	major = bitchx_numver / 10000;
1325 	minor = (bitchx_numver / 100) % 100;
1326 	need_major = required / 10000;
1327 	need_minor = (required / 100) % 100;
1328 	if ((major > need_major) || (major == need_major && minor >= need_minor))
1329 		return 1;
1330 	return INVALID_MODVERSION;
1331 }
1332 
BUILT_IN_COMMAND(unload_dll)1333 BUILT_IN_COMMAND(unload_dll)
1334 {
1335 Packages *new = NULL;
1336 int success = 0;
1337 char *name;
1338 	name = next_arg(args, &args);
1339 	if (name && (new = find_module(name)))
1340 	{
1341 		if (new->cleanup)
1342 			success = (new->cleanup)(&dll_commands, global_table);
1343 		else
1344 		{
1345 			if (new->lock)
1346 			{
1347 				bitchsay("Module is locked");
1348 				return;
1349 			}
1350 			success += remove_module_proc(COMMAND_PROC, name, NULL, NULL);
1351 			success += remove_module_proc(ALIAS_PROC, name, NULL, NULL);
1352 			success += remove_module_proc(CTCP_PROC, name, NULL, NULL);
1353 			success += remove_module_proc(VAR_PROC, name, NULL, NULL);
1354 			success += remove_module_proc(HOOK_PROC, name, NULL, NULL);
1355 			success += remove_module_proc(RAW_PROC, name, NULL, NULL);
1356 			success += remove_module_proc(WINDOW_PROC, name, NULL, NULL);
1357 			success += remove_module_proc(OUTPUT_PROC, name, NULL, NULL);
1358 			success += remove_module_proc(DCC_PROC, name, NULL, NULL);
1359 			success += remove_all_dcc_binds(name);
1360 		}
1361 		if (success)
1362 		{
1363 			remove_package(name);
1364 			put_it("%s", convert_output_format("$G Successfully removed [$0 ($1)]", "%s %d", name, success));
1365 		} else
1366 			put_it("%s", convert_output_format("$G Unsuccessful module unload", NULL, NULL));
1367 	} else
1368 		bitchsay("No such module loaded");
1369 }
1370 
add_module(unsigned int mod_type,Function * table,char * modname)1371 int add_module(unsigned int mod_type, Function * table, char *modname)
1372 {
1373 Function *p = table;
1374 int count = 0;
1375 
1376 	while(p)
1377 	{
1378 		add_module_proc(mod_type, modname, p->name, p->desc, p->id, p->flag, p->func1, p->func2);
1379 		p++;count++;
1380 	}
1381 	return count;
1382 }
1383 #endif
1384 
1385