atcodes.cpp 24.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* 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)		*
 *																			*
rswindell's avatar
rswindell committed
11
 * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html		*
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
 *																			*
 * 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"

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

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

58
	sprintf(str,"%.80s",instr);
59
60
61
62
63
64
65
66
67
68
	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);

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	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;
94
95
	uint	ugrp;
	uint	usub;
96
97
98
99
100
101
102
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

103
	if(!strcmp(sp,"VER"))
104
		return(VERSION);
105

106
107
108
109
	if(!strcmp(sp,"REV")) {
		sprintf(str,"%c",REVISION);
		return(str);
	}
110

111
112
113
	if(!strcmp(sp,"FULL_VER")) {
		sprintf(str,"%s%c%s",VERSION,REVISION,beta_version);
		truncsp(str);
114
#if defined(_DEBUG)
115
		strcat(str," Debug");
116
#endif
117
		return(str);
118
119
	}

120
121
	if(!strcmp(sp,"VER_NOTICE")) 
		return(VERSION_NOTICE);
122

123
124
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
125
126

#ifdef JAVASCRIPT
127
128
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
129
130
#endif

131
132
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
133

134
135
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
136

137
	if(!strcmp(sp,"COMPILER")) {
138
		DESCRIBE_COMPILER(str);
139
		return(str);
140
141
	}

142
	if(!strcmp(sp,"UPTIME")) {
143
144
		extern time_t uptime;
		time_t up=time(NULL)-uptime;
145
146
		if(up<0)
			up=0;
147
148
		char   days[64]="";
		if((up/(24*60*60))>=2) {
149
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
150
151
			up%=(24*60*60);
		}
152
		sprintf(str,"%s%lu:%02lu"
153
	        ,days
154
155
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
156
			);
157
		return(str);
158
159
	}

160
161
162
163
164
165
	if(!strcmp(sp,"SERVED")) {
		extern DWORD served;
		sprintf(str,"%lu",served);
		return(str);
	}

166
	if(!strcmp(sp,"SOCKET_LIB")) 
167
		return(socklib_version(str,SOCKLIB_DESC));
168

169
170
171
172
	if(!strcmp(sp,"MSG_LIB")) {
		sprintf(str,"SMBLIB %s",smb_lib_ver());
		return(str);
	}
173

174
175
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
176

177
178
179
180
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
		sprintf(str,"%lu",cur_rate);
		return(str);
	}
181

182
183
	if(!strcmp(sp,"CONN"))
		return(connection);
184

185
186
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
187

188
189
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
190

191
192
193
194
	if(!strcmp(sp,"NODE")) {
		sprintf(str,"%u",cfg.node_num);
		return(str);
	}
195

196
197
198
199
	if(!strcmp(sp,"TNODE")) {
		sprintf(str,"%u",cfg.sys_nodes);
		return(str);
	}
200

201
202
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
203

204
205
206
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

207
	if(!strcmp(sp,"FIDOADDR")) {
208
		if(cfg.total_faddrs)
209
			return(faddrtoa(&cfg.faddr[0],str));
210
		return(nulstr);
211
212
	}

213
214
	if(!strcmp(sp,"EMAILADDR")) 
		return(usermailaddr(&cfg, str
215
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
216

217
218
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
219

220
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
221
		now=time(NULL);
222
		memset(&tm,0,sizeof(tm));
223
		localtime_r(&now,&tm);
224
		sprintf(str,"%02d:%02d %s"
225
226
227
			,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"); 
228
		return(str);
229
230
	}

231
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
232
		now=time(NULL);
233
234
		return(unixtodstr(&cfg,now,str)); 
	}
235

236
	if(!strcmp(sp,"TMSG")) {
237
238
		l=0;
		for(i=0;i<cfg.total_subs;i++)
239
			l+=getposts(&cfg,i); 		/* l=total posts */
240
241
242
		sprintf(str,"%lu",l); 
		return(str);
	}
243

244
	if(!strcmp(sp,"TUSER")) {
245
		sprintf(str,"%u",total_users(&cfg));
246
247
		return(str);
	}
248

249
	if(!strcmp(sp,"TFILE")) {
250
251
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
252
			l+=getfiles(&cfg,i);
253
254
255
		sprintf(str,"%lu",l); 
		return(str);
	}
256

257
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
258
		getstats(&cfg,0,&stats);
259
260
261
		sprintf(str,"%lu",stats.logons); 
		return(str);
	}
