atcodes.cpp 23.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
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
40
/* atcodes.cpp */

/* Synchronet "@code" functions */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
 * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html		*
 *																			*
 * 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"

rswindell's avatar
rswindell committed
41
extern "C" const char* beta_version;
42

43
44
45
/****************************************************************************/
/* Returns 0 if invalid @ code. Returns length of @ code if valid.          */
/****************************************************************************/
46
int sbbs_t::show_atcode(char *instr)
47
{
48
	char	str[128],str2[128],*p,*tp,*sp;
49
50
51
    int     len;
	bool	padded_left=false;
	bool	padded_right=false;
52

53
	sprintf(str,"%.80s",instr);
54
55
56
57
58
59
60
61
62
63
	tp=strchr(str+1,'@');
	if(!tp)                 /* no terminating @ */
		return(0);
	sp=strchr(str+1,SP);
	if(sp && sp<tp)         /* space before terminating @ */
		return(0);
	len=(tp-str)+1;
	(*tp)=0;
	sp=(str+1);

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	if((p=strstr(sp,"-L"))!=NULL)
		padded_left=true;
	else if((p=strstr(sp,"-R"))!=NULL)
		padded_right=true;
	if(p!=NULL)
		*p=0;

	p=atcode(sp,str2);
	if(p==NULL)
		return(0);

	if(padded_left)
		rprintf("%-*.*s",len,len,p);
	else if(padded_right)
		rprintf("%*.*s",len,len,p);
	else
		rputs(p);

	return(len);
}

char* sbbs_t::atcode(char* sp, char* str)
{
	char*	tp;
	uint	i;
89
90
	uint	ugrp;
	uint	usub;
91
92
93
94
95
96
97
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

98
	if(!strcmp(sp,"VER"))
99
		return(VERSION);
100

101
102
103
104
	if(!strcmp(sp,"REV")) {
		sprintf(str,"%c",REVISION);
		return(str);
	}
105

106
107
108
	if(!strcmp(sp,"FULL_VER")) {
		sprintf(str,"%s%c%s",VERSION,REVISION,beta_version);
		truncsp(str);
109
#if defined(_DEBUG)
110
		strcat(str," Debug");
111
#endif
112
		return(str);
113
114
	}

115
116
	if(!strcmp(sp,"VER_NOTICE")) 
		return(VERSION_NOTICE);
117

118
119
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
120
121

#ifdef JAVASCRIPT
122
123
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
124
125
#endif

126
127
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
128

129
130
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
131

132
	if(!strcmp(sp,"COMPILER")) {
133
		DESCRIBE_COMPILER(str);
134
		return(str);
135
136
	}

137
	if(!strcmp(sp,"UPTIME")) {
138
139
		extern time_t uptime;
		time_t up=time(NULL)-uptime;
140
141
		if(up<0)
			up=0;
142
143
		char   days[64]="";
		if((up/(24*60*60))>=2) {
144
	        sprintf(days,"%u days ",up/(24*60*60));
145
146
			up%=(24*60*60);
		}
147
		sprintf(str,"%s%u:%02u"
148
149
150
151
	        ,days
			,up/(60*60)
			,(up/60)%60
			);
152
		return(str);
153
154
	}

155
156
	if(!strcmp(sp,"SOCKET_LIB")) 
		return(socklib_version(str));
157

158
159
160
161
	if(!strcmp(sp,"MSG_LIB")) {
		sprintf(str,"SMBLIB %s",smb_lib_ver());
		return(str);
	}
162

163
164
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
165

166
167
168
169
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
		sprintf(str,"%lu",cur_rate);
		return(str);
	}
170

171
172
	if(!strcmp(sp,"CONN"))
		return(connection);
173

174
175
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
176

177
178
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
179

180
181
182
183
	if(!strcmp(sp,"NODE")) {
		sprintf(str,"%u",cfg.node_num);
		return(str);
	}
184

