atcodes.cpp 33.3 KB
Newer Older
1
/* Synchronet "@code" functions */
2
// vi: tabstop=4
3
4
5
6
7
8
9

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
10
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"
#include "cmdshell.h"

40
41
42
43
44
45
46
#if defined(_WINSOCKAPI_)
	extern WSADATA WSAData;
	#define SOCKLIB_DESC WSAData.szDescription
#else
	#define	SOCKLIB_DESC NULL
#endif

47
48
49
/****************************************************************************/
/* Returns 0 if invalid @ code. Returns length of @ code if valid.          */
/****************************************************************************/
50
int sbbs_t::show_atcode(const char *instr)
51
{
52
	char	str[128],str2[128],*tp,*sp,*p;
53
    int     len;
54
	int		disp_len;
55
56
	bool	padded_left=false;
	bool	padded_right=false;
57
	bool	centered=false;
58
	bool	zero_padded=false;
59
	const char *cp;
60

61
	SAFECOPY(str,instr);
62
63
64
	tp=strchr(str+1,'@');
	if(!tp)                 /* no terminating @ */
		return(0);
65
	sp=strchr(str+1,' ');
66
67
68
69
70
71
	if(sp && sp<tp)         /* space before terminating @ */
		return(0);
	len=(tp-str)+1;
	(*tp)=0;
	sp=(str+1);

72
	disp_len=len;
73
74
75
76
	if((p=strstr(sp,"-L"))!=NULL)
		padded_left=true;
	else if((p=strstr(sp,"-R"))!=NULL)
		padded_right=true;
77
78
	else if((p=strstr(sp,"-C"))!=NULL)
		centered=true;
79
80
	else if((p=strstr(sp,"-Z"))!=NULL)
		zero_padded=true;
81
82
83
	if(p!=NULL) {
		if(*(p+2) && isdigit(*(p+2)))
			disp_len=atoi(p+2);
84
		*p=0;
85
	}
86

87
88
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
89
90
91
		return(0);

	if(padded_left)
92
		bprintf("%-*.*s",disp_len,disp_len,cp);
93
	else if(padded_right)
94
		bprintf("%*.*s",disp_len,disp_len,cp);
95
	else if(centered) {
rswindell's avatar
rswindell committed
96
		int vlen = strlen(cp);
97
98
99
100
		if(vlen < disp_len) {
			int left = (disp_len - vlen) / 2;
			bprintf("%*s%-*s", left, "", disp_len - left, cp);
		} else
101
			bprintf("%.*s", disp_len, cp);
102
	} else if(zero_padded) {
103
104
		int vlen = strlen(cp);
		if(vlen < disp_len)
105
			bprintf("%-.*s%s", (int)(disp_len - strlen(cp)), "0000000000", cp);
106
107
		else
			bprintf("%.*s", disp_len, cp);
108
	} else
109
		bputs(cp);
110
111
112
113

	return(len);
}

114
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
115
116
117
{
	char*	tp;
	uint	i;
118
119
	uint	ugrp;
	uint	usub;
120
121
122
123
124
125
126
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

127
	if(!strcmp(sp,"VER"))
128
		return(VERSION);
129

130
	if(!strcmp(sp,"REV")) {
131
		safe_snprintf(str,maxlen,"%c",REVISION);
132
133
		return(str);
	}
134

135
	if(!strcmp(sp,"FULL_VER")) {
136
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
137
		truncsp(str);
138
#if defined(_DEBUG)
139
		strcat(str," Debug");
140
#endif
141
		return(str);
142
143
	}

144
	if(!strcmp(sp,"VER_NOTICE"))
145
		return(VERSION_NOTICE);
146

147
148
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
149
150

#ifdef JAVASCRIPT
151
152
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
153
154
#endif

155
156
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
157

158
159
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
160

161
	if(!strcmp(sp,"COMPILER")) {
162
163
164
		char compiler[32];
		DESCRIBE_COMPILER(compiler);
		strncpy(str, compiler, maxlen);
165
		return(str);
166
167
	}

168
	if(!strcmp(sp,"UPTIME")) {
169
		extern volatile time_t uptime;
170
171
172
173
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
174
175
		char   days[64]="";
		if((up/(24*60*60))>=2) {
176
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
177
178
			up%=(24*60*60);
		}
179
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
180
	        ,days
181
182
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
183
			);
184
		return(str);
185
186
	}

187
	if(!strcmp(sp,"SERVED")) {
188
		extern volatile ulong served;
189
		safe_snprintf(str,maxlen,"%lu",served);
190
191
192
		return(str);
	}

193
	if(!strcmp(sp,"SOCKET_LIB"))