262

263
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
264
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
265
		return(lastuseron);
266

267
	if(!strcmp(sp,"CLS")) {
268
		CLS;
269
270
		return(nulstr);
	}
271

272
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
273
		pause();
274
275
		return(nulstr);
	}
276

277
	if(!strcmp(sp,"RESETPAUSE")) {
278
		lncntr=0;
279
280
		return(nulstr);
	}
281

282
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
283
		sys_status^=SS_PAUSEOFF;
284
285
		return(nulstr);
	}
286

287
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
288
		sys_status^=SS_PAUSEON;
289
290
		return(nulstr);
	}
291
292
293
294
295

	/* NOSTOP */

	/* STOP */

296
297
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
298

299
300
301
302
303
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
		return(timestr(&event_time));
	}
304
305
306

	/* LASTCALL */

307
	if(!strncmp(sp,"NODE",4)) {
308
309
310
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
311
312
313
314
			printnodedat(i,&node); 
		} 
		return(nulstr);
	}
315

316
	if(!strcmp(sp,"WHO")) {
317
		whos_online(true);
318
319
		return(nulstr);
	}
320
321
322

	/* User Codes */

323
324
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
325

326
327
328
	if(!strcmp(sp,"FIRST")) {
		strcpy(str,useron.alias);
		tp=strchr(str,SP);
329
		if(tp) *tp=0;
330
331
		return(str); 
	}
332

333
334
335
336
	if(!strcmp(sp,"USERNUM")) {
		sprintf(str,"%u",useron.number);
		return(str);
	}
337

338
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
339
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
340
		return(useron.phone);
341

342
343
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
344

345
346
	if(!strcmp(sp,"FROM"))
		return(useron.location);
347

348
349
350
	if(!strcmp(sp,"CITY")) {
		strcpy(str,useron.location);
		char* p=strchr(str,',');
351
352
		if(p) {
			*p=0;
353
354
355
356
			return(str); 
		} 
		return(nulstr);
	}
357

358
359
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
360
361
362
363
		if(p) {
			p++;
			if(*p==SP)
				p++;
364
365
366
367
			return(p); 
		} 
		return(nulstr);
	}
368

369
370
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
371
		
372
373
	if(!strcmp(sp,"HOST"))
		return(client_name);
374

375
376
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
377

378
379
380
381
	if(!strcmp(sp,"AGE")) {
		sprintf(str,"%u",getage(&cfg,useron.birth));
		return(str);
	}
rswindell's avatar
rswindell committed
382

383
384
385
386
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
		sprintf(str,"%u",useron.logons);
		return(str);
	}
387

388
389
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
390

391
392
393
394
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
		sprintf(str,"%u",useron.level);
		return(str);
	}
395

396
397
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
398

399
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
400
		now=time(NULL);
401
		sprintf(str,"%lu",(ulong)(now-logontime)/60L); 
402
403
		return(str);
	}
404

405
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
406
		now=time(NULL);
407
408
		return(sectostr(now-logontime,str)+1); 
	}
409

410
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
411
		gettimeleft();
412
413
		return(sectostr(timeleft,str)+1); 
	}
414

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

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

421
422
423
424
	if(!strcmp(sp,"TIMELIMIT")) {
		sprintf(str,"%u",cfg.level_timepercall[useron.level]);
		return(str);
	}
425

426
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
427
		gettimeleft();
428
		sprintf(str,"%lu",timeleft/60); 
429
430
		return(str);
	}
431

432
433
	if(!strcmp(sp,"LASTON")) 
		return(timestr(&useron.laston));
434

435
436
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
437

