atcodes.cpp 24.3 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)		*
 *																			*
11
 * Copyright 2005 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
	tp=strchr(str+1,'@');
	if(!tp)                 /* no terminating @ */
		return(0);
62
	sp=strchr(str+1,' ');
63
64
65
66
67
68
	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
	if(!strcmp(sp,"VER_NOTICE"))
121
		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(smb_faddrtoa(&cfg.faddr[0],str));
210
		return(nulstr);
211
212
	}

213
	if(!strcmp(sp,"EMAILADDR"))
214
		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
225
226
227
228
229
230
231
		if(cfg.sys_misc&SM_MILITARY)
			sprintf(str,"%02d:%02d"
		        	,tm.tm_hour,tm.tm_min);
		else
			sprintf(str,"%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");
232
		return(str);
233
234
	}

235
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
236
		now=time(NULL);
237
		return(unixtodstr(&cfg,now,str));
238
	}
239

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

248
	if(!strcmp(sp,"TUSER")) {
249
		sprintf(str,"%u",total_users(&cfg));
250
251
		return(str);
	}
252

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

261
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
262
		getstats(&cfg,0,&stats);
263
		sprintf(str,"%lu",stats.logons);
264
265
		return(str);
	}
266

267
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
268
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
269
		return(lastuseron);
270

271
	if(!strcmp(sp,"CLS")) {
272
		CLS;
273
274
		return(nulstr);
	}
275

276
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
277
		pause();
278
279
		return(nulstr);
	}
280

281
	if(!strcmp(sp,"RESETPAUSE")) {
282
		lncntr=0;
283
284
		return(nulstr);
	}
285

286
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
287
		sys_status^=SS_PAUSEOFF;
288
289
		return(nulstr);
	}
290

291
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
292
		sys_status^=SS_PAUSEON;
293
294
		return(nulstr);
	}
295
296
297
298
299

	/* NOSTOP */

	/* STOP */

300
301
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
302

303
304
305
306
307
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
		return(timestr(&event_time));
	}
308
309
310

	/* LASTCALL */

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

320
	if(!strcmp(sp,"WHO")) {
321
		whos_online(true);
322
323
		return(nulstr);
	}
324
325
326

	/* User Codes */

327
328
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
329

330
331
	if(!strcmp(sp,"FIRST")) {
		strcpy(str,useron.alias);
332
		tp=strchr(str,' ');
333
		if(tp) *tp=0;
334
		return(str);
335
	}
336

337
338
339
340
	if(!strcmp(sp,"USERNUM")) {
		sprintf(str,"%u",useron.number);
		return(str);
	}
341

342
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
343
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
344
		return(useron.phone);
345

346
347
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
348

349
350
	if(!strcmp(sp,"FROM"))
		return(useron.location);
351

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

362
363
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
364
365
		if(p) {
			p++;
366
			if(*p==' ')
367
				p++;
368
369
			return(p);
		}
370
371
		return(nulstr);
	}
372

373
374
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
375

376
377
	if(!strcmp(sp,"HOST"))
		return(client_name);
378

379
380
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
381

382
383
384
385
	if(!strcmp(sp,"AGE")) {
		sprintf(str,"%u",getage(&cfg,useron.birth));
		return(str);
	}
rswindell's avatar
rswindell committed
386

387
388
389
390
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
		sprintf(str,"%u",useron.logons);
		return(str);
	}
391

392
393
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
394

395
396
397
398
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
		sprintf(str,"%u",useron.level);
		return(str);
	}
399

400
401
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
402

403
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
404
		now=time(NULL);
405
		sprintf(str,"%lu",(ulong)(now-logontime)/60L);
406
407
		return(str);
	}
408

409
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
410
		now=time(NULL);
411
		return(sectostr(now-logontime,str)+1);
412
	}
413

414
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
415
		gettimeleft();
416
		return(sectostr(timeleft,str)+1);
417
	}
418

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

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

425
426
427
428
	if(!strcmp(sp,"TIMELIMIT")) {
		sprintf(str,"%u",cfg.level_timepercall[useron.level]);
		return(str);
	}
429

430
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
431
		gettimeleft();
432
		sprintf(str,"%lu",timeleft/60);
433
434
		return(str);
	}
