atcodes.cpp 22.9 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
89
90
91
92
93
94
95
96
	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;
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;
	struct	tm * tm_p;

	str[0]=0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

192
	if(!strcmp(sp,"FIDOADDR")) {
193
		if(cfg.total_faddrs)
194
			return(faddrtoa(&cfg.faddr[0],str));
195
		return(nulstr);
196
197
	}

198
199
	if(!strcmp(sp,"EMAILADDR")) 
		return(usermailaddr(&cfg, str
200
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
201

202
203
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
204

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

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

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

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

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

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

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

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

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

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

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

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

	/* NOSTOP */

	/* STOP */

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

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

	/* LASTCALL */

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

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

	/* User Codes */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	/* MAXDL */

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

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

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

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

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

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

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

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

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

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

543
544
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
545

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

549
550
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
551

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

	/* Synchronet Specific */

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

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

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

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

579
580
	if(!strcmp(sp,"QUESTION"))
		return(question);
581

582
583
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
584

585
586
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
587

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

594
595
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
596

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

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

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

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

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

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

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

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

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

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

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

648
649
	if(!strcmp(sp,"GRP"))
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr);
650

651
652
	if(!strcmp(sp,"GRPL"))
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
653

654
655
656
657
	if(!strcmp(sp,"GN")) {
		sprintf(str,"%u",usrgrps ? curgrp+1 : 0);
		return(str);
	}
658

659
660
661
662
	if(!strcmp(sp,"GL")) {
		sprintf(str,"%-4u",usrgrps ? curgrp+1 : 0);
		return(str);
	}
663

664
665
666
667
	if(!strcmp(sp,"GR")) {
		sprintf(str,"%4u",usrgrps ? curgrp+1 : 0);
		return(str);
	}
668

669
670
	if(!strcmp(sp,"SUB"))
		return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
671

672
673
	if(!strcmp(sp,"SUBL"))
		return(usrgrps  ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->lname : nulstr);
674

675
676
677
678
	if(!strcmp(sp,"SN")) {
		sprintf(str,"%u",usrgrps ? cursub[curgrp]+1 : 0);
		return(str);
	}
679

680
681
682
683
	if(!strcmp(sp,"SL")) {
		sprintf(str,"%-4u",usrgrps ? cursub[curgrp]+1 : 0);
		return(str);
	}
684

685
686
687
688
	if(!strcmp(sp,"SR")) {
		sprintf(str,"%4u",usrgrps ? cursub[curgrp]+1 : 0);
		return(str);
	}
689

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

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

696
697
698
699
	if(!strcmp(sp,"LN")) {
		sprintf(str,"%u",usrlibs ? curlib+1 : 0);
		return(str);
	}
700

701
702
703
704
	if(!strcmp(sp,"LL")) {
		sprintf(str,"%-4u",usrlibs ? curlib+1 : 0);
		return(str);
	}
705

706
707
708
709
	if(!strcmp(sp,"LR")) {
		sprintf(str,"%4u",usrlibs  ? curlib+1 : 0);
		return(str);
	}
710

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

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

717
718
719
720
	if(!strcmp(sp,"DN")) {
		sprintf(str,"%u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
721

722
723
724
725
	if(!strcmp(sp,"DL")) {
		sprintf(str,"%-4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
726

727
728
729
730
	if(!strcmp(sp,"DR")) {
		sprintf(str,"%4u",usrlibs ? curdir[curlib]+1 : 0);
		return(str);
	}
731

732
	if(!strcmp(sp,"NOACCESS")) {
733
		if(noaccess_str==text[NoAccessTime])
734
			sprintf(str,noaccess_str,noaccess_val/60,noaccess_val%60);
735
		else if(noaccess_str==text[NoAccessDay])
736
			sprintf(str,noaccess_str,wday[noaccess_val]);
737
		else
738
739
740
			sprintf(str,noaccess_str,noaccess_val); 
		return(str);
	}
741

742
	if(!strcmp(sp,"LAST")) {
743
744
745
		tp=strrchr(useron.alias,SP);
		if(tp) tp++;
		else tp=useron.alias;
746
747
		return(tp); 
	}
748

749
750
751
	if(!strcmp(sp,"REAL")) {
		strcpy(str,useron.name);
		tp=strchr(str,SP);
752
		if(tp) *tp=0;
753
754
		return(str); 
	}
755

756
757
758
	if(!strcmp(sp,"FIRSTREAL")) {
		strcpy(str,useron.name);
		tp=strchr(str,SP);
759
		if(tp) *tp=0;
760
761
		return(str); 
	}
762

763
	if(!strcmp(sp,"LASTREAL")) {
764
765
766
		tp=strrchr(useron.name,SP);
		if(tp) tp++;
		else tp=useron.name;
767
768
		return(tp); 
	}
769

770
771
772
773
	if(!strcmp(sp,"MAILW")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,0));
		return(str);
	}
774

775
776
777
778
	if(!strcmp(sp,"MAILP")) {
		sprintf(str,"%u",getmail(&cfg,useron.number,1));
		return(str);
	}
779

780
781
782
783
	if(!strncmp(sp,"MAILW:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),0));
		return(str);
	}
784

785
786
787
788
	if(!strncmp(sp,"MAILP:",6)) {
		sprintf(str,"%u",getmail(&cfg,atoi(sp+6),1));
		return(str);
	}
789

790
791
792
793
	if(!strcmp(sp,"MSGREPLY")) {
		sprintf(str,"%c",cfg.sys_misc&SM_RA_EMU ? 'R' : 'A');
		return(str);
	}
794

795
796
797
798
	if(!strcmp(sp,"MSGREREAD")) {
		sprintf(str,"%c",cfg.sys_misc&SM_RA_EMU ? 'A' : 'R');
		return(str);
	}
799

800
	if(!strncmp(sp,"STATS.",6)) {
801
802
803
		getstats(&cfg,0,&stats);
		sp+=6;
		if(!strcmp(sp,"LOGONS")) 
804
			sprintf(str,"%lu",stats.logons);
805
		else if(!strcmp(sp,"LTODAY")) 
806
			sprintf(str,"%lu",stats.ltoday);
807
		else if(!strcmp(sp,"TIMEON")) 
808
			sprintf(str,"%lu",stats.timeon);
809
		else if(!strcmp(sp,"TTODAY")) 
810
			sprintf(str,"%lu",stats.ttoday);
811
		else if(!strcmp(sp,"ULS")) 
812
			sprintf(str,"%lu",stats.uls);
813
		else if(!strcmp(sp,"ULB")) 
814
			sprintf(str,"%lu",stats.ulb);
815
		else if(!strcmp(sp,"DLS")) 
816
			sprintf(str,"%lu",stats.dls);
817
		else if(!strcmp(sp,"DLB")) 
818
			sprintf(str,"%lu",stats.dlb);
819
		else if(!strcmp(sp,"PTODAY")) 
820
			sprintf(str,"%lu",stats.ptoday);
821
		else if(!strcmp(sp,"ETODAY")) 
822
			sprintf(str,"%lu",stats.etoday);
823
		else if(!strcmp(sp,"FTODAY")) 
824
			sprintf(str,"%lu",stats.ftoday);
825
		else if(!strcmp(sp,"NUSERS")) 
826
			sprintf(str,"%u",stats.nusers);
827
		return(str);
828
829
	}

830
	/* Message header codes */
831
832
833
	if(!strcmp(sp,"MSG_TO") && current_msg!=NULL) {
		if(current_msg->to==NULL)
			return(nulstr);
834
		if(current_msg->to_ext!=NULL)
835
836
837
			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
838
				,net_addr(&current_msg->to_net));
839
840
841
		else
			strcpy(str,current_msg->to);
		return(str);
842
	}
843
844
845
846
847
848
849
	if(!strcmp(sp,"MSG_TO_NAME") && current_msg!=NULL)
		return(current_msg->to==NULL ? nulstr : current_msg->to);
	if(!strcmp(sp,"MSG_TO_EXT") && current_msg!=NULL) {
		if(current_msg->to_ext==NULL)
			return(nulstr);
		return(current_msg->to_ext);
	}
850
851
	if(!strcmp(sp,"MSG_TO_NET") && current_msg!=NULL)
		return(net_addr(&current_msg->to_net));
852
853
854
855
856
857
858
859
860
	if(!strcmp(sp,"MSG_FROM") && current_msg!=NULL) {
		if(current_msg->from==NULL)
			return(nulstr);
		if(current_msg->hdr.attr&MSG_ANONYMOUS && !SYSOP)
			return(text[Anonymous]);
		if(current_msg->from_ext!=NULL)
			sprintf(str,"%s #%s",current_msg->from,current_msg->from_ext);
		else if(current_msg->from_net.type!=NET_NONE)
			sprintf(str,"%s (%s)",current_msg->from
861
				,net_addr(&current_msg->from_net));
862
863
864
		else
			strcpy(str,current_msg->from);
		return(str);
865
	}
866
867
868
869
870
871
872
873
	if(!strcmp(sp,"MSG_FROM_NAME") && current_msg!=NULL) {
		if(current_msg->from==NULL)
			return(nulstr);
		if(current_msg->hdr.attr&MSG_ANONYMOUS && !SYSOP)
			return(text[Anonymous]);
		return(current_msg->from);
	}		
	if(!strcmp(sp,"MSG_FROM_EXT") && current_msg!=NULL) {
874
		if(!(current_msg->hdr.attr&MSG_ANONYMOUS) || SYSOP)
875
			if(current_msg->from_ext!=NULL)
876
877
				return(current_msg->from_ext);
		return(nulstr);
878
	}
879
880
	if(!strcmp(sp,"MSG_FROM_NET") && current_msg!=NULL) {
		if(current_msg->from_net.type!=NET_NONE
881
			&& (!(current_msg->hdr.attr&MSG_ANONYMOUS) || SYSOP))
882
883
			return(net_addr(&current_msg->from_net));
		return(nulstr);
884
	}
885
886
887
888
889
890
891
892
	if(!strcmp(sp,"MSG_SUBJECT") && current_msg!=NULL)
		return(current_msg->subj==NULL ? nulstr : current_msg->subj);
	if(!strcmp(sp,"MSG_DATE") && current_msg!=NULL)
		return(timestr((time_t *)&current_msg->hdr.when_written.time));
	if(!strcmp(sp,"MSG_TIMEZONE") && current_msg!=NULL)
		return(zonestr(current_msg->hdr.when_written.zone));
	if(!strcmp(sp,"MSG_ATTR") && current_msg!=NULL) {
		sprintf(str,"%s%s%s%s%s%s%s%s%s%s"