438
	if(!strcmp(sp,"LASTTIMEON")) {
439
440
		memset(&tm,0,sizeof(tm));
		localtime_r(&useron.laston,&tm);
441
		sprintf(str,"%02d:%02d %s"
442
443
444
			,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"); 
445
		return(str);
446
447
	}

448
449
450
451
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
		sprintf(str,"%u",useron.posts);
		return(str);
	}
452

453
	if(!strcmp(sp,"MSGREAD")) {
454
		sprintf(str,"%lu",posts_read);
455
456
		return(str);
	}
457

458
	if(!strcmp(sp,"FREESPACE")) {
459
460
461
462
463
464
		sprintf(str,"%lu",getfreediskspace(cfg.temp_dir,0)); 
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
		sprintf(str,"%lu",getfreediskspace(cfg.temp_dir,1024)); 
465
466
		return(str);
	}
467

468
469
470
471
	if(!strcmp(sp,"UPBYTES")) {
		sprintf(str,"%lu",useron.ulb);
		return(str);
	}
472

473
474
475
476
	if(!strcmp(sp,"UPK")) {
		sprintf(str,"%lu",useron.ulb/1024L);
		return(str);
	}
477

478
479
480
481
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
		sprintf(str,"%u",useron.uls);
		return(str);
	}
482

483
484
485
486
	if(!strcmp(sp,"DLBYTES")) {
		sprintf(str,"%lu",useron.dlb);
		return(str);
	}
487

488
489
490
491
	if(!strcmp(sp,"DOWNK")) {
		sprintf(str,"%lu",useron.dlb/1024L);
		return(str);
	}
492

493
494
495
496
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
		sprintf(str,"%u",useron.dls);
		return(str);
	}
497

498
499
	if(!strcmp(sp,"LASTNEW"))
		return(unixtodstr(&cfg,ns_time,str));
500

501
502
	if(!strcmp(sp,"NEWFILETIME"))
		return(timestr(&ns_time));
503
504
505

	/* MAXDL */

506
507
508
509
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
		return(str);
	}
510

511
512
513
514
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
		return(str);
	}
515

