atcodes.cpp 24 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
41
42
43
 *																			*
 * 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"

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

51
	sprintf(str,"%.80s",instr);
52
53
54
55
56
57
58
59
60
61
	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);

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	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;
87
88
	uint	ugrp;
	uint	usub;
89
90
91
92
93
94
95
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

96
	if(!strcmp(sp,"VER"))
97
		return(VERSION);
98

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

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

113
114
	if(!strcmp(sp,"VER_NOTICE")) 
		return(VERSION_NOTICE);
115

116
117
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
118
119

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

124
125
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
126

127
128
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
129

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

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

153
154
155
156
157
158
	if(!strcmp(sp,"SERVED")) {
		extern DWORD served;
		sprintf(str,"%lu",served);
		return(str);
	}

159
160
	if(!strcmp(sp,"SOCKET_LIB")) 
		return(socklib_version(str));
161

162
163
164
165
	if(!strcmp(sp,"MSG_LIB")) {
		sprintf(str,"SMBLIB %s",smb_lib_ver());
		return(str);
	}
166

167
168
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
169

170
171
172
173
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
		sprintf(str,"%lu",cur_rate);
		return(str);
	}
174

175
176
	if(!strcmp(sp,"CONN"))
		return(connection);
177

178
179
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
180

181
182
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
183

184
185
186
187
	if(!strcmp(sp,"NODE")) {
		sprintf(str,"%u",cfg.node_num);
		return(str);
	}
188

189
190
191
192
	if(!strcmp(sp,"TNODE")) {
		sprintf(str,"%u",cfg.sys_nodes);
		return(str);
	}
193

194
195
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
196

197
198
199
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

200
	if(!strcmp(sp,"FIDOADDR")) {
201
		if(cfg.total_faddrs)
202
			return(faddrtoa(&cfg.faddr[0],str));
203
		return(nulstr);
204
205
	}

206
207
	if(!strcmp(sp,"EMAILADDR")) 
		return(usermailaddr(&cfg, str
208
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
209

210
211
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
212

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

224
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
225
		now=time(NULL);
226
227
		return(unixtodstr(&cfg,now,str)); 
	}
228

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

237
	if(!strcmp(sp,"TUSER")) {
238
		sprintf(str,"%u",total_users(&cfg));
239
240
		return(str);
	}
241

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

250
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
251
		getstats(&cfg,0,&stats);
252
253
254
		sprintf(str,"%lu",stats.logons); 
		return(str);
	}
255

256
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
257
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
258
		return(lastuseron);
259

260
	if(!strcmp(sp,"CLS")) {
261
		CLS;
262
263
		return(nulstr);
	}
264

265
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
266
		pause();
267
268
		return(nulstr);
	}
269

270
	if(!strcmp(sp,"RESETPAUSE")) {
271
		lncntr=0;
272
273
		return(nulstr);
	}
274

275
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
276
		sys_status^=SS_PAUSEOFF;
277
278
		return(nulstr);
	}
279

280
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
281
		sys_status^=SS_PAUSEON;
282
283
		return(nulstr);
	}
284
285
286
287
288

	/* NOSTOP */

	/* STOP */

289
290
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
291

292
293
294
295
296
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
		return(timestr(&event_time));
	}
297
298
299

	/* LASTCALL */

300
	if(!strncmp(sp,"NODE",4)) {
301
302
303
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
304
305
306
307
			printnodedat(i,&node); 
		} 
		return(nulstr);
	}
308

309
	if(!strcmp(sp,"WHO")) {
310
		whos_online(true);
311
312
		return(nulstr);
	}
313
314
315

	/* User Codes */

316
317
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
318

319
320
321
	if(!strcmp(sp,"FIRST")) {
		strcpy(str,useron.alias);
		tp=strchr(str,SP);
322
		if(tp) *tp=0;
323
324
		return(str); 
	}
325

326
327
328
329
	if(!strcmp(sp,"USERNUM")) {
		sprintf(str,"%u",useron.number);
		return(str);
	}
330

331
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
332
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
333
		return(useron.phone);
334

335
336
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
337

338
339
	if(!strcmp(sp,"FROM"))
		return(useron.location);
340

341
342
343
	if(!strcmp(sp,"CITY")) {
		strcpy(str,useron.location);
		char* p=strchr(str,',');
344
345
		if(p) {
			*p=0;
346
347
348
349
			return(str); 
		} 
		return(nulstr);
	}
350

351
352
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
353
354
355
356
		if(p) {
			p++;
			if(*p==SP)
				p++;
357
358
359
360
			return(p); 
		} 
		return(nulstr);
	}
361

362
363
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
364
		
365
366
	if(!strcmp(sp,"HOST"))
		return(client_name);
367

368
369
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
370

371
372
373
374
	if(!strcmp(sp,"AGE")) {
		sprintf(str,"%u",getage(&cfg,useron.birth));
		return(str);
	}
rswindell's avatar
rswindell committed
375