185
186
187
188
	if(!strcmp(sp,"TNODE")) {
		sprintf(str,"%u",cfg.sys_nodes);
		return(str);
	}
189

190
191
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
192

193
194
195
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

196
	if(!strcmp(sp,"FIDOADDR")) {
197
		if(cfg.total_faddrs)
198
			return(faddrtoa(&cfg.faddr[0],str));
199
		return(nulstr);
200
201
	}

202
203
	if(!strcmp(sp,"EMAILADDR")) 
		return(usermailaddr(&cfg, str
204
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
205

206
207
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
208

209
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
210
		now=time(NULL);
211
		memset(&tm,0,sizeof(tm));
212
		localtime_r(&now,&tm);
213
		sprintf(str,"%02d:%02d %s"
214
215
216
			,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"); 
217
		return(str);
218
219
	}

220
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
221
		now=time(NULL);
222
223
		return(unixtodstr(&cfg,now,str)); 
	}
224

225
	if(!strcmp(sp,"TMSG")) {
226
227
		l=0;
		for(i=0;i<cfg.total_subs;i++)
228
			l+=getposts(&cfg,i); 		/* l=total posts */
229
230
231
		sprintf(str,"%lu",l); 
		return(str);
	}
232

233
234
235
236
	if(!strcmp(sp,"TUSER")) {
		sprintf(str,"%u",lastuser(&cfg));
		return(str);
	}
237

238
	if(!strcmp(sp,"TFILE")) {
239
240
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
241
			l+=getfiles(&cfg,i);
242
243
244
		sprintf(str,"%lu",l); 
		return(str);
	}
245

246
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
247
		getstats(&cfg,0,&stats);
248
249
250
		sprintf(str,"%lu",stats.logons); 
		return(str);
	}
251

252
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
253
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
254
		return(lastuseron);
255

256
	if(!strcmp(sp,"CLS")) {
257
		CLS;
258
259
		return(nulstr);
	}
260

261
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
262
		pause();
263
264
		return(nulstr);
	}
265

266
	if(!strcmp(sp,"RESETPAUSE")) {
267
		lncntr=0;
268
269
		return(nulstr);
	}
270

271
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
272
		sys_status^=SS_PAUSEOFF;
273
274
		return(nulstr);
	}
275

276
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
277
		sys_status^=SS_PAUSEON;
278
279
		return(nulstr);
	}
280
281
282
283
284

	/* NOSTOP */

	/* STOP */

285
286
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
287
288

	// else if(!strcmp(sp,"EVENT"))
289
	//	  return(sectostr(sys_eventtime,str2));
290
291
292

	/* LASTCALL */

293
	if(!strncmp(sp,"NODE",4)) {
294
295
296
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
297
298
299
300
			printnodedat(i,&node); 
		} 
		return(nulstr);
	}
301

302
	if(!strcmp(sp,"WHO")) {
303
		whos_online(true);
304
305
		return(nulstr);
	}
306
307
308

	/* User Codes */

309
310
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
311

312
313
314
	if(!strcmp(sp,"FIRST")) {
		strcpy(str,useron.alias);
		tp=strchr(str,SP);
315
		if(tp) *tp=0;
316
317
		return(str); 
	}
318

319
320
321
322
	if(!strcmp(sp,"USERNUM")) {
		sprintf(str,"%u",useron.number);
		return(str);
	}
323

324
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
325
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
326
		return(useron.phone);
327

328
329
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
330

331
332
	if(!strcmp(sp,"FROM"))
		return(useron.location);
333

334
335
336
	if(!strcmp(sp,"CITY")) {
		strcpy(str,useron.location);
		char* p=strchr(str,',');
337
338
		if(p) {
			*p=0;
339
340
341
342
			return(str); 
		} 
		return(nulstr);
	}
343

344
345
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
346
347
348
349
		if(p) {
			p++;
			if(*p==SP)
				p++;
350
351
352
353
			return(p); 
		} 
		return(nulstr);
	}