516
517
518
519
	if(!strcmp(sp,"BYTELIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]);
		return(str);
	}
520

521
522
523
524
	if(!strcmp(sp,"KBLEFT")) {
		sprintf(str,"%lu",(useron.cdt+useron.freecdt)/1024L);
		return(str);
	}
525

526
527
528
529
	if(!strcmp(sp,"BYTESLEFT")) {
		sprintf(str,"%lu",useron.cdt+useron.freecdt);
		return(str);
	}
530

531
	if(!strcmp(sp,"CONF")) {
rswindell's avatar
rswindell committed
532
		sprintf(str,"%s %s"
533
534
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
535
536
		return(str);
	}
537

538
539
540
541
	if(!strcmp(sp,"CONFNUM")) {
		sprintf(str,"%u %u",curgrp+1,cursub[curgrp]+1);
		return(str);
	}
542

543
544
545
546
	if(!strcmp(sp,"NUMDIR")) {
		sprintf(str,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
547

548
549
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
550

551
	if(!strcmp(sp,"EXPDAYS")) {
552
553
554
555
		now=time(NULL);
		l=useron.expire-now;
		if(l<0)
			l=0;
556
		sprintf(str,"%lu",l/(1440L*60L)); 
557
558
		return(str);
	}
559

560
561
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
562

563
564
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
565

566
567
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
568

569
	if(!strcmp(sp,"HANGUP")) {
570
		hangup();
571
572
		return(nulstr);
	}
573
574
575

	/* Synchronet Specific */

576
	if(!strncmp(sp,"SETSTR:",7)) {
577
		strcpy(main_csi.str,sp+7);
578
579
		return(nulstr);
	}
580

581
	if(!strncmp(sp,"EXEC:",5)) {
582
		exec_bin(sp+5,&main_csi);
583
584
		return(nulstr);
	}
585

586
	if(!strncmp(sp,"MENU:",5)) {
587
		menu(sp+5);
588
589
		return(nulstr);
	}
590

591
592
593
594
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
595

596
597
	if(!strcmp(sp,"QUESTION"))
		return(question);
598

599
600
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
601

602
603
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
604

605
	if(!strcmp(sp,"LOCAL-IP")) {
606
		struct in_addr in_addr;
607
		in_addr.s_addr=local_addr;
608
		return(inet_ntoa(in_addr));
609
610
	}

611
612
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
613

614
	if(!strcmp(sp,"PUSHXY")) {
615
		ANSI_SAVE();
616
617
		return(nulstr);
	}
618

619
	if(!strcmp(sp,"POPXY")) {
620
		ANSI_RESTORE();
621
622
		return(nulstr);
	}
623

624
625
	if(!strcmp(sp,"UP")) 
		return("\x1b[A");
626

627
628
	if(!strcmp(sp,"DOWN")) 
		return("\x1b[B");
629

630
631
	if(!strcmp(sp,"RIGHT")) 
		return("\x1b[C");
632

633
634
	if(!strcmp(sp,"LEFT")) 
		return("\x1b[D");
635

636
637
638
639
	if(!strncmp(sp,"UP:",3)) {
		sprintf(str,"\x1b[%dA",atoi(sp+3));
		return(str);
	}
640

641
642
643
644
	if(!strncmp(sp,"DOWN:",5)) {
		sprintf(str,"\x1b[%dB",atoi(sp+5));
		return(str);
	}
645

646
647
648
649
	if(!strncmp(sp,"LEFT:",5)) {
		sprintf(str,"\x1b[%dC",atoi(sp+5));
		return(str);
	}
650

651
652
653
654
	if(!strncmp(sp,"RIGHT:",6)) {
		sprintf(str,"\x1b[%dD",atoi(sp+6));
		return(str);
	}
655

656
	if(!strncmp(sp,"GOTOXY:",7)) {
657
658
659
660
661
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
			GOTOXY(atoi(sp+7),atoi(tp));
		}
662
		return(nulstr);
663
664
	}

665
666
667
668
669
670
671
	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);
		}
672
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr);
673
	}
674

675
676
677
678
679
680
681
	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);
		}
682
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
683
	}
684

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

694
	if(!strcmp(sp,"GL")) {
695
696
697
698
699
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
		else 
			ugrp=usrgrps ? curgrp+1 : 0;
		sprintf(str,"%-4u",ugrp);
700
701
		return(str);
	}
702

703
	if(!strcmp(sp,"GR")) {
704
705
706
707
708
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
		else 
			ugrp=usrgrps ? curgrp+1 : 0;
		sprintf(str,"%4u",ugrp);
709
710
		return(str);
	}
711

712
713
714
715
716
717
718
	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);
		}
719
		return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
720
	}
721

722
723
724
725
726
727
728
	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);
		}
729
		return(usrgrps  ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->lname : nulstr);
730
	}
731

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

741
	if(!strcmp(sp,"SL")) {
742
743
744
745
746
		if(SMB_IS_OPEN(&smb))
			usub=getusrsub(smb.subnum);
		else
			usub=usrgrps ? cursub[curgrp]+1 : 0;
		sprintf(str,"%-4u",usub);
747
748
		return(str);
	}
749

750
	if(!strcmp(sp,"SR")) {
751
752
753
754
755
		if(SMB_IS_OPEN(&smb))
			usub=getusrsub(smb.subnum);
		else
			usub=usrgrps ? cursub[curgrp]+1 : 0;
		sprintf(str,"%4u",usub);
756
757
		return(str);
	}
758

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

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

765
766
767
768
	if(!strcmp(sp,"LN")) {
		sprintf(str,"%u",usrlibs ? curlib+1 : 0);
		return(str);
	}
769

770
771
772
773
	if(!strcmp(sp,"LL")) {
		sprintf(str,"%-4u",usrlibs ? curlib+1 : 0);
		return(str);
	}
774