376
377
378
379
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
		sprintf(str,"%u",useron.logons);
		return(str);
	}
380

381
382
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
383

384
385
386
387
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
		sprintf(str,"%u",useron.level);
		return(str);
	}
388

389
390
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
391

392
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
393
		now=time(NULL);
394
		sprintf(str,"%lu",(ulong)(now-logontime)/60L); 
395
396
		return(str);
	}
397

398
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
399
		now=time(NULL);
400
401
		return(sectostr(now-logontime,str)+1); 
	}
402

403
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
404
		gettimeleft();
405
406
		return(sectostr(timeleft,str)+1); 
	}
407

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

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

414
415
416
417
	if(!strcmp(sp,"TIMELIMIT")) {
		sprintf(str,"%u",cfg.level_timepercall[useron.level]);
		return(str);
	}
418

419
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
420
		gettimeleft();
421
		sprintf(str,"%lu",timeleft/60); 
422
423
		return(str);
	}
424

425
426
	if(!strcmp(sp,"LASTON")) 
		return(timestr(&useron.laston));
427

428
429
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
430

431
	if(!strcmp(sp,"LASTTIMEON")) {
432
433
		memset(&tm,0,sizeof(tm));
		localtime_r(&useron.laston,&tm);
434
		sprintf(str,"%02d:%02d %s"
435
436
437
			,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"); 
438
		return(str);
439
440
	}

441
442
443
444
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
		sprintf(str,"%u",useron.posts);
		return(str);
	}
445

446
	if(!strcmp(sp,"MSGREAD")) {
447
		sprintf(str,"%lu",posts_read);
448
449
		return(str);
	}
450

451
	if(!strcmp(sp,"FREESPACE")) {
452
453
454
455
456
457
		sprintf(str,"%lu",getfreediskspace(cfg.temp_dir,0)); 
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
		sprintf(str,"%lu",getfreediskspace(cfg.temp_dir,1024)); 
458
459
		return(str);
	}
460

461
462
463
464
	if(!strcmp(sp,"UPBYTES")) {
		sprintf(str,"%lu",useron.ulb);
		return(str);
	}
465

466
467
468
469
	if(!strcmp(sp,"UPK")) {
		sprintf(str,"%lu",useron.ulb/1024L);
		return(str);
	}
470

471
472
473
474
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
		sprintf(str,"%u",useron.uls);
		return(str);
	}
475

476
477
478
479
	if(!strcmp(sp,"DLBYTES")) {
		sprintf(str,"%lu",useron.dlb);
		return(str);
	}
480

481
482
483
484
	if(!strcmp(sp,"DOWNK")) {
		sprintf(str,"%lu",useron.dlb/1024L);
		return(str);
	}
485

486
487
488
489
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
		sprintf(str,"%u",useron.dls);
		return(str);
	}
490

491
492
	if(!strcmp(sp,"LASTNEW"))
		return(unixtodstr(&cfg,ns_time,str));
493

494
495
	if(!strcmp(sp,"NEWFILETIME"))
		return(timestr(&ns_time));
496
497
498

	/* MAXDL */

499
500
501
502
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
		return(str);
	}
503

504
505
506
507
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
		return(str);
	}
508