354

355
356
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
357
		
358
359
	if(!strcmp(sp,"HOST"))
		return(client_name);
360

361
362
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
363

364
365
366
367
	if(!strcmp(sp,"AGE")) {
		sprintf(str,"%u",getage(&cfg,useron.birth));
		return(str);
	}
rswindell's avatar
rswindell committed
368

369
370
371
372
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
		sprintf(str,"%u",useron.logons);
		return(str);
	}
373

374
375
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
376

377
378
379
380
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
		sprintf(str,"%u",useron.level);
		return(str);
	}
381

382
383
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
384

385
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
386
		now=time(NULL);
387
		sprintf(str,"%lu",(now-logontime)/60L); 
388
389
		return(str);
	}
390

391
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
392
		now=time(NULL);
393
394
		return(sectostr(now-logontime,str)+1); 
	}
395

396
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
397
		gettimeleft();
398
399
		return(sectostr(timeleft,str)+1); 
	}
400

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

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

407
408
409
410
	if(!strcmp(sp,"TIMELIMIT")) {
		sprintf(str,"%u",cfg.level_timepercall[useron.level]);
		return(str);
	}
411

412
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
413
		gettimeleft();
414
		sprintf(str,"%lu",timeleft/60); 
415
416
		return(str);
	}
417

418
419
	if(!strcmp(sp,"LASTON")) 
		return(timestr(&useron.laston));
420

421
422
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
423

424
	if(!strcmp(sp,"LASTTIMEON")) {
425
426
		memset(&tm,0,sizeof(tm));
		localtime_r(&useron.laston,&tm);
427
		sprintf(str,"%02d:%02d %s"
428
429
430
			,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"); 
431
		return(str);
432
433
	}

434
435
436
437
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
		sprintf(str,"%u",useron.posts);
		return(str);
	}
438

439
	if(!strcmp(sp,"MSGREAD")) {
440
		sprintf(str,"%lu",posts_read);
441
442
		return(str);
	}
443

444
445
446
447
	if(!strcmp(sp,"FREESPACE")) {
		sprintf(str,"%lu",getfreediskspace(cfg.temp_dir)); 
		return(str);
	}
448

449
450
451
452
	if(!strcmp(sp,"UPBYTES")) {
		sprintf(str,"%lu",useron.ulb);
		return(str);
	}
453

454
455
456
457
	if(!strcmp(sp,"UPK")) {
		sprintf(str,"%lu",useron.ulb/1024L);
		return(str);
	}
458

459
460
461
462
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
		sprintf(str,"%u",useron.uls);
		return(str);
	}
463

464
465
466
467
	if(!strcmp(sp,"DLBYTES")) {
		sprintf(str,"%lu",useron.dlb);
		return(str);
	}
468

469
470
471
472
	if(!strcmp(sp,"DOWNK")) {
		sprintf(str,"%lu",useron.dlb/1024L);
		return(str);
	}
473

474
475
476
477
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
		sprintf(str,"%u",useron.dls);
		return(str);
	}
478

479
480
	if(!strcmp(sp,"LASTNEW"))
		return(unixtodstr(&cfg,ns_time,str));
481

482
483
	if(!strcmp(sp,"NEWFILETIME"))
		return(timestr(&ns_time));
484
485
486

	/* MAXDL */

487
488
489
490
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
		return(str);
	}
491

492
493
494
495
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
		return(str);
	}
496