435

436
	if(!strcmp(sp,"LASTON"))
437
		return(timestr(&useron.laston));
438

439
440
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
441

442
	if(!strcmp(sp,"LASTTIMEON")) {
443
444
		memset(&tm,0,sizeof(tm));
		localtime_r(&useron.laston,&tm);
445
		sprintf(str,"%02d:%02d %s"
446
447
			,tm.tm_hour==0 ? 12
			: tm.tm_hour>12 ? tm.tm_hour-12
448
			: tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am");
449
		return(str);
450
451
	}

452
453
454
455
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
		sprintf(str,"%u",useron.posts);
		return(str);
	}
456

457
	if(!strcmp(sp,"MSGREAD")) {
458
		sprintf(str,"%lu",posts_read);
459
460
		return(str);
	}
461

462
	if(!strcmp(sp,"FREESPACE")) {
463
		sprintf(str,"%lu",getfreediskspace(cfg.temp_dir,0));
464
465
466
467
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
468
		sprintf(str,"%lu",getfreediskspace(cfg.temp_dir,1024));
469
470
		return(str);
	}
471

472
473
474
475
	if(!strcmp(sp,"UPBYTES")) {
		sprintf(str,"%lu",useron.ulb);
		return(str);
	}
476

477
478
479
480
	if(!strcmp(sp,"UPK")) {
		sprintf(str,"%lu",useron.ulb/1024L);
		return(str);
	}
481

482
483
484
485
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
		sprintf(str,"%u",useron.uls);
		return(str);
	}
486

487
488
489
490
	if(!strcmp(sp,"DLBYTES")) {
		sprintf(str,"%lu",useron.dlb);
		return(str);
	}
491

492
493
494
495
	if(!strcmp(sp,"DOWNK")) {
		sprintf(str,"%lu",useron.dlb/1024L);
		return(str);
	}
496

497
498
499
500
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
		sprintf(str,"%u",useron.dls);
		return(str);
	}
501

502
503
	if(!strcmp(sp,"LASTNEW"))
		return(unixtodstr(&cfg,ns_time,str));
504

505
506
	if(!strcmp(sp,"NEWFILETIME"))
		return(timestr(&ns_time));
507
508
509

	/* MAXDL */

510
511
512
513
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
		return(str);
	}
514

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

520
521
522
523
	if(!strcmp(sp,"BYTELIMIT")) {
		sprintf(str,"%lu",cfg.level_freecdtperday[useron.level]);
		return(str);
	}
524

525
526
527
528
	if(!strcmp(sp,"KBLEFT")) {
		sprintf(str,"%lu",(useron.cdt+useron.freecdt)/1024L);
		return(str);
	}
529

530
531
532
533
	if(!strcmp(sp,"BYTESLEFT")) {
		sprintf(str,"%lu",useron.cdt+useron.freecdt);
		return(str);
	}
534

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

542
543
544
545
	if(!strcmp(sp,"CONFNUM")) {
		sprintf(str,"%u %u",curgrp+1,cursub[curgrp]+1);
		return(str);
	}
546