775
776
777
778
	if(!strcmp(sp,"LR")) {
		sprintf(str,"%4u",usrlibs  ? curlib+1 : 0);
		return(str);
	}
779

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

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

786
787
788
789
	if(!strcmp(sp,"DN")) {
		sprintf(str,"%u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
790

791
792
793
794
	if(!strcmp(sp,"DL")) {
		sprintf(str,"%-4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
795

796
797
798
799
	if(!strcmp(sp,"DR")) {
		sprintf(str,"%4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
800

801
	if(!strcmp(sp,"NOACCESS")) {
802
		if(noaccess_str==text[NoAccessTime])
803
			sprintf(str,noaccess_str,noaccess_val/60,noaccess_val%60);
804
		else if(noaccess_str==text[NoAccessDay])
805
			sprintf(str,noaccess_str,wday[noaccess_val]);
806
		else
807
808
809
			sprintf(str,noaccess_str,noaccess_val); 
		return(str);
	}
810

811
	if(!strcmp(sp,"LAST")) {
812
813
814
		tp=strrchr(useron.alias,SP);
		if(tp) tp++;
		else tp=useron.alias;
815
816
		return(tp); 
	}
817

818
819
820
	if(!strcmp(sp,"REAL")) {
		strcpy(str,useron.name);
		tp=strchr(str,SP);
821
		if(tp) *tp=0;
822
823
		return(str); 
	}
824

825
826
827
	if(!strcmp(sp,"FIRSTREAL")) {
		strcpy(str,useron.name);
		tp=strchr(str,SP);
828
		if(tp) *tp=0;
829
830
		return(str); 
	}
831

832
	if(!strcmp(sp,"LASTREAL")) {
833
834
835
		tp=strrchr(useron.name,SP);
		if(tp) tp++;
		else tp=useron.name;
836
837
		return(tp); 
	}
838

839
840
841
842
	if(!strcmp(sp,"MAILW")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,0));
		return(str);
	}
843

844
845
846
847
	if(!strcmp(sp,"MAILP")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,1));
		return(str);
	}
848

849
850
851
852
	if(!strncmp(sp,"MAILW:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),0));
		return(str);
	}
853

854
855
856
857
	if(!strncmp(sp,"MAILP:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),1));
		return(str);
	}
858

859
860
861
862
	if(!strcmp(sp,"MSGREPLY")) {
		sprintf(str,"%c",cfg.sys_misc&SM_RA_EMU ? 'R' : 'A');
		return(str);
	}
863

864
865
866
867
	if(!strcmp(sp,"MSGREREAD")) {
		sprintf(str,"%c",cfg.sys_misc&SM_RA_EMU ? 'A' : 'R');
		return(str);
	}
868

869
	if(!strncmp(sp,"STATS.",6)) {
870
871
872
		getstats(&cfg,0,&stats);
		sp+=6;
		if(!strcmp(sp,"LOGONS")) 
873
			sprintf(str,"%lu",stats.logons);
874
		else if(!strcmp(sp,"LTODAY")) 
875
			sprintf(str,"%lu",stats.ltoday);
876
		else if(!strcmp(sp,"TIMEON")) 
877
			sprintf(str,"%lu",stats.timeon);
878
		else if(!strcmp(sp,"TTODAY")) 
879
			sprintf(str,"%lu",stats.ttoday);
880
		else if(!strcmp(sp,"ULS")) 
881
			sprintf(str,"%lu",stats.uls);
882
		else if(!strcmp(sp,"ULB")) 
883
			sprintf(str,"%lu",stats.ulb);
884
		else if(!strcmp(sp,"DLS")) 
885
			sprintf(str,"%lu",stats.dls);
886
		else if(!strcmp(sp,"DLB")) 
887
			sprintf(str,"%lu",stats.dlb);
888
		else if(!strcmp(sp,"PTODAY")) 
889
			sprintf(str,"%lu",stats.ptoday);
890
		else if(!strcmp(sp,"ETODAY")) 
891
			sprintf(str,"%lu",stats.etoday);
892
		else if(!strcmp(sp,"FTODAY"))