497
498
499
500
	if(!strcmp(sp,"BYTELIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]);
		return(str);
	}
501

502
503
504
505
	if(!strcmp(sp,"KBLEFT")) {
		sprintf(str,"%lu",(useron.cdt+useron.freecdt)/1024L);
		return(str);
	}
506

507
508
509
510
	if(!strcmp(sp,"BYTESLEFT")) {
		sprintf(str,"%lu",useron.cdt+useron.freecdt);
		return(str);
	}
511

512
	if(!strcmp(sp,"CONF")) {
rswindell's avatar
rswindell committed
513
		sprintf(str,"%s %s"
514
515
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
516
517
		return(str);
	}
518

519
520
521
522
	if(!strcmp(sp,"CONFNUM")) {
		sprintf(str,"%u %u",curgrp+1,cursub[curgrp]+1);
		return(str);
	}
523

524
525
526
527
	if(!strcmp(sp,"NUMDIR")) {
		sprintf(str,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
528

529
530
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
531

532
	if(!strcmp(sp,"EXPDAYS")) {
533
534
535
536
		now=time(NULL);
		l=useron.expire-now;
		if(l<0)
			l=0;
537
		sprintf(str,"%lu",l/(1440L*60L)); 
538
539
		return(str);
	}
540

541
542
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
543

544
545
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
546

547
548
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
549

550
	if(!strcmp(sp,"HANGUP")) {
551
		hangup();
552
553
		return(nulstr);
	}
554
555
556

	/* Synchronet Specific */

557
	if(!strncmp(sp,"SETSTR:",7)) {
558
		strcpy(main_csi.str,sp+7);
559
560
		return(nulstr);
	}
561

562
	if(!strncmp(sp,"EXEC:",5)) {
563
		exec_bin(sp+5,&main_csi);
564
565
		return(nulstr);
	}
566

567
	if(!strncmp(sp,"MENU:",5)) {
568
		menu(sp+5);
569
570
		return(nulstr);
	}
571

572
573
574
575
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
576

577
578
	if(!strcmp(sp,"QUESTION"))
		return(question);
579

580
581
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
582

583
584
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
585

586
	if(!strcmp(sp,"LOCAL-IP")) {
587
		struct in_addr in_addr;
588
		in_addr.s_addr=local_addr;
589
		return(inet_ntoa(in_addr));
590
591
	}

592
593
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
594

595
	if(!strcmp(sp,"PUSHXY")) {
596
		ANSI_SAVE();
597
598
		return(nulstr);
	}
599

600
	if(!strcmp(sp,"POPXY")) {
601
		ANSI_RESTORE();
602
603
		return(nulstr);
	}
604

605
606
	if(!strcmp(sp,"UP")) 
		return("\x1b[A");
607

608
609
	if(!strcmp(sp,"DOWN")) 
		return("\x1b[B");
610

611
612
	if(!strcmp(sp,"RIGHT")) 
		return("\x1b[C");
613

614
615
	if(!strcmp(sp,"LEFT")) 
		return("\x1b[D");
616

617
618
619
620
	if(!strncmp(sp,"UP:",3)) {
		sprintf(str,"\x1b[%dA",atoi(sp+3));
		return(str);
	}
621

622
623
624
625
	if(!strncmp(sp,"DOWN:",5)) {
		sprintf(str,"\x1b[%dB",atoi(sp+5));
		return(str);
	}
626

627
628
629
630
	if(!strncmp(sp,"LEFT:",5)) {
		sprintf(str,"\x1b[%dC",atoi(sp+5));
		return(str);
	}
631

632
633
634
635
	if(!strncmp(sp,"RIGHT:",6)) {
		sprintf(str,"\x1b[%dD",atoi(sp+6));
		return(str);
	}
636

637
	if(!strncmp(sp,"GOTOXY:",7)) {
638
639
640
641
642
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
			GOTOXY(atoi(sp+7),atoi(tp));
		}
643
		return(nulstr);
644
645
	}

646
647
648
649
650
651
652
	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);
		}
653
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr);
654
	}
655

656
657
658
659
660
661
662
	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);
		}
663
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
664
	}
665

666
	if(!strcmp(sp,"GN")) {
667
668
669
670
671
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
		else 
			ugrp=usrgrps ? curgrp+1 : 0;
		sprintf(str,"%u",ugrp);
672
673
		return(str);
	}
