Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/source/functions.c
1069 views
1
/*
2
* functions.c -- Built-in functions for ircII
3
*
4
* Written by Michael Sandrof
5
* Copyright(c) 1990 Michael Sandrof
6
* See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT
7
*
8
*/
9
10
#include "irc.h"
11
static char cvsrevision[] = "$Id: functions.c 204 2012-06-02 14:53:37Z keaston $";
12
CVS_REVISION(functions_c)
13
#include "struct.h"
14
15
#include "alias.h"
16
#include "alist.h"
17
#include "array.h"
18
#include "dcc.h"
19
#include "commands.h"
20
#include "files.h"
21
#include "history.h"
22
#include "hook.h"
23
#include "ignore.h"
24
#include "input.h"
25
#include "ircaux.h"
26
#include "names.h"
27
#include "output.h"
28
#include "list.h"
29
#include "parse.h"
30
#include "screen.h"
31
#include "server.h"
32
#include "status.h"
33
#include "vars.h"
34
#include "window.h"
35
#include "ircterm.h"
36
#include "notify.h"
37
#include "misc.h"
38
#include "userlist.h"
39
#include "numbers.h"
40
#include "ignore.h"
41
#include "hash2.h"
42
#include "struct.h"
43
#include "cset.h"
44
#include "log.h"
45
#include "gui.h"
46
#define MAIN_SOURCE
47
#include "modval.h"
48
49
#include "options.h"
50
#include <sys/stat.h>
51
52
#ifdef HAVE_REGEX_H
53
#include <regex.h>
54
#endif
55
#ifdef HAVE_UNAME
56
#include <sys/utsname.h>
57
#endif
58
59
#ifdef WANT_HEBREW
60
#include "hebrew.h"
61
#endif
62
63
#include "tcl_bx.h"
64
65
static char *alias_detected (void);
66
static char *alias_sent_nick (void);
67
static char *alias_recv_nick (void);
68
static char *alias_msg_body (void);
69
static char *alias_joined_nick (void);
70
static char *alias_public_nick (void);
71
static char *alias_dollar (void);
72
static char *alias_channel (void);
73
static char *alias_server (void);
74
static char *alias_query_nick (void);
75
static char *alias_target (void);
76
static char *alias_nick (void);
77
static char *alias_invite (void);
78
static char *alias_cmdchar (void);
79
static char *alias_line (void);
80
static char *alias_away (void);
81
static char *alias_oper (void);
82
static char *alias_chanop (void);
83
static char *alias_modes (void);
84
static char *alias_buffer (void);
85
static char *alias_time (void);
86
static char *alias_version (void);
87
static char *alias_currdir (void);
88
static char *alias_current_numeric (void);
89
static char *alias_server_version (void);
90
static char *alias_show_userhost (void);
91
static char *alias_show_realname (void);
92
static char *alias_online (void);
93
static char *alias_idle (void);
94
static char *alias_version_str (void);
95
static char *alias_version_str1 (void);
96
static char *alias_thingansi (void);
97
static char *alias_uptime (void);
98
static char *alias_serverport (void);
99
static char *alias_tclsupport (void);
100
static char *alias_current_network (void);
101
static char *alias_bitchx (void);
102
static char *alias_hookname (void);
103
static char *alias_awaytime (void);
104
static char *alias_thisaliasname (void);
105
static char *alias_serverlag (void);
106
static char *alias_currentwindow (void);
107
static char *alias_serverlistsize (void);
108
109
typedef struct
110
{
111
char name;
112
char *(*func) (void);
113
} BuiltIns;
114
115
static BuiltIns built_in[] =
116
{
117
{ '.', alias_sent_nick },
118
{ ',', alias_recv_nick },
119
{ ':', alias_joined_nick },
120
{ ';', alias_public_nick },
121
{ '`', alias_uptime },
122
{ '$', alias_dollar },
123
{ 'A', alias_away },
124
{ 'B', alias_msg_body },
125
{ 'C', alias_channel },
126
{ 'D', alias_detected },
127
{ 'E', alias_idle },
128
{ 'F', alias_online },
129
{ 'G', alias_thingansi },
130
{ 'H', alias_current_numeric },
131
{ 'I', alias_invite },
132
{ 'J', alias_version_str },
133
{ 'K', alias_cmdchar },
134
{ 'L', alias_line },
135
{ 'M', alias_modes },
136
{ 'N', alias_nick },
137
{ 'O', alias_oper },
138
{ 'P', alias_chanop },
139
{ 'Q', alias_query_nick },
140
{ 'R', alias_server_version },
141
{ 'S', alias_server },
142
{ 'T', alias_target },
143
{ 'U', alias_buffer },
144
{ 'V', alias_version },
145
{ 'W', alias_currdir },
146
{ 'X', alias_show_userhost },
147
{ 'Y', alias_show_realname },
148
{ 'Z', alias_time },
149
{ 'a', alias_version_str1 },
150
{ 'b', alias_bitchx },
151
{ 'h', alias_hookname },
152
{ 'l', alias_serverlag },
153
{ 'n', alias_current_network },
154
{ 's', alias_serverport },
155
{ 't', alias_thisaliasname },
156
{ 'u', alias_awaytime },
157
{ 'v', alias_tclsupport },
158
{ 'w', alias_currentwindow },
159
{ 'z', alias_serverlistsize },
160
{ 0, NULL }
161
};
162
163
/* the 30 "standard" functions */
164
static char *function_channels (char *, char *);
165
static char *function_connect (char *, char *);
166
static char *function_curpos (char *, char *);
167
char *function_decode (char *, unsigned char *);
168
static char *function_encode (char *, unsigned char *);
169
static char *function_index (char *, char *);
170
static char *function_ischannel (char *, char *);
171
static char *function_ischanop (char *, char *);
172
static char *function_ishalfop (char *, char *);
173
static char *function_left (char *, char *);
174
static char *function_listen (char *, char *);
175
static char *function_match (char *, char *);
176
static char *function_mid (char *, char *);
177
static char *function_notify (char *, char *);
178
static char *function_pid (char *, char *);
179
static char *function_ppid (char *, char *);
180
static char *function_rand (char *, char *);
181
static char *function_right (char *, char *);
182
static char *function_rindex (char *, char *);
183
static char *function_rmatch (char *, char *);
184
static char *function_servers (char *, char *);
185
static char *function_srand (char *, char *);
186
static char *function_stime (char *, char *);
187
static char *function_strip (char *, char *);
188
static char *function_tdiff (char *, char *);
189
static char *function_tdiff2 (char *, char *);
190
static char *function_time (char *, char *);
191
static char *function_tolower (char *, char *);
192
static char *function_toupper (char *, char *);
193
static char *function_userhost (char *, char *);
194
static char *function_winnum (char *, char *);
195
static char *function_winnam (char *, char *);
196
static char *function_winnames (char *, char *);
197
static char *function_word (char *, char *);
198
static char *function_utime (char *, char *);
199
static char *function_umode (char *, char *);
200
201
/* CDE added functions */
202
static char *function_uptime (char *, char *);
203
static char *function_cluster (char *, char *);
204
static char *function_checkshit (char *, char *);
205
static char *function_checkuser (char *, char *);
206
static char *function_rot13 (char *, char *);
207
char *function_addtabkey (char *, char *);
208
char *function_gettabkey (char *, char *);
209
static char *function_lastnotice (char *, char *);
210
static char *function_lastmessage (char *, char *);
211
static char *function_help (char *, char *);
212
static char *function_isuser (char *, char *);
213
/* Thanks Jordy */
214
static char *function_pad (char *, char *);
215
static char *function_isban (char *, char *);
216
static char *function_isop (char *, char *);
217
static char *function_isvoice (char *, char *);
218
static char *function_randomnick (char *, char *);
219
220
static char *function_openserver (char *, char *);
221
static char *function_readserver (char *, char *);
222
static char *function_readchar (char *, char *);
223
static char *function_writeserver (char *, char *);
224
static char *function_closeserver (char *, char *);
225
static char *function_getreason (char *, char *);
226
227
/* the 53 "extended" functions */
228
static char * function_after (char *, char *);
229
static char * function_afterw (char *, char *);
230
static char * function_aliasctl (char *, char *);
231
static char * function_ascii (char *, char *);
232
static char * function_before (char *, char *);
233
static char * function_beforew (char *, char *);
234
static char * function_center (char *, char *);
235
static char * function_cexist (char *, char *);
236
static char * function_currchans (char *, char *);
237
static char * function_channelmode (char *, char *);
238
static char * function_channelnicks (char *, char *);
239
static char * function_chngw (char *, char *);
240
static char * function_chop (char *, char *);
241
static char * function_chops (char *, char *);
242
static char * function_chr (char *, char *);
243
static char * function_close (char *, char *);
244
static char * function_common (char *, char *);
245
static char * function_convert (char *, char *);
246
static char * function_copattern (char *, char *);
247
static char * function_crypt (char *, char *);
248
static char * function_diff (char *, char *);
249
static char * function_epic (char *, char *);
250
static char * function_eof (char *, char *);
251
static char * function_fnexist (char *, char *);
252
static char * function_glob (char *, char *);
253
static char * function_fexist (char *, char *);
254
static char * function_filter (char *, char *);
255
static char * function_fromw (char *, char *);
256
static char * function_fsize (char *, char *);
257
static char * function_geom (char *, char *);
258
static char * function_info (char *, char *);
259
static char * function_insertw (char *, char *);
260
static char * function_iptoname (char *, char *);
261
static char * function_isalpha (char *, char *);
262
static char * function_isdigit (char *, char *);
263
static char * function_jot (char *, char *);
264
static char * function_key (char *, char *);
265
static char * function_lastserver (char *, char *);
266
static char * function_leftw (char *, char *);
267
static char * function_mkdir (char *, char *);
268
static char * function_midw (char *, char *);
269
static char * function_nametoip (char *, char *);
270
static char * function_nochops (char *, char *);
271
static char * function_notw (char *, char *);
272
static char * function_numonchannel (char *, char *);
273
static char * function_numwords (char *, char *);
274
static char * function_numsort (char *, char *);
275
static char * function_onchannel (char *, char *);
276
static char * function_open (char *, char *);
277
static char * function_pass (char *, char *);
278
static char * function_pattern (char *, char *);
279
static char * function_read (char *, char *);
280
static char * function_remw (char *, char *);
281
static char * function_rename (char *, char *);
282
static char * function_restw (char *, char *);
283
static char * function_reverse (char *, char *);
284
static char * function_revw (char *, char *);
285
static char * function_rfilter (char *, char *);
286
static char * function_rightw (char *, char *);
287
static char * function_rmdir (char *, char *);
288
static char * function_rpattern (char *, char *);
289
static char * function_sar (char *, char *);
290
static char * function_server_version (char *, char *);
291
static char * function_servername (char *, char *);
292
static char * function_sort (char *, char *);
293
static char * function_split (char *, char *);
294
static char * function_splice (char *, char *);
295
static char * function_stripansi (char *, char *);
296
static char * function_stripansicodes (char *, char *);
297
static char * function_strftime (char *, char *);
298
static char * function_strlen (char *, char *);
299
static char * function_tow (char *, char *);
300
static char * function_translate (char *, char *);
301
static char * function_truncate (char *, char *);
302
static char * function_unlink (char *, char *);
303
static char * function_umask (char *, char *);
304
static char * function_which (char *, char *);
305
static char * function_winserv (char *, char *);
306
static char * function_winsize (char *, char *);
307
static char * function_write (char *, char *);
308
static char * function_writeb (char *, char *);
309
static char * function_idle (char *, char *);
310
static char * function_repeat (char *, char *);
311
static char * function_bcopy (char *, char *);
312
char * function_cparse (char *, char *);
313
static char * function_chmod (char *, char *);
314
static char * function_twiddle (char *, char *);
315
static char * function_uniq (char *, char *);
316
static char * function_uhost (char *, char *);
317
static char * function_numdiff (char *, char *);
318
char * function_getkey (char *, char *);
319
static char * function_winvisible (char *, char *);
320
static char * function_mircansi (char *, char *);
321
static char * function_banonchannel (char *, char *);
322
static char * function_chanwin (char *, char *);
323
static char * function_gethost (char *, char *);
324
static char * function_getenv (char *, char *);
325
static char * function_getvar (char *, char *);
326
static char * function_status (char *, char *);
327
char * function_push (char *, char *);
328
char * function_pop (char *, char *);
329
char * function_shift (char *, char *);
330
char * function_unshift (char *, char *);
331
static char * function_get_info (char *, char *);
332
static char * function_set_info (char *, char *);
333
static char * function_statsparse (char *, char *);
334
static char * function_absstrlen (char *, char *);
335
static char * function_findw (char *, char *);
336
static char * function_countansi (char *, char *);
337
static char * function_strstr (char *, char *);
338
static char * function_substr (char *, char *);
339
static char * function_longip (char *, char *);
340
static char * function_iplong (char *, char *);
341
static char * function_rword (char *, char *);
342
static char * function_winlen (char *, char *);
343
static char * function_isignored (char *, char *);
344
static char * function_channel (char *, char *);
345
static char * function_ftime (char *, char *);
346
static char * function_irclib (char *, char *);
347
static char * function_winbound (char *, char *);
348
static char * function_rstrstr (char *, char *);
349
static char * function_rsubstr (char *, char *);
350
static char * function_country (char *, char *);
351
static char * function_servernick (char *, char *);
352
static char * function_fparse (char *, char *);
353
static char * function_isconnected (char *, char *);
354
static char * function_bmatch (char *, char *);
355
static char * function_regcomp (char *, char *);
356
static char * function_regexec (char *, char *);
357
static char * function_regerror (char *, char *);
358
static char * function_regfree (char *, char *);
359
char * function_cdcc (char *, char *);
360
char * function_sendcdcc (char *, char *);
361
static char * function_count (char *, char *);
362
static char * function_msar (char *, char *);
363
static char * function_getcset (char *, char *);
364
365
static char * function_leftpc (char *, char *);
366
static char * function_mask (char *, char *);
367
static char * function_querywin (char *, char *);
368
static char * function_uname (char *, char *);
369
static char * function_winrefs (char *, char *);
370
371
static char * function_getgid (char *, char *);
372
static char * function_getlogin (char *, char *);
373
static char * function_getpgrp (char *, char *);
374
static char * function_getuid (char *, char *);
375
static char * function_iscurchan (char *, char *);
376
static char * function_remws (char *, char *);
377
static char * function_uhc (char *, char *);
378
static char * function_deuhc (char *, char *);
379
static char * function_getfsets (char *, char *);
380
static char * function_rest (char *, char *);
381
static char * function_isnumber (char *, char *);
382
static char * function_getsets (char *, char *);
383
static char * function_servref (char *, char *);
384
static char * function_getflags (char *, char *);
385
static char * function_numlines (char *, char *);
386
static char * function_winlevel (char *, char *);
387
static char * function_stripc (char *, char *);
388
static char * function_topic (char *, char *);
389
static char * function_stripcrap (char *, char *);
390
#if 0
391
static char * function_parse_and_return (char *, char *);
392
#endif
393
static char * function_dccitem (char *, char *);
394
static char * function_winitem (char *, char *);
395
static char * function_servgroup (char *, char *);
396
static char * function_ajoinitem (char *, char *);
397
static char * function_long_to_comma (char *, char *);
398
static char * function_nohighlight (char *, char *);
399
static char * function_getopt (char *, char *);
400
static char * function_isaway (char *, char *);
401
static char * function_banwords (char *, char *);
402
static char * function_hash_32bit (char *, char *);
403
404
static char * function_nickcomp (char *, char *);
405
static char * function_filecomp (char *, char *);
406
static char * function_log (char *, char *);
407
static char * function_indextoword (char *, char *);
408
static char * function_ttyname (char *, char *);
409
static char * function_functioncall (char *, char *);
410
static char * function_prefix (char *, char *);
411
static char * function_stat (char *, char *);
412
static char * function_maxlen (char *, char *);
413
static char * function_insert (char *, char *);
414
static char * function_realpath (char *, char *);
415
static char * function_serverlag (char *, char *);
416
static char * function_servports (char *, char *);
417
static char * function_isalnum (char *, char *);
418
static char * function_isspace (char *, char *);
419
static char * function_isxdigit (char *, char *);
420
static char * function_serverpass (char *, char *);
421
static char * function_igmask (char *, char *);
422
static char * function_rigmask (char *, char *);
423
static char * function_igtype (char *, char *);
424
static char * function_rigtype (char *, char *);
425
extern char * function_istimer (char *, char *);
426
static char * function_strchar (char *, char *);
427
static char * function_watch (char *, char *);
428
static char * function_getcap (char *, char *);
429
static char * function_isdisplaying (char *, char *);
430
static char * function_getset (char *, char *);
431
static char * function_builtin (char *, char *);
432
extern char * function_timer (char *, char *);
433
static char * function_runlevel (char *, char *);
434
static char * function_ovserver (char *, char *);
435
436
#ifdef GUI
437
static char * function_mciapi (char *, char *);
438
static char * function_lastclickline (char *, char *);
439
static char * function_lastclickx (char *, char *);
440
static char * function_lastclicky (char *, char *);
441
static char * function_screensize (char *, char *);
442
static char * function_menucontrol (char *, char *);
443
#endif
444
445
static char * function_ipv6 (char *, char *);
446
447
#undef BUILT_IN_FUNCTION
448
#define BUILT_IN_FUNCTION(x, y) static char * x (char *fn, char * y)
449
450
/*
451
* This is the built-in function list. This list *must* be sorted because
452
* it is binary searched. See the code for each function to see how it
453
* is used. Or see the help files. Or see both. Or look at the code
454
* and see how it REALLY works, irregardless of the documentation >;-)
455
*/
456
static BuiltInFunctions built_in_functions[] =
457
{
458
{ "ABSSTRLEN", function_absstrlen },
459
{ "ADDTABKEY", function_addtabkey },
460
{ "AFTER", function_after },
461
{ "AFTERW", function_afterw },
462
{ "AJOINITEM", function_ajoinitem },
463
{ "ALIASCTL", function_aliasctl },
464
{ "ASCII", function_ascii },
465
{ "BANONCHANNEL", function_banonchannel },
466
{ "BANWORDS", function_banwords },
467
{ "BCOPY", function_bcopy },
468
{ "BEFORE", function_before },
469
{ "BEFOREW", function_beforew },
470
{ "BITCHX", function_epic },
471
{ "BMATCH", function_bmatch },
472
{ "BUILTIN_EXPANDO", function_builtin },
473
{ "CENTER", function_center },
474
{ "CEXIST", function_cexist },
475
{ "CHANMODE", function_channelmode },
476
{ "CHANNEL", function_channel },
477
{ "CHANNICKS", function_channelnicks },
478
{ "CHANUSERS", function_onchannel },
479
{ "CHANWIN", function_chanwin },
480
{ "CHANWINDOW", function_chanwin },
481
{ "CHECKSHIT", function_checkshit },
482
{ "CHECKUSER", function_checkuser },
483
{ "CHMOD", function_chmod },
484
{ "CHNGW", function_chngw },
485
{ "CHOP", function_chop },
486
{ "CHOPS", function_chops },
487
{ "CHR", function_chr },
488
{ "CLOSE", function_close },
489
#ifndef BITCHX_LITE
490
{ "CLOSESOCKET", function_closeserver },
491
#endif
492
{ "CLUSTER", function_cluster },
493
{ "COMMON", function_common },
494
{ "CONNECT", function_connect },
495
{ "CONVERT", function_convert },
496
{ "COPATTERN", function_copattern },
497
{ "COUNT", function_count },
498
{ "COUNTANSI", function_countansi },
499
{ "COUNTRY", function_country },
500
{ "CPARSE", function_cparse },
501
{ "CRYPT", function_crypt },
502
{ "CURPOS", function_curpos },
503
{ "CURRCHANS", function_currchans },
504
{ "DCCITEM", function_dccitem },
505
{ "DECODE", (bf *)function_decode },
506
{ "DELARRAY", function_delarray },
507
{ "DELITEM", function_delitem },
508
{ "DEUHC", function_deuhc },
509
{ "DIFF", function_diff },
510
{ "ENCODE", (bf *)function_encode },
511
{ "EOF", function_eof },
512
{ "EPIC", function_epic },
513
{ "FEXIST", function_fexist },
514
{ "FILECOMP", function_filecomp },
515
{ "FILTER", function_filter },
516
{ "FINDITEM", function_finditem },
517
{ "FINDW", function_findw },
518
{ "FNEXIST", function_fnexist },
519
{ "FPARSE", function_fparse },
520
{ "FROMW", function_fromw },
521
{ "FSIZE", function_fsize },
522
{ "FTIME", function_ftime },
523
{ "FUNCTIONCALL", function_functioncall },
524
{ "GEOM", function_geom },
525
{ "GETARRAYS", function_getarrays },
526
{ "GETCAP", function_getcap },
527
{ "GETCDCC", function_cdcc },
528
{ "GETCSET", function_getcset },
529
{ "GETGID", function_getgid },
530
{ "GETENV", function_getenv },
531
{ "GETFLAGS", function_getflags },
532
{ "GETFSETS", function_getfsets },
533
{ "GETHOST", function_gethost },
534
{ "GETINFO", function_get_info },
535
{ "GETITEM", function_getitem },
536
{ "GETKEY", function_getkey },
537
{ "GETLOGIN", function_getlogin },
538
{ "GETMATCHES", function_getmatches },
539
{ "GETOPT", function_getopt },
540
{ "GETPGRP", function_getpgrp },
541
{ "GETREASON", function_getreason },
542
{ "GETRMATCHES", function_getrmatches },
543
{ "GETSET", function_getset },
544
{ "GETSETS", function_getsets },
545
{ "GETTABKEY", function_gettabkey },
546
{ "GETTMATCH", function_gettmatch },
547
{ "GETUID", function_getuid },
548
{ "GETVAR", function_getvar },
549
{ "GLOB", function_glob },
550
#ifdef GTK
551
{ "GTKBITCHX", function_epic },
552
#endif
553
{ "HASH_32BIT", function_hash_32bit },
554
{ "HELP", function_help },
555
{ "IDLE", function_idle },
556
{ "IFINDFIRST", function_ifindfirst },
557
{ "IFINDITEM", function_ifinditem },
558
{ "IGETITEM", function_igetitem },
559
{ "IGETMATCHES", function_igetmatches },
560
{ "IGMASK", function_igmask },
561
{ "IGTYPE", function_igtype },
562
{ "INDEX", function_index },
563
{ "INDEXTOITEM", function_indextoitem },
564
{ "INDEXTOWORD", function_indextoword },
565
{ "INFO", function_info },
566
{ "INSERT", function_insert },
567
{ "INSERTW", function_insertw },
568
{ "IPLONG", function_iplong },
569
{ "IPTONAME", function_iptoname },
570
{ "IPV6", function_ipv6 },
571
{ "IRCLIB", function_irclib },
572
{ "ISALNUM", function_isalnum },
573
{ "ISALPHA", function_isalpha },
574
{ "ISAWAY", function_isaway },
575
{ "ISBAN", function_isban },
576
{ "ISCHANNEL", function_ischannel },
577
{ "ISCHANOP", function_ischanop },
578
{ "ISCHANVOICE", function_isvoice },
579
{ "ISCONNECTED", function_isconnected },
580
{ "ISCURCHAN", function_iscurchan },
581
{ "ISDIGIT", function_isdigit },
582
{ "ISDISPLAYING", function_isdisplaying },
583
{ "ISHALFOP", function_ishalfop },
584
{ "ISIGNORED", function_isignored },
585
{ "ISNUMBER", function_isnumber },
586
{ "ISOP", function_isop },
587
{ "ISSPACE", function_isspace },
588
{ "ISTIMER", function_istimer },
589
{ "ISUSER", function_isuser },
590
{ "ISVOICE", function_isvoice },
591
{ "ISXDIGIT", function_isxdigit },
592
{ "ITEMTOINDEX", function_itemtoindex },
593
{ "JOT", function_jot },
594
{ "KEY", function_key },
595
{ "LAG", function_serverlag },
596
597
#ifdef GUI
598
{ "LASTCLICKLINE", function_lastclickline },
599
{ "LASTCLICKX", function_lastclickx },
600
{ "LASTCLICKY", function_lastclicky },
601
#endif
602
{ "LASTLOG", function_lastlog },
603
{ "LASTMESSAGE", function_lastmessage },
604
{ "LASTNOTICE", function_lastnotice },
605
{ "LASTSERVER", function_lastserver },
606
{ "LEFT", function_left },
607
{ "LEFTPC", function_leftpc },
608
{ "LEFTW", function_leftw },
609
{ "LENGTH", function_strlen },
610
{ "LINE", function_line },
611
{ "LISTARRAY", function_listarray },
612
{ "LISTEN", function_listen },
613
{ "LOG", function_log },
614
{ "LONGCOMMA", function_long_to_comma },
615
{ "LONGIP", function_longip },
616
{ "MASK", function_mask },
617
{ "MATCH", function_match },
618
{ "MATCHITEM", function_matchitem },
619
{ "MAXLEN", function_maxlen },
620
#ifdef GUI
621
{ "MCIAPI", function_mciapi },
622
{ "MENUCONTROL", function_menucontrol },
623
#endif
624
{ "MID", function_mid },
625
{ "MIDW", function_midw },
626
#ifndef BITCHX_LITE
627
{ "MIRCANSI", function_mircansi },
628
#endif
629
{ "MKDIR", function_mkdir },
630
{ "MSAR", function_msar },
631
{ "MYCHANNELS", function_channels },
632
{ "MYSERVERS", function_servers },
633
{ "NAMETOIP", function_nametoip },
634
{ "NICKCOMP", function_nickcomp },
635
{ "NOCHOPS", function_nochops },
636
{ "NOHIGHLIGHT", function_nohighlight },
637
{ "NOTIFY", function_notify },
638
{ "NOTW", function_notw },
639
{ "NUMARRAYS", function_numarrays },
640
{ "NUMDIFF", function_numdiff },
641
{ "NUMITEMS", function_numitems },
642
{ "NUMLINES", function_numlines },
643
{ "NUMONCHANNEL", function_numonchannel },
644
{ "NUMSORT", function_numsort },
645
{ "NUMWORDS", function_numwords },
646
{ "ONCHANNEL", function_onchannel },
647
{ "OPEN", function_open },
648
#ifndef BITCHX_LITE
649
{ "OPENSOCKET", function_openserver },
650
#endif
651
{ "OVSERVER", function_ovserver },
652
{ "PAD", function_pad },
653
#if 0
654
{ "PARSE", function_parse_and_return},
655
#endif
656
{ "PASS", function_pass },
657
{ "PATTERN", function_pattern },
658
{ "PID", function_pid },
659
#ifdef __EMXPM__
660
{ "PMBITCHX", function_epic },
661
#endif
662
{ "POP", function_pop },
663
{ "PPID", function_ppid },
664
{ "PREFIX", function_prefix },
665
{ "PRINTLEN", function_countansi },
666
{ "PUSH", function_push },
667
{ "QUERYWIN", function_querywin },
668
{ "RAND", function_rand },
669
{ "RANDOMNICK", function_randomnick },
670
{ "READ", function_read },
671
{ "REALPATH", function_realpath },
672
{ "REGCOMP", function_regcomp },
673
{ "REGERROR", function_regerror },
674
{ "REGEXEC", function_regexec },
675
{ "REGFREE", function_regfree },
676
#ifndef BITCHX_LITE
677
{ "READCHAR", function_readchar },
678
{ "READSOCKET", function_readserver },
679
#endif
680
{ "REMW", function_remw },
681
{ "REMWS", function_remws },
682
{ "RENAME", function_rename },
683
{ "REPEAT", function_repeat },
684
{ "REST", function_rest },
685
{ "RESTW", function_restw },
686
{ "REVERSE", function_reverse },
687
{ "REVW", function_revw },
688
{ "RFILTER", function_rfilter },
689
{ "RIGHT", function_right },
690
{ "RIGHTW", function_rightw },
691
{ "RIGMASK", function_rigmask },
692
{ "RIGTYPE", function_rigtype },
693
{ "RINDEX", function_rindex },
694
{ "RMATCH", function_rmatch },
695
{ "RMATCHITEM", function_rmatchitem },
696
{ "RMDIR", function_rmdir },
697
{ "ROT13", function_rot13 },
698
{ "RPATTERN", function_rpattern },
699
{ "RSTRSTR", function_rstrstr },
700
{ "RSUBSTR", function_rsubstr },
701
{ "RUNLEVEL", function_runlevel },
702
{ "RWORD", function_rword },
703
{ "SAR", function_sar },
704
#ifdef GUI
705
{ "SCREENSIZE", function_screensize },
706
#endif
707
{ "SENDCDCC", function_sendcdcc },
708
{ "SERVERGROUP", function_servgroup },
709
{ "SERVERNAME", function_servername },
710
{ "SERVERNICK", function_servernick },
711
{ "SERVERNUM", function_servref },
712
{ "SERVERPASS", function_serverpass },
713
{ "SERVPORTS", function_servports },
714
{ "SETINFO", function_set_info },
715
{ "SERVERPORT", function_servports },
716
{ "SETITEM", function_setitem },
717
{ "SHIFT", function_shift },
718
{ "SORT", function_sort },
719
{ "SPLICE", function_splice },
720
{ "SPLIT", function_split },
721
{ "SRAND", function_srand },
722
{ "STAT", function_stat },
723
{ "STATSPARSE", function_statsparse },
724
{ "STATUS", function_status },
725
{ "STIME", function_stime },
726
{ "STRCHR", function_strchar },
727
{ "STRFTIME", function_strftime },
728
{ "STRIP", function_strip },
729
{ "STRIPANSI", function_stripansi },
730
{ "STRIPANSICODES", function_stripansicodes },
731
{ "STRIPC", function_stripc },
732
{ "STRIPCRAP", function_stripcrap },
733
#ifndef BITCHX_LITE
734
{ "STRIPMIRC", function_stripc },
735
#endif
736
{ "STRLEN", function_strlen },
737
{ "STRRCHR", function_strchar },
738
{ "STRSTR", function_strstr },
739
{ "SUBSTR", function_substr },
740
{ "TDIFF", function_tdiff },
741
{ "TDIFF2", function_tdiff2 },
742
{ "TIME", function_time },
743
{ "TIMER", function_timer },
744
{ "TIMEREXISTS", function_istimer },
745
{ "TOLOWER", function_tolower },
746
{ "TOPIC", function_topic },
747
{ "TOUPPER", function_toupper },
748
{ "TOW", function_tow },
749
{ "TR", function_translate },
750
{ "TRUNC", function_truncate },
751
{ "TTYNAME", function_ttyname },
752
{ "TWIDDLE", function_twiddle },
753
{ "UHC", function_uhc },
754
{ "UHOST", function_uhost },
755
{ "UMASK", function_umask },
756
{ "UNAME", function_uname },
757
{ "UNIQ", function_uniq },
758
{ "UNLINK", function_unlink },
759
{ "UNSHIFT", function_unshift },
760
{ "UPTIME", function_uptime },
761
{ "USERHOST", function_userhost },
762
{ "USERMODE", function_umode },
763
{ "UTIME", function_utime },
764
{ "VERSION", function_server_version },
765
{ "WATCH", function_watch },
766
{ "WHICH", function_which },
767
{ "WINBOUND", function_winbound },
768
{ "WINCHAN", function_chanwin },
769
{ "WINITEM", function_winitem },
770
{ "WINLEN", function_winlen },
771
{ "WINLEVEL", function_winlevel },
772
{ "WINNAM", function_winnam },
773
{ "WINNICKLIST", function_winnames },
774
{ "WINNUM", function_winnum },
775
{ "WINREFS", function_winrefs },
776
{ "WINSERV", function_winserv },
777
{ "WINSIZE", function_winsize },
778
{ "WINVISIBLE", function_winvisible },
779
{ "WORD", function_word },
780
{ "WRITE", function_write },
781
{ "WRITEB", function_writeb },
782
#ifndef BITCHX_LITE
783
{ "WRITESOCKET", function_writeserver },
784
#endif
785
{ NULL, NULL }
786
};
787
788
#define NUMBER_OF_FUNCTIONS (sizeof(built_in_functions) / sizeof(BuiltInFunctions)) - 2
789
790
#include "hash2.h"
791
792
#define FUNCTION_HASHSIZE 251
793
HashEntry functions[FUNCTION_HASHSIZE] = { { NULL } };
794
795
int done_init_functions = 0;
796
797
798
static int func_exist (char *name)
799
{
800
int cnt, pos;
801
char *tmp;
802
803
tmp = LOCAL_COPY(name);
804
upper(tmp);
805
806
find_fixed_array_item(built_in_functions, sizeof(BuiltInFunctions), NUMBER_OF_FUNCTIONS + 1, tmp, &cnt, &pos);
807
if (cnt < 0)
808
return 1;
809
810
return 0;
811
}
812
813
int in_cparse = 0;
814
815
#ifdef WANT_TCL
816
817
void add_tcl_alias (Tcl_Interp *tcl_interp, void *func1, void *func2)
818
{
819
int i = 0;
820
char str[80];
821
while (built_in_functions[i].func)
822
{
823
sprintf(str, "_%s", built_in_functions[i].name);
824
Tcl_CreateCommand(tcl_interp, lower(str), func1?func1:built_in_functions[i].func, NULL, NULL);
825
i++;
826
}
827
i = 0;
828
while (built_in[i].func)
829
{
830
sprintf(str, "_%c", built_in[i].name);
831
Tcl_CreateCommand(tcl_interp, str, func2?func2:built_in[i].func, NULL, NULL);
832
i++;
833
}
834
}
835
836
#endif
837
838
typedef struct _built_in_new {
839
struct _built_in_new *next;
840
char *name;
841
char *(*func)(char *, char *);
842
} NewBuiltInFunctions;
843
844
static inline void move_link_to_top(NewBuiltInFunctions *tmp, NewBuiltInFunctions *prev, HashEntry *location)
845
{
846
if (prev)
847
{
848
NewBuiltInFunctions *old_list;
849
old_list = (NewBuiltInFunctions *) location->list;
850
location->list = (void *) tmp;
851
prev->next = tmp->next;
852
tmp->next = old_list;
853
}
854
}
855
856
static void init_functions(void)
857
{
858
int i;
859
unsigned long hash;
860
NewBuiltInFunctions *new;
861
862
for (i = 0; i <= NUMBER_OF_FUNCTIONS; i++)
863
{
864
if (!built_in_functions[i].func)
865
break;
866
hash = hash_nickname(built_in_functions[i].name, FUNCTION_HASHSIZE);
867
new = (NewBuiltInFunctions *)new_malloc(sizeof(NewBuiltInFunctions));
868
new->name = built_in_functions[i].name;
869
new->func = built_in_functions[i].func;
870
new->next = (NewBuiltInFunctions *)functions[hash].list;
871
functions[hash].list = (void *) new;
872
functions[hash].links++;
873
}
874
done_init_functions++;
875
}
876
877
BUILT_IN_COMMAND(debugfunc)
878
{
879
NewBuiltInFunctions *ptr;
880
int i;
881
for (i = 0; i < FUNCTION_HASHSIZE; i++)
882
{
883
if (!(ptr = (NewBuiltInFunctions *)functions[i].list))
884
continue;
885
while (ptr)
886
{
887
put_it("DEBUG_FUNC[%d]: %s %d links %d hits", i, ptr->name, functions[i].links, functions[i].hits);
888
ptr = ptr->next;
889
}
890
}
891
892
}
893
894
BuiltIns *find_func_aliasvar(char *name)
895
{
896
BuiltIns *tmp = NULL;
897
int i = 0;
898
while (built_in[i].func)
899
{
900
if (!(*name == built_in[i].name))
901
{
902
i++;
903
continue;
904
}
905
tmp = &built_in[i];
906
break;
907
}
908
return tmp;
909
}
910
911
BuiltInFunctions *find_func_alias(char *name)
912
{
913
unsigned long hash = 0;
914
HashEntry *location;
915
register NewBuiltInFunctions *tmp, *prev = NULL;
916
static BuiltInFunctions new;
917
918
if (!done_init_functions)
919
init_functions();
920
hash = hash_nickname(name, FUNCTION_HASHSIZE);
921
location = &functions[hash];
922
for (tmp = (NewBuiltInFunctions *)location->list; tmp; tmp = tmp->next)
923
{
924
if (!my_stricmp(name, tmp->name))
925
{
926
move_link_to_top(tmp, prev, location);
927
location->hits++;
928
new.name = tmp->name;
929
new.func = tmp->func;
930
return &new;
931
}
932
}
933
return NULL;
934
#if 0
935
while (built_in_functions[i].func && i <= NUMBER_OF_FUNCTIONS)
936
{
937
if (!my_stricmp(name, built_in_functions[i].name))
938
return &built_in_functions[i];
939
i++;
940
}
941
#endif
942
return NULL;
943
}
944
945
char **get_builtins(char *name, int *cnt)
946
{
947
char *last_match = NULL;
948
int matches_size = 5;
949
int i = 0;
950
int len;
951
char **matches = NULL;
952
#ifdef WANT_DLL
953
BuiltInDllFunctions *dll = NULL;
954
#endif
955
956
len = strlen(name);
957
*cnt = 0;
958
RESIZE(matches, char *, matches_size);
959
while (built_in_functions[i].func && i <= NUMBER_OF_FUNCTIONS)
960
{
961
if (strncmp(name, built_in_functions[i].name, len) == 0)
962
{
963
matches[*cnt] = NULL;
964
malloc_strcpy(&(matches[*cnt]), built_in_functions[i].name);
965
last_match = matches[*cnt];
966
if (++(*cnt) == matches_size)
967
{
968
matches_size += 5;
969
RESIZE(matches, char *, matches_size);
970
}
971
}
972
else if (*cnt)
973
break;
974
i++;
975
}
976
#ifdef WANT_DLL
977
for (dll = dll_functions; dll; dll = dll->next)
978
{
979
if (strncasecmp(name, dll->name, len) == 0)
980
{
981
matches[*cnt] = NULL;
982
malloc_strcpy(&(matches[*cnt]), dll->name);
983
if (++(*cnt) == matches_size)
984
{
985
matches_size += 5;
986
RESIZE(matches, char *, matches_size);
987
}
988
}
989
}
990
#endif
991
return matches;
992
}
993
994
char *built_in_alias (char c, int *returnval)
995
{
996
BuiltIns *tmp;
997
998
for (tmp = built_in;tmp->name;tmp++)
999
{
1000
if (c == tmp->name)
1001
{
1002
if (returnval)
1003
{
1004
*returnval = 1;
1005
return NULL;
1006
}
1007
else
1008
return tmp->func();
1009
}
1010
}
1011
return NULL;
1012
}
1013
1014
char *call_function (char *name, const char *args, int *args_flag)
1015
{
1016
extern char *check_tcl_alias (char *command, char *args);
1017
char *tmp;
1018
char *result = NULL;
1019
char *debug_copy = NULL;
1020
BuiltInFunctions *funcptr = NULL;
1021
#ifdef WANT_DLL
1022
register BuiltInDllFunctions *dll = NULL;
1023
#endif
1024
char *lparen, *rparen;
1025
1026
if ((lparen = strchr(name, '(')))
1027
{
1028
if ((rparen = MatchingBracket(lparen + 1, '(', ')')))
1029
*rparen++ = 0;
1030
else
1031
debugyell("Unmatched lparen in function call [%s]", name);
1032
1033
*lparen++ = 0;
1034
}
1035
else
1036
lparen = empty_string;
1037
1038
tmp = expand_alias(lparen, args, args_flag, NULL);
1039
if ((internal_debug & DEBUG_FUNC) && !in_debug_yell)
1040
debug_copy = LOCAL_COPY(tmp);
1041
1042
upper(name);
1043
#ifdef WANT_DLL
1044
for (dll = dll_functions; dll; dll = dll->next)
1045
if (!strcasecmp(name, dll->name))
1046
break;
1047
if (dll)
1048
result = (dll->func)(name, tmp);
1049
else
1050
#endif
1051
{
1052
#ifdef WANT_TCL
1053
if (!(result = check_tcl_alias(name, tmp)))
1054
#endif
1055
{
1056
if ((funcptr = find_func_alias(name)))
1057
result = funcptr->func(name, tmp);
1058
else
1059
result = call_user_function(name, tmp);
1060
}
1061
}
1062
if (debug_copy && alias_debug)
1063
{
1064
#if 0
1065
if (!alias_debug)
1066
debugyell("Function %s(%s) returned %s", name, debug_copy, result);
1067
else
1068
#endif
1069
debugyell("%3d %s(%s) -> %s", debug_count++, name, debug_copy, result);
1070
}
1071
new_free(&tmp);
1072
return result;
1073
}
1074
1075
1076
extern char hook_name[];
1077
1078
/* built in expando functions */
1079
static char *alias_version_str1 (void) { return m_strdup(_VERSION_); }
1080
static char *alias_line (void) { return m_strdup(get_input()); }
1081
static char *alias_buffer (void) { return m_strdup(cut_buffer); }
1082
static char *alias_time (void) { return m_strdup(update_clock(GET_TIME)); }
1083
static char *alias_dollar (void) { return m_strdup("$"); }
1084
static char *alias_detected (void) { return m_strdup(last_notify_nick); }
1085
static char *alias_nick (void) { return m_strdup((current_window->server != -1? get_server_nickname(current_window->server) : empty_string)); }
1086
char *alias_away (void) { return m_strdup(get_server_away(from_server)); }
1087
static char *alias_sent_nick (void) { return m_strdup(get_server_sent_nick(from_server)); }
1088
static char *alias_recv_nick (void) { return m_strdup(get_server_recv_nick(from_server)); }
1089
static char *alias_msg_body (void) { return m_strdup(get_server_sent_body(from_server)); }
1090
static char *alias_joined_nick (void) { return m_strdup((joined_nick) ? joined_nick : empty_string); }
1091
static char *alias_public_nick (void) { return m_strdup((public_nick) ? public_nick : empty_string); }
1092
static char *alias_show_realname (void) { return m_strdup(realname); }
1093
static char *alias_version_str (void) { return m_strdup(irc_version); }
1094
static char *alias_invite (void) { return m_strdup((invite_channel) ? invite_channel : empty_string); }
1095
static char *alias_oper (void) { return m_strdup(get_server_operator(from_server) ? get_string_var(STATUS_OPER_VAR) : empty_string); }
1096
static char *alias_version (void) { return m_strdup(internal_version); }
1097
static char *alias_online (void) { return m_sprintf("%ld",(long)start_time); }
1098
static char *alias_idle (void) { return m_sprintf("%ld",now-idle_time); }
1099
static char *alias_show_userhost (void) { return m_strdup(get_server_userhost(from_server)); }
1100
static char *alias_current_numeric (void) { return m_sprintf("%03d", -current_numeric); }
1101
static char *alias_hookname (void) { return m_sprintf("%s", *hook_name?hook_name:empty_string); }
1102
static char *alias_thingansi (void) { return m_strdup(numeric_banner()); }
1103
static char *alias_uptime (void) { return m_sprintf("%s", convert_time(now-start_time)); }
1104
static char *alias_bitchx (void) { return m_strdup("[BX]"); }
1105
extern char *return_this_alias (void);
1106
static char *alias_thisaliasname (void) { return m_strdup(return_this_alias()); }
1107
static char *alias_serverlag (void) { return m_sprintf("%ld", get_server_lag(from_server)); }
1108
static char *alias_currentwindow (void) { return m_sprintf("%d", current_window ? current_window->refnum : 0); }
1109
static char *alias_serverlistsize (void) { return m_sprintf("%d", server_list_size()); }
1110
1111
#ifdef WANT_TCL
1112
extern char tcl_versionstr[];
1113
static char *alias_tclsupport (void) { return m_strdup(tcl_versionstr); }
1114
#else
1115
static char *alias_tclsupport (void) { return m_strdup(empty_string); }
1116
#endif
1117
static char *alias_currdir (void)
1118
{
1119
char *tmp = (char *)new_malloc(MAXPATHLEN+1);
1120
return getcwd(tmp, MAXPATHLEN);
1121
}
1122
1123
static char *alias_channel (void)
1124
{
1125
char *tmp;
1126
char buffer[BIG_BUFFER_SIZE+1];
1127
if ((tmp = get_current_channel_by_refnum(0)))
1128
{
1129
strlcpy(buffer, tmp, BIG_BUFFER_SIZE);
1130
tmp = double_quote(tmp, "{}()\"", buffer);
1131
#ifdef WANT_HEBREW
1132
if (get_int_var(HEBREW_TOGGLE_VAR))
1133
hebrew_process(tmp);
1134
#endif
1135
return m_strdup(tmp);
1136
}
1137
else
1138
return m_strdup(zero);
1139
}
1140
1141
static char *alias_server (void)
1142
{
1143
return m_strdup((parsing_server_index != -1) ?
1144
get_server_itsname(parsing_server_index) :
1145
(get_window_server(0) != -1) ?
1146
get_server_itsname(get_window_server(0)) : empty_string);
1147
}
1148
1149
static char *alias_awaytime (void)
1150
{
1151
return m_sprintf("%lu", parsing_server_index != -1 ?
1152
get_server_awaytime(parsing_server_index):
1153
get_window_server(0) != -1 ?
1154
get_server_awaytime(get_window_server(0)):
1155
0);
1156
}
1157
1158
static char *alias_current_network (void)
1159
{
1160
return m_strdup((parsing_server_index != -1) ?
1161
get_server_network(parsing_server_index) :
1162
(get_window_server(0) != -1) ?
1163
get_server_network(get_window_server(0)) : empty_string);
1164
}
1165
1166
static char *alias_serverport (void)
1167
{
1168
return m_sprintf("%d", (parsing_server_index != -1) ?
1169
get_server_port(parsing_server_index):
1170
(get_window_server(0) != -1) ?
1171
get_server_port(get_window_server(0)) : 0);
1172
}
1173
1174
static char *alias_query_nick (void)
1175
{
1176
char *tmp;
1177
return m_strdup((tmp = current_window->query_nick) ? tmp : empty_string);
1178
}
1179
1180
static char *alias_target (void)
1181
{
1182
char *tmp;
1183
return m_strdup((tmp = get_target_by_refnum(0)) ? tmp : empty_string);
1184
}
1185
1186
static char *alias_cmdchar (void)
1187
{
1188
char *cmdchars, tmp[2];
1189
1190
if ((cmdchars = get_string_var(CMDCHARS_VAR)) == NULL)
1191
cmdchars = DEFAULT_CMDCHARS;
1192
tmp[0] = cmdchars[0];
1193
tmp[1] = 0;
1194
return m_strdup(tmp);
1195
}
1196
1197
static char *alias_chanop (void)
1198
{
1199
char *tmp;
1200
return m_strdup(((tmp = get_current_channel_by_refnum(0)) && get_channel_oper(tmp, from_server)) ?
1201
"@" : empty_string);
1202
}
1203
1204
static char *alias_modes (void)
1205
{
1206
char *tmp;
1207
return m_strdup((tmp = get_current_channel_by_refnum(0)) ?
1208
get_channel_mode(tmp, from_server) : empty_string);
1209
}
1210
1211
static char *alias_server_version (void)
1212
{
1213
int s = from_server;
1214
1215
if (s == -1)
1216
{
1217
if (primary_server != -1)
1218
s = primary_server;
1219
else
1220
return m_strdup(empty_string);
1221
}
1222
1223
return m_strdup(get_server_version_string(s));
1224
}
1225
1226
1227
/* * * * * * * * * *
1228
These are the built-in functions.
1229
1230
About 80 of them are here, the rest are in array.c. All of the
1231
stock client's functions are supported, as well as about 60 more.
1232
Most of the 30 stock client's functions have been re-written for
1233
optimization reasons, and also to further distance ircii's code
1234
from EPIC.
1235
* * * * * * * * * */
1236
1237
/*
1238
* These are defined to make the construction of the built-in functions
1239
* easier and less prone to bugs and unexpected behaviors. As long as
1240
* you consistently use these macros to do the dirty work for you, you
1241
* will never have to do bounds checking as the macros do that for you. >;-)
1242
*
1243
* Yes, i realize it makes the code slightly less efficient, but i feel that
1244
* the cost is minimal compared to how much time i have spent over the last
1245
* year debugging these functions and the fact i wont have to again. ;-)
1246
*/
1247
1248
#define EMPTY empty_string
1249
#define EMPTY_STRING m_strdup(EMPTY)
1250
#define RETURN_EMPTY return EMPTY_STRING
1251
#define RETURN_IF_EMPTY(x) if (empty( x )) RETURN_EMPTY
1252
#define GET_INT_ARG(x, y) {RETURN_IF_EMPTY(y); x = atol(safe_new_next_arg(y, &y));}
1253
#define GET_FLOAT_ARG(x, y) {RETURN_IF_EMPTY(y); x = atof(safe_new_next_arg(y, &y));}
1254
#define GET_STR_ARG(x, y) {RETURN_IF_EMPTY(y); x = new_next_arg(y, &y);RETURN_IF_EMPTY(x);}
1255
#define RETURN_STR(x) return m_strdup(x ? x : EMPTY)
1256
#define RETURN_MSTR(x) return ((x) ? (x) : EMPTY_STRING);
1257
#define RETURN_INT(x) return m_strdup(ltoa(x))
1258
1259
#undef BUILT_IN_FUNCTION
1260
#define BUILT_IN_FUNCTION(x, y) static char * x (char *fn, char * y)
1261
1262
/*
1263
* Usage: $left(number text)
1264
* Returns: the <number> leftmost characters in <text>.
1265
* Example: $left(5 the quick brown frog) returns "the q"
1266
*
1267
* Note: the difference between $[10]foo and $left(10 foo) is that the former
1268
* is padded and the latter is not.
1269
*/
1270
BUILT_IN_FUNCTION(function_left, input)
1271
{
1272
long count;
1273
1274
GET_INT_ARG(count, input);
1275
RETURN_IF_EMPTY(input);
1276
if (count < 0)
1277
RETURN_EMPTY;
1278
1279
if (strlen(input) > count)
1280
input[count] = 0;
1281
1282
RETURN_STR(input);
1283
}
1284
1285
char *function_getkey(char *n, char *input)
1286
{
1287
char *temp;
1288
RETURN_IF_EMPTY(input);
1289
temp = get_channel_key(input, from_server);
1290
RETURN_STR(temp);
1291
}
1292
1293
/*
1294
* Usage: $right(number text)
1295
* Returns: the <number> rightmost characters in <text>.
1296
* Example: $right(5 the quick brown frog) returns " frog"
1297
*/
1298
BUILT_IN_FUNCTION(function_right, word)
1299
{
1300
long count;
1301
1302
GET_INT_ARG(count, word);
1303
RETURN_IF_EMPTY(word);
1304
if (count < 0)
1305
RETURN_EMPTY;
1306
1307
if (strlen(word) > count)
1308
word += strlen(word) - count;
1309
1310
RETURN_STR(word);
1311
}
1312
1313
/*
1314
* Usage: $mid(start number text)
1315
* Returns: the <start>th through <start>+<number>th characters in <text>.
1316
* Example: $mid(3 4 the quick brown frog) returns " qui"
1317
*
1318
* Note: the first character is numbered zero.
1319
*/
1320
BUILT_IN_FUNCTION(function_mid, word)
1321
{
1322
long start, length;
1323
1324
GET_INT_ARG(start, word);
1325
GET_INT_ARG(length, word);
1326
RETURN_IF_EMPTY(word);
1327
1328
if (start < strlen(word))
1329
{
1330
word += start;
1331
if (length < 0)
1332
RETURN_EMPTY;
1333
if (length < strlen(word))
1334
word[length] = 0;
1335
}
1336
else
1337
word = EMPTY;
1338
1339
RETURN_STR(word);
1340
}
1341
1342
1343
/*
1344
* Usage: $rand(max)
1345
* Returns: A random number from zero to max-1.
1346
* Example: $rand(10) might return any number from 0 to 9.
1347
*/
1348
BUILT_IN_FUNCTION(function_rand, word)
1349
{
1350
long tempin;
1351
int result;
1352
1353
GET_INT_ARG(tempin, word);
1354
if (tempin == 0)
1355
tempin = (unsigned long) -1; /* This is cheating. :P */
1356
result = random_number(0L) % tempin;
1357
RETURN_INT(result);
1358
}
1359
1360
/*
1361
* Usage: $srand(seed)
1362
* Returns: Nothing.
1363
* Side effect: seeds the random number generater.
1364
* Note: the argument is ignored.
1365
*/
1366
BUILT_IN_FUNCTION(function_srand, word)
1367
{
1368
random_number((long) now);
1369
RETURN_EMPTY;
1370
}
1371
1372
/*
1373
* Usage: $time()
1374
* Returns: The number of seconds that has elapsed since Jan 1, 1970, GMT.
1375
* Example: $time() returned something around 802835348 at the time I
1376
* wrote this comment.
1377
*/
1378
BUILT_IN_FUNCTION(function_time, input)
1379
{
1380
RETURN_INT(time(NULL));
1381
}
1382
1383
/*
1384
* Usage: $stime(time)
1385
* Returns: The human-readable form of the date based on the <time> argument.
1386
* Example: $stime(1000) returns what time it was 1000 seconds froM the epoch.
1387
*
1388
* Note: $stime() is really useful when you givE it the argument $time(), ala
1389
* $stime($time()) is the human readable form for now.
1390
*/
1391
BUILT_IN_FUNCTION(function_stime, input)
1392
{
1393
time_t ltime;
1394
1395
GET_INT_ARG(ltime, input);
1396
RETURN_STR(my_ctime(ltime));
1397
}
1398
1399
/*
1400
* Usage: $tdiff(seconds)
1401
* Returns: The time that has elapsed represented in days/hours/minutes/seconds
1402
* corresponding to the number of seconds passed as the argument.
1403
* Example: $tdiff(3663) returns "1 hour 1 minute 3 seconds"
1404
*/
1405
BUILT_IN_FUNCTION(function_tdiff, input)
1406
{
1407
long ltime;
1408
1409
long days = 0,
1410
hours = 0,
1411
minutes = 0,
1412
seconds = 0;
1413
char *tstr, *tmp;
1414
char *after = NULL;
1415
1416
tmp = alloca(strlen(input) + 180);
1417
*tmp = 0;
1418
1419
ltime = strtol(input, &after, 10);
1420
tstr = tmp;
1421
1422
if (after > input)
1423
{
1424
seconds = ltime % 60;
1425
ltime = (ltime - seconds) / 60;
1426
minutes = ltime % 60;
1427
ltime = (ltime - minutes) / 60;
1428
hours = ltime % 24;
1429
days = (ltime - hours) / 24;
1430
1431
if (days)
1432
{
1433
sprintf(tstr, "%ld day%s ", days, plural(days));
1434
tstr += strlen(tstr);
1435
}
1436
if (hours)
1437
{
1438
sprintf(tstr, "%ld hour%s ", hours, plural(hours));
1439
tstr += strlen(tstr);
1440
}
1441
if (minutes)
1442
{
1443
sprintf(tstr, "%ld minute%s ", minutes, plural(minutes));
1444
tstr += strlen(tstr);
1445
}
1446
}
1447
if (seconds || (!days && !hours && !minutes) || (*after == '.' && is_number(after + 1)))
1448
{
1449
long number = 0;
1450
/*
1451
* If we have a decmial point, and is_number() returns 1,
1452
* then we know that we have a real, authentic number AFTER
1453
* the decmial point. As long as it isnt zero, we want it.
1454
*/
1455
if (*after == '.')
1456
number = atol(after + 1);
1457
1458
/*
1459
* *IF* and *ONLY IF* either the seconds OR the decmial
1460
* part of the number is non zero do we tack on the seconds
1461
* argument. If both are zero, we do nothing.
1462
*/
1463
if (seconds != 0 || number != 0)
1464
{
1465
if (number == 0)
1466
sprintf(tstr, "%ld second%s", seconds, plural(seconds));
1467
else
1468
sprintf(tstr, "%ld%s seconds", seconds, after);
1469
}
1470
}
1471
else
1472
*--tstr = 0;
1473
1474
RETURN_STR(tmp);
1475
}
1476
1477
/*
1478
* Usage: $index(characters text)
1479
* Returns: The number of leading characters in <text> that do not occur
1480
* anywhere in the <characters> argument.
1481
* Example: $index(f three fine frogs) returns 6 (the 'f' in 'fine')
1482
* $index(frg three fine frogs) returns 2 (the 'r' in 'three')
1483
*/
1484
BUILT_IN_FUNCTION(function_index, input)
1485
{
1486
char *schars;
1487
char *iloc;
1488
1489
GET_STR_ARG(schars, input);
1490
iloc = sindex(input, schars);
1491
RETURN_INT(iloc ? iloc - input : -1);
1492
}
1493
1494
/*
1495
* Usage: $rindex(characters text)
1496
* Returns: The number of leading characters in <text> that occur before the
1497
* *last* occurance of any of the characters in the <characters>
1498
* argument.
1499
* Example: $rindex(f three fine frogs) returns 12 (the 'f' in 'frogs')
1500
* $rindex(frg three fine frogs) returns 15 (the 'g' in 'froGs')
1501
*/
1502
BUILT_IN_FUNCTION(function_rindex, word)
1503
{
1504
char *chars, *last;
1505
1506
/* need to find out why ^x doesnt work */
1507
GET_STR_ARG(chars, word);
1508
last = rsindex(word + strlen(word) - 1, word, chars, 1);
1509
RETURN_INT(last ? last - word : -1);
1510
}
1511
1512
/*
1513
* Usage: $match(pattern list of words)
1514
* Returns: if no words in the list match the pattern, it returns 0.
1515
* Otherwise, it returns the number of the word that most
1516
* exactly matches the pattern (first word is numbered one)
1517
* Example: $match(f*bar foofum barfoo foobar) returns 3
1518
* $match(g*ant foofum barfoo foobar) returns 0
1519
*
1520
* Note: it is possible to embed spaces inside of a word or pattern simply
1521
* by including the entire word or pattern in quotation marks. (")
1522
*/
1523
BUILT_IN_FUNCTION(function_match, input)
1524
{
1525
char *pattern, *word;
1526
long current_match, best_match = 0, match = 0, match_index = 0;
1527
1528
GET_STR_ARG(pattern, input);
1529
1530
while (input && *input)
1531
{
1532
while (input && my_isspace(*input))
1533
input++;
1534
match_index++;
1535
GET_STR_ARG(word, input);
1536
if ((current_match = wild_match(pattern, word)) > best_match)
1537
{
1538
match = match_index;
1539
best_match = current_match;
1540
}
1541
}
1542
1543
RETURN_INT(match);
1544
}
1545
1546
/*
1547
* Usage: $rmatch(word list of patterns)
1548
* Returns: if no pattern in the list matches the word, it returns 0.
1549
* Otherwise, it returns the number of the pattern that most
1550
* exactly matches the word (first word is numbered one)
1551
* Example: $rmatch(foobar f*bar foo*ar g*ant) returns 2
1552
* $rmatch(booya f*bar foo*ar g*ant) returns 0
1553
*
1554
* Note: It is possible to embed spaces into a word or pattern simply by
1555
* including the entire word or pattern within quotation marks (")
1556
*/
1557
BUILT_IN_FUNCTION(function_rmatch, input)
1558
{
1559
char *pattern, *word;
1560
int current_match, best_match = 0, match = 0, rmatch_index = 0;
1561
1562
GET_STR_ARG(word, input);
1563
1564
while (input && *input)
1565
{
1566
while (input && my_isspace(*input))
1567
input++;
1568
rmatch_index++;
1569
GET_STR_ARG(pattern, input);
1570
if ((current_match = wild_match(pattern, word)) > best_match)
1571
{
1572
match = rmatch_index;
1573
best_match = current_match;
1574
}
1575
/* WARNING WARNING HACK IN PROGRESS WARNING WARNING */
1576
while (input && my_isspace(*input))
1577
input++;
1578
}
1579
1580
RETURN_INT(match);
1581
}
1582
1583
/*
1584
* Usage: $userhost()
1585
* Returns: the userhost (if any) of the most previously recieved message.
1586
* Caveat: $userhost() changes with every single line that appears on
1587
* your screen, so if you want to save it, you will need to assign
1588
* it to a variable.
1589
*/
1590
BUILT_IN_FUNCTION(function_userhost, input)
1591
{
1592
if (input && *input)
1593
{
1594
char *retval = NULL;
1595
char *nick;
1596
const char *userhost;
1597
1598
while (input && *input)
1599
{
1600
GET_STR_ARG(nick, input);
1601
if ((userhost = fetch_userhost(from_server, nick)))
1602
m_s3cat(&retval, space, userhost);
1603
else
1604
m_s3cat(&retval, space, unknown_userhost);
1605
}
1606
return retval; /* DONT USE RETURN_STR HERE! */
1607
}
1608
RETURN_STR(FromUserHost);
1609
}
1610
1611
/*
1612
* Usage: $strip(characters text)
1613
* Returns: <text> with all instances of any characters in the <characters>
1614
* argument removed.
1615
* Example: $strip(f free fine frogs) returns "ree ine rogs"
1616
*
1617
* Note: it can be difficult (actually, not possible) to remove spaces from
1618
* a string using this function. To remove spaces, simply use this:
1619
* $tr(/ //$text)
1620
*
1621
* Actually, i recommend not using $strip() at all and just using
1622
* $tr(/characters//$text)
1623
* (but then again, im biased. >;-)
1624
*/
1625
BUILT_IN_FUNCTION(function_strip, input)
1626
{
1627
char *result;
1628
char *chars;
1629
char *cp, *dp;
1630
1631
GET_STR_ARG(chars, input);
1632
RETURN_IF_EMPTY(input);
1633
1634
result = (char *)new_malloc(strlen(input) + 1);
1635
for (cp = input, dp = result; *cp; cp++)
1636
{
1637
/* This is expensive -- gotta be a better way */
1638
if (!strchr(chars, *cp))
1639
*dp++ = *cp;
1640
}
1641
*dp = '\0';
1642
1643
return result; /* DONT USE RETURN_STR HERE! */
1644
}
1645
1646
/*
1647
* Usage: $encode(text)
1648
* Returns: a string, uniquely identified with <text> such that the string
1649
* can be used as a variable name.
1650
* Example: $encode(fe fi fo fum) returns "GGGFCAGGGJCAGGGPCAGGHFGN"
1651
*
1652
* Note: $encode($decode(text)) returns text (most of the time)
1653
* $decode($encode(text)) also returns text.
1654
*/
1655
static char * function_encode (char *n, unsigned char * input)
1656
{
1657
char *result;
1658
int i = 0;
1659
1660
result = (char *)new_malloc(strlen((char *)input) * 2 + 1);
1661
while (*input)
1662
{
1663
result[i++] = (*input >> 4) + 0x41;
1664
result[i++] = (*input & 0x0f) + 0x41;
1665
input++;
1666
}
1667
result[i] = '\0';
1668
1669
return result; /* DONT USE RETURN_STR HERE! */
1670
}
1671
1672
1673
/*
1674
* Usage: $decode(text)
1675
* Returns: If <text> was generated with $encode(), it returns the string
1676
* you originally encoded. If it wasnt, you will probably get
1677
* nothing useful in particular.
1678
* Example: $decode(GGGFCAGGGJCAGGGPCAGGHFGN) returns "fe fi fo fum"
1679
*
1680
* Note: $encode($decode(text)) returns "text"
1681
* $decode($encode(text)) returns "text" too.
1682
*
1683
* Note: Yes. $decode(plain-text) does compress the data by a factor of 2.
1684
* But it ignores non-ascii text, so use this as compression at your
1685
* own risk and peril.
1686
*/
1687
char *function_decode(char *n, unsigned char * input)
1688
{
1689
unsigned char *result;
1690
int i = 0;
1691
1692
result = (unsigned char *)new_malloc(strlen((char *)input) / 2 + 1);
1693
1694
while (input[0] && input[1])
1695
{
1696
/* oops, this isnt quite right. */
1697
result[i] = ((input[0] - 0x41) << 4) | (input[1] - 0x41);
1698
input += 2;
1699
i++;
1700
}
1701
result[i] = '\0';
1702
1703
return result; /* DONT USE RETURN_STR HERE! */
1704
}
1705
1706
1707
/*
1708
* Usage: $ischannel(text)
1709
* Returns: If <text> could be a valid channel name, 1 is returned.
1710
* If <text> is an illegal channel name, 0 is returned.
1711
*
1712
* Note: Contrary to popular belief, this function does NOT determine
1713
* whether a given channel name is in use!
1714
*/
1715
BUILT_IN_FUNCTION(function_ischannel, input)
1716
{
1717
RETURN_INT(is_channel(input));
1718
}
1719
1720
/*
1721
* Usage: $ischanop(nick channel)
1722
* Returns: 1 if <nick> is a channel operator on <channel>
1723
* 0 if <nick> is not a channel operator on <channel>
1724
* * O R *
1725
* if you are not on <channel>
1726
*
1727
* Note: Contrary to popular belief, this function can only tell you
1728
* who the channel operators are for channels you are already on!
1729
*
1730
* Boo Hiss: This should be $ischanop(channel nick <nick...nick>)
1731
* and return a list (1 1 ... 0), which would allow us to
1732
* call is_chanop() without ripping off the nick, and allow
1733
* us to abstract is_chanop() to take a list. oh well...
1734
* Too late to change it now. :/
1735
*/
1736
BUILT_IN_FUNCTION(function_ischanop, input)
1737
{
1738
char *nick;
1739
1740
GET_STR_ARG(nick, input);
1741
if (is_channel(nick))
1742
{
1743
char *blah;
1744
blah = is_chanoper(nick, input);
1745
return blah ? blah : m_strdup(empty_string);
1746
}
1747
else
1748
RETURN_INT(is_chanop(input, nick));
1749
}
1750
1751
/*
1752
* Usage: $ishalfop(nick channel)
1753
* Returns: 1 if <nick> is a channel half-op on <channel>
1754
* 0 if <nick> is not a channel half-op on <channel>
1755
* * O R *
1756
* if you are not on <channel>
1757
*
1758
*/
1759
BUILT_IN_FUNCTION(function_ishalfop, input)
1760
{
1761
char *nick;
1762
1763
GET_STR_ARG(nick, input);
1764
RETURN_INT(is_halfop(input, nick));
1765
}
1766
1767
1768
/*
1769
* Usage: $word(jUmber text)
1770
* Returns: the <number>th word in <text>. The first word is numbered zero.
1771
* Example: $word(3 one two three four five) returns "four" (think about it)
1772
*/
1773
BUILT_IN_FUNCTION(function_word, word)
1774
{
1775
int cvalue;
1776
char *w_word;
1777
1778
GET_INT_ARG(cvalue, word);
1779
if (cvalue < 0)
1780
RETURN_EMPTY;
1781
1782
while (cvalue-- > 0)
1783
GET_STR_ARG(w_word, word);
1784
1785
GET_STR_ARG(w_word, word);
1786
RETURN_STR(w_word);
1787
}
1788
1789
1790
/*
1791
* Usage: $winnum()
1792
* Returns: the index number for the current window
1793
*
1794
* Note: returns -1 if there are no windows open (ie, in dumb mode)
1795
*/
1796
BUILT_IN_FUNCTION(function_winnum, input)
1797
{
1798
Window *win = NULL;
1799
if (!(win = *input ? get_window_by_desc(input) : current_window))
1800
RETURN_INT(-1);
1801
RETURN_INT(win->refnum);
1802
}
1803
1804
BUILT_IN_FUNCTION(function_winnam, input)
1805
{
1806
Window *win = NULL;
1807
if (!(win = *input ? get_window_by_desc(input) : current_window))
1808
RETURN_EMPTY;
1809
RETURN_STR(win->name);
1810
}
1811
1812
BUILT_IN_FUNCTION(function_winnames, input)
1813
{
1814
Window *win = NULL;
1815
char *s = NULL;
1816
if (*input)
1817
win = get_window_by_desc(input);
1818
else
1819
win = current_window;
1820
if (!win)
1821
RETURN_EMPTY;
1822
1823
return (s = get_nicklist_by_window(win)) ? s : m_strdup(empty_string);
1824
}
1825
1826
BUILT_IN_FUNCTION(function_connect, input)
1827
{
1828
char *host;
1829
int port;
1830
1831
GET_STR_ARG(host, input);
1832
GET_INT_ARG(port, input);
1833
1834
return dcc_raw_connect(host, port); /* DONT USE RETURN_STR HERE! */
1835
}
1836
1837
1838
BUILT_IN_FUNCTION(function_listen, input)
1839
{
1840
int port = 0;
1841
char *result;
1842
1843
/* Oops. found by CrowMan, listen() has a default. erf. */
1844
if (input && *input)
1845
{
1846
char *tmp, *ptr;
1847
if ((tmp = new_next_arg(input, &input)))
1848
{
1849
port = strtoul(tmp, &ptr, 10);
1850
if (ptr == tmp)
1851
RETURN_EMPTY; /* error. */
1852
}
1853
}
1854
1855
result = dcc_raw_listen(port);
1856
RETURN_STR(result); /* DONT REMOVE RESULT! */
1857
}
1858
1859
BUILT_IN_FUNCTION(function_toupper, input)
1860
{
1861
return (upper(m_strdup(input)));
1862
}
1863
1864
BUILT_IN_FUNCTION(function_tolower, input)
1865
{
1866
return (lower(m_strdup(input)));
1867
}
1868
1869
BUILT_IN_FUNCTION(function_curpos, input)
1870
{
1871
RETURN_INT(current_window->screen->buffer_pos);
1872
}
1873
1874
BUILT_IN_FUNCTION(function_channels, input)
1875
{
1876
long winnum;
1877
Window *window = current_window;
1878
1879
if (isdigit((unsigned char)*input))
1880
{
1881
GET_INT_ARG(winnum, input);
1882
window = get_window_by_refnum(winnum);
1883
}
1884
if (window->server <= -1)
1885
RETURN_EMPTY;
1886
return create_channel_list(window); /* DONT USE RETURN_STR HERE! */
1887
}
1888
1889
BUILT_IN_FUNCTION(function_servers, input)
1890
{
1891
return create_server_list(input); /* DONT USE RETURN_STR HERE! */
1892
}
1893
1894
BUILT_IN_FUNCTION(function_pid, input)
1895
{
1896
RETURN_INT(getpid());
1897
}
1898
1899
BUILT_IN_FUNCTION(function_ppid, input)
1900
{
1901
RETURN_INT(getppid());
1902
}
1903
1904
/*
1905
* strftime() patch from hari ([email protected])
1906
*/
1907
BUILT_IN_FUNCTION(function_strftime, input)
1908
{
1909
char result[128];
1910
time_t ltime;
1911
struct tm *tm;
1912
1913
if (isdigit((unsigned char)*input))
1914
ltime = strtoul(input, &input, 10);
1915
else
1916
ltime = now;
1917
1918
while (*input && my_isspace(*input))
1919
++input;
1920
1921
if (!*input)
1922
return m_strdup(empty_string);
1923
1924
1925
tm = localtime(&ltime);
1926
1927
if (!strftime(result, 128, input, tm))
1928
return m_strdup(empty_string);
1929
1930
return m_strdup(result);
1931
}
1932
1933
BUILT_IN_FUNCTION(function_idle, input)
1934
{
1935
return alias_idle();
1936
}
1937
1938
1939
1940
/* The new "added" functions */
1941
1942
/* $before(chars string of text)
1943
* returns the part of "string of text" that occurs before the
1944
* first instance of any character in "chars"
1945
* EX: $before(! [email protected]) returns "hop"
1946
*/
1947
BUILT_IN_FUNCTION(function_before, word)
1948
{
1949
char *pointer = NULL;
1950
char *chars;
1951
char *tmp;
1952
long numint;
1953
1954
GET_STR_ARG(tmp, word); /* DONT DELETE TMP! */
1955
numint = atol(tmp);
1956
1957
if (numint)
1958
{
1959
GET_STR_ARG(chars, word);
1960
}
1961
else
1962
{
1963
numint = 1;
1964
chars = tmp;
1965
}
1966
1967
if (numint < 0 && strlen(word))
1968
pointer = word + strlen(word) - 1;
1969
1970
pointer = strsearch(word, pointer, chars, numint);
1971
1972
if (!pointer)
1973
RETURN_EMPTY;
1974
1975
*pointer = '\0';
1976
RETURN_STR(word);
1977
}
1978
1979
/* $after(chars string of text)
1980
* returns the part of "string of text" that occurs after the
1981
* first instance of any character in "chars"
1982
* EX: $after(! [email protected]) returns "[email protected]"
1983
*/
1984
BUILT_IN_FUNCTION(function_after, word)
1985
{
1986
char *chars;
1987
char *pointer = NULL;
1988
char *tmp;
1989
long numint;
1990
1991
GET_STR_ARG(tmp, word);
1992
numint = atol(tmp);
1993
1994
if (numint)
1995
chars = new_next_arg(word, &word);
1996
else
1997
{
1998
numint = 1;
1999
chars = tmp;
2000
}
2001
2002
if (numint < 0 && strlen(word))
2003
pointer = word + strlen(word) - 1;
2004
2005
pointer = strsearch(word, pointer, chars, numint);
2006
2007
if (!pointer || !*pointer)
2008
RETURN_EMPTY;
2009
2010
RETURN_STR(pointer + 1);
2011
}
2012
2013
/* $leftw(num string of text)
2014
* returns the left "num" words in "string of text"
2015
* EX: $leftw(3 now is the time for) returns "now is the"
2016
*/
2017
BUILT_IN_FUNCTION(function_leftw, word)
2018
{
2019
int value;
2020
2021
GET_INT_ARG(value, word);
2022
if (value < 1)
2023
RETURN_EMPTY;
2024
2025
return (extract(word, 0, value-1)); /* DONT USE RETURN_STR HERE! */
2026
}
2027
2028
/* $rightw(num string of text)
2029
* returns the right num words in "string of text"
2030
* EX: $rightw(3 now is the time for) returns "the time for"
2031
*/
2032
BUILT_IN_FUNCTION(function_rightw, word)
2033
{
2034
int value;
2035
2036
GET_INT_ARG(value, word);
2037
if (value < 1)
2038
RETURN_EMPTY;
2039
2040
return extract2(word, -value, EOS);
2041
}
2042
2043
2044
/* $midw(start num string of text)
2045
* returns "num" words starting at word "start" in the string "string of text"
2046
* NOTE: The first word is word #0.
2047
* EX: $midw(2 2 now is the time for) returns "the time"
2048
*/
2049
BUILT_IN_FUNCTION(function_midw, word)
2050
{
2051
int start, num;
2052
2053
GET_INT_ARG(start, word);
2054
GET_INT_ARG(num, word);
2055
2056
if (num < 1)
2057
RETURN_EMPTY;
2058
2059
return extract(word, start, (start + num - 1));
2060
}
2061
2062
/* $notw(num string of text)
2063
* returns "string of text" with word number "num" removed.
2064
* NOTE: The first word is numbered 0.
2065
* EX: $notw(3 now is the time for) returns "now is the for"
2066
*/
2067
BUILT_IN_FUNCTION(function_notw, word)
2068
{
2069
char *booya = NULL;
2070
int where;
2071
2072
GET_INT_ARG(where, word);
2073
2074
/* An illegal word simpli returns the string as-is */
2075
if (where < 0)
2076
RETURN_STR(word);
2077
2078
if (where > 0)
2079
{
2080
char *part1, *part2;
2081
part1 = extract(word, 0, (where - 1));
2082
part2 = extract(word, (where + 1), EOS);
2083
2084
booya = m_strdup(part1);
2085
m_s3cat_s(&booya, space, part2);
2086
new_free(&part1);
2087
new_free(&part2);
2088
}
2089
else /* where == 0 */
2090
booya = extract(word, 1, EOS);
2091
2092
return booya; /* DONT USE RETURN_STR HERE! */
2093
}
2094
2095
/* $restw(num string of text)
2096
* returns "string of text" that occurs starting with and including
2097
* word number "num"
2098
* NOTE: the first word is numbered 0.
2099
* EX: $restw(3 now is the time for) returns "time for"
2100
*/
2101
BUILT_IN_FUNCTION(function_restw, word)
2102
{
2103
int where;
2104
2105
GET_INT_ARG(where, word);
2106
if (where < 0)
2107
RETURN_EMPTY;
2108
return extract(word, where, EOS);
2109
}
2110
2111
/* $remw(word string of text)
2112
* returns "string of text" with the word "word" removed
2113
* EX: $remw(the now is the time for) returns "now is time for"
2114
*/
2115
BUILT_IN_FUNCTION(function_remw, word)
2116
{
2117
char *word_to_remove;
2118
int len;
2119
char *str;
2120
2121
GET_STR_ARG(word_to_remove, word);
2122
len = strlen(word_to_remove);
2123
2124
str = stristr(word, word_to_remove);
2125
for (; str && *str; str = stristr(str + 1, word_to_remove))
2126
{
2127
if (str == word || isspace((unsigned char)str[-1]))
2128
{
2129
if (!str[len] || isspace((unsigned char)str[len]))
2130
{
2131
if (!str[len])
2132
{
2133
if (str != word)
2134
str--;
2135
*str = 0;
2136
}
2137
else if (str > word)
2138
{
2139
char *safe = (char *)alloca(strlen(str));
2140
strcpy(safe, str + len);
2141
strcpy(str - 1, safe);
2142
}
2143
else
2144
{
2145
char *safe = (char *)alloca(strlen(str));
2146
strcpy(safe, str + len + 1);
2147
strcpy(str, safe);
2148
}
2149
break;
2150
}
2151
}
2152
}
2153
2154
RETURN_STR(word);
2155
}
2156
2157
/* $insertw(num word string of text)
2158
* returns "string of text" such that "word" is the "num"th word
2159
* in the string.
2160
* NOTE: the first word is numbered 0.
2161
* EX: $insertw(3 foo now is the time for) returns "now is the foo time for"
2162
*/
2163
BUILT_IN_FUNCTION(function_insertw, word)
2164
{
2165
int where;
2166
char *what;
2167
char *booya= NULL;
2168
char *str1, *str2;
2169
2170
GET_INT_ARG(where, word);
2171
2172
/* If the word goes at the front of the string, then it
2173
already is: return it. ;-) */
2174
if (where < 1)
2175
booya = m_strdup(word);
2176
else
2177
{
2178
GET_STR_ARG(what, word);
2179
str1 = extract(word, 0, (where - 1));
2180
str2 = extract(word, where, EOS);
2181
booya = m_strdup(str1);
2182
if (str1 && *str1)
2183
booya = m_2dup(str1, space);
2184
malloc_strcat(&booya, what);
2185
m_s3cat_s(&booya, space, str2);
2186
new_free(&str1);
2187
new_free(&str2);
2188
}
2189
2190
return booya; /* DONT USE RETURN_STR HERE! */
2191
}
2192
2193
/* $chngw(num word string of text)
2194
* returns "string of text" such that the "num"th word is removed
2195
* and replaced by "word"
2196
* NOTE: the first word is numbered 0
2197
* EX: $chngw(3 foo now is the time for) returns "now is the foo for"
2198
*/
2199
BUILT_IN_FUNCTION(function_chngw, word)
2200
{
2201
int which;
2202
char *what;
2203
char *booya= NULL;
2204
char *str1, *str2;
2205
2206
GET_INT_ARG(which, word);
2207
GET_STR_ARG(what, word);
2208
2209
if (which < 0)
2210
RETURN_STR(word);
2211
2212
/* hmmm. if which is 0, extract does the wrong thing. */
2213
str1 = extract(word, 0, which - 1);
2214
str2 = extract(word, which + 1, EOS);
2215
booya = m_strdup(str1);
2216
if (str1 && *str1)
2217
booya = m_2dup(str1, space);
2218
malloc_strcat(&booya, what);
2219
m_s3cat_s(&booya, space, str2);
2220
new_free(&str1);
2221
new_free(&str2);
2222
2223
return (booya);
2224
}
2225
2226
2227
/* $common (string of text / string of text)
2228
* Given two sets of words seperated by a forward-slash '/', returns
2229
* all words that are found in both sets.
2230
* EX: $common(one two three / buckle my two shoe one) returns "one two"
2231
* NOTE: returned in order found in first string.
2232
*/
2233
BUILT_IN_FUNCTION(function_common, word)
2234
{
2235
char *left = NULL, **leftw = NULL,
2236
*right = NULL, **rightw = NULL, *booya = NULL;
2237
int leftc, lefti;
2238
int rightc, righti;
2239
2240
left = word;
2241
if ((right = strchr(word,'/')) == NULL)
2242
RETURN_EMPTY;
2243
2244
*right++ = 0;
2245
leftc = splitw(left, &leftw);
2246
rightc = splitw(right, &rightw);
2247
2248
for (lefti = 0; lefti < leftc; lefti++)
2249
{
2250
for (righti = 0; righti < rightc; righti++)
2251
{
2252
if (rightw[righti] && !my_stricmp(leftw[lefti], rightw[righti]))
2253
{
2254
m_s3cat(&booya, space, leftw[lefti]);
2255
rightw[righti] = NULL;
2256
}
2257
}
2258
}
2259
new_free((char **)&leftw);
2260
new_free((char **)&rightw);
2261
if (!booya)
2262
RETURN_EMPTY;
2263
2264
return (booya); /* DONT USE RETURN_STR HERE! */
2265
}
2266
2267
/* $diff(string of text / string of text)
2268
* given two sets of words, seperated by a forward-slash '/', returns
2269
* all words that are not found in both sets
2270
* EX: $diff(one two three / buckle my two shoe)
2271
* returns "one two three buckle my shoe"
2272
*/
2273
BUILT_IN_FUNCTION(function_diff, word)
2274
{
2275
char *left = NULL, **leftw = NULL,
2276
*right = NULL, **rightw = NULL, *booya = NULL;
2277
int lefti, leftc,
2278
righti, rightc;
2279
int found;
2280
2281
left = word;
2282
if ((right = strchr(word,'/')) == NULL)
2283
RETURN_EMPTY;
2284
2285
*right++ = 0;
2286
leftc = splitw(left, &leftw);
2287
rightc = splitw(right, &rightw);
2288
2289
for (lefti = 0; lefti < leftc; lefti++)
2290
{
2291
found = 0;
2292
for (righti = 0; righti < rightc; righti++)
2293
{
2294
if (rightw[righti] && !my_stricmp(leftw[lefti], rightw[righti]))
2295
{
2296
found = 1;
2297
rightw[righti] = NULL;
2298
}
2299
}
2300
if (!found)
2301
m_s3cat(&booya, space, leftw[lefti]);
2302
}
2303
2304
for (righti = 0; righti < rightc; righti++)
2305
{
2306
if (rightw[righti])
2307
m_s3cat(&booya, space, rightw[righti]);
2308
}
2309
2310
new_free((char **)&leftw);
2311
new_free((char **)&rightw);
2312
2313
if (!booya)
2314
RETURN_EMPTY;
2315
2316
return (booya);
2317
}
2318
2319
/* $pattern(pattern string of words)
2320
* givEn a pattern and a string of words, returns all words that
2321
* are matched by the pattern
2322
* EX: $pattern(f* one two three four five) returns "four five"
2323
*/
2324
BUILT_IN_FUNCTION(function_pattern, word)
2325
{
2326
char *blah;
2327
char *booya = NULL;
2328
char *pattern;
2329
2330
GET_STR_ARG(pattern, word);
2331
while (((blah = new_next_arg(word, &word)) != NULL))
2332
{
2333
if (wild_match(pattern, blah))
2334
m_s3cat(&booya, space, blah);
2335
}
2336
RETURN_MSTR(booya);
2337
}
2338
2339
/* $filter(pattern string of words)
2340
* given a pattern and a string of words, returns all words that are
2341
* NOT matched by the pattern
2342
* $filter(f* one two three four five) returns "one two three"
2343
*/
2344
BUILT_IN_FUNCTION(function_filter, word)
2345
{
2346
char *blah;
2347
char *booya = NULL;
2348
char *pattern;
2349
2350
GET_STR_ARG(pattern, word);
2351
while ((blah = new_next_arg(word, &word)) != NULL)
2352
{
2353
if (!wild_match(pattern, blah))
2354
m_s3cat(&booya, space, blah);
2355
}
2356
RETURN_MSTR(booya);
2357
}
2358
2359
/* $rpattern(word list of patterns)
2360
* Given a word and a list of patterns, return all patterns that
2361
* match the word.
2362
* EX: $rpattern([email protected] *@* jnelson@* f*@*.edu)
2363
* returns "*@* jnelson@*"
2364
*/
2365
BUILT_IN_FUNCTION(function_rpattern, word)
2366
{
2367
char *blah;
2368
char *booya = NULL;
2369
char *pattern;
2370
2371
GET_STR_ARG(blah, word);
2372
while ((pattern = new_next_arg(word, &word)) != NULL)
2373
{
2374
if (wild_match(pattern, blah))
2375
m_s3cat(&booya, space, pattern);
2376
}
2377
RETURN_MSTR(booya);
2378
}
2379
2380
/* $rfilter(word list of patterns)
2381
* given a word and a list of patterns, return all patterns that
2382
* do NOT match the word
2383
* EX: $rfilter([email protected] *@* jnelson@* f*@*.edu)
2384
* returns "f*@*.edu"
2385
*/
2386
BUILT_IN_FUNCTION(function_rfilter, word)
2387
{
2388
char *blah;
2389
char *booya = NULL;
2390
char *pattern;
2391
2392
GET_STR_ARG(blah, word);
2393
while ((pattern = new_next_arg(word, &word)) != NULL)
2394
{
2395
if (!wild_match(pattern, blah))
2396
m_s3cat(&booya, space, pattern);
2397
}
2398
RETURN_MSTR(booya);
2399
}
2400
2401
/* $copattern(pattern var_1 var_2)
2402
* Given a pattern and two variable names, it returns all words
2403
* in the variable_2 corresponding to any words in variable_1 that
2404
* are matched by the pattern
2405
* EX: @nicks = [hop IRSMan skip]
2406
* @userh = [[email protected] [email protected] [email protected]]
2407
* $copattern(*@iastate.edu userh nicks)
2408
* returns "hop IRSMan"
2409
*/
2410
BUILT_IN_FUNCTION(function_copattern, word)
2411
{
2412
char *booya = NULL,
2413
*pattern = NULL,
2414
*firstl = NULL, *firstlist = NULL, *firstel = NULL,
2415
*secondl = NULL, *secondlist = NULL, *secondel = NULL;
2416
char *sfirstl, *ssecondl;
2417
2418
GET_STR_ARG(pattern, word);
2419
GET_STR_ARG(firstlist, word);
2420
GET_STR_ARG(secondlist, word);
2421
2422
firstl = get_variable(firstlist);
2423
secondl = get_variable(secondlist);
2424
2425
sfirstl = firstl;
2426
ssecondl = secondl;
2427
2428
while ((firstel = new_next_arg(firstl, &firstl)))
2429
{
2430
if (!(secondel = new_next_arg(secondl, &secondl)))
2431
break;
2432
2433
if (wild_match(pattern, firstel))
2434
m_s3cat(&booya, space, secondel);
2435
}
2436
new_free(&sfirstl);
2437
new_free(&ssecondl);
2438
2439
if (!booya)
2440
RETURN_EMPTY;
2441
2442
return (booya);
2443
}
2444
2445
/* $beforew(pattern string of words)
2446
* returns the portion of "string of words" that occurs before the
2447
* first word that is matched by "pattern"
2448
* EX: $beforew(three one two three o leary) returns "one two"
2449
*/
2450
BUILT_IN_FUNCTION(function_beforew, word)
2451
{
2452
int where;
2453
char *lame = NULL;
2454
char *placeholder;
2455
2456
lame = LOCAL_COPY(word);
2457
where = my_atol((placeholder = function_rmatch(NULL, word)));
2458
new_free(&placeholder);
2459
2460
if (where < 1)
2461
{
2462
RETURN_EMPTY;
2463
}
2464
placeholder = extract(lame, 1, where - 1);
2465
return placeholder;
2466
}
2467
2468
/* Same as above, but includes the word being matched */
2469
BUILT_IN_FUNCTION(function_tow, word)
2470
{
2471
int where;
2472
char *lame = NULL;
2473
char *placeholder;
2474
2475
lame = LOCAL_COPY(word);
2476
where = my_atol((placeholder = function_rmatch(NULL, word)));
2477
new_free(&placeholder);
2478
2479
if (where < 1)
2480
RETURN_EMPTY;
2481
placeholder = extract(lame, 1, where);
2482
return placeholder;
2483
}
2484
2485
/* Returns the string after the word being matched */
2486
BUILT_IN_FUNCTION(function_afterw, word)
2487
{
2488
int where;
2489
char *lame = NULL;
2490
char *placeholder;
2491
2492
lame = LOCAL_COPY(word);
2493
where = my_atol((placeholder = function_rmatch(NULL, word)));
2494
new_free(&placeholder);
2495
2496
if (where < 1)
2497
RETURN_EMPTY;
2498
placeholder = extract(lame, where + 1, EOS);
2499
return placeholder;
2500
}
2501
2502
/* Returns the string starting with the word being matched */
2503
BUILT_IN_FUNCTION(function_fromw, word)
2504
{
2505
int where;
2506
char *lame = NULL;
2507
char *placeholder;
2508
2509
lame = LOCAL_COPY(word);
2510
where = my_atol((placeholder = function_rmatch(NULL, word)));
2511
new_free(&placeholder);
2512
2513
if (where < 1)
2514
RETURN_EMPTY;
2515
2516
placeholder = extract(lame, where, EOS);
2517
return placeholder;
2518
}
2519
2520
/* Cut and paste a string */
2521
BUILT_IN_FUNCTION(function_splice, word)
2522
{
2523
char *variable;
2524
int start;
2525
int length;
2526
char *left_part = NULL;
2527
char *middle_part = NULL;
2528
char *right_part = NULL;
2529
char *old_value = NULL;
2530
char *new_value = NULL;
2531
int old_display = window_display;
2532
int num_words;
2533
2534
GET_STR_ARG(variable, word);
2535
GET_INT_ARG(start, word);
2536
GET_INT_ARG(length, word);
2537
2538
old_value = get_variable(variable);
2539
num_words = word_count(old_value);
2540
2541
if (start < 0)
2542
{
2543
if ((length += start) <= 0)
2544
RETURN_EMPTY;
2545
start = 0;
2546
}
2547
2548
if (start >= num_words)
2549
{
2550
left_part = m_strdup(old_value);
2551
middle_part = m_strdup(empty_string);
2552
right_part = m_strdup(empty_string);
2553
}
2554
2555
else if (start + length >= num_words)
2556
{
2557
left_part = extract(old_value, 0, start - 1);
2558
middle_part = extract(old_value, start, EOS);
2559
right_part = m_strdup(empty_string);
2560
}
2561
2562
else
2563
{
2564
left_part = extract(old_value, 0, start - 1);
2565
middle_part = extract(old_value, start, start + length - 1);
2566
right_part = extract(old_value, start + length, EOS);
2567
}
2568
2569
new_value = NULL;
2570
malloc_strcpy(&new_value, left_part);
2571
if (new_value && *new_value && word && *word)
2572
malloc_strcat(&new_value, space);
2573
if (word && *word)
2574
malloc_strcat(&new_value, word);
2575
if (new_value && *new_value && *right_part && *right_part)
2576
malloc_strcat(&new_value, space);
2577
if (right_part && *right_part)
2578
malloc_strcat(&new_value, right_part);
2579
2580
window_display = 0;
2581
add_var_alias(variable, new_value);
2582
window_display = old_display;
2583
2584
new_free(&old_value);
2585
new_free(&new_value);
2586
new_free(&left_part);
2587
new_free(&right_part);
2588
return middle_part;
2589
}
2590
2591
BUILT_IN_FUNCTION(function_numonchannel, word)
2592
{
2593
char *channel;
2594
ChannelList *chan = NULL; /* XXX */
2595
NickList *tmp = NULL;
2596
int counter = 0;
2597
2598
/* this does the right thing CDE */
2599
channel = next_arg(word, &word);
2600
if ((chan = lookup_channel(channel, from_server, 0)))
2601
{
2602
for (tmp = next_nicklist(chan, NULL); tmp; tmp = next_nicklist(chan, tmp))
2603
counter++;
2604
}
2605
RETURN_INT(counter);
2606
}
2607
2608
BUILT_IN_FUNCTION(function_onchannel, word)
2609
{
2610
char *channel;
2611
ChannelList *chan = NULL; /* XXX */
2612
NickList *tmp = NULL;
2613
char *nicks = NULL;
2614
int sort_type = NICKSORT_NORMAL;
2615
2616
/* DO NOT use new_next_arg() in here. NULL is a legit value to pass CDE*/
2617
channel = next_arg(word, &word);
2618
if ((chan = lookup_channel(channel, from_server, 0)))
2619
{
2620
NickList *list=NULL;
2621
if (word && *word)
2622
GET_INT_ARG(sort_type, word);
2623
list = sorted_nicklist(chan, sort_type);
2624
for (tmp = list; tmp; tmp = tmp->next)
2625
m_s3cat(&nicks, space, tmp->nick);
2626
clear_sorted_nicklist(&list);
2627
return (nicks ? nicks : m_strdup(empty_string));
2628
}
2629
else
2630
{
2631
nicks = channel;
2632
channel = next_arg(word, &word);
2633
RETURN_INT(is_on_channel(channel, from_server, nicks) ? 1 : 0);
2634
}
2635
}
2636
2637
BUILT_IN_FUNCTION(function_channelnicks, word)
2638
{
2639
char *channel;
2640
ChannelList *chan = NULL; /* XXX */
2641
NickList *tmp = NULL;
2642
char *nicks = NULL;
2643
int sort_type = NICKSORT_NORMAL;
2644
2645
channel = next_arg(word, &word);
2646
if ((chan = lookup_channel(channel, from_server, 0)))
2647
{
2648
NickList *list = NULL;
2649
if (word && *word)
2650
GET_INT_ARG(sort_type, word);
2651
list = sorted_nicklist(chan, NICKSORT_NORMAL);
2652
for (tmp = list; tmp; tmp = tmp->next)
2653
m_s3cat(&nicks, ",", tmp->nick);
2654
clear_sorted_nicklist(&list);
2655
return (nicks ? nicks : m_strdup(empty_string));
2656
}
2657
else
2658
{
2659
nicks = channel;
2660
channel = next_arg(word, &word);
2661
RETURN_INT(is_on_channel(channel, from_server, nicks) ? 1 : 0);
2662
}
2663
}
2664
2665
BUILT_IN_FUNCTION(function_servports, input)
2666
{
2667
int servnum = from_server;
2668
2669
if (*input)
2670
GET_INT_ARG(servnum, input);
2671
2672
if (servnum == -1)
2673
servnum = from_server;
2674
if (servnum < 0 || servnum > server_list_size())
2675
RETURN_EMPTY;
2676
2677
return m_sprintf("%d %d", get_server_port(servnum),
2678
get_server_local_port(servnum));
2679
}
2680
2681
BUILT_IN_FUNCTION(function_chop, input)
2682
{
2683
char *buffer;
2684
int howmany = 1;
2685
2686
if (my_atol(input))
2687
GET_INT_ARG(howmany, input);
2688
2689
buffer = m_strdup(input);
2690
chop(buffer, howmany);
2691
return buffer;
2692
}
2693
2694
BUILT_IN_FUNCTION(function_winlevel, input)
2695
{
2696
Window *win;
2697
char *desc;
2698
2699
if (input && *input)
2700
{
2701
GET_STR_ARG(desc, input);
2702
win = get_window_by_desc(desc);
2703
}
2704
else
2705
win = current_window;
2706
2707
if (!win)
2708
RETURN_EMPTY;
2709
2710
RETURN_STR(bits_to_lastlog_level(win->window_level));
2711
}
2712
2713
BUILT_IN_FUNCTION(function_chops, word)
2714
{
2715
char *channel;
2716
ChannelList *chan;
2717
NickList *tmp;
2718
char *nicks = NULL;
2719
2720
channel = next_arg(word, &word);
2721
if ((chan = lookup_channel(channel,from_server,0)))
2722
{
2723
NickList *list = NULL;
2724
list = sorted_nicklist(chan, NICKSORT_NORMAL);
2725
for (tmp = list; tmp; tmp = tmp->next)
2726
if (nick_isop(tmp))
2727
m_s3cat(&nicks, space, tmp->nick);
2728
clear_sorted_nicklist(&list);
2729
}
2730
return (nicks ? nicks : m_strdup(empty_string));
2731
}
2732
2733
BUILT_IN_FUNCTION(function_nochops, word)
2734
{
2735
ChannelList *chan;
2736
NickList *tmp;
2737
char *nicks = NULL;
2738
char *channel;
2739
2740
channel = next_arg(word, &word);
2741
if ((chan = lookup_channel(channel,from_server,0)))
2742
{
2743
NickList *list = NULL;
2744
list = sorted_nicklist(chan, NICKSORT_NORMAL);
2745
for (tmp = list; tmp; tmp = tmp->next)
2746
if (!nick_isop(tmp))
2747
m_s3cat(&nicks, space, tmp->nick);
2748
clear_sorted_nicklist(&list);
2749
}
2750
return (nicks ? nicks : m_strdup(empty_string));
2751
}
2752
2753
BUILT_IN_FUNCTION(function_key, word)
2754
{
2755
char *channel;
2756
char *booya = NULL;
2757
char *key;
2758
2759
do
2760
{
2761
channel = next_arg(word, &word);
2762
if ((!channel || !*channel) && booya)
2763
break;
2764
2765
key = get_channel_key(channel, from_server);
2766
m_s3cat(&booya, space, (key && *key) ? key : "*");
2767
}
2768
while (word && *word);
2769
2770
return (booya ? booya : m_strdup(empty_string));
2771
}
2772
2773
BUILT_IN_FUNCTION(function_revw, words)
2774
{
2775
char *booya = NULL;
2776
2777
while (words && *words)
2778
m_s3cat(&booya, space, last_arg(&words));
2779
if (!booya)
2780
RETURN_EMPTY;
2781
2782
return booya;
2783
}
2784
2785
BUILT_IN_FUNCTION(function_reverse, words)
2786
{
2787
int length = strlen(words);
2788
char *booya = NULL;
2789
int x = 0;
2790
2791
booya = (char *)new_malloc(length+1);
2792
for (length--; length >= 0; length--,x++)
2793
booya[x] = words[length];
2794
booya[x] = '\0';
2795
return (booya);
2796
}
2797
2798
BUILT_IN_FUNCTION(function_substr, input)
2799
{
2800
char *search;
2801
char *ptr;
2802
2803
GET_STR_ARG(search, input);
2804
2805
if ((ptr = stristr(input, search)))
2806
RETURN_INT((unsigned long)(ptr - input));
2807
else
2808
RETURN_INT(-1);
2809
}
2810
2811
BUILT_IN_FUNCTION(function_rsubstr, input)
2812
{
2813
char *search;
2814
char *ptr;
2815
2816
GET_STR_ARG(search, input);
2817
2818
if ((ptr = rstristr(input, search)))
2819
RETURN_INT((unsigned long)(ptr - input));
2820
else
2821
RETURN_INT(-1);
2822
}
2823
2824
BUILT_IN_FUNCTION(function_nohighlight, input)
2825
{
2826
char *outbuf, *ptr;
2827
2828
ptr = outbuf = alloca(strlen(input) * 3 + 1);
2829
while (*input)
2830
{
2831
switch (*input)
2832
{
2833
case REV_TOG:
2834
case UND_TOG:
2835
case BOLD_TOG:
2836
case BLINK_TOG:
2837
case ALL_OFF:
2838
case '\003':
2839
case '\033':
2840
{
2841
*ptr++ = REV_TOG;
2842
*ptr++ = (*input++ | 0x40);
2843
*ptr++ = REV_TOG;
2844
break;
2845
}
2846
default:
2847
{
2848
*ptr++ = *input++;
2849
break;
2850
}
2851
}
2852
}
2853
2854
*ptr = 0;
2855
RETURN_STR(outbuf);
2856
}
2857
2858
2859
BUILT_IN_FUNCTION(function_strstr, input)
2860
{
2861
char *p, *word;
2862
GET_STR_ARG(word, input);
2863
RETURN_IF_EMPTY(input);
2864
if ((p = stristr(input, word)))
2865
RETURN_STR(p);
2866
else
2867
RETURN_EMPTY;
2868
}
2869
2870
BUILT_IN_FUNCTION(function_rstrstr, input)
2871
{
2872
char *p, *word;
2873
GET_STR_ARG(word, input);
2874
RETURN_IF_EMPTY(input);
2875
if ((p = rstristr(input, word)))
2876
RETURN_STR(p);
2877
else
2878
RETURN_EMPTY;
2879
}
2880
2881
BUILT_IN_FUNCTION(function_jot, input)
2882
{
2883
int start = 0;
2884
int stop = 0;
2885
int interval = 1;
2886
int counter;
2887
char *booya = NULL;
2888
int range;
2889
size_t size;
2890
2891
GET_INT_ARG(start,input)
2892
GET_INT_ARG(stop, input)
2893
if (input && *input)
2894
GET_INT_ARG(interval, input)
2895
else
2896
interval = 1;
2897
2898
if (interval < 0)
2899
interval = -interval;
2900
2901
range = abs(stop - start) + 1;
2902
size = range * 10;
2903
booya = new_malloc(size);
2904
size--;
2905
2906
if (start < stop)
2907
{
2908
strlcpy(booya, ltoa(start), size);
2909
for (counter = start + interval; counter <= stop; counter += interval)
2910
{
2911
strlcat(booya, space, size);
2912
strlcat(booya, ltoa(counter), size);
2913
}
2914
}
2915
else
2916
{
2917
strlcpy(booya, ltoa(start),size);
2918
for (counter = start - interval; counter >= stop; counter -= interval)
2919
{
2920
strlcat(booya, space, size);
2921
strlcat(booya, ltoa(counter), size);
2922
}
2923
}
2924
2925
return booya;
2926
}
2927
2928
char *function_shift(char *n, char *word)
2929
{
2930
char *value = NULL;
2931
char *var = NULL;
2932
char *booya = NULL;
2933
int old_display = window_display;
2934
char *placeholder;
2935
2936
GET_STR_ARG(var, word);
2937
2938
if (word && *word)
2939
RETURN_STR(var);
2940
2941
value = get_variable(var);
2942
2943
if (!value || !*value)
2944
{
2945
new_free(&value);
2946
RETURN_EMPTY;
2947
}
2948
2949
placeholder = value;
2950
booya = m_strdup(new_next_arg(value, &value));
2951
/* do not free value at this point */
2952
if (var)
2953
{
2954
window_display = 0;
2955
add_var_alias(var, value);
2956
window_display = old_display;
2957
}
2958
new_free(&placeholder);
2959
if (!booya)
2960
RETURN_EMPTY;
2961
return booya;
2962
}
2963
2964
char *function_unshift(char *n, char *word)
2965
{
2966
char *value = NULL;
2967
char *var = NULL;
2968
char *booya = NULL;
2969
int old_display = window_display;
2970
2971
GET_STR_ARG(var, word);
2972
value = get_variable(var);
2973
if (!word || !*word)
2974
return value;
2975
2976
booya = m_strdup(word);
2977
m_s3cat_s(&booya, space, value);
2978
2979
window_display = 0;
2980
add_var_alias(var, booya);
2981
window_display = old_display;
2982
new_free(&value);
2983
return booya;
2984
}
2985
2986
char *function_push(char *n, char *word)
2987
{
2988
char *value = NULL;
2989
char *var = NULL;
2990
int old_display = window_display;
2991
2992
GET_STR_ARG(var, word);
2993
value = get_variable(var);
2994
m_s3cat(&value, space, word);
2995
window_display = 0;
2996
add_var_alias(var, value);
2997
window_display = old_display;
2998
return value;
2999
}
3000
3001
char *function_pop(char *n, char *word)
3002
{
3003
char *value = NULL;
3004
char *var = NULL;
3005
char *pointer = NULL;
3006
int old_display = window_display;
3007
char *blech = NULL;
3008
3009
GET_STR_ARG(var, word);
3010
3011
if (word && *word)
3012
{
3013
pointer = strrchr(word, ' ');
3014
RETURN_STR(pointer ? pointer : word);
3015
}
3016
3017
value = get_variable(var);
3018
if (!value || !*value)
3019
{
3020
new_free(&value);
3021
RETURN_EMPTY;
3022
}
3023
3024
if (!(pointer = strrchr(value, ' ')))
3025
{
3026
window_display = 0;
3027
add_var_alias(var, empty_string); /* dont forget this! */
3028
window_display = old_display;
3029
return value; /* one word -- return it */
3030
}
3031
3032
*pointer++ = '\0';
3033
window_display = 0;
3034
add_var_alias(var, value);
3035
window_display = old_display;
3036
3037
/* because pointer points to value, we *must* make a copy of it
3038
* *before* we free value! (And we cant forget to free value, either)
3039
*/
3040
blech = m_strdup(pointer);
3041
new_free(&value);
3042
return blech;
3043
}
3044
3045
3046
/* Search and replace function --
3047
Usage: $sar(c/search/replace/data)
3048
Commands:
3049
r - treat data as a variable name and
3050
return the replaced data to the variable
3051
g - Replace all instances, not just the first one
3052
The delimiter may be any character that is not a command (typically /)
3053
The delimiter MUST be the first character after the command
3054
Returns emppy string on error
3055
*/
3056
BUILT_IN_FUNCTION(function_sar, word)
3057
{
3058
register char delimiter;
3059
register char *pointer = NULL;
3060
char *search = NULL;
3061
char *replace = NULL;
3062
char *data = NULL;
3063
char *value = NULL;
3064
char *booya = NULL;
3065
int variable = 0,this_global = 0,searchlen,oldwindow = window_display;
3066
char *(*func) (const char *, const char *) = strstr;
3067
char *svalue;
3068
3069
while (((*word == 'r') && (variable = 1)) || ((*word == 'g') && (this_global = 1)) || ((*word == 'i') && (func = (char *(*)(const char *, const char *))global[STRISTR])))
3070
word++;
3071
3072
RETURN_IF_EMPTY(word);
3073
3074
delimiter = *word;
3075
search = word + 1;
3076
if ((replace = strchr(search, delimiter)) == 0)
3077
RETURN_EMPTY;
3078
3079
*replace++ = 0;
3080
if ((data = strchr(replace,delimiter)) == 0)
3081
RETURN_EMPTY;
3082
3083
*data++ = '\0';
3084
3085
value = (variable == 1) ? get_variable(data) : m_strdup(data);
3086
3087
if (!value || !*value)
3088
{
3089
new_free(&value);
3090
RETURN_EMPTY;
3091
}
3092
3093
pointer = svalue = value;
3094
searchlen = strlen(search) - 1;
3095
if (searchlen < 0)
3096
searchlen = 0;
3097
if (this_global)
3098
{
3099
while ((pointer = func(pointer,search)) != NULL)
3100
{
3101
pointer[0] = pointer[searchlen] = 0;
3102
pointer += searchlen + 1;
3103
m_e3cat(&booya, value, replace);
3104
value = pointer;
3105
if (!*pointer)
3106
break;
3107
}
3108
}
3109
else
3110
{
3111
if ((pointer = func(pointer,search)) != NULL)
3112
{
3113
pointer[0] = pointer[searchlen] = 0;
3114
pointer += searchlen + 1;
3115
m_e3cat(&booya, value, replace);
3116
value = pointer;
3117
}
3118
}
3119
3120
malloc_strcat(&booya, value);
3121
if (variable)
3122
{
3123
window_display = 0;
3124
add_var_alias(data, booya);
3125
window_display = oldwindow;
3126
}
3127
new_free(&svalue);
3128
return (booya);
3129
}
3130
3131
/* Search and replace function --
3132
Usage: $msar(c/search/replace/data)
3133
Commands:
3134
r - treat data as a variable name and
3135
return the replaced data to the variable
3136
g - Replace all instances, not just the first one
3137
The delimiter may be any character that is not a command (typically /)
3138
The delimiter MUST be the first character after the command
3139
Returns empty string on error
3140
*/
3141
#if 0
3142
BUILT_IN_FUNCTION(function_msar, word)
3143
{
3144
register char delimiter;
3145
register char *pointer = NULL;
3146
char *search = NULL;
3147
char *replace = NULL;
3148
char *data = NULL;
3149
char *value = NULL;
3150
char *booya = NULL;
3151
char *p = NULL;
3152
int variable = 0,this_global = 0,searchlen,oldwindow = window_display;
3153
char *(*func) (const char *, const char *) = strstr;
3154
char *svalue = NULL;
3155
3156
while (((*word == 'r') && (variable = 1)) || ((*word == 'g') && (this_global = 1)) || ((*word == 'i') && (func = (char *(*)(const char *, const char *))global[STRISTR])))
3157
word++;
3158
3159
RETURN_IF_EMPTY(word);
3160
3161
delimiter = *word;
3162
search = word + 1;
3163
if (!(replace = strchr(search, delimiter)))
3164
RETURN_EMPTY;
3165
3166
*replace++ = 0;
3167
if (!(data = strchr(replace,delimiter)))
3168
RETURN_EMPTY;
3169
3170
*data++ = 0;
3171
3172
if (!(p = strrchr(data, delimiter)))
3173
value = (variable == 1) ? get_variable(data) : m_strdup(data);
3174
else
3175
{
3176
*p++ = 0;
3177
value = (variable == 1) ? get_variable(p) : m_strdup(p);
3178
}
3179
3180
if (!value || !*value)
3181
{
3182
new_free(&value);
3183
RETURN_EMPTY;
3184
}
3185
3186
pointer = svalue = value;
3187
3188
do
3189
{
3190
if ( (searchlen = (strlen(search) - 1)) < 0)
3191
searchlen = 0;
3192
if (this_global)
3193
{
3194
while ((pointer = func(pointer,search)))
3195
{
3196
pointer[0] = pointer[searchlen] = 0;
3197
pointer += searchlen + 1;
3198
m_e3cat(&booya, value, replace);
3199
value = pointer;
3200
if (!*pointer)
3201
break;
3202
}
3203
}
3204
else
3205
{
3206
if ((pointer = func(pointer,search)))
3207
{
3208
pointer[0] = pointer[searchlen] = 0;
3209
pointer += searchlen + 1;
3210
m_e3cat(&booya, value, replace);
3211
value = pointer;
3212
}
3213
}
3214
malloc_strcat(&booya, value);
3215
if (data && *data)
3216
{
3217
new_free(&svalue);
3218
search = data;
3219
if ((replace = strchr(data, delimiter)))
3220
{
3221
*replace++ = 0;
3222
if ((data = strchr(replace, delimiter)))
3223
*data++ = 0;
3224
}
3225
/* patch from RoboHak */
3226
if (!replace || !search)
3227
{
3228
pointer = value = svalue;
3229
break;
3230
}
3231
pointer = value = svalue = booya;
3232
booya = NULL;
3233
} else
3234
break;
3235
} while (1);
3236
3237
if (variable)
3238
{
3239
window_display = 0;
3240
add_var_alias(data, booya);
3241
window_display = oldwindow;
3242
}
3243
new_free(&svalue);
3244
return booya ? booya : m_strdup(empty_string);
3245
}
3246
#endif
3247
BUILT_IN_FUNCTION(function_msar, word)
3248
{
3249
char delimiter;
3250
char *pointer = NULL;
3251
char *search = NULL;
3252
char *replace = NULL;
3253
char *data = NULL;
3254
char *value = NULL;
3255
char *booya = NULL;
3256
char *p = NULL;
3257
int variable = 0,
3258
this_global = 0,
3259
searchlen,
3260
oldwindow = window_display;
3261
char *(*func) (const char *, const char *) = strstr;
3262
char *svalue;
3263
3264
while (((*word == 'r') && (variable = 1)) || ((*word == 'g') && (this_global = 1)) || ((*word == 'i') && (func = (char *(*)(const char *, const char *))global[STRISTR])))
3265
word++;
3266
3267
RETURN_IF_EMPTY(word);
3268
3269
delimiter = *word;
3270
search = word + 1;
3271
if (!(replace = strchr(search, delimiter)))
3272
RETURN_EMPTY;
3273
3274
*replace++ = 0;
3275
if (!(data = strchr(replace,delimiter)))
3276
RETURN_EMPTY;
3277
3278
*data++ = 0;
3279
3280
if (!(p = strrchr(data, delimiter)))
3281
value = (variable == 1) ? get_variable(data) : m_strdup(data);
3282
else
3283
{
3284
*p++ = 0;
3285
value = (variable == 1) ? get_variable(p) : m_strdup(p);
3286
}
3287
3288
if (!value || !*value)
3289
{
3290
new_free(&value);
3291
RETURN_EMPTY;
3292
}
3293
3294
pointer = svalue = value;
3295
3296
do
3297
{
3298
searchlen = strlen(search) - 1;
3299
if (searchlen < 0)
3300
searchlen = 0;
3301
if (this_global)
3302
{
3303
while ((pointer = func(pointer,search)))
3304
{
3305
pointer[0] = pointer[searchlen] = 0;
3306
pointer += searchlen + 1;
3307
m_e3cat(&booya, value, replace);
3308
value = pointer;
3309
if (!*pointer)
3310
break;
3311
}
3312
}
3313
else
3314
{
3315
if ((pointer = func(pointer,search)))
3316
{
3317
pointer[0] = pointer[searchlen] = 0;
3318
pointer += searchlen + 1;
3319
m_e3cat(&booya, value, replace);
3320
value = pointer;
3321
}
3322
}
3323
malloc_strcat(&booya, value);
3324
if (data && *data)
3325
{
3326
new_free(&svalue);
3327
search = data;
3328
if ((replace = strchr(data, delimiter)))
3329
{
3330
*replace++ = 0;
3331
if ((data = strchr(replace, delimiter)))
3332
*data++ = 0;
3333
}
3334
/* patch from RoboHak */
3335
if (!replace || !search)
3336
{
3337
pointer = value = svalue;
3338
break;
3339
}
3340
pointer = value = svalue = booya;
3341
booya = NULL;
3342
} else
3343
break;
3344
} while (1);
3345
3346
if (variable)
3347
{
3348
window_display = 0;
3349
add_var_alias(data, booya);
3350
window_display = oldwindow;
3351
}
3352
new_free(&svalue);
3353
return (booya);
3354
}
3355
3356
3357
BUILT_IN_FUNCTION(function_center, word)
3358
{
3359
int length,pad,width;
3360
char *padc;
3361
3362
if (!word || !*word)
3363
RETURN_EMPTY;
3364
3365
width = atoi(new_next_arg(word, &word));
3366
RETURN_IF_EMPTY(word);
3367
length = strlen(word);
3368
3369
if ((pad = width - length) < 0)
3370
RETURN_STR(word);
3371
3372
pad /= 2;
3373
padc = (char *)new_malloc(width+1);
3374
memset(padc, ' ', pad);
3375
padc[pad] = '\0';
3376
3377
return strcat(padc, word);
3378
}
3379
3380
BUILT_IN_FUNCTION(function_split, word)
3381
{
3382
char *chrs;
3383
register char *pointer;
3384
3385
chrs = next_arg(word, &word);
3386
pointer = word;
3387
while ((pointer = sindex(pointer,chrs)))
3388
*pointer++ = ' ';
3389
3390
RETURN_STR(word);
3391
}
3392
3393
BUILT_IN_FUNCTION(function_chr, word)
3394
{
3395
char aboo[BIG_BUFFER_SIZE];
3396
unsigned char *ack = aboo;
3397
char *blah;
3398
3399
while ((blah = next_arg(word, &word)))
3400
*ack++ = (unsigned char)atoi(blah);
3401
3402
*ack = '\0';
3403
RETURN_STR(aboo);
3404
}
3405
3406
BUILT_IN_FUNCTION(function_ascii, word)
3407
{
3408
char *aboo = NULL;
3409
unsigned char *w = word;
3410
if (!word || !*word)
3411
RETURN_EMPTY;
3412
3413
aboo = m_strdup(ltoa((unsigned long) *w));
3414
while (*++w)
3415
m_3cat(&aboo, space, ltoa((unsigned long) *w));
3416
3417
return (aboo);
3418
}
3419
3420
BUILT_IN_FUNCTION(function_which, word)
3421
{
3422
#ifdef PUBLIC_ACCESS
3423
RETURN_INT(0);
3424
#else
3425
char *file1;
3426
3427
GET_STR_ARG(file1, word);
3428
3429
if ((file1 = path_search(file1, (word && *word) ? word :
3430
get_string_var(LOAD_PATH_VAR))))
3431
{
3432
RETURN_STR(file1);
3433
}
3434
else
3435
{
3436
new_free(&file1);
3437
RETURN_EMPTY;
3438
}
3439
#endif
3440
}
3441
3442
3443
BUILT_IN_FUNCTION(function_isalpha, input)
3444
{
3445
if (isalpha((unsigned char)*input))
3446
RETURN_INT(1);
3447
else
3448
RETURN_INT(0);
3449
}
3450
3451
BUILT_IN_FUNCTION(function_isdigit, input)
3452
{
3453
if (isdigit((unsigned char)*input))
3454
RETURN_INT(1);
3455
else
3456
RETURN_INT(0);
3457
}
3458
3459
BUILT_IN_FUNCTION(function_isalnum, input)
3460
{
3461
if (isalpha((unsigned char)*input) || isdigit((unsigned char)*input))
3462
RETURN_INT(1);
3463
else
3464
RETURN_INT(0);
3465
}
3466
3467
BUILT_IN_FUNCTION(function_isspace, input)
3468
{
3469
if (isspace((unsigned char)*input))
3470
RETURN_INT(1);
3471
else
3472
RETURN_INT(0);
3473
}
3474
3475
BUILT_IN_FUNCTION(function_isxdigit, input)
3476
{
3477
#define ishex(x) \
3478
((x >= 'A' && x <= 'F') || (x >= 'a' && x <= 'f'))
3479
3480
if (isdigit((unsigned char)*input) || ishex(*input))
3481
RETURN_INT(1);
3482
else
3483
RETURN_INT(0);
3484
}
3485
3486
BUILT_IN_FUNCTION(function_serverpass, input)
3487
{
3488
int servnum = from_server;
3489
3490
if (*input)
3491
GET_INT_ARG(servnum, input);
3492
3493
if (servnum == -1)
3494
servnum = from_server;
3495
if (servnum < 0 || servnum > server_list_size())
3496
RETURN_EMPTY;
3497
3498
return m_sprintf("%d", get_server_pass(servnum));
3499
}
3500
3501
BUILT_IN_FUNCTION(function_open, words)
3502
{
3503
#ifdef PUBLIC_ACCESS
3504
RETURN_INT(0);
3505
#else
3506
char *filename;
3507
char *mode;
3508
char *bin_mode = NULL;
3509
3510
GET_STR_ARG(filename, words);
3511
GET_STR_ARG(mode, words);
3512
if (in_cparse)
3513
RETURN_EMPTY;
3514
if (words && *words)
3515
bin_mode = words;
3516
3517
if (*mode == 'R' || *mode == 'r')
3518
{
3519
if (bin_mode && (*bin_mode == 'B' || *bin_mode == 'b'))
3520
RETURN_INT(open_file_for_read(filename));
3521
else
3522
RETURN_INT(open_file_for_read(filename));
3523
}
3524
else if (*mode == 'W' || *mode == 'w')
3525
{
3526
if (bin_mode && (*bin_mode == 'B' || *bin_mode == 'b'))
3527
RETURN_INT(open_file_for_bwrite(filename));
3528
else
3529
RETURN_INT(open_file_for_write(filename));
3530
}
3531
RETURN_EMPTY;
3532
#endif
3533
}
3534
3535
BUILT_IN_FUNCTION(function_close, words)
3536
{
3537
#ifdef PUBLIC_ACCESS
3538
RETURN_INT(0);
3539
#else
3540
RETURN_IF_EMPTY(words);
3541
if (in_cparse)
3542
RETURN_INT(0);
3543
RETURN_INT(file_close(atoi(new_next_arg(words, &words))));
3544
#endif
3545
}
3546
3547
BUILT_IN_FUNCTION(function_write, words)
3548
{
3549
#ifdef PUBLIC_ACCESS
3550
RETURN_INT(0);
3551
#else
3552
char *fdc;
3553
if (in_cparse)
3554
RETURN_INT(0);
3555
GET_STR_ARG(fdc, words);
3556
RETURN_INT(file_write(atoi(fdc), words));
3557
#endif
3558
}
3559
3560
BUILT_IN_FUNCTION(function_writeb, words)
3561
{
3562
#ifdef PUBLIC_ACCESS
3563
RETURN_INT(0);
3564
#else
3565
char *fdc;
3566
if (in_cparse)
3567
RETURN_INT(0);
3568
GET_STR_ARG(fdc, words);
3569
RETURN_INT(file_writeb(atoi(fdc), words));
3570
#endif
3571
}
3572
3573
BUILT_IN_FUNCTION(function_read, words)
3574
{
3575
#ifdef PUBLIC_ACCESS
3576
RETURN_INT(0);
3577
#else
3578
char *fdc = NULL, *numb = NULL;
3579
if (in_cparse)
3580
RETURN_INT(0);
3581
3582
GET_STR_ARG(fdc, words);
3583
if (words && *words)
3584
GET_STR_ARG(numb, words);
3585
3586
if (numb)
3587
return file_readb (atoi(fdc), atoi(numb));
3588
else
3589
return file_read (atoi(fdc));
3590
#endif
3591
}
3592
3593
BUILT_IN_FUNCTION(function_eof, words)
3594
{
3595
#ifdef PUBLIC_ACCESS
3596
RETURN_INT(0);
3597
#else
3598
RETURN_IF_EMPTY(words);
3599
RETURN_INT(file_eof(atoi(new_next_arg(words, &words))));
3600
#endif
3601
}
3602
3603
3604
BUILT_IN_FUNCTION(function_iptoname, words)
3605
{
3606
char *ret = ip_to_host(words);
3607
RETURN_STR(ret);
3608
}
3609
3610
BUILT_IN_FUNCTION(function_nametoip, words)
3611
{
3612
char *ret = host_to_ip(words);
3613
RETURN_STR(ret);
3614
}
3615
3616
BUILT_IN_FUNCTION(function_convert, words)
3617
{
3618
char *ret = one_to_another(words);
3619
RETURN_STR(ret);
3620
}
3621
3622
BUILT_IN_FUNCTION(function_translate, words)
3623
{
3624
register char * oldc;
3625
char * newc,
3626
* text,
3627
delim;
3628
register char * ptr;
3629
int size_old,
3630
size_new,
3631
x;
3632
3633
RETURN_IF_EMPTY(words);
3634
3635
oldc = words;
3636
/* First character can be a slash. If it is, we just skip over it */
3637
delim = *oldc++;
3638
newc = strchr(oldc, delim);
3639
3640
if (!newc)
3641
RETURN_EMPTY; /* no text in, no text out */
3642
3643
text = strchr(++newc, delim);
3644
3645
if (newc == oldc)
3646
RETURN_EMPTY;
3647
3648
if (!text)
3649
RETURN_EMPTY;
3650
*text++ = '\0';
3651
3652
if (newc == text)
3653
{
3654
*newc = '\0';
3655
newc = empty_string;
3656
}
3657
else
3658
newc[-1] = 0;
3659
3660
/* this is cheating, but oh well, >;-) */
3661
text = m_strdup(text);
3662
3663
size_new = strlen(newc);
3664
size_old = strlen(oldc);
3665
3666
for (ptr = text; ptr && *ptr; ptr++)
3667
{
3668
for (x = 0;x < size_old;(void)x++)
3669
{
3670
if (*ptr == oldc[x])
3671
{
3672
/* Check to make sure we arent
3673
just eliminating the character.
3674
If we arent, put in the new char,
3675
otherwise strcpy it away */
3676
if (size_new)
3677
*ptr = newc[(x<size_new)?x:size_new-1];
3678
else
3679
{
3680
ov_strcpy (ptr, ptr+1);
3681
ptr--;
3682
}
3683
break;
3684
}
3685
}
3686
}
3687
return text;
3688
}
3689
3690
BUILT_IN_FUNCTION(function_server_version, word)
3691
{
3692
int servnum;
3693
int version;
3694
3695
servnum = ((word && *word) ? atoi(next_arg(word, &word)) : primary_server);
3696
3697
if (servnum > server_list_size())
3698
RETURN_STR("unknown");
3699
3700
version = get_server_version(servnum);
3701
3702
if (version == Server2_8) RETURN_STR("2.8");
3703
else if (version == Server2_9) RETURN_STR("2.9");
3704
else if (version == Server2_10) RETURN_STR("2.10");
3705
else if (version == Server2_8ts4) RETURN_STR("2.8ts4");
3706
else if (version == Server2_8hybrid) RETURN_STR("2.8hybrid5");
3707
else if (version == Server2_8hybrid6) RETURN_STR("2.8hybrid6");
3708
else if (version == Server2_8comstud) RETURN_STR("2.8comstud");
3709
3710
else if (version == Server_u2_8) RETURN_STR("u2.8");
3711
else if (version == Server_u2_9) RETURN_STR("u2.9");
3712
else if (version == Server_u2_10) RETURN_STR("u2.10");
3713
else if (version == Server_u3_0) RETURN_STR("u3.0");
3714
3715
RETURN_STR("Unknown");
3716
}
3717
3718
BUILT_IN_FUNCTION(function_unlink, words)
3719
{
3720
#ifdef PUBLIC_ACCESS
3721
RETURN_INT(0);
3722
#else
3723
char * expanded;
3724
int failure = 0;
3725
if (in_cparse)
3726
RETURN_INT(0);
3727
3728
while (words && *words)
3729
{
3730
expanded = expand_twiddle(new_next_arg(words, &words));
3731
failure -= unlink(expanded);
3732
new_free(&expanded);
3733
}
3734
RETURN_INT(failure);
3735
#endif
3736
}
3737
3738
BUILT_IN_FUNCTION(function_rename, words)
3739
{
3740
#ifdef PUBLIC_ACCESS
3741
RETURN_INT(0);
3742
#else
3743
char * filename1,
3744
* filename2;
3745
char *expanded1, *expanded2;
3746
int failure = 0;
3747
if (in_cparse)
3748
RETURN_INT(failure);
3749
3750
GET_STR_ARG(filename1, words);
3751
GET_STR_ARG(filename2, words);
3752
expanded1 = expand_twiddle(filename1);
3753
expanded2 = expand_twiddle(filename2);
3754
failure = rename(expanded1, expanded2);
3755
new_free(&expanded1); new_free(&expanded2);
3756
RETURN_INT(failure);
3757
#endif
3758
}
3759
3760
BUILT_IN_FUNCTION(function_rmdir, words)
3761
{
3762
#ifdef PUBLIC_ACCESS
3763
RETURN_INT(0);
3764
#else
3765
int failure = 0;
3766
char *expanded;
3767
3768
if (in_cparse)
3769
RETURN_INT(failure);
3770
3771
while (words && *words)
3772
{
3773
expanded = expand_twiddle(new_next_arg(words, &words));
3774
failure -= rmdir(expanded);
3775
new_free(&expanded);
3776
}
3777
3778
RETURN_INT(failure);
3779
#endif
3780
}
3781
3782
BUILT_IN_FUNCTION(function_truncate, words)
3783
{
3784
int num = 0;
3785
double value = 0;
3786
char buffer[BIG_BUFFER_SIZE],
3787
format[BIG_BUFFER_SIZE];
3788
3789
GET_INT_ARG(num, words);
3790
GET_FLOAT_ARG(value, words);
3791
3792
if (num < 0)
3793
{
3794
float foo;
3795
int end;
3796
3797
sprintf(format, "%%.%de", -num-1);
3798
sprintf(buffer, format, value);
3799
foo = atof(buffer);
3800
sprintf(buffer, "%f", foo);
3801
end = strlen(buffer) - 1;
3802
if (end == 0)
3803
RETURN_EMPTY;
3804
while (buffer[end] == '0')
3805
end--;
3806
if (buffer[end] == '.')
3807
end--;
3808
buffer[end+1] = 0;
3809
}
3810
else if (num > 0)
3811
{
3812
sprintf(format, "%%10.%dlf", num);
3813
sprintf(buffer, format, value);
3814
}
3815
else
3816
RETURN_EMPTY;
3817
3818
while (*buffer == ' ')
3819
ov_strcpy(buffer, buffer+1);
3820
3821
RETURN_STR(buffer);
3822
}
3823
3824
3825
/*
3826
* Apprantly, this was lifted from a CS client. I reserve the right
3827
* to replace this code in future versions. (hop)
3828
*/
3829
/*
3830
I added this little function so that I can have stuff formatted
3831
into days, hours, minutes, seconds; but with d, h, m, s abreviations.
3832
-Taner
3833
*/
3834
3835
BUILT_IN_FUNCTION(function_tdiff2, input)
3836
{
3837
time_t ltime;
3838
time_t days,
3839
hours,
3840
minutes,
3841
seconds;
3842
char tmp[80];
3843
char *tstr;
3844
3845
GET_INT_ARG(ltime, input);
3846
3847
seconds = ltime % 60;
3848
ltime = (ltime - seconds) / 60;
3849
minutes = ltime%60;
3850
ltime = (ltime - minutes) / 60;
3851
hours = ltime % 24;
3852
days = (ltime - hours) / 24;
3853
tstr = tmp;
3854
3855
if (days)
3856
{
3857
sprintf(tstr, "%ldd ", days);
3858
tstr += strlen(tstr);
3859
}
3860
if (hours)
3861
{
3862
sprintf(tstr, "%ldh ", hours);
3863
tstr += strlen(tstr);
3864
}
3865
if (minutes)
3866
{
3867
sprintf(tstr, "%ldm ", minutes);
3868
tstr += strlen(tstr);
3869
}
3870
if (seconds || (!days && !hours && !minutes))
3871
{
3872
sprintf(tstr, "%lds", seconds);
3873
tstr += strlen(tstr);
3874
}
3875
else
3876
*--tstr = 0; /* chop off that space! */
3877
3878
RETURN_STR(tmp);
3879
}
3880
3881
3882
/*
3883
* Apparantly, this was lifted from a CS client. I reserve the right
3884
* to replace this code in a future release.
3885
*/
3886
BUILT_IN_FUNCTION(function_utime, input)
3887
{
3888
struct timeval tp;
3889
get_time(&tp);
3890
return m_sprintf("%ld %ld",(unsigned long)tp.tv_sec, (unsigned long)tp.tv_usec);
3891
}
3892
3893
3894
/*
3895
* This inverts any ansi sequence present in the string
3896
* from: Scott H Kilau <[email protected]>
3897
*/
3898
BUILT_IN_FUNCTION(function_stripansi, input)
3899
{
3900
register unsigned char *cp;
3901
for (cp = input; *cp; cp++)
3902
if (*cp < 31 && *cp > 13)
3903
if (*cp != 15 && *cp !=22)
3904
*cp = (*cp & 127) | 64;
3905
RETURN_STR(input);
3906
}
3907
3908
#if 0
3909
BUILT_IN_FUNCTION(function_stripansicodes, inPut)
3910
{
3911
RETURN_IF_EMPTY(input);
3912
RETURN_STR(stripansicodes(input));
3913
}
3914
#endif
3915
3916
BUILT_IN_FUNCTION(function_stripc, input)
3917
{
3918
char *retval;
3919
retval = LOCAL_COPY(input);
3920
strcpy_nocolorcodes(retval, input);
3921
RETURN_STR(retval);
3922
}
3923
3924
BUILT_IN_FUNCTION(function_servername, input)
3925
{
3926
int sval = from_server;
3927
const char *which;
3928
3929
if(*input)
3930
GET_INT_ARG(sval, input);
3931
3932
/* garbage in, garbage out. */
3933
if (sval < 0 || sval >= server_list_size())
3934
RETURN_EMPTY;
3935
3936
/* First we try to see what the server thinks it name is */
3937
which = get_server_itsname(sval);
3938
3939
/* Next we try what we think its name is */
3940
if (!which)
3941
which = get_server_name(sval);
3942
3943
/* Ok. i give up, return a null. */
3944
RETURN_STR(which);
3945
}
3946
3947
BUILT_IN_FUNCTION(function_lastserver, input)
3948
{
3949
RETURN_INT(last_server);
3950
}
3951
3952
/*
3953
* Date: Sat, 26 Apr 1997 13:41:11 +1200
3954
* Author: IceKarma ([email protected])
3955
* Contributed by: author
3956
*
3957
* Usage: $winchan(#channel <server refnum|server name>)
3958
* Given a channel name and either a server refnum or a direct server
3959
* name or an effective server name, this function will return the
3960
* refnum of the window where the channel is the current channel (on that
3961
* server if appropriate.)
3962
*
3963
* Returns -1 (Too few arguments specified, or Window Not Found) on error.
3964
*/
3965
BUILT_IN_FUNCTION(function_chanwin, input)
3966
{
3967
char *arg1 = NULL;
3968
3969
if (input && *input)
3970
GET_STR_ARG(arg1, input);
3971
3972
/*
3973
* Return window refnum by channel
3974
*/
3975
if (arg1 && is_channel(arg1))
3976
{
3977
int servnum = from_server;
3978
char *chan,
3979
*serv = NULL;
3980
ChannelList *ch = NULL;
3981
3982
chan = arg1;
3983
if ((serv = new_next_arg(input, &input)))
3984
{
3985
if (my_isdigit(serv))
3986
servnum = my_atol(serv);
3987
else
3988
servnum = find_in_server_list(serv, 0);
3989
}
3990
3991
if((ch = lookup_channel(chan, servnum, CHAN_NOUNLINK)) && ch->window)
3992
RETURN_INT(ch->window->refnum);
3993
3994
if (fn && !strcmp(fn, "CHANWINDOW"))
3995
RETURN_INT(0);
3996
else
3997
RETURN_INT(-1);
3998
}
3999
4000
/*
4001
* Return channel by window refnum/desc
4002
*/
4003
else
4004
{
4005
Window *win = current_window;
4006
4007
if (arg1 && *arg1)
4008
win = get_window_by_desc(arg1);
4009
4010
if (!win)
4011
RETURN_EMPTY;
4012
4013
RETURN_STR(win->current_channel);
4014
}
4015
if (fn && !strcmp(fn, "CHANWINDOW"))
4016
RETURN_INT(0);
4017
RETURN_INT(-1);
4018
}
4019
4020
BUILT_IN_FUNCTION(function_winserv, input)
4021
{
4022
int win = 0;
4023
char *tmp;
4024
Window *winp;
4025
4026
if (input && *input)
4027
{
4028
if ((tmp = new_next_arg(input, &input)))
4029
win = atoi(tmp);
4030
}
4031
if ((winp = get_window_by_refnum(win)))
4032
RETURN_INT(winp->server);
4033
4034
RETURN_INT(-1);
4035
}
4036
4037
BUILT_IN_FUNCTION(function_numwords, input)
4038
{
4039
RETURN_INT(word_count(input));
4040
}
4041
4042
BUILT_IN_FUNCTION(function_strlen, input)
4043
{
4044
RETURN_INT(strlen(input));
4045
}
4046
4047
/*
4048
* Next two contributed by Scott H Kilau (sheik), who for some reason doesnt
4049
* want to take credit for them. *shrug* >;-)
4050
*
4051
* Deciding not to be controversial, im keeping the original (contributed)
4052
* semantics of these two functions, which is to return 1 on success and
4053
* -1 on error. If you dont like it, then tough. =) I didnt write it, and
4054
* im not going to second guess any useful contributions. >;-)
4055
*/
4056
BUILT_IN_FUNCTION(function_fexist, words)
4057
{
4058
#ifdef PUBLIC_ACCESS
4059
RETURN_INT(0);
4060
#else
4061
char FileBuf[BIG_BUFFER_SIZE+1];
4062
char *filename, *fullname;
4063
4064
*FileBuf = 0;
4065
if ((filename = new_next_arg(words, &words)))
4066
{
4067
if (*filename == '/')
4068
strlcpy(FileBuf, filename, BIG_BUFFER_SIZE);
4069
4070
else if (*filename == '~')
4071
{
4072
if (!(fullname = expand_twiddle(filename)))
4073
RETURN_INT(-1);
4074
4075
strmcpy(FileBuf, fullname, BIG_BUFFER_SIZE);
4076
new_free(&fullname);
4077
}
4078
#if defined(__EMX__) || defined(WINNT)
4079
else if (is_dos(filename))
4080
strmcpy(FileBuf, filename, BIG_BUFFER_SIZE);
4081
#endif
4082
else
4083
{
4084
getcwd(FileBuf, BIG_BUFFER_SIZE);
4085
strmcat(FileBuf, "/", BIG_BUFFER_SIZE);
4086
strmcat(FileBuf, filename, BIG_BUFFER_SIZE);
4087
}
4088
#if defined(__EMX__) || defined(WINNT)
4089
convert_dos(FileBuf);
4090
#endif
4091
if (access(FileBuf, R_OK) == -1)
4092
RETURN_INT(-1);
4093
4094
else
4095
RETURN_INT(1);
4096
}
4097
RETURN_INT(-1);
4098
#endif
4099
}
4100
4101
/* XXXX - ugh. do we really have to do a access() call first? */
4102
BUILT_IN_FUNCTION(function_fsize, words)
4103
{
4104
#ifdef PUBLIC_ACCESS
4105
RETURN_INT(0);
4106
#else
4107
char FileBuf[BIG_BUFFER_SIZE+1];
4108
char *filename, *fullname;
4109
struct stat stat_buf;
4110
off_t filesize = 0;
4111
4112
filename = new_next_arg(words, &words);
4113
*FileBuf = 0;
4114
if (filename && *filename)
4115
{
4116
if (*filename == '/')
4117
strlcpy(FileBuf, filename, BIG_BUFFER_SIZE);
4118
4119
else if (*filename == '~')
4120
{
4121
if (!(fullname = expand_twiddle(filename)))
4122
RETURN_INT(-1);
4123
4124
strmcpy(FileBuf, fullname, BIG_BUFFER_SIZE);
4125
new_free(&fullname);
4126
}
4127
#if defined(__EMX__) || defined(WINNT)
4128
else if (is_dos(filename))
4129
strmcpy(FileBuf, filename, BIG_BUFFER_SIZE);
4130
#endif
4131
else
4132
{
4133
getcwd(FileBuf, BIG_BUFFER_SIZE);
4134
strmcat(FileBuf, "/", BIG_BUFFER_SIZE);
4135
strmcat(FileBuf, filename, BIG_BUFFER_SIZE);
4136
}
4137
4138
#if defined(__EMX__) || defined(WINNT)
4139
convert_dos(FileBuf);
4140
#endif
4141
if ((stat(FileBuf, &stat_buf)) != -1)
4142
{
4143
filesize = stat_buf.st_size;
4144
RETURN_INT(filesize);
4145
}
4146
}
4147
RETURN_INT(-1);
4148
#endif
4149
}
4150
4151
/*
4152
* Contributed by CrowMan
4153
* I changed two instances of "RETURN_INT(result)"
4154
* (where result was a null pointer) to RETURN_STR(empty_string)
4155
* because i dont think he meant to return a null pointer as an int value.
4156
*/
4157
/*
4158
* $crypt(password seed)
4159
* What it does: Returns a 13-char encrypted string when given a seed and
4160
* password. Returns zero (0) if one or both args missing. Additional
4161
* args ignored.
4162
* Caveats: Password truncated to 8 chars. Spaces allowed, but password
4163
* must be inside "" quotes.
4164
* Credits: Thanks to Strongbow for showing me how crypt() works.
4165
* This cheap hack by: CrowMan
4166
*/
4167
BUILT_IN_FUNCTION(function_crypt, words)
4168
{
4169
#if defined(WINNT)
4170
RETURN_STR(empty_string);
4171
#else
4172
char pass[9] = "\0";
4173
char seed[3] = "\0";
4174
char *blah, *bleh, *crypt (const char *, const char *);
4175
4176
GET_STR_ARG(blah, words)
4177
GET_STR_ARG(bleh, words)
4178
strmcpy(pass, blah, 8);
4179
strmcpy(seed, bleh, 2);
4180
4181
RETURN_STR(crypt(pass, seed));
4182
#endif
4183
}
4184
4185
BUILT_IN_FUNCTION(function_info, words)
4186
{
4187
/*
4188
char *which;
4189
extern char *compile_info;
4190
extern char *info_c_sum;
4191
4192
GET_STR_ARG(which, words);
4193
4194
if (!my_strnicmp(which, "C", 1))
4195
RETURN_STR(compile_info);
4196
else if (!my_strnicmp(which, "S", 1))
4197
RETURN_STR(info_c_sum);
4198
4199
else
4200
*/
4201
return m_sprintf("%s+%s", version, compile_time_options);
4202
/* more to be added as neccesary */
4203
}
4204
4205
/*
4206
* Based on a contribution made a very long time ago by wintrhawk
4207
*/
4208
BUILT_IN_FUNCTION(function_channelmode, word)
4209
{
4210
char *channel;
4211
char *booya = NULL;
4212
char *mode;
4213
int type_mode = 0;
4214
do
4215
{
4216
channel = new_next_arg(word, &word);
4217
if ((!channel || !*channel) && booya)
4218
break;
4219
if (word && *word && isdigit((unsigned char)*word))
4220
GET_INT_ARG(type_mode, word);
4221
switch(type_mode)
4222
{
4223
case 1: /* bans */
4224
case 2: /* ban who time */
4225
case 3: /* exemptions [ts4] */
4226
mode = get_channel_bans(channel, from_server, type_mode);
4227
m_s3cat(&booya, space, (mode && *mode) ? mode : "*");
4228
new_free(&mode);
4229
continue;
4230
case 0:
4231
default:
4232
mode = get_channel_mode(channel, from_server);
4233
break;
4234
}
4235
m_s3cat(&booya, space, (mode && *mode) ? mode : "*");
4236
}
4237
while (word && *word);
4238
4239
return (booya ? booya : m_strdup(empty_string));
4240
}
4241
4242
BUILT_IN_FUNCTION(function_geom, words)
4243
{
4244
/* Erf. CO and LI are ints. (crowman) */
4245
return m_sprintf("%d %d", current_term->TI_cols, current_term->TI_lines);
4246
}
4247
4248
BUILT_IN_FUNCTION(function_pass, words)
4249
{
4250
char *lookfor;
4251
char *final, *ptr;
4252
4253
GET_STR_ARG(lookfor, words);
4254
final = (char *)new_malloc(strlen(words) + 1);
4255
ptr = final;
4256
4257
while (*words)
4258
{
4259
if (strchr(lookfor, *words))
4260
*ptr++ = *words;
4261
words++;
4262
}
4263
4264
*ptr = 0;
4265
return final;
4266
}
4267
4268
BUILT_IN_FUNCTION(function_uptime, input)
4269
{
4270
time_t ltime;
4271
time_t days,hours,minutes,seconds;
4272
struct timeval tp;
4273
static time_t timestart = 0;
4274
time_t timediff;
4275
char buffer[BIG_BUFFER_SIZE+1];
4276
4277
*buffer = '\0';
4278
4279
get_time(&tp);
4280
if (timestart == 0)
4281
{
4282
timestart = tp.tv_sec;
4283
timediff = 0;
4284
} else
4285
timediff = tp.tv_sec - timestart;
4286
4287
ltime = timediff;
4288
seconds = ltime % 60;
4289
ltime = (ltime - seconds) / 60;
4290
minutes = ltime%60;
4291
ltime = (ltime - minutes) / 60;
4292
hours = ltime % 24;
4293
days = (ltime - hours) / 24;
4294
sprintf(buffer, "%ldd %ldh %ldm %lds", days, hours, minutes, seconds);
4295
RETURN_STR(buffer);
4296
}
4297
4298
BUILT_IN_FUNCTION(function_cluster, input)
4299
{
4300
char *q;
4301
RETURN_IF_EMPTY(input);
4302
if ((q = cluster(input)))
4303
RETURN_STR(q);
4304
else
4305
RETURN_EMPTY;
4306
}
4307
4308
BUILT_IN_FUNCTION(function_checkshit, input)
4309
{
4310
char *uh = NULL;
4311
char *channel = NULL;
4312
register ShitList *tmp;
4313
int matched = 0;
4314
GET_STR_ARG(uh, input);
4315
GET_STR_ARG(channel, input);
4316
4317
for (tmp = shitlist_list; tmp; tmp = tmp->next)
4318
{
4319
if (wild_match(tmp->filter, uh) && check_channel_match(tmp->channels, channel))
4320
{
4321
matched = 1;
4322
break;
4323
}
4324
}
4325
4326
if (tmp && matched)
4327
return m_sprintf("%d %s %s %s", tmp->level, tmp->channels, tmp->filter, tmp->reason);
4328
RETURN_EMPTY;
4329
}
4330
4331
BUILT_IN_FUNCTION(function_get_info, input)
4332
{
4333
#ifdef WANT_USERLIST
4334
char *nick;
4335
register UserList *tmp;
4336
void *needed = NULL;
4337
int size = -1;
4338
GET_STR_ARG(nick, input);
4339
for (tmp = next_userlist(NULL, &size, &needed); tmp; tmp = next_userlist(tmp, &size, &needed))
4340
{
4341
if (!my_stricmp(nick, tmp->nick) || wild_match(nick, tmp->nick))
4342
{
4343
if (tmp->comment)
4344
RETURN_STR(tmp->comment);
4345
}
4346
}
4347
#endif
4348
RETURN_EMPTY;
4349
}
4350
4351
BUILT_IN_FUNCTION(function_set_info, input)
4352
{
4353
#ifdef WANT_USERLIST
4354
char *nick;
4355
register UserList *tmp;
4356
void *location = NULL;
4357
int size = -1;
4358
int done = 0;
4359
GET_STR_ARG(nick, input);
4360
for (tmp = next_userlist(NULL, &size, &location); tmp; tmp = next_userlist(tmp, &size, &location))
4361
{
4362
if (!my_stricmp(tmp->nick, nick) || wild_match(nick, tmp->nick))
4363
{
4364
if (input && *input)
4365
malloc_strcpy(&tmp->comment, input);
4366
else
4367
new_free(&tmp->comment);
4368
done++;
4369
}
4370
}
4371
if (done)
4372
RETURN_INT(1);
4373
#endif
4374
RETURN_INT(0);
4375
}
4376
4377
BUILT_IN_FUNCTION(function_checkuser, input)
4378
{
4379
#ifdef WANT_USERLIST
4380
char *uh = NULL;
4381
char *channel = NULL;
4382
register UserList *tmp;
4383
GET_STR_ARG(uh, input);
4384
GET_STR_ARG(channel, input);
4385
if (!uh || !*uh || !channel || !*channel)
4386
RETURN_EMPTY;
4387
if ((tmp = find_bestmatch("*", uh, channel, NULL)))
4388
return m_sprintf("%d %s %s %s", tmp->flags, tmp->host, tmp->channels, tmp->password?tmp->password:empty_string);
4389
#endif
4390
RETURN_EMPTY;
4391
}
4392
4393
BUILT_IN_FUNCTION(function_rot13, input)
4394
{
4395
char temp[BIG_BUFFER_SIZE+1];
4396
register char *p = NULL;
4397
int rotate = 13;
4398
strmcpy(temp, input, BIG_BUFFER_SIZE);
4399
for (p = temp; *p; p++) {
4400
if (*p >= 'A' && *p <='Z')
4401
*p = (*p - 'A' + rotate) % 26 + 'A';
4402
else if (*p >= 'a' && *p <= 'z')
4403
*p = (*p - 'a' + rotate) % 26 + 'a';
4404
}
4405
RETURN_STR(temp);
4406
}
4407
4408
BUILT_IN_FUNCTION(function_repeat, words)
4409
{
4410
register int num;
4411
char *final = NULL;
4412
4413
GET_INT_ARG(num, words);
4414
if (num < 1)
4415
RETURN_EMPTY;
4416
4417
final = (char *)new_malloc(strlen(words) * num + 1);
4418
for (; num > 0; num--)
4419
strcat(final, words);
4420
if (strlen(final) > BIG_BUFFER_SIZE)
4421
final[BIG_BUFFER_SIZE] = 0;
4422
return final;
4423
}
4424
4425
4426
BUILT_IN_FUNCTION(function_bcopy, words)
4427
{
4428
#ifdef PUBLIC_ACCESS
4429
RETURN_INT(0);
4430
#else
4431
int from, to;
4432
if (in_cparse)
4433
RETURN_INT(0);
4434
GET_INT_ARG(from, words);
4435
GET_INT_ARG(to, words);
4436
RETURN_INT(file_copy(from, to));
4437
#endif
4438
}
4439
4440
BUILT_IN_FUNCTION(function_epic, words)
4441
{
4442
RETURN_INT(1);
4443
}
4444
4445
BUILT_IN_FUNCTION(function_runlevel, words)
4446
{
4447
extern int run_level;
4448
4449
RETURN_INT(run_level);
4450
}
4451
4452
BUILT_IN_FUNCTION(function_ovserver, words)
4453
{
4454
int ovserver;
4455
char *servname = NULL;
4456
4457
GET_INT_ARG(ovserver, words);
4458
if(ovserver > -1)
4459
servname = ov_server(ovserver);
4460
4461
if(servname)
4462
RETURN_STR(servname);
4463
4464
RETURN_EMPTY;
4465
}
4466
4467
BUILT_IN_FUNCTION(function_winsize, words)
4468
{
4469
int refnum;
4470
Window *win;
4471
4472
if (words && *words)
4473
{
4474
GET_INT_ARG(refnum, words);
4475
win = get_window_by_refnum(refnum);
4476
}
4477
else
4478
win = current_window;
4479
4480
if (!win)
4481
RETURN_EMPTY;
4482
4483
RETURN_INT(win->display_size);
4484
}
4485
4486
BUILT_IN_FUNCTION(function_umode, words)
4487
{
4488
int servnum;
4489
4490
if (words && *words)
4491
{
4492
GET_INT_ARG(servnum, words);
4493
}
4494
else
4495
servnum = from_server;
4496
4497
RETURN_STR(get_umode(servnum));
4498
}
4499
4500
4501
BUILT_IN_FUNCTION(function_lastnotice, words)
4502
{
4503
int count = 0;
4504
char *str = NULL;
4505
GET_INT_ARG(count, words);
4506
if (count >= MAX_LAST_MSG)
4507
count = 0;
4508
RETURN_IF_EMPTY(last_notice[count].last_msg);
4509
malloc_sprintf(&str, "%s %s %s %s %s", last_notice[count].time, last_notice[count].from, last_notice[count].uh, last_notice[count].to, last_notice[count].last_msg);
4510
return str;
4511
}
4512
4513
BUILT_IN_FUNCTION(function_lastmessage, words)
4514
{
4515
int count = 0;
4516
char *str = NULL;
4517
GET_INT_ARG(count, words);
4518
if (count >= MAX_LAST_MSG)
4519
count = 0;
4520
RETURN_IF_EMPTY(last_msg[count].last_msg);
4521
malloc_sprintf(&str, "%s %s %s %s %s", last_msg[count].time, last_msg[count].from, last_msg[count].uh, last_msg[count].to, last_msg[count].last_msg);
4522
return str;
4523
}
4524
4525
char *function_addtabkey (char *n, char *words)
4526
{
4527
char *arrayname = NULL;
4528
char *nick = NULL;
4529
4530
GET_STR_ARG(nick, words);
4531
if (words && *words)
4532
arrayname = new_next_arg(words, &words);
4533
addtabkey(nick, NULL, arrayname ? 1: 0);
4534
RETURN_EMPTY;
4535
}
4536
4537
char *function_gettabkey (char *n, char *words)
4538
{
4539
char *arrayname = NULL;
4540
NickTab *nick = NULL;
4541
int direction;
4542
4543
GET_INT_ARG(direction, words);
4544
4545
if (words && *words)
4546
arrayname = new_next_arg(words, &words);
4547
4548
if (arrayname && !my_stricmp(arrayname, "AUTOREPLY"))
4549
nick = gettabkey(direction, 1, NULL);
4550
else
4551
nick = gettabkey(direction, 0, NULL);
4552
4553
return nick ? m_strdup(nick->nick) : m_strdup(empty_string);
4554
}
4555
4556
static int sort_it (const void *one, const void *two)
4557
{
4558
return my_stricmp(*(char **)one, *(char **)two);
4559
}
4560
4561
BUILT_IN_FUNCTION(function_sort, words)
4562
{
4563
int wordc;
4564
char **wordl;
4565
4566
wordc = splitw(words, &wordl);
4567
qsort((void *)wordl, wordc, sizeof(char *), sort_it);
4568
return unsplitw(&wordl, wordc); /* DONT USE RETURN_STR() HERE */
4569
}
4570
4571
BUILT_IN_FUNCTION(function_notify, words)
4572
{
4573
int showon = -1, showserver = from_server;
4574
char *firstw;
4575
int len = 0;
4576
char *buf = NULL, *ret = NULL;
4577
4578
while (words && *words)
4579
{
4580
firstw = new_next_arg(words, &words);
4581
len = strlen(firstw);
4582
if (*firstw == '+')
4583
{
4584
if (len == 1)
4585
showon = 1;
4586
else
4587
buf = get_notify_nicks(showserver, 1, firstw+1, 0);
4588
}
4589
else if (*firstw == '-')
4590
{
4591
if (len == 1)
4592
showon = 0;
4593
else
4594
buf = get_notify_nicks(showserver, 1, firstw+1, 0);
4595
}
4596
else if (*firstw == '!')
4597
{
4598
if (len != 1)
4599
buf = get_notify_nicks(showserver, showon, firstw+1, 1);
4600
}
4601
else if (!my_strnicmp(firstw, "serv", 4))
4602
GET_INT_ARG(showserver, words);
4603
4604
if (buf)
4605
{
4606
m_s3cat(&ret, space, buf);
4607
new_free(&buf);
4608
}
4609
}
4610
4611
/* dont use RETURN_STR() here. */
4612
return ret ? ret : get_notify_nicks(showserver, showon, NULL, 0);
4613
}
4614
4615
BUILT_IN_FUNCTION(function_watch, words)
4616
{
4617
int showon = -1, showserver = from_server;
4618
char *firstw;
4619
int len = 0;
4620
char *buf = NULL, *ret = NULL;
4621
4622
while (words && *words)
4623
{
4624
firstw = new_next_arg(words, &words);
4625
len = strlen(firstw);
4626
if (*firstw == '+')
4627
{
4628
if (len == 1)
4629
showon = 1;
4630
else
4631
buf = get_watch_nicks(showserver, 1, firstw+1, 0);
4632
}
4633
else if (*firstw == '-')
4634
{
4635
if (len == 1)
4636
showon = 0;
4637
else
4638
buf = get_watch_nicks(showserver, 1, firstw+1, 0);
4639
}
4640
else if (*firstw == '!')
4641
{
4642
if (len != 1)
4643
buf = get_watch_nicks(showserver, showon, firstw+1, 1);
4644
}
4645
else if (!my_strnicmp(firstw, "serv", 4))
4646
GET_INT_ARG(showserver, words);
4647
4648
if (buf)
4649
{
4650
m_s3cat(&ret, space, buf);
4651
new_free(&buf);
4652
}
4653
}
4654
4655
/* dont use RETURN_STR() here. */
4656
return ret ? ret : get_watch_nicks(showserver, showon, NULL, 0);
4657
}
4658
4659
static int num_sort_it (const void *one, const void *two)
4660
{
4661
char *oneptr = *(char **)one;
4662
char *twoptr = *(char **)two;
4663
long val1, val2;
4664
4665
while (*oneptr && *twoptr)
4666
{
4667
while (*oneptr && *twoptr && !isdigit((unsigned char)*oneptr) && !isdigit((unsigned char)*twoptr))
4668
{
4669
if (*oneptr != *twoptr)
4670
return (*oneptr - *twoptr);
4671
oneptr++, twoptr++;
4672
}
4673
4674
if (!*oneptr || !*twoptr)
4675
break;
4676
4677
val1 = strtol(oneptr, (char **)&oneptr, 10);
4678
val2 = strtol(twoptr, (char **)&twoptr, 10);
4679
if (val1 != val2)
4680
return val1 - val2;
4681
}
4682
return (*oneptr - *twoptr);
4683
}
4684
4685
BUILT_IN_FUNCTION(function_numsort, words)
4686
{
4687
int wordc;
4688
char **wordl;
4689
4690
wordc = splitw(words, &wordl);
4691
qsort((void *)wordl, wordc, sizeof(char *), num_sort_it);
4692
4693
return unsplitw(&wordl, wordc); /* DONT USE RETURN_STR() HERE */
4694
}
4695
4696
#ifdef NEED_GLOB
4697
#define glob bsd_glob
4698
#define globfree bsd_globfree
4699
#endif
4700
4701
BUILT_IN_FUNCTION(function_glob, word)
4702
{
4703
#if defined(INCLUDE_GLOB_FUNCTION) && !defined(PUBLIC_ACCESS)
4704
char *path,
4705
*path2 = NULL,
4706
*retval = NULL;
4707
int numglobs,
4708
i;
4709
glob_t globbers;
4710
4711
memset(&globbers, 0, sizeof(glob_t));
4712
while (word && *word)
4713
{
4714
GET_STR_ARG(path, word);
4715
path2 = expand_twiddle(path);
4716
if (!path2)
4717
path2 = m_strdup(path);
4718
4719
numglobs = glob(path2, GLOB_MARK, NULL, &globbers);
4720
if (numglobs < 0)
4721
{
4722
new_free(&path2);
4723
RETURN_INT(numglobs);
4724
}
4725
for (i = 0; i < globbers.gl_pathc; i++)
4726
{
4727
if (strchr(globbers.gl_pathv[i], ' '))
4728
{
4729
int len = strlen(globbers.gl_pathv[i])+4;
4730
char *b = alloca(len+1);
4731
*b = 0;
4732
strmopencat(b, len, "\"", globbers.gl_pathv[i], "\"", NULL);
4733
m_s3cat(&retval, space, b);
4734
}
4735
else
4736
m_s3cat(&retval, space, globbers.gl_pathv[i]);
4737
}
4738
globfree(&globbers);
4739
new_free(&path2);
4740
}
4741
return retval ? retval : m_strdup(empty_string);
4742
#else
4743
RETURN_EMPTY;
4744
#endif
4745
}
4746
4747
BUILT_IN_FUNCTION(function_mkdir, words)
4748
{
4749
#ifdef PUBLIC_ACCESS
4750
RETURN_EMPTY;
4751
#else
4752
int failure = 0;
4753
char *expanded;
4754
4755
while (words && *words)
4756
{
4757
expanded = expand_twiddle(new_next_arg(words, &words));
4758
failure -= mkdir(expanded, 0777);
4759
new_free(&expanded);
4760
}
4761
4762
RETURN_INT(failure);
4763
#endif
4764
}
4765
4766
BUILT_IN_FUNCTION(function_umask, words)
4767
{
4768
int new_umask;
4769
GET_INT_ARG(new_umask, words);
4770
RETURN_INT(umask(new_umask));
4771
}
4772
4773
BUILT_IN_FUNCTION(function_help, words)
4774
{
4775
#if defined(WANT_CHELP) && !defined(PUBLIC_ACCESS)
4776
extern void get_help_topic(const char *, int);
4777
extern int read_file(FILE *, int);
4778
4779
static int first_time = 1;
4780
char *subject;
4781
4782
GET_STR_ARG(subject, words);
4783
4784
if (first_time)
4785
{
4786
FILE *help_file;
4787
char *new_file = NULL;
4788
4789
malloc_strcpy(&new_file, get_string_var(SCRIPT_HELP_VAR));
4790
help_file = uzfopen(&new_file, get_string_var(LOAD_PATH_VAR), 0);
4791
new_free(&new_file);
4792
4793
if (!help_file)
4794
RETURN_EMPTY;
4795
4796
first_time = 0;
4797
read_file(help_file, 1);
4798
fclose(help_file);
4799
}
4800
4801
get_help_topic(subject, 1);
4802
#endif
4803
RETURN_EMPTY;
4804
}
4805
4806
BUILT_IN_FUNCTION(function_isuser, words)
4807
{
4808
#ifdef WANT_USERLIST
4809
char *nick = NULL;
4810
char *uhost = NULL;
4811
char *channel = NULL;
4812
register UserList *User;
4813
register ShitList *Shit;
4814
4815
GET_STR_ARG(nick, words);
4816
GET_STR_ARG(uhost, words);
4817
if (words && *words)
4818
channel = words;
4819
else
4820
channel = "*";
4821
if ((User = lookup_userlevelc("*", uhost, channel, NULL)))
4822
return m_sprintf("USER %d %s %s", User->flags, User->host, User->channels);
4823
if ((Shit = nickinshit(nick, uhost)) && check_channel_match(Shit->channels, channel))
4824
return m_sprintf("SHIT %s %d %s", Shit->filter, Shit->level, Shit->channels);
4825
#endif
4826
RETURN_EMPTY;
4827
}
4828
4829
/*
4830
$pad(N string of text goes here)
4831
if N is negative, it'll pad to the right
4832
if N is positive, it'll pad to the left
4833
4834
so something like: $pad(20 letters) would output:
4835
letters
4836
and $pad(20 some string) would be:
4837
some string
4838
GREAT way to allign shit, and if you use $curpos() can can add that and
4839
figure out the indent :p
4840
hohoho, aren't we ingenious, better yet, you can do a strlen() on the
4841
string youw anna output, then - the curpos, and if its over, grab all
4842
words to the right of that position and output them [so its on one line]
4843
then indent, grab the next section of words( and then the next and then
4844
next
4845
4846
Jordy ([email protected]) 19960622
4847
*/
4848
4849
BUILT_IN_FUNCTION(function_pad, word)
4850
{
4851
int length = 0;
4852
GET_INT_ARG(length, word);
4853
return m_sprintf("%*s", length, word);
4854
}
4855
4856
BUILT_IN_FUNCTION(function_isban, word)
4857
{
4858
char *channel;
4859
char *ban;
4860
ShitList *Ban;
4861
GET_STR_ARG(channel, word);
4862
GET_STR_ARG(ban, word);
4863
if ((Ban = (ShitList *)find_in_list((List **)&shitlist_list, ban, 0)) && check_channel_match(channel, Ban->channels))
4864
RETURN_INT(1);
4865
RETURN_INT(0);
4866
}
4867
4868
BUILT_IN_FUNCTION(function_isignored, word)
4869
{
4870
char *nick;
4871
GET_STR_ARG(nick, word);
4872
if (check_is_ignored(nick))
4873
RETURN_INT(1);
4874
RETURN_INT(0);
4875
}
4876
4877
BUILT_IN_FUNCTION(function_banonchannel, word)
4878
{
4879
ChannelList *chan;
4880
char *channel;
4881
char *ban;
4882
GET_STR_ARG(channel, word);
4883
GET_STR_ARG(ban, word);
4884
if ((chan = lookup_channel(channel, from_server, 0)))
4885
{
4886
if (ban_is_on_channel(ban, chan))
4887
RETURN_INT(1);
4888
}
4889
RETURN_INT(0);
4890
}
4891
4892
BUILT_IN_FUNCTION(function_isop, word)
4893
{
4894
char *channel;
4895
char *nick;
4896
ChannelList *chan;
4897
NickList *Nick;
4898
GET_STR_ARG(channel, word);
4899
GET_STR_ARG(nick, word);
4900
if ((chan = lookup_channel(channel, from_server, CHAN_NOUNLINK)))
4901
{
4902
if ((Nick = find_nicklist_in_channellist(nick, chan, 0)) &&
4903
(Nick->userlist && (Nick->userlist->flags & ADD_OPS)))
4904
RETURN_INT(1);
4905
}
4906
RETURN_INT(0);
4907
}
4908
4909
BUILT_IN_FUNCTION(function_isvoice, word)
4910
{
4911
char *channel, *nickname;
4912
ChannelList *chan;
4913
NickList *Nick;
4914
char *ret = NULL;
4915
4916
GET_STR_ARG(channel, word);
4917
/* Note: This is the old way, maintained for compatibility */
4918
if ((chan = lookup_channel(channel, from_server, CHAN_NOUNLINK)))
4919
{
4920
while ((nickname = next_in_comma_list(word, &word)))
4921
{
4922
if (!nickname || !*nickname) break;
4923
Nick = find_nicklist_in_channellist(nickname, chan, 0);
4924
m_s3cat(&ret, comma, Nick? (nick_isvoice(Nick) ? one : zero) : zero);
4925
}
4926
return ret;
4927
} else {
4928
/* args are in proper order, channel is actually the nick */
4929
nickname = channel;
4930
GET_STR_ARG(channel, word);
4931
4932
if ((chan = lookup_channel(channel, from_server, CHAN_NOUNLINK))) {
4933
Nick = find_nicklist_in_channellist(nickname, chan, 0);
4934
RETURN_STR(Nick ? (nick_isvoice(Nick) ? one : zero) : zero);
4935
}
4936
}
4937
4938
RETURN_INT(0);
4939
}
4940
4941
BUILT_IN_FUNCTION(function_randomnick, word)
4942
{
4943
int len1 = 3, len2 = 9;
4944
if (word && *word)
4945
GET_INT_ARG(len1, word);
4946
if (word && *word)
4947
GET_INT_ARG(len2, word);
4948
RETURN_STR(random_str(len1,len2));
4949
}
4950
4951
4952
#ifndef BITCHX_LITE
4953
BUILT_IN_FUNCTION(function_openserver, word)
4954
{
4955
#ifdef PUBLIC_ACCESS
4956
RETURN_INT(0);
4957
#else
4958
int port = -1;
4959
char *servern = NULL;
4960
int socket_num = -1;
4961
unsigned short this_sucks;
4962
int notify_mode = 0;
4963
GET_STR_ARG(servern, word);
4964
GET_INT_ARG(port, word);
4965
if (word && *word && toupper(*word) == 'N')
4966
notify_mode = 1;
4967
if (port > 0)
4968
{
4969
this_sucks = (unsigned short)port;
4970
if ((socket_num = connect_by_number(servern, &this_sucks, SERVICE_CLIENT, PROTOCOL_TCP, 1)) < 0)
4971
RETURN_INT(-1);
4972
if ((add_socketread(socket_num, port, 0, servern, !notify_mode ? read_clonelist :read_clonenotify, NULL)) < 0)
4973
{
4974
close_socketread(socket_num);
4975
RETURN_INT(-1);
4976
}
4977
}
4978
RETURN_INT(socket_num);
4979
#endif
4980
}
4981
4982
BUILT_IN_FUNCTION(function_closeserver, word)
4983
{
4984
#ifdef PUBLIC_ACCESS
4985
RETURN_INT(0);
4986
#else
4987
int socket_num = -1;
4988
GET_INT_ARG(socket_num, word);
4989
if (socket_num > 0 && check_socket(socket_num))
4990
close_socketread(socket_num);
4991
RETURN_INT(socket_num);
4992
#endif
4993
}
4994
4995
BUILT_IN_FUNCTION(function_readserver, word)
4996
{
4997
#ifdef PUBLIC_ACCESS
4998
RETURN_INT(0);
4999
#else
5000
int socket_num = -1;
5001
GET_INT_ARG(socket_num, word);
5002
if ((socket_num > 0) && check_socket(socket_num))
5003
{
5004
char buffer[IRCD_BUFFER_SIZE+1];
5005
char *str;
5006
char *s;
5007
*buffer = 0;
5008
str = buffer;
5009
switch(dgets(str, socket_num, 0, IRCD_BUFFER_SIZE, NULL))
5010
{
5011
case 0:
5012
socket_num = 0;
5013
break;
5014
case -1:
5015
close_socketread(socket_num);
5016
socket_num = -1;
5017
break;
5018
default:
5019
if ((buffer[strlen(buffer)-1] == '\r') || (buffer[strlen(buffer)-1] == '\n'))
5020
buffer[strlen(buffer)-1] = 0;
5021
if ((buffer[strlen(buffer)-1] == '\r') || (buffer[strlen(buffer)-1] == '\n'))
5022
buffer[strlen(buffer)-1] = 0;
5023
s = m_sprintf("%d %s", strlen(buffer), buffer);
5024
return s;
5025
}
5026
}
5027
RETURN_INT(socket_num);
5028
#endif
5029
}
5030
5031
5032
BUILT_IN_FUNCTION(function_readchar, word)
5033
{
5034
#ifdef PUBLIC_ACCESS
5035
RETURN_INT(0);
5036
#else
5037
int socket_num = -1;
5038
GET_INT_ARG(socket_num, word);
5039
if ((socket_num >= 0) && check_socket(socket_num))
5040
{
5041
char buffer[10];
5042
char *str;
5043
char *s;
5044
*buffer = 0;
5045
*(buffer+1) = 0;
5046
str = buffer;
5047
if ((read(socket_num, str, 1) == 1))
5048
s = m_sprintf("%c", *buffer);
5049
else
5050
s = m_sprintf(empty_string);
5051
return s;
5052
}
5053
RETURN_INT(socket_num);
5054
#endif
5055
}
5056
5057
BUILT_IN_FUNCTION(function_writeserver, word)
5058
{
5059
#ifdef PUBLIC_ACCESS
5060
RETURN_INT(0);
5061
#else
5062
int socket_num = -1;
5063
int len = -1;
5064
GET_INT_ARG(socket_num, word);
5065
if ((socket_num > 0) && check_socket(socket_num))
5066
len = write_sockets(socket_num, word, strlen(word), 1);
5067
RETURN_INT(len);
5068
#endif
5069
}
5070
#endif
5071
5072
char *function_cparse(char *n, char *word)
5073
{
5074
char *format = NULL;
5075
char *blah;
5076
GET_STR_ARG(format, word);
5077
in_cparse++;
5078
blah = convert_output_format(format, word && *word? "%s":NULL, word&&*word?word:NULL);
5079
in_cparse--;
5080
RETURN_STR(blah);
5081
}
5082
5083
BUILT_IN_FUNCTION(function_getreason, word)
5084
{
5085
char *nick = NULL;
5086
GET_STR_ARG(nick, word);
5087
RETURN_STR(get_reason(nick, word));
5088
}
5089
5090
BUILT_IN_FUNCTION(function_chmod, words)
5091
{
5092
#ifdef PUBLIC_ACCESS
5093
RETURN_INT(0);
5094
#else
5095
char *filearg, *after;
5096
int fd = -1;
5097
char *perm_s;
5098
mode_t perm;
5099
5100
GET_STR_ARG(filearg, words);
5101
fd = (int) strtoul(filearg, &after, 10);
5102
GET_STR_ARG(perm_s, words);
5103
perm = (mode_t) strtol(perm_s, &perm_s, 8);
5104
5105
if (after != words && *after == 0)
5106
{
5107
if (file_valid(fd))
5108
#if defined(__EMX__) || defined(__OPENNT)
5109
RETURN_INT(0644);
5110
#else
5111
RETURN_INT(fchmod(fd, perm));
5112
#endif
5113
else
5114
RETURN_EMPTY;
5115
}
5116
else
5117
{
5118
char *expanded;
5119
int retval;
5120
expanded = expand_twiddle(filearg);
5121
retval = chmod(expanded, perm);
5122
new_free(&expanded);
5123
RETURN_INT(retval);
5124
}
5125
#endif
5126
}
5127
5128
BUILT_IN_FUNCTION(function_twiddle, words)
5129
{
5130
if (words && *words)
5131
return expand_twiddle(new_next_arg(words, &words));
5132
5133
RETURN_EMPTY;
5134
}
5135
5136
5137
/*
5138
* Date: Sun, 29 Sep 1996 19:17:25 -0700
5139
* Author: Thomas Morgan <[email protected]>
5140
* Submitted-by: Archon <[email protected]>
5141
*
5142
* $uniq (string of text)
5143
* Given a set of words, returns a new set of words with duplicates
5144
* removed.
5145
* EX: $uniq(one two one two) returns "one two"
5146
*/
5147
BUILT_IN_FUNCTION(function_uniq, word)
5148
{
5149
char **list = NULL, *booya = NULL;
5150
int listc, listi;
5151
char *input, *tval;
5152
5153
RETURN_IF_EMPTY(word);
5154
listc = splitw(word, &list);
5155
if (!listc)
5156
RETURN_EMPTY;
5157
5158
booya = m_strdup(list[0]);
5159
for (listi = 1; listi < listc; listi++)
5160
{
5161
input = alloca(strlen(list[listi]) + strlen(booya) + 2);
5162
strcpy(input, list[listi]);
5163
strcat(input, space);
5164
strcat(input, booya);
5165
5166
tval = function_findw(NULL, input);
5167
if (my_atol(tval) == -1)
5168
m_s3cat(&booya, space, list[listi]);
5169
new_free(&tval);
5170
}
5171
new_free((char **)&list);
5172
RETURN_MSTR(booya);
5173
}
5174
5175
BUILT_IN_FUNCTION(function_uhost, word)
5176
{
5177
char *nick;
5178
char *answer = NULL;
5179
int i;
5180
register ChannelList *chan;
5181
NickList *n1;
5182
GET_STR_ARG(nick, word);
5183
for (i = 0; i < server_list_size(); i++)
5184
{
5185
for (chan = get_server_channels(i); chan; chan = chan->next)
5186
{
5187
if ((n1 = find_nicklist_in_channellist(nick, chan, 0)))
5188
{
5189
malloc_strcat(&answer, n1->host);
5190
malloc_strcat(&answer, space);
5191
}
5192
}
5193
}
5194
if (!answer)
5195
RETURN_EMPTY;
5196
return answer;
5197
}
5198
5199
BUILT_IN_FUNCTION(function_numdiff, word)
5200
{
5201
int value1 = 0, value2 = 0;
5202
GET_INT_ARG(value1, word);
5203
GET_INT_ARG(value2, word);
5204
RETURN_INT(value1-value2);
5205
}
5206
5207
BUILT_IN_FUNCTION(function_winvisible, word)
5208
{
5209
RETURN_INT(get_visible_by_refnum(word));
5210
}
5211
5212
#ifndef BITCHX_LITE
5213
BUILT_IN_FUNCTION(function_mircansi, word)
5214
{
5215
extern char *mircansi(char *);
5216
RETURN_STR(mircansi(word));
5217
}
5218
#endif
5219
5220
BUILT_IN_FUNCTION(function_getenv, word)
5221
{
5222
char *p;
5223
char *q;
5224
GET_STR_ARG(q, word);
5225
p = getenv(q);
5226
if (p && *p)
5227
RETURN_STR(p);
5228
RETURN_EMPTY;
5229
}
5230
5231
BUILT_IN_FUNCTION(function_gethost, word)
5232
{
5233
register ChannelList *chan;
5234
register NickList *nick;
5235
char *arg;
5236
GET_STR_ARG(arg, word);
5237
if (from_server != -1)
5238
{
5239
for (chan = get_server_channels(from_server); chan; chan = chan->next)
5240
{
5241
for (nick = next_nicklist(chan, NULL); nick; nick = next_nicklist(chan, nick))
5242
{
5243
if (!my_stricmp(arg, nick->nick))
5244
RETURN_STR(nick->host);
5245
}
5246
}
5247
}
5248
RETURN_EMPTY;
5249
}
5250
5251
BUILT_IN_FUNCTION(function_getvar, words)
5252
{
5253
char *alias;
5254
int num = 0;
5255
int old_alias_debug = alias_debug;
5256
if ((alias = (char *)get_cmd_alias(upper(words), &num, NULL, NULL)))
5257
{
5258
alias_debug = old_alias_debug;
5259
RETURN_STR(alias);
5260
}
5261
RETURN_EMPTY;
5262
}
5263
5264
5265
BUILT_IN_FUNCTION(function_aliasctl, input)
5266
{
5267
extern char *aliasctl (char *, char *);
5268
return aliasctl(NULL, input);
5269
}
5270
5271
BUILT_IN_FUNCTION(function_status, word)
5272
{
5273
int window_refnum;
5274
int status_line;
5275
5276
GET_INT_ARG(window_refnum, word);
5277
GET_INT_ARG(status_line, word);
5278
RETURN_STR(get_status_by_refnum(window_refnum, status_line));
5279
}
5280
extern char *stat_convert_format (Window *, char *);
5281
BUILT_IN_FUNCTION(function_statsparse, word)
5282
{
5283
return stat_convert_format(current_window, word);
5284
}
5285
5286
BUILT_IN_FUNCTION(function_absstrlen, word)
5287
{
5288
char *tmp;
5289
if (!word || !*word)
5290
RETURN_INT(0);
5291
tmp = stripansicodes(word);
5292
RETURN_INT(strlen(tmp));
5293
}
5294
5295
BUILT_IN_FUNCTION(function_findw, input)
5296
{
5297
char *word, *this_word;
5298
int word_cnt = 0;
5299
5300
GET_STR_ARG(word, input);
5301
5302
while (input && *input)
5303
{
5304
GET_STR_ARG(this_word, input);
5305
if (!my_stricmp(this_word, word))
5306
RETURN_INT(word_cnt);
5307
5308
word_cnt++;
5309
}
5310
5311
RETURN_INT(-1);
5312
}
5313
5314
5315
BUILT_IN_FUNCTION(function_countansi, input)
5316
{
5317
RETURN_INT(output_with_count(input, 0, 0));
5318
}
5319
5320
BUILT_IN_FUNCTION(function_iplong, word)
5321
{
5322
char *blah;
5323
struct in_addr addr = {0};
5324
GET_STR_ARG(blah, word);
5325
if (inet_aton(blah, &addr))
5326
return m_sprintf("%lu", (unsigned long)htonl(addr.s_addr));
5327
RETURN_EMPTY;
5328
}
5329
5330
BUILT_IN_FUNCTION(function_longip, word)
5331
{
5332
char *blah = NULL;
5333
struct in_addr addr = {0};
5334
GET_STR_ARG(blah, word);
5335
addr.s_addr = atol(blah);
5336
RETURN_STR(inet_ntoa(addr));
5337
}
5338
5339
#include <stdlib.h>
5340
BUILT_IN_FUNCTION(function_rword, word)
5341
{
5342
int num = 0;
5343
long rn;
5344
char *p;
5345
#ifndef RAND_MAX
5346
#define RAND_MAX 2147483647
5347
#endif
5348
RETURN_IF_EMPTY(word);
5349
num = word_count(word);
5350
rn = (int)(((float)num)*rand()/(RAND_MAX+1.0));
5351
p = extract(word, rn, rn);
5352
return p;
5353
}
5354
5355
BUILT_IN_FUNCTION(function_winlen, word)
5356
{
5357
int refnum;
5358
int len = 0;
5359
Window *win = current_window;
5360
if (word && *word)
5361
{
5362
refnum = my_atol(word);
5363
win = get_window_by_refnum(refnum);
5364
if (!win)
5365
RETURN_INT(-1);
5366
}
5367
len = win->display_size;
5368
RETURN_INT(len);
5369
}
5370
5371
BUILT_IN_FUNCTION(function_channel, word)
5372
{
5373
char *chan;
5374
ChannelList *channel = NULL; /* XXX */
5375
NickList *tmp = NULL;
5376
char *nicks = NULL;
5377
int sort_order = NICKSORT_NORMAL;
5378
chan = next_arg(word, &word);
5379
if (!chan)
5380
chan = get_current_channel_by_refnum(0);
5381
RETURN_IF_EMPTY(chan);
5382
if ((channel = lookup_channel(chan, from_server, 0)))
5383
{
5384
NickList *list = NULL;
5385
if (word && *word)
5386
GET_INT_ARG(sort_order, word);
5387
list = sorted_nicklist(channel, sort_order);
5388
for (tmp = list; tmp; tmp = tmp->next)
5389
{
5390
if (nick_isircop(tmp))
5391
malloc_strcat(&nicks, "*");
5392
if (tmp->userlist)
5393
malloc_strcat(&nicks, "&");
5394
else if (tmp->shitlist)
5395
malloc_strcat(&nicks, "!");
5396
if (nick_isop(tmp))
5397
m_3cat(&nicks, "@", tmp->nick);
5398
else if (nick_ishalfop(tmp))
5399
m_3cat(&nicks, "%", tmp->nick);
5400
else if (nick_isvoice(tmp))
5401
m_3cat(&nicks, "+", tmp->nick);
5402
else
5403
m_3cat(&nicks, ".", tmp->nick);
5404
malloc_strcat(&nicks, space);
5405
}
5406
clear_sorted_nicklist(&list);
5407
}
5408
return (nicks ? nicks : m_strdup(empty_string));
5409
5410
}
5411
5412
/*
5413
* Given a channel, tells you what window its bound to.
5414
* Given a window, tells you what channel its bound to.
5415
*/
5416
BUILT_IN_FUNCTION(function_winbound, input)
5417
{
5418
Window *foo;
5419
char *stuff;
5420
5421
stuff = new_next_arg(input, &input);
5422
if (my_atol(stuff) && (foo = get_window_by_refnum((unsigned)my_atol(stuff))))
5423
RETURN_STR(get_bound_channel(foo));
5424
else if ((foo = get_window_by_name(stuff)))
5425
RETURN_STR(get_bound_channel(foo));
5426
else if ((foo = get_window_bound_channel(stuff)))
5427
RETURN_STR(get_refnum_by_window(foo));
5428
5429
RETURN_EMPTY;
5430
}
5431
5432
BUILT_IN_FUNCTION(function_ftime, words)
5433
{
5434
#ifdef PUBLIC_ACCESS
5435
RETURN_INT(0);
5436
#else
5437
char FileBuf[BIG_BUFFER_SIZE+1];
5438
char *filename, *fullname;
5439
struct stat s;
5440
5441
*FileBuf = 0;
5442
if ((filename = new_next_arg(words, &words)))
5443
{
5444
if (*filename == '/')
5445
strlcpy(FileBuf, filename, BIG_BUFFER_SIZE);
5446
5447
else if (*filename == '~')
5448
{
5449
if (!(fullname = expand_twiddle(filename)))
5450
RETURN_EMPTY;
5451
5452
strmcpy(FileBuf, fullname, BIG_BUFFER_SIZE);
5453
new_free(&fullname);
5454
}
5455
#if defined(__EMX__) || defined(WINNT)
5456
else if (is_dos(filename))
5457
strmcpy(FileBuf, filename, BIG_BUFFER_SIZE);
5458
#endif
5459
else
5460
{
5461
getcwd(FileBuf, BIG_BUFFER_SIZE);
5462
strmcat(FileBuf, "/", BIG_BUFFER_SIZE);
5463
strmcat(FileBuf, filename, BIG_BUFFER_SIZE);
5464
}
5465
#if defined(__EMX__) || defined(WINNT)
5466
convert_dos(FileBuf);
5467
#endif
5468
if (stat(FileBuf, &s) == -1)
5469
RETURN_EMPTY;
5470
else
5471
RETURN_INT(s.st_mtime);
5472
}
5473
RETURN_EMPTY;
5474
#endif
5475
}
5476
5477
BUILT_IN_FUNCTION(function_irclib, input)
5478
{
5479
RETURN_STR(irc_lib);
5480
}
5481
5482
BUILT_IN_FUNCTION(function_country, input)
5483
{
5484
RETURN_STR(country(input));
5485
}
5486
5487
BUILT_IN_FUNCTION(function_servernick, input)
5488
{
5489
char *servdesc;
5490
int refnum;
5491
5492
if(*input)
5493
{
5494
GET_STR_ARG(servdesc, input);
5495
if ((refnum = parse_server_index(servdesc)) == -1)
5496
if ((refnum = find_in_server_list(servdesc, 0)) == -1)
5497
RETURN_EMPTY;
5498
} else if(from_server != -1)
5499
refnum = from_server;
5500
else
5501
RETURN_EMPTY;
5502
5503
RETURN_STR(get_server_nickname(refnum));
5504
}
5505
5506
BUILT_IN_FUNCTION(function_fparse, input)
5507
{
5508
char *format;
5509
char *f = NULL;
5510
Alias *a = NULL;
5511
int owd = window_display;
5512
GET_STR_ARG(f, input);
5513
if (!f || !*f)
5514
RETURN_EMPTY;
5515
if ((format = make_fstring_var(f)))
5516
{
5517
f = convert_output_format(format, "%s", input?input:empty_string);
5518
new_free(&format);
5519
RETURN_STR(f);
5520
}
5521
window_display = 0;
5522
if ((a = find_var_alias(f)) && a->stuff && input && *input)
5523
f = convert_output_format(a->stuff, "%s", input?input:empty_string);
5524
else if (input && *input)
5525
add_var_alias(f, input);
5526
else
5527
delete_var_alias(f, 0);
5528
window_display = owd;
5529
RETURN_STR(f);
5530
}
5531
5532
BUILT_IN_FUNCTION(function_isconnected, input)
5533
{
5534
int server = 0;
5535
if (!input || !*input)
5536
server = from_server;
5537
else
5538
GET_INT_ARG(server, input);
5539
RETURN_INT(is_server_connected(server));
5540
}
5541
5542
BUILT_IN_FUNCTION(function_bmatch, input)
5543
{
5544
char *to = NULL;
5545
char *p, *q, *m;
5546
GET_STR_ARG(to, input);
5547
p = q = m_strdup(input);
5548
while((m = next_arg(p, &p)))
5549
{
5550
if (wild_match(m, to))
5551
{
5552
char *ret = m_strdup(m);
5553
new_free(&q);
5554
return ret;
5555
}
5556
}
5557
new_free(&q);
5558
RETURN_EMPTY;
5559
}
5560
5561
BUILT_IN_FUNCTION(function_currchans, input)
5562
{
5563
int server = -1;
5564
Window *blah = NULL;
5565
char *retval = NULL;
5566
5567
if (input && *input)
5568
GET_INT_ARG(server, input)
5569
else
5570
server = -2;
5571
5572
if (server == -1)
5573
server = from_server;
5574
5575
while (traverse_all_windows(&blah))
5576
{
5577
if (server != -2 && blah->server != server)
5578
continue;
5579
if (!blah->current_channel)
5580
continue;
5581
5582
m_s3cat(&retval, space, "\"");
5583
malloc_strcat(&retval, ltoa(blah->server));
5584
malloc_strcat(&retval, space);
5585
malloc_strcat(&retval, blah->current_channel);
5586
malloc_strcat(&retval, "\"");
5587
}
5588
RETURN_MSTR(retval);
5589
}
5590
5591
/*
5592
* Returns 1 if the specified function name is a built in function,
5593
* Returns 0 if not.
5594
*/
5595
BUILT_IN_FUNCTION(function_fnexist, input)
5596
{
5597
char *fname;
5598
5599
GET_STR_ARG(fname, input);
5600
RETURN_INT(func_exist(fname));
5601
}
5602
5603
BUILT_IN_FUNCTION(function_cexist, input)
5604
{
5605
char *fname;
5606
5607
GET_STR_ARG(fname, input);
5608
RETURN_INT(command_exist(fname));
5609
}
5610
5611
#if defined(HAVE_REGEX_H) && !defined(__EMX__) && !defined(WINNT)
5612
/*
5613
* These are used as an interface to regex support. Here's the plan:
5614
*
5615
* $regcomp(<pattern>)
5616
* will return an $encode()d string that is suitable for
5617
* assigning to a variable. The return value of this
5618
* function must at some point be passed to $regfree()!
5619
*
5620
* $regexec(<compiled> <string>)
5621
* Will return "0" or "1" depending on whether or not the given string
5622
* was matched by the previously compiled string. The value
5623
* for <compiled> must be a value previously returned by $regex().
5624
* Failure to do this will result in undefined chaos.
5625
*
5626
* $regerror(<compiled>)
5627
* Will return the error string for why the previous $regmatch() or
5628
* $regex() call failed.
5629
*
5630
* $regfree(<compiled>)
5631
* Will free off any of the data that might be contained in <compiled>
5632
* You MUST call $regfree() on any value that was previously
5633
* returned by $regex(), or you will leak memory. This is not
5634
* my problem (tm). It returns the FALSE value.
5635
*/
5636
5637
static int last_error = 0; /* XXX */
5638
5639
BUILT_IN_FUNCTION(function_regcomp, input)
5640
{
5641
regex_t preg = {0};
5642
if (input && *input)
5643
{
5644
last_error = regcomp(&preg, input, REG_EXTENDED | REG_ICASE | REG_NOSUB);
5645
return encode((char *)&preg, sizeof(regex_t));
5646
}
5647
RETURN_EMPTY;
5648
}
5649
5650
BUILT_IN_FUNCTION(function_regexec, input)
5651
{
5652
char *unsaved;
5653
regex_t *preg = NULL;
5654
int retval = -1;
5655
5656
GET_STR_ARG(unsaved, input);
5657
if (input && *input)
5658
{
5659
char *p;
5660
if ((p = decode(unsaved)) && *p)
5661
{
5662
preg = (regex_t *)p;
5663
retval = regexec(preg, input, 0, NULL, 0);
5664
new_free((char **)&preg);
5665
}
5666
}
5667
RETURN_INT(retval); /* DONT PASS FUNC CALL TO RETURN_INT */
5668
}
5669
5670
BUILT_IN_FUNCTION(function_regerror, input)
5671
{
5672
char *unsaved, *p;
5673
regex_t *preg = NULL;
5674
char error_buf[1024];
5675
int errcode;
5676
5677
GET_INT_ARG(errcode, input);
5678
GET_STR_ARG(unsaved, input);
5679
*error_buf = 0;
5680
if ((p = decode(unsaved)) && *p)
5681
{
5682
preg = (regex_t *)p;
5683
5684
if (errcode == -1)
5685
errcode = last_error;
5686
regerror(errcode, preg, error_buf, 1023);
5687
new_free((char **)&preg);
5688
}
5689
RETURN_STR(error_buf);
5690
}
5691
5692
BUILT_IN_FUNCTION(function_regfree, input)
5693
{
5694
char *unsaved, *p;
5695
regex_t *preg;
5696
5697
GET_STR_ARG(unsaved, input);
5698
if ((p = decode(unsaved)) && *p)
5699
{
5700
preg = (regex_t *)p;
5701
regfree(preg);
5702
new_free((char **)&preg);
5703
}
5704
RETURN_EMPTY;
5705
}
5706
#else
5707
BUILT_IN_FUNCTION(function_regexec, input) { RETURN_EMPTY; }
5708
BUILT_IN_FUNCTION(function_regcomp, input) { RETURN_EMPTY; }
5709
BUILT_IN_FUNCTION(function_regerror, input) { RETURN_STR("no regex support"); }
5710
BUILT_IN_FUNCTION(function_regfree, input) { RETURN_EMPTY; }
5711
#endif
5712
5713
/*
5714
* Usage: $igmask(pattern)
5715
* Returns: All the ignore patterns that are matched by the pattern
5716
* Example: $igmask(*) returns your entire ignore list
5717
* Based on work contributed by pavlov
5718
*/
5719
BUILT_IN_FUNCTION(function_igmask, input)
5720
{
5721
return get_ignores_by_pattern(input, 0); /* DONT MALLOC THIS */
5722
}
5723
5724
/*
5725
* Usage: $rigmask(pattern)
5726
* Returns: All the ignore patterns that would trigger on the given input
5727
* Example: $igmask([email protected]) would return a pattern like
5728
* *!*@*frenzy.com or like *!bhauber@*
5729
*/
5730
BUILT_IN_FUNCTION(function_rigmask, input)
5731
{
5732
return get_ignores_by_pattern(input, 1); /* DONT MALLOC THIS */
5733
}
5734
5735
BUILT_IN_FUNCTION(function_count, input)
5736
{
5737
char *str, *str2;
5738
int count = 0;
5739
5740
GET_STR_ARG(str, input);
5741
str2 = input;
5742
5743
for (;;)
5744
{
5745
if ((str2 = stristr(str2, str)))
5746
count++, str2++;
5747
else
5748
break;
5749
}
5750
5751
RETURN_INT(count);
5752
}
5753
5754
/*
5755
* Usage: $leftpc(COUNT TEXT)
5756
* Return the *longest* initial part of TEXT that includes COUNT printable
5757
* characters.
5758
*/
5759
BUILT_IN_FUNCTION(function_leftpc, word)
5760
{
5761
u_char **prepared = NULL;
5762
int lines = 1;
5763
int count;
5764
5765
GET_INT_ARG(count, word);
5766
if (count <= 0 || !*word)
5767
RETURN_EMPTY;
5768
5769
prepared = prepare_display(word, count, &lines, PREPARE_NOWRAP);
5770
RETURN_STR((char *)prepared[0]);
5771
}
5772
/*
5773
* $uname()
5774
* Returns system information. Expandoes %a, %s, %r, %v, %m, and %n
5775
* correspond to uname(1)'s -asrvmn switches. %% expands to a literal
5776
* '%'. If no arguments are given, the function returns %s and %r (the
5777
* same information given in the client's ctcp version reply).
5778
*
5779
* Contributed by Matt Carothers (CrackBaby) on Dec 20, 1997
5780
*/
5781
BUILT_IN_FUNCTION(function_uname, input)
5782
{
5783
#ifndef HAVE_UNAME
5784
RETURN_STR("unknown");
5785
#else
5786
struct utsname un;
5787
char tmp[BIG_BUFFER_SIZE+1];
5788
char *ptr = tmp;
5789
size_t size = BIG_BUFFER_SIZE;
5790
int i;
5791
int len;
5792
5793
if (uname(&un) == -1)
5794
RETURN_STR("unknown");
5795
5796
if (!*input)
5797
input = "%s %r";
5798
5799
*tmp = 0;
5800
for (i = 0, len = strlen(input); i < len; i++)
5801
{
5802
if (ptr - tmp >= size)
5803
break;
5804
5805
if (input[i] == '%')
5806
{
5807
switch (input[++i])
5808
{
5809
case 'm': strlcpy(ptr, un.machine, size);
5810
break;
5811
case 'n': strlcpy(ptr, un.nodename, size);
5812
break;
5813
case 'r': strlcpy(ptr, un.release, size);
5814
break;
5815
case 's': strlcpy(ptr, un.sysname, size);
5816
break;
5817
case 'v': strlcpy(ptr, un.version, size);
5818
break;
5819
case 'a':
5820
snprintf(ptr, size, "%s %s %s %s %s",
5821
un.sysname, un.nodename,
5822
un.release, un.version,
5823
un.machine);
5824
break;
5825
case '%': strlcpy(ptr, "%", size);
5826
}
5827
ptr += strlen(ptr);
5828
}
5829
else
5830
*ptr++ = input[i];
5831
}
5832
*ptr = 0;
5833
5834
RETURN_STR(tmp);
5835
#endif
5836
}
5837
5838
BUILT_IN_FUNCTION(function_querywin, args)
5839
{
5840
Window *w = NULL;
5841
5842
while (traverse_all_windows(&w))
5843
if (w->query_nick && !my_stricmp(w->query_nick, args))
5844
RETURN_INT(w->refnum);
5845
5846
RETURN_INT(-1);
5847
}
5848
5849
BUILT_IN_FUNCTION(function_winrefs, args)
5850
{
5851
Window *w = NULL;
5852
char *retval = NULL;
5853
5854
while (traverse_all_windows(&w))
5855
m_s3cat(&retval, space, ltoa(w->refnum));
5856
5857
return retval; /* DONT MALLOC THIS! */
5858
}
5859
5860
5861
#define DOT (*host ? dot : empty_string)
5862
5863
BUILT_IN_FUNCTION(function_uhc, input)
5864
{
5865
char *nick, *user, *host, *domain;
5866
int ip;
5867
5868
if (!input || !*input)
5869
RETURN_EMPTY;
5870
5871
if (figure_out_address(input, &nick, &user, &host, &domain, &ip))
5872
RETURN_STR(input);
5873
else if (ip == 0)
5874
return m_sprintf("%s!%s@%s%s%s", nick, user, host, DOT, domain);
5875
else
5876
return m_sprintf("%s!%s@%s%s%s", nick, user, domain, DOT, host);
5877
}
5878
5879
/*
5880
* Opposite of $uhc(). Breaks down a complete nick!user@host
5881
* into smaller components, based upon absolute wildcards.
5882
* Eg, *!user@host becomes user@host. And *!*@*.host becomes *.host
5883
* Based on the contribution and further changes by Peter V. Evans
5884
* ([email protected])
5885
*/
5886
BUILT_IN_FUNCTION(function_deuhc, input)
5887
{
5888
char *buf;
5889
5890
buf = LOCAL_COPY(input);
5891
5892
if (!strchr(buf, '!') || !strchr(buf, '@'))
5893
RETURN_EMPTY;
5894
5895
if (!strncmp(buf, "*!", 2))
5896
{
5897
buf += 2;
5898
if (!strncmp(buf, "*@", 2))
5899
buf += 2;
5900
}
5901
5902
RETURN_STR(buf);
5903
}
5904
5905
5906
/*
5907
* $mask(type address) OR
5908
* $mask(address type)
5909
* Returns address with a mask specified by type.
5910
*
5911
* $mask(1 [email protected]) returns *!*[email protected]
5912
* $mask(2 [email protected]) returns *!*@mardam.demon.co.uk
5913
*
5914
* The available types are:
5915
*
5916
* 0: *[email protected]
5917
* 1: *!*[email protected]
5918
* 2: *!*@host.domain
5919
* 3: *!*user@*.domain
5920
* 4: *!*@*.domain
5921
* 5: [email protected]
5922
* 6: nick!*[email protected]
5923
* 7: nick!*@host.domain
5924
* 8: nick!*user@*.domain
5925
* 9: nick!*@*.domain
5926
* 10: *!*@<number-masked-host>.domain (matt)
5927
* 11: *!*user@<nember-masked-host>.domain (matt)
5928
* 12: nick!*@<number-masked-host>.domain (matt)
5929
* 13: nick!*user@<number-masked-host>.domain (matt)
5930
*/
5931
BUILT_IN_FUNCTION(function_mask, args)
5932
{
5933
char * nuh;
5934
char * nick = NULL;
5935
char * user = NULL;
5936
char * host = NULL;
5937
char * domain = NULL;
5938
int which;
5939
char stuff[BIG_BUFFER_SIZE + 1];
5940
int ip;
5941
char *first_arg;
5942
char *ptr;
5943
5944
first_arg = new_next_arg(args, &args);
5945
if (is_number(first_arg))
5946
{
5947
which = my_atol(first_arg);
5948
nuh = args;
5949
}
5950
else
5951
{
5952
nuh = first_arg;
5953
GET_INT_ARG(which, args);
5954
}
5955
5956
if (figure_out_address(nuh, &nick, &user, &host, &domain, &ip))
5957
RETURN_EMPTY;
5958
5959
/*
5960
* Deal with [email protected] for exapmle, and all sorts
5961
* of other av2.9 breakage.
5962
*/
5963
if (strchr("~^-+=", *user))
5964
user++;
5965
5966
/* Make sure 'user' isnt too long for a ban... */
5967
if (strlen(user) > 7)
5968
{
5969
user[7] = '*';
5970
user[8] = 0;
5971
}
5972
5973
#define USER (user == star ? empty_string : user)
5974
#define MASK1(x, y) snprintf(stuff, BIG_BUFFER_SIZE, x, y); break;
5975
#define MASK2(x, y, z) snprintf(stuff, BIG_BUFFER_SIZE, x, y, z); break;
5976
#define MASK3(x, y, z, a) snprintf(stuff, BIG_BUFFER_SIZE, x, y, z, a); break;
5977
#define MASK4(x, y, z, a, b) snprintf(stuff, BIG_BUFFER_SIZE, x, y, z, a, b); break;
5978
#define MASK5(x, y, z, a, b, c) snprintf(stuff, BIG_BUFFER_SIZE, x, y, z, a, b, c); break;
5979
5980
if (ip == 0)
5981
switch (which)
5982
{
5983
case 0: MASK4("*!%s@%s%s%s", user, host, DOT, domain)
5984
case 1: MASK4("*!*%s@%s%s%s", USER, host, DOT, domain)
5985
case 2: MASK3("*!*@%s%s%s", host, DOT, domain)
5986
case 3: MASK3("*!*%s@*%s%s", USER, DOT, domain)
5987
case 4: MASK2("*!*@*%s%s", DOT, domain)
5988
case 5: MASK5("%s!%s@%s%s%s", nick, user, host, DOT, domain)
5989
case 6: MASK5("%s!*%s@%s%s%s", nick, USER, host, DOT, domain)
5990
case 7: MASK4("%s!*@%s%s%s", nick, host, DOT, domain)
5991
case 8: MASK4("%s!*%s@*%s%s", nick, USER, DOT, domain)
5992
case 9: MASK3("%s!*@*%s%s", nick, DOT, domain)
5993
case 10: mask_digits(&host);
5994
MASK3("*!*@%s%s%s", host, DOT, domain)
5995
case 11: mask_digits(&host);
5996
MASK4("*!*%s@%s%s%s", USER, host, DOT, domain)
5997
case 12: mask_digits(&host);
5998
MASK4("%s!*@%s%s%s", nick, host, DOT, domain)
5999
case 13: mask_digits(&host);
6000
MASK5("%s!*%s@%s%s%s", nick, USER, host, DOT, domain)
6001
}
6002
else
6003
switch (which)
6004
{
6005
case 0: MASK3("*!%s@%s.%s", user, domain, host)
6006
case 1: MASK3("*!*%s@%s.%s", USER, domain, host)
6007
case 2: MASK2("*!*@%s.%s", domain, host)
6008
case 3: MASK2("*!*%s@%s.*", USER, domain)
6009
case 4: MASK1("*!*@%s.*", domain)
6010
case 5: MASK4("%s!%s@%s.%s", nick, user, domain, host)
6011
case 6: MASK4("%s!*%s@%s.%s", nick, USER, domain, host)
6012
case 7: MASK3("%s!*@%s.%s", nick, domain, host)
6013
case 8: MASK3("%s!*%s@%s.*", nick, USER, domain)
6014
case 9: MASK2("%s!*@%s.*", nick, domain)
6015
case 10: MASK1("*!*@%s.*", domain)
6016
case 11: MASK2("*!*%s@%s.*", USER, domain)
6017
case 12: MASK2("%s!*@%s.*", nick, domain)
6018
case 13: MASK3("%s!*%s@%s.*", nick, USER, domain)
6019
}
6020
6021
/* Clean up any non-printable chars */
6022
for (ptr = stuff; *ptr; ptr++)
6023
if (!isgraph((unsigned char)*ptr))
6024
*ptr = '?';
6025
6026
RETURN_STR(stuff);
6027
}
6028
6029
/*
6030
* $remws(word word word / word word word)
6031
* Returns the right hand side unchanged, except that any word on the right
6032
* hand side that is also found on the left hand side will be removed.
6033
* Space is *not* retained. So there.
6034
*/
6035
BUILT_IN_FUNCTION(function_remws, word)
6036
{
6037
char *left = NULL,
6038
**lhs = NULL,
6039
*right = NULL,
6040
**rhs = NULL,
6041
*booya = NULL;
6042
int leftc,
6043
lefti,
6044
rightc,
6045
righti;
6046
int found = 0;
6047
6048
left = word;
6049
if (!(right = strchr(word,'/')))
6050
RETURN_EMPTY;
6051
6052
*right++ = 0;
6053
leftc = splitw(left, &lhs);
6054
rightc = splitw(right, &rhs);
6055
6056
for (righti = 0; righti < rightc; righti++)
6057
{
6058
found = 0;
6059
for (lefti = 0; lefti < leftc; lefti++)
6060
{
6061
if (rhs[righti] && lhs[lefti] &&
6062
!my_stricmp(lhs[lefti], rhs[righti]))
6063
{
6064
found = 1;
6065
break;
6066
}
6067
}
6068
if (!found)
6069
m_s3cat(&booya, space, rhs[righti]);
6070
rhs[righti] = NULL;
6071
}
6072
6073
new_free((char **)&lhs);
6074
new_free((char **)&rhs);
6075
6076
if (!booya)
6077
RETURN_EMPTY;
6078
6079
return (booya); /* DONT USE RETURN_STR HERE! */
6080
}
6081
6082
BUILT_IN_FUNCTION(function_stripansicodes, input)
6083
{
6084
#if 0
6085
return strip_ansi(input);
6086
#else
6087
RETURN_STR(stripansicodes(input));
6088
#endif
6089
}
6090
6091
BUILT_IN_FUNCTION(function_igtype, input)
6092
{
6093
RETURN_STR(get_ignore_types_by_pattern(input));
6094
}
6095
6096
BUILT_IN_FUNCTION(function_rigtype, input)
6097
{
6098
return get_ignore_patterns_by_type(input); /* DONT MALLOC! */
6099
}
6100
6101
BUILT_IN_FUNCTION(function_getuid, input)
6102
{
6103
RETURN_INT(getuid());
6104
}
6105
6106
BUILT_IN_FUNCTION(function_getgid, input)
6107
{
6108
RETURN_INT(getgid());
6109
}
6110
6111
BUILT_IN_FUNCTION(function_getlogin, input)
6112
{
6113
#ifdef HAVE_GETLOGIN
6114
RETURN_STR(getlogin());
6115
#else
6116
RETURN_STR(getenv("LOGNAME"));
6117
#endif
6118
}
6119
6120
BUILT_IN_FUNCTION(function_getpgrp, input)
6121
{
6122
RETURN_INT(getpgrp());
6123
}
6124
6125
BUILT_IN_FUNCTION(function_iscurchan, input)
6126
{
6127
char *chan;
6128
Window *w = NULL;
6129
6130
GET_STR_ARG(chan, input);
6131
while (traverse_all_windows(&w))
6132
{
6133
/*
6134
* Check to see if the channel specified is the current
6135
* channel on *any* window for the current server.
6136
*/
6137
if (w->current_channel &&
6138
!my_stricmp(chan, w->current_channel) &&
6139
w->server == from_server)
6140
RETURN_INT(1);
6141
}
6142
6143
RETURN_INT(0);
6144
}
6145
6146
BUILT_IN_FUNCTION(function_getcset, input)
6147
{
6148
char *var = NULL;
6149
char *channel = NULL;
6150
ChannelList *chan = NULL;
6151
GET_STR_ARG(var, input);
6152
if (input && *input)
6153
channel = next_arg(input, &input);
6154
else
6155
channel = get_current_channel_by_refnum(0);
6156
chan = lookup_channel(channel, from_server, 0);
6157
if (!channel || !chan)
6158
RETURN_EMPTY;
6159
if (input && *input)
6160
return get_cset(var, chan, input);
6161
else
6162
return get_cset(var, chan, NULL);
6163
}
6164
6165
BUILT_IN_FUNCTION(function_getfsets, input)
6166
{
6167
extern char *get_fset(char *);
6168
char *s = NULL;
6169
char *ret = NULL;
6170
if (!input || !*input)
6171
return get_fset(NULL);
6172
while ((s = next_arg(input, &input)))
6173
{
6174
char *r;
6175
r = get_fset(s);
6176
m_s3cat(&ret, space, r);
6177
new_free(&r);
6178
}
6179
return ret;
6180
}
6181
6182
BUILT_IN_FUNCTION(function_getsets, input)
6183
{
6184
extern char *get_set(char *);
6185
char *s = NULL;
6186
char *ret = NULL;
6187
if (!input || !*input)
6188
return get_set(NULL);
6189
while ((s = next_arg(input, &input)))
6190
{
6191
char *r;
6192
r = get_set(s);
6193
m_s3cat(&ret, space, r);
6194
new_free(&r);
6195
}
6196
return ret;
6197
}
6198
6199
/*
6200
* $isnumber(number base)
6201
* returns the empty value if nothing is passed to it
6202
* returns 0 if the value passed is not a number
6203
* returns 1 if the value passed is a number.
6204
*
6205
* The "base" number is optional and should be prefixed by the
6206
* character 'b'. ala, $isnumber(0x0F b16) for hexadecimal.
6207
* the special base zero (b0) means to 'auto-detect'. Base must
6208
* be between 0 and 36, inclusive. If not, it defaults to 0.
6209
*/
6210
BUILT_IN_FUNCTION(function_isnumber, input)
6211
{
6212
int base = 0;
6213
char *endptr;
6214
char *barg;
6215
char *number = NULL;
6216
6217
/*
6218
* See if the first arg is the base
6219
*/
6220
barg = new_next_arg(input, &input);
6221
6222
/*
6223
* If it is, the number is the 2nd arg
6224
*/
6225
if (barg && *barg == 'b' && is_number(barg + 1))
6226
{
6227
GET_STR_ARG(number, input);
6228
}
6229
/*
6230
* Otherwise, the first arg is the number,
6231
* the 2nd arg probably is the base
6232
*/
6233
else
6234
{
6235
number = barg;
6236
barg = new_next_arg(input, &input);
6237
}
6238
6239
/*
6240
* If the user specified a base, parse it.
6241
* Must be between 0 and 36.
6242
*/
6243
if (barg && *barg == 'b')
6244
{
6245
base = my_atol(barg + 1);
6246
if (base < 0 || base > 36)
6247
base = 0;
6248
}
6249
6250
/*
6251
* Must have specified a number, though.
6252
*/
6253
RETURN_IF_EMPTY(number);
6254
6255
strtol(number, &endptr, base);
6256
if (*endptr == '.')
6257
strtol(endptr + 1, &endptr, base);
6258
6259
if (*endptr)
6260
RETURN_INT(0);
6261
else
6262
RETURN_INT(1);
6263
}
6264
6265
/*
6266
* $rest(index string)
6267
* Returns 'string' starting at the 'index'th character
6268
* Just like $restw() does for words.
6269
*/
6270
BUILT_IN_FUNCTION(function_rest, input)
6271
{
6272
int start = 1;
6273
6274
if (my_atol(input))
6275
GET_INT_ARG(start, input);
6276
6277
if (start <= 0)
6278
RETURN_STR(input);
6279
6280
if (start >= strlen(input))
6281
RETURN_EMPTY;
6282
6283
RETURN_STR(input + start);
6284
}
6285
6286
/*
6287
* take a servername and return it's refnum or -1
6288
*/
6289
BUILT_IN_FUNCTION(function_servref, input)
6290
{
6291
char *servname = NULL;
6292
int i;
6293
6294
if (input)
6295
servname = new_next_arg(input, &input);
6296
6297
if (empty(servname))
6298
RETURN_INT(from_server);
6299
6300
for (i = 0; i < server_list_size(); i++)
6301
{
6302
if (!my_stricmp(get_server_itsname(i), servname) ||
6303
!my_stricmp(get_server_name(i), servname))
6304
{
6305
RETURN_INT(i);
6306
}
6307
}
6308
6309
RETURN_INT(-1);
6310
}
6311
6312
/*
6313
* sd_([email protected]) needed the following function to return a
6314
* set of flags from the userlist. we pass in a user@host and a channel
6315
* and that user's flags are returned.
6316
*/
6317
6318
BUILT_IN_FUNCTION(function_getflags, input)
6319
{
6320
#ifdef WANT_USERLIST
6321
char *uh = NULL, *channel = NULL;
6322
register UserList *tmp;
6323
void *location = NULL;
6324
int size = -1;
6325
6326
GET_STR_ARG(uh, input);
6327
GET_STR_ARG(channel, input);
6328
6329
if ((tmp = find_bestmatch("*", uh, channel, NULL)))
6330
RETURN_STR(convert_flags_to_str(tmp->flags));
6331
for (tmp = next_userlist(NULL, &size, &location); tmp; tmp = next_userlist(tmp, &size, &location))
6332
{
6333
register UserList *blah = NULL;
6334
if (!wild_match(uh, tmp->host) && !wild_match(tmp->host, uh))
6335
continue;
6336
6337
uh = tmp->host;
6338
6339
if ((blah = find_bestmatch("*", uh, channel, NULL)))
6340
RETURN_STR(convert_flags_to_str(blah->flags));
6341
}
6342
#endif
6343
RETURN_EMPTY;
6344
}
6345
6346
BUILT_IN_FUNCTION(function_numlines, input)
6347
{
6348
int count = 0;
6349
unsigned char **lines = NULL;
6350
char *s = NULL;
6351
if (input && *input)
6352
{
6353
int cols;
6354
s = LOCAL_COPY(input);
6355
if (current_window->screen)
6356
cols = current_window->screen->co;
6357
else
6358
cols = current_window->columns;
6359
for (lines = split_up_line(s, cols + 1); *lines; lines++)
6360
count++;
6361
}
6362
RETURN_INT(count);
6363
}
6364
6365
BUILT_IN_FUNCTION(function_topic, input)
6366
{
6367
char *ch = NULL;
6368
ChannelList *chan;
6369
if (input && *input)
6370
ch = next_arg(input, &input);
6371
if (!ch || !*ch)
6372
ch = get_current_channel_by_refnum(0);
6373
if (ch && *ch && (chan = lookup_channel(ch, from_server, 0)))
6374
RETURN_STR(chan->topic);
6375
RETURN_EMPTY;
6376
}
6377
6378
BUILT_IN_FUNCTION(function_stripcrap, input)
6379
{
6380
char *how;
6381
int mangle;
6382
char *output;
6383
6384
GET_STR_ARG(how, input);
6385
mangle = parse_mangle(how, 0, NULL);
6386
6387
output = new_malloc(strlen(input) * 2 + 1);
6388
strcpy(output, input);
6389
mangle_line(output, mangle, strlen(input) * 2);
6390
return output; /* DONT MALLOC THIS */
6391
}
6392
6393
6394
6395
#if 0
6396
BUILT_IN_FUNCTION(function_parse_and_return, str)
6397
{
6398
unsigned char buffer[3*BIG_BUFFER_SIZE+1];
6399
register unsigned char *s;
6400
char *copy = NULL;
6401
char *tmpc = NULL;
6402
int arg_flags;
6403
6404
if (!str)
6405
return m_strdup(empty_string);
6406
6407
memset(buffer, 0, BIG_BUFFER_SIZE);
6408
copy = tmpc = str;
6409
s = buffer;
6410
while (*tmpc)
6411
{
6412
if (*tmpc == '$')
6413
{
6414
char *new_str = NULL;
6415
tmpc++;
6416
in_cparse++;
6417
tmpc = alias_special_char(&new_str, tmpc, copy, NULL, &arg_flags);
6418
in_cparse--;
6419
if (new_str)
6420
strcat(s, new_str);
6421
new_free(&new_str);
6422
if (!tmpc) break;
6423
continue;
6424
} else
6425
*s = *tmpc;
6426
tmpc++; s++;
6427
}
6428
*s = 0;
6429
return m_strdup(buffer);
6430
}
6431
#endif
6432
6433
BUILT_IN_FUNCTION(function_long_to_comma, word)
6434
{
6435
long l = 0;
6436
if (word && *word)
6437
l = strtol(word, NULL, 10);
6438
RETURN_STR(longcomma(l));
6439
}
6440
6441
BUILT_IN_FUNCTION(function_dccitem, word)
6442
{
6443
int dcc_item;
6444
SocketList *s = NULL;
6445
DCC_int *n1 = NULL;
6446
int i = 0, found = 0;
6447
char *str;
6448
if (!(str = next_arg(word, &word)))
6449
RETURN_EMPTY;
6450
if (*str == '#' && *(str+1))
6451
{
6452
dcc_item = my_atol(str+1);
6453
if (check_dcc_socket(dcc_item) && (s = get_socket(dcc_item)))
6454
{
6455
found++;
6456
n1 = (DCC_int *) s->info;
6457
i = dcc_item;
6458
}
6459
}
6460
else if (isdigit((unsigned char)*str))
6461
{
6462
dcc_item = my_atol(str);
6463
for (i = 0; i < get_max_fd()+1; i++)
6464
{
6465
if (check_dcc_socket(i) && (s = get_socket(i)))
6466
{
6467
n1 = (DCC_int *) s->info;
6468
if (n1 && (n1->dccnum == dcc_item))
6469
{
6470
found++;
6471
break;
6472
}
6473
}
6474
}
6475
}
6476
if (!found || !s || !n1)
6477
RETURN_EMPTY;
6478
return get_dcc_info(s, n1, i);
6479
}
6480
6481
BUILT_IN_FUNCTION(function_winitem, word)
6482
{
6483
int win_item = -1;
6484
char *str;
6485
Window *window = NULL;
6486
char none[] = "<none>";
6487
char flags[10];
6488
int j = 0;
6489
#ifdef GUI
6490
char fontinfo[100];
6491
int winx, winy, wincx, wincy;
6492
#endif
6493
6494
if ((str = next_arg(word, &word)))
6495
{
6496
if (*str == '%' && *(str+1))
6497
{
6498
win_item = my_atol(str+1);
6499
window = get_window_by_refnum(win_item);
6500
}
6501
else if (isdigit((unsigned char)*str))
6502
{
6503
if (!(win_item = my_atol(str)))
6504
window = get_window_by_refnum(win_item);
6505
else
6506
{
6507
while (traverse_all_windows(&window) && ++j != win_item) ;
6508
if (win_item > j)
6509
RETURN_EMPTY;
6510
}
6511
}
6512
}
6513
else
6514
{
6515
win_item = 0;
6516
window = get_window_by_refnum(win_item);
6517
}
6518
if (!window || win_item == -1)
6519
RETURN_EMPTY;
6520
memset(flags, 0, sizeof(flags));
6521
if (window->log)
6522
strcat(flags, "L");
6523
#ifdef GUI
6524
fontinfo[0] = 0;
6525
gui_query_window_info(window->screen, fontinfo, &winx, &winy, &wincx, &wincy);
6526
return m_sprintf("%u %s %d %s %s %s %s %d %d %d %s %d %d %d %d %s \"%s\" \"%s\" %s %s %s",
6527
#else
6528
return m_sprintf("%u %s %d %s %s %s %s %d %d %d %s %s %s %s %s %s \"%s\" \"%s\" %s %s %s",
6529
#endif
6530
window->refnum,
6531
window->name?window->name:none,
6532
window->server,
6533
window->current_channel?window->current_channel:none,
6534
window->query_nick?window->query_nick:none,
6535
window->waiting_channel?window->waiting_channel:none,
6536
(window->screen && window->screen->menu)?window->screen->menu:none, /* oirc menu name */
6537
window->visible,
6538
window->screen ? window->screen->co : 0,
6539
window->screen ? window->screen->li : 0,
6540
#ifdef GUI
6541
fontinfo,
6542
winx,
6543
winy,
6544
wincx,
6545
wincy,
6546
#else
6547
none, none, none, none, none, /* font windowx windowy window-width window-height */
6548
#endif
6549
window->logfile?window->logfile:none, flags,
6550
window->nicks?"n":empty_string,
6551
none, none,
6552
bits_to_lastlog_level(window->window_level));
6553
}
6554
6555
BUILT_IN_FUNCTION(function_ajoinitem, input)
6556
{
6557
extern AJoinList *ajoin_list;
6558
AJoinList *new = NULL;
6559
int ajl_num, count = 0;
6560
char *ret = NULL;
6561
GET_INT_ARG(ajl_num, input);
6562
6563
for (new = ajoin_list; new; new = new->next)
6564
{
6565
if ((ajl_num == -1) || (count == ajl_num))
6566
{
6567
m_s3cat(&ret, ",", new->name);
6568
m_s3cat(&ret, space, new->key ? new->key : "<none>");
6569
}
6570
if ((count == ajl_num))
6571
break;
6572
count++;
6573
}
6574
if (!ret)
6575
RETURN_EMPTY;
6576
return ret;
6577
}
6578
6579
BUILT_IN_FUNCTION(function_servgroup, input)
6580
{
6581
int snum;
6582
char *s;
6583
GET_INT_ARG(snum, input);
6584
s = get_server_network(snum);
6585
RETURN_STR(s ? s : empty_string);
6586
}
6587
6588
6589
#ifdef GUI
6590
BUILT_IN_FUNCTION(function_mciapi, input)
6591
{
6592
char *firstarg;
6593
static char szReturnString[BIG_BUFFER_SIZE] = "";
6594
if (input && *input)
6595
{
6596
GET_STR_ARG(firstarg, input)
6597
if (!my_stricmp(firstarg, "raw"))
6598
RETURN_INT(gui_send_mci_string(input, szReturnString));
6599
else if (!my_stricmp(firstarg, "result"))
6600
RETURN_STR(szReturnString);
6601
else if (!my_stricmp(firstarg, "playfile"))
6602
{
6603
char *fullfile;
6604
if (input && *input)
6605
{
6606
fullfile = expand_twiddle(input);
6607
gui_play_sound(fullfile);
6608
new_free(&fullfile);
6609
}
6610
RETURN_STR(empty_string);
6611
}
6612
else if (!my_stricmp(firstarg, "errstring"))
6613
{
6614
int errnum;
6615
char szErrorString[BIG_BUFFER_SIZE];
6616
*szErrorString = 0;
6617
GET_INT_ARG(errnum, input);
6618
gui_get_sound_error(errnum, szErrorString);
6619
RETURN_STR(szErrorString);
6620
}
6621
}
6622
RETURN_INT(1);
6623
}
6624
6625
BUILT_IN_FUNCTION(function_menucontrol, input)
6626
{
6627
char *menuname, *what, *param;
6628
int refnum = -1;
6629
6630
GET_STR_ARG(menuname, input);
6631
GET_INT_ARG(refnum, input);
6632
GET_STR_ARG(what, input);
6633
GET_STR_ARG(param, input);
6634
6635
if (menuname && *menuname && what && *what && param && *param)
6636
{
6637
if (refnum > -1 && gui_setmenuitem(menuname, refnum, what, param))
6638
RETURN_STR("1");
6639
}
6640
RETURN_STR(empty_string);
6641
}
6642
6643
BUILT_IN_FUNCTION(function_lastclickline, input)
6644
{
6645
extern char *lastclicklinedata;
6646
extern int lastclickcol;
6647
int info=0,i,e,c,d;
6648
char retinfo[BIG_BUFFER_SIZE],
6649
6650
newclicklinedata[BIG_BUFFER_SIZE + 1];
6651
6652
*retinfo = 0;
6653
if (input && *input)
6654
GET_INT_ARG(info, input)
6655
else
6656
info=0;
6657
6658
if (!lastclicklinedata)
6659
RETURN_EMPTY;
6660
6661
/* Remove color codes if necessary */
6662
strncpy(newclicklinedata, stripansicodes(lastclicklinedata), BIG_BUFFER_SIZE);
6663
6664
switch(info)
6665
{
6666
case 0:
6667
RETURN_STR(newclicklinedata);
6668
break;
6669
case 1:
6670
/* Color codes */
6671
RETURN_STR(lastclicklinedata);
6672
break;
6673
case 2:
6674
/* Color codes (replaced with ^O)....same as case 1 */
6675
RETURN_STR(lastclicklinedata);
6676
break;
6677
case 3:
6678
if (newclicklinedata[lastclickcol] != ' ')
6679
{
6680
i = lastclickcol;
6681
while (newclicklinedata[i] != ' ' && i > -1)
6682
i--;
6683
i++;
6684
e = lastclickcol;
6685
while (newclicklinedata[e] != ' ' && e < strlen(newclicklinedata))
6686
e++;
6687
if (newclicklinedata[i]=='[' || newclicklinedata[i]=='(' || newclicklinedata[i]=='<')
6688
i++;
6689
if (newclicklinedata[e-1]==']' || newclicklinedata[e-1]==')' || newclicklinedata[e-1]=='>')
6690
e--;
6691
for (c = i; c < e; c++)
6692
retinfo[(c-i)] = newclicklinedata[c];
6693
c++;
6694
retinfo[c-i] = 0;
6695
RETURN_STR(retinfo);
6696
}
6697
break;
6698
case 4:
6699
if (newclicklinedata[lastclickcol] != ' ')
6700
{
6701
i = lastclickcol;
6702
while (newclicklinedata[i] != ' ' && i > -1)
6703
i--;
6704
i++;
6705
e = lastclickcol;
6706
while (newclicklinedata[e] != ' ' && e < strlen(newclicklinedata))
6707
e++;
6708
if (newclicklinedata[i] == '[' || newclicklinedata[i]=='(' || newclicklinedata[i]=='<')
6709
i++;
6710
if (newclicklinedata[e-1] == ']' || newclicklinedata[e-1]==')' || newclicklinedata[e-1]=='>')
6711
e--;
6712
again:
6713
if (newclicklinedata[i] == '#' || newclicklinedata[i]=='@' || newclicklinedata[i]=='+' || newclicklinedata[i]=='%' || newclicklinedata[i]=='*')
6714
{
6715
i++;
6716
goto again;
6717
}
6718
d = i;
6719
while (newclicklinedata[d]!='@' && d < e)
6720
d++;
6721
for (c = i; c < d; c++)
6722
retinfo[(c-i)] = newclicklinedata[c];
6723
retinfo[(c-i)] = 0;
6724
RETURN_STR(retinfo);
6725
}
6726
break;
6727
default:
6728
RETURN_EMPTY;
6729
break;
6730
}
6731
RETURN_EMPTY;
6732
}
6733
6734
BUILT_IN_FUNCTION(function_lastclickx, input)
6735
{
6736
extern int lastclickcol;
6737
RETURN_INT(lastclickcol);
6738
}
6739
6740
BUILT_IN_FUNCTION(function_lastclicky, input)
6741
{
6742
extern int lastclickrow;
6743
RETURN_INT(lastclickrow);
6744
}
6745
6746
BUILT_IN_FUNCTION(function_screensize, input)
6747
{
6748
char retbuffer[50];
6749
6750
if (!my_stricmp(input, "cx"))
6751
sprintf(retbuffer, "%d", gui_screen_width());
6752
else if (!my_stricmp(input, "cy"))
6753
sprintf(retbuffer, "%d", gui_screen_height());
6754
else
6755
sprintf(retbuffer, "%d %d", gui_screen_width(), gui_screen_height());
6756
6757
RETURN_STR(retbuffer);
6758
}
6759
#endif
6760
6761
/*
6762
* Date: Wed, 2 Sep 1998 18:20:34 -0500 (CDT)
6763
* From: CrackBaby <[email protected]>
6764
*/
6765
/*
6766
* $getopt(<optopt var> <optarg var> <opt string> <argument list>)
6767
*
6768
* Processes a list of switches and args. Returns one switch char each time
6769
* it's called, sets $<optopt var> to the char, and sets $<optarg var> to the
6770
* value of the next argument if the switch needs one.
6771
*
6772
* Syntax for <opt string> and <argument list> should be identical to
6773
* getopt(3). A ':' in <opt string> is a required argument, and a "::" is an
6774
* optional one. A '-' by itself in <argument list> is a null argument, and
6775
* switch parsing stops after a "--"
6776
*
6777
* If a switch requires an argument, but the argument is missing, $getopt()
6778
* returns a '-' If a switch is given which isn't in the opt string, the
6779
* function returns a '!' $<optopt var> is still set in both cases.
6780
*
6781
* Example usage:
6782
* while (option = getopt(optopt optarg "ab:c:" $*)) {
6783
* switch ($option) {
6784
* (a) {echo * option "$optopt" used}
6785
* (b) {echo * option "$optopt" used - $optarg}
6786
* (c) {echo * option "$optopt" used - $optarg}
6787
* (!) {echo * option "$optopt" is an invalid option}
6788
* (-) {echo * option "$optopt" is missing an argument}
6789
* }
6790
* }
6791
*/
6792
BUILT_IN_FUNCTION(function_getopt, input)
6793
{
6794
static char switches [INPUT_BUFFER_SIZE+1] = "",
6795
args [INPUT_BUFFER_SIZE+1] = "",
6796
last_input [INPUT_BUFFER_SIZE+1] = "",
6797
*sptr = switches,
6798
*aptr = args;
6799
char *optopt_var,
6800
*optarg_var,
6801
*optstr,
6802
*optptr,
6803
*tmp;
6804
char extra_args [INPUT_BUFFER_SIZE+1] = "";
6805
int old_window_display = window_display,
6806
arg_flag = 0;
6807
6808
if (strcmp(last_input, input))
6809
{
6810
strlcpy(last_input, input, INPUT_BUFFER_SIZE);
6811
6812
*switches = 0;
6813
*args = 0;
6814
sptr = switches;
6815
aptr = args;
6816
}
6817
6818
GET_STR_ARG(optopt_var, input);
6819
GET_STR_ARG(optarg_var, input);
6820
GET_STR_ARG(optstr, input);
6821
6822
if (!(optopt_var || optarg_var || optstr))
6823
RETURN_EMPTY;
6824
6825
if (!*switches && !*args && strcmp(last_input, input))
6826
{
6827
/* Process each word in the input string */
6828
while ((tmp = next_arg(input, &input)))
6829
{
6830
/* Word is a switch or a group of switches */
6831
if (tmp[0] == '-' && tmp[1] && tmp[1] != '-'
6832
&& !arg_flag)
6833
{
6834
/* Look at each char after the '-' */
6835
for (++tmp; *tmp; tmp++)
6836
{
6837
/* If the char is found in optstr
6838
and doesn't need an argument,
6839
it's added to the switches list.
6840
switches are stored as "xy" where
6841
x is the switch letter and y is
6842
'_' normal switch
6843
':' switch with arg
6844
'-' switch with missing arg
6845
'!' unrecognized switch
6846
*/
6847
strlcat(switches, space, INPUT_BUFFER_SIZE);
6848
strncat(switches, tmp, 1);
6849
/* char is a valid switch */
6850
if ((optptr = strchr(optstr, *tmp)))
6851
{
6852
/* char requires an argument */
6853
if (*(optptr + 1) == ':')
6854
{
6855
/* -xfoo, argument is
6856
"foo" */
6857
if (*(tmp + 1))
6858
{
6859
tmp++;
6860
strlcat(args, tmp, INPUT_BUFFER_SIZE);
6861
strlcat(args, space, INPUT_BUFFER_SIZE);
6862
strlcat(switches, ":", INPUT_BUFFER_SIZE);
6863
break;
6864
}
6865
/* Otherwise note that
6866
the next word in
6867
the input is our
6868
arg. */
6869
else if (*(optptr + 2) == ':')
6870
arg_flag = 2;
6871
else
6872
arg_flag = 1;
6873
}
6874
/* Switch needs no argument */
6875
else strlcat(switches, "_", INPUT_BUFFER_SIZE);
6876
}
6877
/* Switch is not recognized */
6878
else strlcat(switches, "!", INPUT_BUFFER_SIZE);
6879
}
6880
}
6881
else
6882
{
6883
/* Everything after a "--" is added to
6884
extra_args */
6885
if (*tmp == '-' && *(tmp + 1) == '-')
6886
{
6887
tmp += 2;
6888
strlcat(extra_args, tmp, INPUT_BUFFER_SIZE);
6889
strlcat(extra_args, input, INPUT_BUFFER_SIZE);
6890
*input = 0;
6891
}
6892
/* A '-' by itself is a null arg */
6893
else if (*tmp == '-' && !*(tmp + 1))
6894
{
6895
if (arg_flag == 1)
6896
strlcat(switches, "-", INPUT_BUFFER_SIZE);
6897
else if (arg_flag == 2)
6898
strlcat(switches, "_", INPUT_BUFFER_SIZE);
6899
*tmp = 0;
6900
arg_flag = 0;
6901
}
6902
/* If the word doesn't start with a '-,' it must be
6903
either the argument of a switch or just extra
6904
info. */
6905
else if (arg_flag)
6906
{
6907
/* If arg_flag is positive, we've processes
6908
a switch which requires an arg and we can
6909
just tack the word onto the end of args[] */
6910
6911
strlcat(args, tmp, INPUT_BUFFER_SIZE);
6912
strlcat(args, space, INPUT_BUFFER_SIZE);
6913
strlcat(switches, ":", INPUT_BUFFER_SIZE);
6914
arg_flag = 0;
6915
}
6916
else
6917
{
6918
/* If not, we'll put it aside and add it to
6919
args[] after all the switches have been
6920
looked at. */
6921
6922
strlcat(extra_args, tmp, INPUT_BUFFER_SIZE);
6923
strlcat(extra_args, space, INPUT_BUFFER_SIZE);
6924
}
6925
}
6926
}
6927
/* If we're expecting an argument to a switch, but we've
6928
reached the end of our input, the switch is missing its
6929
arg. */
6930
if (arg_flag == 1)
6931
strlcat(switches, "-", INPUT_BUFFER_SIZE);
6932
else if (arg_flag == 2)
6933
strlcat(switches, "_", INPUT_BUFFER_SIZE);
6934
strlcat(args, extra_args, INPUT_BUFFER_SIZE);
6935
}
6936
6937
window_display = 0;
6938
6939
if ((tmp = next_arg(sptr, &sptr)))
6940
{
6941
switch (*(tmp + 1))
6942
{
6943
case '_':
6944
*(tmp + 1) = 0;
6945
6946
add_var_alias(optopt_var, tmp);
6947
add_var_alias(optarg_var, NULL);
6948
6949
window_display = old_window_display;
6950
RETURN_STR(tmp);
6951
case ':':
6952
*(tmp + 1) = 0;
6953
6954
add_var_alias(optopt_var, tmp);
6955
add_var_alias(optarg_var, next_arg(aptr, &aptr));
6956
window_display = old_window_display;
6957
RETURN_STR(tmp);
6958
case '-':
6959
*(tmp + 1) = 0;
6960
6961
add_var_alias(optopt_var, tmp);
6962
add_var_alias(optarg_var, NULL);
6963
6964
window_display = old_window_display;
6965
RETURN_STR("-");
6966
case '!':
6967
*(tmp + 1) = 0;
6968
6969
add_var_alias(optopt_var, tmp);
6970
add_var_alias(optarg_var, NULL);
6971
6972
window_display = old_window_display;
6973
RETURN_STR("!");
6974
default:
6975
/* This shouldn't happen */
6976
debugyell("*** getopt switch broken: %s", tmp);
6977
RETURN_EMPTY;
6978
}
6979
}
6980
else
6981
{
6982
add_var_alias(optopt_var, NULL);
6983
add_var_alias(optarg_var, aptr);
6984
window_display = old_window_display;
6985
6986
*switches = 0;
6987
*args = 0;
6988
sptr = switches;
6989
aptr = args;
6990
6991
RETURN_EMPTY;
6992
}
6993
}
6994
6995
BUILT_IN_FUNCTION(function_isaway, input)
6996
{
6997
int refnum = -1;
6998
6999
if (!*input)
7000
refnum = from_server;
7001
else
7002
GET_INT_ARG(refnum, input);
7003
7004
if (get_server_away(refnum))
7005
RETURN_INT(1);
7006
7007
RETURN_INT(0);
7008
}
7009
7010
BUILT_IN_FUNCTION(function_banwords, input)
7011
{
7012
char *ch = NULL;
7013
char *ret = NULL;
7014
extern WordKickList *ban_words;
7015
if (input && *input)
7016
{
7017
GET_STR_ARG(ch, input);
7018
}
7019
else
7020
ch = get_current_channel_by_refnum(0);
7021
if (ban_words)
7022
{
7023
WordKickList *ban;
7024
for (ban = ban_words; ban; ban = ban->next)
7025
{
7026
if (wild_match(ban->channel, ch))
7027
m_s3cat(&ret, space, ban->string);
7028
}
7029
}
7030
RETURN_STR(ret ? ret : empty_string);
7031
}
7032
7033
/*
7034
* Creates a 32 bit hash value for a specified string
7035
* Usage: $hash_32bit(word length)
7036
*
7037
* "word" is the value to be hashed, and "length" is the number
7038
* of characters to hash. If "length" is omitted or not 0 < length <= 64,
7039
* then it defaults to 20.
7040
*
7041
* This was contributed by srfrog ([email protected]). I make no claims about
7042
* the usefulness of this hashing algorithm.
7043
*
7044
* The name was chosen just in case we decided to implement other hashing
7045
* algorithms for different sizes or types of return values.
7046
*/
7047
BUILT_IN_FUNCTION(function_hash_32bit, input)
7048
{
7049
unsigned char * u_word;
7050
char * word;
7051
char c;
7052
unsigned bit_hi = 0;
7053
int bit_low = 0;
7054
int h_val;
7055
int len;
7056
7057
GET_STR_ARG(word, input)
7058
len = my_atol(input);
7059
7060
if (len <= 0 || len > 64)
7061
len = 20;
7062
7063
for (u_word = (u_char *)word; *u_word && len > 0; ++u_word, --len)
7064
{
7065
c = tolower(*u_word);
7066
bit_hi = (bit_hi << 1) + c;
7067
bit_low = (bit_low >> 1) + c;
7068
}
7069
h_val = ((bit_hi & 2047) << 3) + (bit_low & 0x7);
7070
RETURN_INT(h_val);
7071
}
7072
7073
BUILT_IN_FUNCTION(function_filecomp, input)
7074
{
7075
#ifdef WANT_TABKEY
7076
char *ret, *possible;
7077
int count = 0; /* 6 */
7078
possible = next_arg(input, &input);
7079
ret = get_completions(3, possible, &count, NULL);
7080
return m_sprintf("%d %s", count, ret ? ret : empty_string);
7081
#else
7082
RETURN_EMPTY;
7083
#endif
7084
}
7085
7086
BUILT_IN_FUNCTION(function_nickcomp, input)
7087
{
7088
#ifdef WANT_TABKEY
7089
char *ret, *possible;
7090
int count = 0;/* 4 */
7091
possible = next_arg(input, &input);
7092
ret = get_completions(7, possible, &count, NULL);
7093
return m_sprintf("%d %s", count, ret ? ret : empty_string);
7094
#else
7095
RETURN_EMPTY;
7096
#endif
7097
}
7098
7099
BUILT_IN_FUNCTION(function_log, args)
7100
{
7101
extern FILE *irclog_fp;
7102
add_to_log(irclog_fp, time(NULL), args, logfile_line_mangler);
7103
if (irclog_fp)
7104
RETURN_INT(0);
7105
else
7106
RETURN_INT(-1);
7107
}
7108
7109
/*
7110
* KnghtBrd requested this. Returns the length of the longest word
7111
* in the word list.
7112
*/
7113
BUILT_IN_FUNCTION(function_maxlen, input)
7114
{
7115
size_t maxlen = 0;
7116
size_t len;
7117
char *arg;
7118
7119
while (input && *input)
7120
{
7121
GET_STR_ARG(arg, input)
7122
7123
if ((len = strlen(arg)) > maxlen)
7124
maxlen = len;
7125
}
7126
7127
RETURN_INT(maxlen);
7128
}
7129
7130
7131
/*
7132
* KnghtBrd requested this. It returns a string that is the leading
7133
* substring of ALL the words in the word list. If no string is common
7134
* to all words in the word list, then the FALSE value is returned.
7135
*
7136
* I didn't give this a whole lot of thought about the optimal way to
7137
* do this, so if you have a better idea, let me know. All i do here is
7138
* start at 1 character and walk my way longer and longer until i find a
7139
* length that is not common, and then i stop there. So the expense of this
7140
* algorithm is (M*N) where M is the number of words and N is the number of
7141
* characters they have in common when we're all done.
7142
*/
7143
BUILT_IN_FUNCTION(function_prefix, input)
7144
{
7145
char **words = NULL;
7146
int numwords;
7147
int max_len;
7148
int len_index;
7149
int word_index;
7150
char *retval = NULL;
7151
7152
RETURN_IF_EMPTY(input);
7153
7154
numwords = splitw(input, &words);
7155
max_len = strlen(words[0]);
7156
7157
for (len_index = 1; len_index <= max_len; len_index++)
7158
{
7159
for (word_index = 1; word_index < numwords; word_index++)
7160
{
7161
/*
7162
* Basically, our stopping point is the first time we
7163
* see a string that does NOT share the first "len_index"
7164
* characters with words[0] (which is chosen arbitrarily).
7165
* As long as all words start with the same leading chars,
7166
* we march along trying longer and longer substrings,
7167
* until one of them doesnt work, and then we exit right
7168
* there.
7169
*/
7170
if (my_strnicmp(words[0], words[word_index], len_index))
7171
{
7172
retval = new_malloc(len_index + 1);
7173
strmcpy(retval, words[0], len_index - 1);
7174
new_free((char **)&words);
7175
return retval;
7176
}
7177
}
7178
}
7179
7180
retval = m_strdup(words[0]);
7181
new_free((char **)&words);
7182
return retval;
7183
}
7184
7185
/*
7186
* I added this so |rain| would stop asking me for it. ;-) I reserve the
7187
* right to change the implementation of this in the future.
7188
*/
7189
BUILT_IN_FUNCTION(function_functioncall, input)
7190
{
7191
/*
7192
* These two variables are supposed to be private inside alias.c
7193
* Even though i export them here, it is EVIL EVIL EVIL to use
7194
* them outside of alias.c. So do not follow my example and extern
7195
* these for your own use -- because who knows, one day i may make
7196
* them static and your use of them will not be my fault! :p
7197
*/
7198
extern int wind_index; /* XXXXX Ick */
7199
extern int last_function_call_level; /* XXXXX Ick */
7200
7201
/*
7202
* If the last place we slapped down a FUNCTION_RETURN is in the
7203
* current operating stack frame, then we're in a user-function
7204
* call. Otherwise we're not. Pretty simple.
7205
*/
7206
if (last_function_call_level == wind_index)
7207
RETURN_INT(1);
7208
else
7209
RETURN_INT(0);
7210
}
7211
7212
/*
7213
* Usage: $indextoword(position text)
7214
*
7215
* This function returns the word-number (counting from 0) that contains
7216
* the 'position'th character in 'text' (counting from 0), such that the
7217
* following expression:
7218
*
7219
* $word($indextoword($index(. $*) $*))
7220
*
7221
* would return the *entire word* in which the first '.' in $* is found.
7222
* If 'position' is -1, or past the end of the string, -1 is returned as
7223
* an error flag. Note that this function can be used anywhere that a
7224
* word-number would be used, such as $chngw(). The empty value is returned
7225
* if a syntax error returns.
7226
*
7227
* DONT ASK ME to support 'position' less than 0 to indicate a position
7228
* from the end of the string. Either that can be supported, or you can
7229
* directly use $index() as the first argument; you can't do both. I chose
7230
* the latter intentionally. If you really want to calculate from the end of
7231
* your string, then just add your negative value to $strlen(string) and
7232
* pass that.
7233
*/
7234
BUILT_IN_FUNCTION(function_indextoword, input)
7235
{
7236
size_t pos;
7237
size_t len;
7238
7239
GET_INT_ARG(pos, input);
7240
if (pos < 0)
7241
RETURN_EMPTY;
7242
len = strlen(input);
7243
if (pos < 0 || pos >= len)
7244
RETURN_EMPTY;
7245
7246
/*
7247
* XXX
7248
* Using 'word_count' to do this is a really lazy cop-out, but it
7249
* renders the desired effect and its pretty cheap. Anyone want
7250
* to bicker with me about it?
7251
*/
7252
/* Truncate the string if neccesary */
7253
if (pos + 1 < len)
7254
input[pos + 1] = 0;
7255
RETURN_INT(word_count(input));
7256
}
7257
7258
BUILT_IN_FUNCTION(function_realpath, input)
7259
{
7260
#ifdef HAVE_REALPATH
7261
char resolvedname[MAXPATHLEN];
7262
char *retval;
7263
7264
if ((retval = realpath(input, resolvedname)))
7265
RETURN_STR(resolvedname);
7266
else
7267
RETURN_EMPTY;
7268
#else
7269
RETURN_STR(input);
7270
#endif
7271
}
7272
7273
BUILT_IN_FUNCTION(function_ttyname, input)
7274
{
7275
RETURN_STR(ttyname(0));
7276
}
7277
7278
/*
7279
* $insert(num word string of text)
7280
* returns "string of text" such that "word" begins in the "num"th position
7281
* in the string ($index()-wise)
7282
* NOTE: Positions are numbered from 0
7283
* EX: $insert(3 baz foobarbooya) returns "foobazbarbooya"
7284
*/
7285
BUILT_IN_FUNCTION(function_insert, word)
7286
{
7287
int where;
7288
char * inserted;
7289
char * result;
7290
7291
GET_INT_ARG(where, word);
7292
GET_STR_ARG(inserted, word);
7293
7294
if (where <= 0)
7295
result = m_strdup(empty_string);
7296
else
7297
result = strext(word, word + where);
7298
7299
m_3cat(&result, inserted, word + where);
7300
7301
return result; /* DONT USE RETURN_STR HERE! */
7302
}
7303
7304
BUILT_IN_FUNCTION(function_stat, input)
7305
{
7306
char * filename;
7307
char retval[BIG_BUFFER_SIZE];
7308
struct stat sb;
7309
7310
GET_STR_ARG(filename, input);
7311
if (stat(filename, &sb) < 0)
7312
RETURN_EMPTY;
7313
7314
snprintf(retval, BIG_BUFFER_SIZE,
7315
"%d %d %o %d %d %d %d %lu %lu %lu %ld %ld %ld",
7316
(int) sb.st_dev, /* device number */
7317
(int) sb.st_ino, /* Inode number */
7318
(int) sb.st_mode, /* Permissions */
7319
(int) sb.st_nlink, /* Hard links */
7320
(int) sb.st_uid, /* Owner UID */
7321
(int) sb.st_gid, /* Owner GID */
7322
(int) sb.st_rdev, /* Device type */
7323
(u_long)sb.st_size, /* Size of file */
7324
#ifdef __EMX__
7325
(u_long)sb.st_attr, /* OS/2 Attributes */
7326
(u_long)sb.st_reserved, /* OS/2 reserved */
7327
#else
7328
(u_long)sb.st_blksize, /* Size of each block */
7329
(u_long)sb.st_blocks, /* Blocks used in file */
7330
#endif
7331
(long) sb.st_atime, /* Last-access time */
7332
(long) sb.st_mtime, /* Last-modified time */
7333
(long) sb.st_ctime /* Last-change time */
7334
);
7335
7336
RETURN_STR(retval);
7337
}
7338
7339
BUILT_IN_FUNCTION(function_serverlag, input)
7340
{
7341
int server = from_server;
7342
if (input && *input)
7343
server = my_atol(input);
7344
RETURN_INT(get_server_lag(server));
7345
}
7346
7347
BUILT_IN_FUNCTION(function_strchar, input)
7348
{
7349
char *chr, *ret = NULL;
7350
char *(*func)(const char *, int);
7351
GET_STR_ARG(chr, input);
7352
if (!my_stricmp("STRCHR", fn))
7353
func = strchr;
7354
else
7355
func = strrchr;
7356
if (chr && *chr)
7357
ret = func(input, *chr);
7358
RETURN_STR(ret);
7359
}
7360
7361
BUILT_IN_FUNCTION(function_isdisplaying, input)
7362
{
7363
RETURN_INT(window_display);
7364
}
7365
7366
BUILT_IN_FUNCTION(function_getcap, input)
7367
{
7368
char * type;
7369
7370
GET_STR_ARG(type, input);
7371
if (!my_stricmp(type, "TERM"))
7372
{
7373
char * retval;
7374
char * term = NULL;
7375
int querytype = 0;
7376
int mangle = 1;
7377
7378
GET_STR_ARG(term, input);
7379
if (*input)
7380
GET_INT_ARG(querytype, input);
7381
if (*input)
7382
GET_INT_ARG(mangle, input);
7383
7384
if (!term) /* This seems spurious */
7385
RETURN_EMPTY;
7386
7387
if ((retval = get_term_capability(term, querytype, mangle)))
7388
RETURN_STR(retval);
7389
7390
RETURN_EMPTY;
7391
}
7392
7393
RETURN_EMPTY;
7394
}
7395
7396
BUILT_IN_FUNCTION(function_getset, input)
7397
{
7398
RETURN_MSTR(make_string_var(input));
7399
}
7400
7401
BUILT_IN_FUNCTION(function_builtin, input)
7402
{
7403
RETURN_MSTR(built_in_alias (*input, NULL));
7404
}
7405
7406
BUILT_IN_FUNCTION(function_ipv6, input)
7407
{
7408
#ifdef IPV6
7409
RETURN_INT(1);
7410
#else
7411
RETURN_INT(0);
7412
#endif
7413
}
7414
7415