194
		return(socklib_version(str,SOCKLIB_DESC));
195

196
	if(!strcmp(sp,"MSG_LIB")) {
197
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
198
199
		return(str);
	}
200

201
202
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
203

204
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
205
		safe_snprintf(str,maxlen,"%lu",cur_rate);
206
207
		return(str);
	}
208

rswindell's avatar
rswindell committed
209
210
211
212
213
214
215
216
217
218
219
	if(!strcmp(sp,"COLS")) {
		safe_snprintf(str,maxlen,"%lu",cols);
		return(str);
	}
	if(!strcmp(sp,"ROWS")) {
		safe_snprintf(str,maxlen,"%lu",rows);
		return(str);
	}
	if(!strcmp(sp,"TERM"))
		return(terminal);

220
221
	if(!strcmp(sp,"CONN"))
		return(connection);
222

223
224
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
225

226
227
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
228

229
	if(!strcmp(sp,"NODE")) {
230
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
231
232
		return(str);
	}
233

234
	if(!strcmp(sp,"TNODE")) {
235
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
236
237
		return(str);
	}
238

239
240
241
242
243
244
	if(strcmp(sp, "PAGER") == 0)
		return (thisnode.misc&NODE_POFF) ? text[Off] : text[On];

	if(strcmp(sp, "ALERTS") == 0)
		return (thisnode.misc&NODE_AOFF) ? text[Off] : text[On];

245
246
247
	if(strcmp(sp, "SPLITP") == 0)
		return (useron.chat&CHAT_SPLITP) ? text[On] : text[Off];

248
249
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
250

251
252
253
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

254
	if(!strcmp(sp,"FIDOADDR")) {
255
		if(cfg.total_faddrs)
256
			return(smb_faddrtoa(&cfg.faddr[0],str));
257
		return(nulstr);
258
259
	}

260
	if(!strcmp(sp,"EMAILADDR"))
261
		return(usermailaddr(&cfg, str
262
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
263

264
265
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
266

267
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
268
		now=time(NULL);
269
		memset(&tm,0,sizeof(tm));
270
		localtime_r(&now,&tm);
271
		if(cfg.sys_misc&SM_MILITARY)
272
273
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
274
		else
275
			safe_snprintf(str,maxlen,"%02d:%02d %s"
276
277
278
				,tm.tm_hour==0 ? 12
				: tm.tm_hour>12 ? tm.tm_hour-12
				: tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am");
279
		return(str);
280
281
	}

rswindell's avatar
rswindell committed
282
283
284
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

285
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
286
		return(unixtodstr(&cfg,time32(NULL),str));
287
	}
288

rswindell's avatar
rswindell committed
289
290
291
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

292
	if(!strcmp(sp,"TMSG")) {
293
294
		l=0;
		for(i=0;i<cfg.total_subs;i++)
295
			l+=getposts(&cfg,i); 		/* l=total posts */
296
		safe_snprintf(str,maxlen,"%lu",l);
297
298
		return(str);
	}
299

300
	if(!strcmp(sp,"TUSER")) {
301
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
302
303
		return(str);
	}
304

305
	if(!strcmp(sp,"TFILE")) {
306
307
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
308
			l+=getfiles(&cfg,i);
309
		safe_snprintf(str,maxlen,"%lu",l);
310
311
		return(str);
	}
312

313
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
314
		getstats(&cfg,0,&stats);
315
		safe_snprintf(str,maxlen,"%lu",stats.logons);
316
317
		return(str);
	}
318

319
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
320
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
321
		return(lastuseron);
322

rswindell's avatar
rswindell committed
323
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
324
		CLS;
325
326
		return(nulstr);
	}
327

328
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
329
		pause();
330
331
		return(nulstr);
	}
332

333
	if(!strcmp(sp,"RESETPAUSE")) {
334
		lncntr=0;
335
336
		return(nulstr);
	}
337

338
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
339
		sys_status^=SS_PAUSEOFF;
340
341
		return(nulstr);
	}
342

343
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
344
		sys_status^=SS_PAUSEON;
345
346
		return(nulstr);
	}
347
348
349
350
351

	/* NOSTOP */

	/* STOP */

352
353
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
354

355
356
357
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
358
		return(timestr(event_time));
359
	}
360
361
362

	/* LASTCALL */

363
	if(!strncmp(sp,"NODE",4)) {
364
365
366
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
367
368
			printnodedat(i,&node);
		}
369
370
		return(nulstr);
	}
371

372
	if(!strcmp(sp,"WHO")) {
373
		whos_online(true);
374
375
		return(nulstr);
	}