674

675
	if(!strcmp(sp,"GL")) {
676
677
678
679
680
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
		else 
			ugrp=usrgrps ? curgrp+1 : 0;
		sprintf(str,"%-4u",ugrp);
681
682
		return(str);
	}
683

684
	if(!strcmp(sp,"GR")) {
685
686
687
688
689
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
		else 
			ugrp=usrgrps ? curgrp+1 : 0;
		sprintf(str,"%4u",ugrp);
690
691
		return(str);
	}
692

693
694
695
696
697
698
699
	if(!strcmp(sp,"SUB")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Mail");
			else if(smb.subnum<cfg.total_subs)
				return(cfg.sub[smb.subnum]->sname);
		}
700
		return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
701
	}
702

703
704
705
706
707
708
709
	if(!strcmp(sp,"SUBL")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Mail");
			else if(smb.subnum<cfg.total_subs)
				return(cfg.sub[smb.subnum]->lname);
		}
710
		return(usrgrps  ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->lname : nulstr);
711
	}
712

713
	if(!strcmp(sp,"SN")) {
714
715
716
717
718
		if(SMB_IS_OPEN(&smb))
			usub=getusrsub(smb.subnum);
		else
			usub=usrgrps ? cursub[curgrp]+1 : 0;
		sprintf(str,"%u",usub);
719
720
		return(str);
	}
721

722
	if(!strcmp(sp,"SL")) {
723
724
725
726
727
		if(SMB_IS_OPEN(&smb))
			usub=getusrsub(smb.subnum);
		else
			usub=usrgrps ? cursub[curgrp]+1 : 0;
		sprintf(str,"%-4u",usub);
728
729
		return(str);
	}
730

731
	if(!strcmp(sp,"SR")) {
732
733
734
735
736
		if(SMB_IS_OPEN(&smb))
			usub=getusrsub(smb.subnum);
		else
			usub=usrgrps ? cursub[curgrp]+1 : 0;
		sprintf(str,"%4u",usub);
737
738
		return(str);
	}
739

740
741
	if(!strcmp(sp,"LIB"))
		return(usrlibs ? cfg.lib[usrlib[curlib]]->sname : nulstr);
742

743
744
	if(!strcmp(sp,"LIBL"))
		return(usrlibs ? cfg.lib[usrlib[curlib]]->lname : nulstr);
745

746
747
748
749
	if(!strcmp(sp,"LN")) {
		sprintf(str,"%u",usrlibs ? curlib+1 : 0);
		return(str);
	}
750

751
752
753
754
	if(!strcmp(sp,"LL")) {
		sprintf(str,"%-4u",usrlibs ? curlib+1 : 0);
		return(str);
	}
755

756
757
758
759
	if(!strcmp(sp,"LR")) {
		sprintf(str,"%4u",usrlibs  ? curlib+1 : 0);
		return(str);
	}
760

761
762
	if(!strcmp(sp,"DIR"))
		return(usrlibs ? cfg.dir[usrdir[curlib][curdir[curlib]]]->sname :nulstr);
763

764
765
	if(!strcmp(sp,"DIRL"))
		return(usrlibs ? cfg.dir[usrdir[curlib][curdir[curlib]]]->lname : nulstr);
766