547
548
549
550
	if(!strcmp(sp,"NUMDIR")) {
		sprintf(str,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
551

552
553
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
554

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

564
565
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
566

567
568
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
569

570
571
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
572

573
	if(!strcmp(sp,"HANGUP")) {
574
		hangup();
575
576
		return(nulstr);
	}
577
578
579

	/* Synchronet Specific */

580
	if(!strncmp(sp,"SETSTR:",7)) {
581
		strcpy(main_csi.str,sp+7);
582
583
		return(nulstr);
	}
584

585
	if(!strncmp(sp,"EXEC:",5)) {
586
		exec_bin(sp+5,&main_csi);
587
588
		return(nulstr);
	}
589

590
	if(!strncmp(sp,"MENU:",5)) {
591
		menu(sp+5);
592
593
		return(nulstr);
	}
594

595
596
597
598
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
599

600
	if(!strncmp(sp,"INCLUDE:",5)) {
601
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
602
603
604
		return(nulstr);
	}

605
606
	if(!strcmp(sp,"QUESTION"))
		return(question);
607

608
609
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
610

611
612
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
613

614
	if(!strcmp(sp,"LOCAL-IP")) {
615
		struct in_addr in_addr;
616
		in_addr.s_addr=local_addr;
617
		return(inet_ntoa(in_addr));
618
619
	}

620
621
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
622

623
	if(!strcmp(sp,"PUSHXY")) {
624
		ANSI_SAVE();
625
626
		return(nulstr);
	}
627

628
	if(!strcmp(sp,"POPXY")) {
629
		ANSI_RESTORE();
630
631
		return(nulstr);
	}
632

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

636
	if(!strcmp(sp,"DOWN"))
637
		return("\x1b[B");
638

639
	if(!strcmp(sp,"RIGHT"))
640
		return("\x1b[C");
641

642
	if(!strcmp(sp,"LEFT"))
643
		return("\x1b[D");
644

645
646
647
648
	if(!strncmp(sp,"UP:",3)) {
		sprintf(str,"\x1b[%dA",atoi(sp+3));
		return(str);
	}
649

650
651
652
653
	if(!strncmp(sp,"DOWN:",5)) {
		sprintf(str,"\x1b[%dB",atoi(sp+5));
		return(str);
	}
654

655
656
657
658
	if(!strncmp(sp,"LEFT:",5)) {
		sprintf(str,"\x1b[%dC",atoi(sp+5));
		return(str);
	}
659

660
661
662
663
	if(!strncmp(sp,"RIGHT:",6)) {
		sprintf(str,"\x1b[%dD",atoi(sp+6));
		return(str);
	}
664

665
	if(!strncmp(sp,"GOTOXY:",7)) {
666
667
668
669
670
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
			GOTOXY(atoi(sp+7),atoi(tp));
		}
671
		return(nulstr);
672
673
	}

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

684
685
686
687
688
689
690
	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);
		}
691
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
692
	}
693

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

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

712
	if(!strcmp(sp,"GR")) {
713
714
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
715
		else
716
717
			ugrp=usrgrps ? curgrp+1 : 0;
		sprintf(str,"%4u",ugrp);
718
719
		return(str);
	}
720

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

731
732
733
734
735
736
737
	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);
		}
738
		return(usrgrps  ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->lname : nulstr);
739
	}
740

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

750
	if(!strcmp(sp,"SL")) {
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
	if(!strcmp(sp,"SR")) {
760
761
762
763
764
		if(SMB_IS_OPEN(&smb))
			usub=getusrsub(smb.subnum);
		else
			usub=usrgrps ? cursub[curgrp]+1 : 0;
		sprintf(str,"%4u",usub);
765
766
		return(str);
	}
767

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

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

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

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

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

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

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

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

800
801
802
803
	if(!strcmp(sp,"DL")) {
		sprintf(str,"%-4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
804

805
806
807
808
	if(!strcmp(sp,"DR")) {
		sprintf(str,"%4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
809

810
	if(!strcmp(sp,"NOACCESS")) {
811
		if(noaccess_str==text[NoAccessTime])
812
			sprintf(str,noaccess_str,noaccess_val/60,noaccess_val%60);
813
		else if(noaccess_str==text[NoAccessDay])
814
			sprintf(str,noaccess_str,wday[noaccess_val]);
815
		else
816
			sprintf(str,noaccess_str,noaccess_val);
817
818
		return(str);
	}
819

820
	if(!strcmp(sp,"LAST")) {
821
		tp=strrchr(useron.alias,' ');
822
823
		if(tp) tp++;
		else tp=useron.alias;
824
		return(tp);
825
	}
826

827
828
	if(!strcmp(sp,"REAL")) {
		strcpy(str,useron.name);
829
		tp=strchr(str,' ');
830
		if(tp) *tp=0;
831
		return(str);
832
	}
833

834
835
	if(!strcmp(sp,"FIRSTREAL")) {
		strcpy(str,useron.name);
836
		tp=strchr(str,' ');
837
		if(tp) *tp=0;
838
		return(str);
839
	}
840

841
	if(!strcmp(sp,"LASTREAL")) {
842
		tp=strrchr(useron.name,' ');
843
844
		if(tp) tp++;
		else tp=useron.name;
845
		return(tp);
846
	}
847

848
849
850
851
	if(!strcmp(sp,"MAILW")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,0));
		return(str);
	}
852