376
377
378

	/* User Codes */

379
380
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
381

382
	if(!strcmp(sp,"FIRST")) {
383
		safe_snprintf(str,maxlen,"%s",useron.alias);
384
		tp=strchr(str,' ');
385
		if(tp) *tp=0;
386
		return(str);
387
	}
388

389
	if(!strcmp(sp,"USERNUM")) {
390
		safe_snprintf(str,maxlen,"%u",useron.number);
391
392
		return(str);
	}
393

394
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
395
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
396
		return(useron.phone);
397

398
399
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
400

401
402
	if(!strcmp(sp,"FROM"))
		return(useron.location);
403

404
	if(!strcmp(sp,"CITY")) {
405
		safe_snprintf(str,maxlen,"%s",useron.location);
406
		char* p=strchr(str,',');
407
408
		if(p) {
			*p=0;
409
410
			return(str);
		}
411
412
		return(nulstr);
	}
413

414
415
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
416
417
		if(p) {
			p++;
418
			if(*p==' ')
419
				p++;
420
421
			return(p);
		}
422
423
		return(nulstr);
	}
424

425
426
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
427

428
429
	if(!strcmp(sp,"HOST"))
		return(client_name);
430

431
432
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
433

434
	if(!strcmp(sp,"AGE")) {
435
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
436
437
		return(str);
	}
rswindell's avatar
rswindell committed
438

439
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
440
		safe_snprintf(str,maxlen,"%u",useron.logons);
441
442
		return(str);
	}
443

444
445
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
446

447
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
448
		safe_snprintf(str,maxlen,"%u",useron.level);
449
450
		return(str);
	}
451

452
453
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
454

455
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
456
		now=time(NULL);
457
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
458
459
		return(str);
	}
460

461
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
462
		now=time(NULL);
463
		return(sectostr((uint)(now-logontime),str)+1);
464
	}
465

466
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
467
		gettimeleft();
468
		return(sectostr(timeleft,str)+1);
469
	}
470

471
472
	if(!strcmp(sp,"TPERD"))                /* Synchronet only */
		return(sectostr(cfg.level_timeperday[useron.level],str)+1);
473

474
475
	if(!strcmp(sp,"TPERC"))                /* Synchronet only */
		return(sectostr(cfg.level_timepercall[useron.level],str)+1);
476

477
	if(!strcmp(sp,"TIMELIMIT")) {
478
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
479
480
		return(str);
	}
481

482
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
483
		gettimeleft();
484
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
485
486
		return(str);
	}
487

488
	if(!strcmp(sp,"LASTON"))
489
		return(timestr(useron.laston));
490

491
492
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
493

494
	if(!strcmp(sp,"LASTTIMEON")) {
495
		memset(&tm,0,sizeof(tm));
496
		localtime32(&useron.laston,&tm);
497
498
499
500
501
502
503
504
		if(cfg.sys_misc&SM_MILITARY)
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
				,tm.tm_hour, tm.tm_min, tm.tm_sec);
		else
			safe_snprintf(str,maxlen,"%02d:%02d %s"
				,tm.tm_hour==0 ? 12
				: tm.tm_hour>12 ? tm.tm_hour-12
				: tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am");
505
		return(str);
506
507
	}

508
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
509
		safe_snprintf(str,maxlen,"%u",useron.posts);
510
511
		return(str);
	}
512

513
	if(!strcmp(sp,"MSGREAD")) {
514
		safe_snprintf(str,maxlen,"%lu",posts_read);
515
516
		return(str);
	}
517

518
	if(!strcmp(sp,"FREESPACE")) {
519
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
520
521
522
523
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
524
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
525
526
		return(str);
	}
527

528
	if(!strcmp(sp,"UPBYTES")) {
529
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
530
531
		return(str);
	}
532

533
	if(!strcmp(sp,"UPK")) {
534
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
535
536
		return(str);
	}
537

538
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
539
		safe_snprintf(str,maxlen,"%u",useron.uls);
540
541
		return(str);
	}
542

543
	if(!strcmp(sp,"DLBYTES")) {
544
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
545
546
		return(str);
	}
547

548
	if(!strcmp(sp,"DOWNK")) {
549
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
550
551
		return(str);
	}
552

553
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
554
		safe_snprintf(str,maxlen,"%u",useron.dls);
555
556
		return(str);
	}
557

558
	if(!strcmp(sp,"LASTNEW"))
559
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
560

561
	if(!strcmp(sp,"NEWFILETIME"))
562
		return(timestr(ns_time));
563
564
565

	/* MAXDL */

566
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
567
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
568
569
		return(str);
	}