767
768
769
770
	if(!strcmp(sp,"DN")) {
		sprintf(str,"%u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
771

772
773
774
775
	if(!strcmp(sp,"DL")) {
		sprintf(str,"%-4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
776

777
778
779
780
	if(!strcmp(sp,"DR")) {
		sprintf(str,"%4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
781

782
	if(!strcmp(sp,"NOACCESS")) {
783
		if(noaccess_str==text[NoAccessTime])
784
			sprintf(str,noaccess_str,noaccess_val/60,noaccess_val%60);
785
		else if(noaccess_str==text[NoAccessDay])
786
			sprintf(str,noaccess_str,wday[noaccess_val]);
787
		else
788
789
790
			sprintf(str,noaccess_str,noaccess_val); 
		return(str);
	}
791

792
	if(!strcmp(sp,"LAST")) {
793
794
795
		tp=strrchr(useron.alias,SP);
		if(tp) tp++;
		else tp=useron.alias;
796
797
		return(tp); 
	}
798

799
800
801
	if(!strcmp(sp,"REAL")) {
		strcpy(str,useron.name);
		tp=strchr(str,SP);
802
		if(tp) *tp=0;
803
804
		return(str); 
	}
805

806
807
808
	if(!strcmp(sp,"FIRSTREAL")) {
		strcpy(str,useron.name);
		tp=strchr(str,SP);
809
		if(tp) *tp=0;
810
811
		return(str); 
	}
812

813
	if(!strcmp(sp,"LASTREAL")) {
814
815
816
		tp=strrchr(useron.name,SP);
		if(tp) tp++;
		else tp=useron.name;
817
818
		return(tp); 
	}
819

820
821
822
823
	if(!strcmp(sp,"MAILW")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,0));
		return(str);
	}
824

825
826
827
828
	if(!strcmp(sp,"MAILP")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,1));
		return(str);
	}
829

830
831
832
833
	if(!strncmp(sp,"MAILW:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),0));
		return(str);
	}
834

835
836
837
838
	if(!strncmp(sp,"MAILP:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),1));
		return(str);
	}
839

840
841
842
843
	if(!strcmp(sp,"MSGREPLY")) {
		sprintf(str,"%c",cfg.sys_misc&SM_RA_EMU ? 'R' : 'A');
		return(str);
	}
844

845
846
847
848
	if(!strcmp(sp,"MSGREREAD")) {
		sprintf(str,"%c",cfg.sys_misc&SM_RA_EMU ? 'A' : 'R');
		return(str);
	}
849

850
	if(!strncmp(sp,"STATS.",6)) {
851
852
853
		getstats(&cfg,0,&stats);
		sp+=6;
		if(!strcmp(sp,"LOGONS")) 
854
			sprintf(str,"%lu",stats.logons);
855
		else if(!strcmp(sp,"LTODAY")) 
856
			sprintf(str,"%lu",stats.ltoday);
857
		else if(!strcmp(sp,"TIMEON")) 
858
			sprintf(str,"%lu",stats.timeon);
859
		else if(!strcmp(sp,"TTODAY")) 
860
			sprintf(str,"%lu",stats.ttoday);
861
		else if(!strcmp(sp,"ULS")) 
862
			sprintf(str,"%lu",stats.uls);
863
		else if(!strcmp(sp,"ULB")) 
864
			sprintf(str,"%lu",stats.ulb);
865
		else if(!strcmp(sp,"DLS")) 
866
			sprintf(str,"%lu",stats.dls);
867
		else if(!strcmp(sp,"DLB")) 
868
			sprintf(str,"%lu",stats.dlb);
869
		else if(!strcmp(sp,"PTODAY")) 
870
			sprintf(str,"%lu",stats.ptoday);
871
		else if(!strcmp(sp,"ETODAY")) 
872
			sprintf(str,"%lu",stats.etoday);
873
		else if(!strcmp(sp,"FTODAY")) 
874
			sprintf(str,"%lu",stats.ftoday);
875
		else if(!strcmp(sp,"NUSERS")) 
876
			sprintf(str,"%u",stats.nusers);
877
		return(str);
878
879
	}

880
	/* Message header codes */
881
882
883
	if(!strcmp(sp,"MSG_TO") && current_msg!=NULL) {
		if(current_msg->to==NULL)
			return(nulstr);
884
		if(current_msg->to_ext!=NULL)
885
886
887
			sprintf(str,"%s #%s",current_msg->to,current_msg->to_ext);
		else if(current_msg->to_net.type!=NET_NONE)
			sprintf(str,"%s (%s)",current_msg->to