509
510
511
512
	if(!strcmp(sp,"BYTELIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]);
		return(str);
	}
513

514
515
516
517
	if(!strcmp(sp,"KBLEFT")) {
		sprintf(str,"%lu",(useron.cdt+useron.freecdt)/1024L);
		return(str);
	}
518

519
520
521
522
	if(!strcmp(sp,"BYTESLEFT")) {
		sprintf(str,"%lu",useron.cdt+useron.freecdt);
		return(str);
	}
523

524
	if(!strcmp(sp,"CONF")) {
rswindell's avatar
rswindell committed
525
		sprintf(str,"%s %s"
526
527
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
528
529
		return(str);
	}
530

531
532
533
534
	if(!strcmp(sp,"CONFNUM")) {
		sprintf(str,"%u %u",curgrp+1,cursub[curgrp]+1);
		return(str);
	}
535

536
537
538
539
	if(!strcmp(sp,"NUMDIR")) {
		sprintf(str,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
540

541
542
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
543

544
	if(!strcmp(sp,"EXPDAYS")) {
545
546
547
548
		now=time(NULL);
		l=useron.expire-now;
		if(l<0)
			l=0;
549
		sprintf(str,"%lu",l/(1440L*60L)); 
550
551
		return(str);
	}
552

553
554
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
555

556
557
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
558

559
560
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
561

562
	if(!strcmp(sp,"HANGUP")) {
563
		hangup();
564
565
		return(nulstr);
	}
566
567
568

	/* Synchronet Specific */

569
	if(!strncmp(sp,"SETSTR:",7)) {
570
		strcpy(main_csi.str,sp+7);
571
572
		return(nulstr);
	}
573

574
	if(!strncmp(sp,"EXEC:",5)) {
575
		exec_bin(sp+5,&main_csi);
576
577
		return(nulstr);
	}
578

579
	if(!strncmp(sp,"MENU:",5)) {
580
		menu(sp+5);
581
582
		return(nulstr);
	}
583

584
585
586
587
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
588

589
590
	if(!strcmp(sp,"QUESTION"))
		return(question);
591

592
593
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
594

595
596
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
597

598
	if(!strcmp(sp,"LOCAL-IP")) {
599
		struct in_addr in_addr;
600
		in_addr.s_addr=local_addr;
601
		return(inet_ntoa(in_addr));
602
603
	}

604
605
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
606

607
	if(!strcmp(sp,"PUSHXY")) {
608
		ANSI_SAVE();
609
610
		return(nulstr);
	}
611

612
	if(!strcmp(sp,"POPXY")) {
613
		ANSI_RESTORE();
614
615
		return(nulstr);
	}
616

617
618
	if(!strcmp(sp,"UP")) 
		return("\x1b[A");
619

620
621
	if(!strcmp(sp,"DOWN")) 
		return("\x1b[B");
622

623
624
	if(!strcmp(sp,"RIGHT")) 
		return("\x1b[C");
625

626
627
	if(!strcmp(sp,"LEFT")) 
		return("\x1b[D");
628

629
630
631
632
	if(!strncmp(sp,"UP:",3)) {
		sprintf(str,"\x1b[%dA",atoi(sp+3));
		return(str);
	}
633

634
635
636
637
	if(!strncmp(sp,"DOWN:",5)) {
		sprintf(str,"\x1b[%dB",atoi(sp+5));
		return(str);
	}
638

639
640
641
642
	if(!strncmp(sp,"LEFT:",5)) {
		sprintf(str,"\x1b[%dC",atoi(sp+5));
		return(str);
	}
643

644
645
646
647
	if(!strncmp(sp,"RIGHT:",6)) {
		sprintf(str,"\x1b[%dD",atoi(sp+6));
		return(str);
	}
648

649
	if(!strncmp(sp,"GOTOXY:",7)) {
650
651
652
653
654
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
			GOTOXY(atoi(sp+7),atoi(tp));
		}
655
		return(nulstr);
656
657
	}

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

668
669
670
671
672
673
674
	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);
		}
675
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
676
	}
677

678
	if(!strcmp(sp,"GN")) {
679
680
681
682
683
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
		else 
			ugrp=usrgrps ? curgrp+1 : 0;
		sprintf(str,"%u",ugrp);
684
685
		return(str);
	}
686

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

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

705
706
707
708
709
710
711
	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);
		}
712
		return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
713
	}
714

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

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

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

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

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

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

758
759
760
761
	if(!strcmp(sp,"LN")) {
		sprintf(str,"%u",usrlibs ? curlib+1 : 0);
		return(str);
	}
762

763
764
765
766
	if(!strcmp(sp,"LL")) {
		sprintf(str,"%-4u",usrlibs ? curlib+1 : 0);
		return(str);
	}
767

768
769
770
771
	if(!strcmp(sp,"LR")) {
		sprintf(str,"%4u",usrlibs  ? curlib+1 : 0);
		return(str);
	}
772

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

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

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

784
785
786
787
	if(!strcmp(sp,"DL")) {
		sprintf(str,"%-4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
788

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

794
	if(!strcmp(sp,"NOACCESS")) {
795
		if(noaccess_str==text[NoAccessTime])
796
			sprintf(str,noaccess_str,noaccess_val/60,noaccess_val%60);
797
		else if(noaccess_str==text[NoAccessDay])
798
			sprintf(str,noaccess_str,wday[noaccess_val]);
799
		else
800
801
802
			sprintf(str,noaccess_str,noaccess_val); 
		return(str);
	}
803

804
	if(!strcmp(sp,"LAST")) {
805
806
807
		tp=strrchr(useron.alias,SP);
		if(tp) tp++;
		else tp=useron.alias;
808
809
		return(tp); 
	}
810

811
812
813
	if(!strcmp(sp,"REAL")) {
		strcpy(str,useron.name);
		tp=strchr(str,SP);
814
		if(tp) *tp=0;
815
816
		return(str); 
	}
817

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

825
	if(!strcmp(sp,"LASTREAL")) {
826
827
828
		tp=strrchr(useron.name,SP);
		if(tp) tp++;
		else tp=useron.name;
829
830
		return(tp); 
	}
831

832
833
834
835
	if(!strcmp(sp,"MAILW")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,0));
		return(str);
	}
836

837
838
839
840
	if(!strcmp(sp,"MAILP")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,1));
		return(str);
	}
841

842
843
844
845
	if(!strncmp(sp,"MAILW:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),0));
		return(str);
	}
846

847
848
849
850
	if(!strncmp(sp,"MAILP:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),1));
		return(str);
	}
851

852
853
854
855
	if(!strcmp(sp,"MSGREPLY")) {
		sprintf(str,"%c",cfg.sys_misc&SM_RA_EMU ? 'R' : 'A');
		return(str);
	}
856

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

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