570

571
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
572
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
573
574
		return(str);
	}
575

576
	if(!strcmp(sp,"BYTELIMIT")) {
577
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]);
578
579
		return(str);
	}
580

581
	if(!strcmp(sp,"KBLEFT")) {
582
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
583
584
		return(str);
	}
585

586
	if(!strcmp(sp,"BYTESLEFT")) {
587
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
588
589
		return(str);
	}
590

591
	if(!strcmp(sp,"CONF")) {
592
		safe_snprintf(str,maxlen,"%s %s"
593
594
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
595
596
		return(str);
	}
597

598
	if(!strcmp(sp,"CONFNUM")) {
599
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
600
601
		return(str);
	}
602

603
	if(!strcmp(sp,"NUMDIR")) {
604
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
605
606
		return(str);
	}
607

608
609
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
610

611
	if(!strcmp(sp,"EXPDAYS")) {
612
		now=time(NULL);
613
		l=(long)(useron.expire-now);
614
615
		if(l<0)
			l=0;
616
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
617
618
		return(str);
	}
619

620
621
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
622

623
624
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
625

626
627
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
628

629
	if(!strcmp(sp,"HANGUP")) {
630
		hangup();
631
632
		return(nulstr);
	}
633
634
635

	/* Synchronet Specific */

636
	if(!strncmp(sp,"SETSTR:",7)) {
637
		strcpy(main_csi.str,sp+7);
638
639
		return(nulstr);
	}
640

641
	if(!strncmp(sp,"EXEC:",5)) {
642
		exec_bin(sp+5,&main_csi);
643
644
		return(nulstr);
	}
645

646
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
647
		for(i=0;i<cfg.total_xtrns;i++)
648
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
649
650
651
652
653
654
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

655
	if(!strncmp(sp,"MENU:",5)) {
656
		menu(sp+5);
657
658
		return(nulstr);
	}
659

660
661
662
663
664
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

665
666
667
668
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
669

670
	if(!strncmp(sp,"INCLUDE:",8)) {
671
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
672
673
674
		return(nulstr);
	}

675
676
	if(!strcmp(sp,"QUESTION"))
		return(question);
677

678
679
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
680

681
682
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
683

deuce's avatar
deuce committed
684
685
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
686

687
688
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
689

690
	if(!strcmp(sp,"PUSHXY")) {
691
		ansi_save();
692
693
		return(nulstr);
	}
694

695
	if(!strcmp(sp,"POPXY")) {
696
		ansi_restore();
697
698
		return(nulstr);
	}
699

rswindell's avatar
rswindell committed
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
	if(!strcmp(sp,"HOME")) {
		cursor_home();
		return(nulstr);
	}

	if(!strcmp(sp,"CLRLINE")) {
		clearline();
		return(nulstr);
	}

	if(!strcmp(sp,"CLR2EOL")) {
		cleartoeol();
		return(nulstr);
	}

	if(!strcmp(sp,"CLR2EOS")) {
		cleartoeos();
		return(nulstr);
	}

720
	if(!strncmp(sp,"UP:",3)) {
721
		cursor_up(atoi(sp+3));
722
723
		return(str);
	}
724

725
	if(!strncmp(sp,"DOWN:",5)) {
726
		cursor_down(atoi(sp+5));
727
728
		return(str);
	}
729

730
	if(!strncmp(sp,"LEFT:",5)) {
731
		cursor_left(atoi(sp+5));
732
733
		return(str);
	}
734

735
	if(!strncmp(sp,"RIGHT:",6)) {
736
		cursor_right(atoi(sp+6));
737
738
		return(str);
	}
739

740
	if(!strncmp(sp,"GOTOXY:",7)) {
741
742
743
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
744
			ansi_gotoxy(atoi(sp+7),atoi(tp));
745
		}
746
		return(nulstr);
747
748
	}

749
750
751
752
753
754
755
	if(!strcmp(sp,"GRP")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Local");
			if(smb.subnum<cfg.total_subs)
				return(cfg.grp[cfg.sub[smb.subnum]->grp]->sname);
		}
756
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr);
757
	}
758

759
760
761
762
763
764
765
	if(!strcmp(sp,"GRPL")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Local");
			if(smb.subnum<cfg.total_subs)
				return(cfg.grp[cfg.sub[smb.subnum]->grp]->lname);
		}
766
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
767
	}
768

769
	if(!strcmp(sp,"GN")) {
770
771
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
772
		else
773
			ugrp=usrgrps ? curgrp+1 : 0;
774
		safe_snprintf(str,maxlen,"%u",ugrp);
775
776
		return(str);
	}
777