atcodes.cpp 32.8 KB
Newer Older
1
2
3
4
5
6
7
8
/* 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)		*
 *																			*
9
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
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
 *																			*
 * 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"

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

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

60
	SAFECOPY(str,instr);
61
62
63
	tp=strchr(str+1,'@');
	if(!tp)                 /* no terminating @ */
		return(0);
64
	sp=strchr(str+1,' ');
65
66
67
68
69
70
	if(sp && sp<tp)         /* space before terminating @ */
		return(0);
	len=(tp-str)+1;
	(*tp)=0;
	sp=(str+1);

71
	disp_len=len;
72
73
74
75
	if((p=strstr(sp,"-L"))!=NULL)
		padded_left=true;
	else if((p=strstr(sp,"-R"))!=NULL)
		padded_right=true;
76
77
	else if((p=strstr(sp,"-C"))!=NULL)
		centered=true;
78
79
	else if((p=strstr(sp,"-Z"))!=NULL)
		zero_padded=true;
80
81
82
	if(p!=NULL) {
		if(*(p+2) && isdigit(*(p+2)))
			disp_len=atoi(p+2);
83
		*p=0;
84
	}
85

86
87
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
88
89
90
		return(0);

	if(padded_left)
91
		bprintf("%-*.*s",disp_len,disp_len,cp);
92
	else if(padded_right)
93
		bprintf("%*.*s",disp_len,disp_len,cp);
94
	else if(centered) {
rswindell's avatar
rswindell committed
95
		int vlen = strlen(cp);
96
97
98
99
		if(vlen < disp_len) {
			int left = (disp_len - vlen) / 2;
			bprintf("%*s%-*s", left, "", disp_len - left, cp);
		} else
100
			bprintf("%.*s", disp_len, cp);
101
	} else if(zero_padded) {
102
103
104
105
106
		int vlen = strlen(cp);
		if(vlen < disp_len)
			bprintf("%-.*s%s", disp_len - strlen(cp), "0000000000", cp);
		else
			bprintf("%.*s", disp_len, cp);
107
	} else
108
		bputs(cp);
109
110
111
112

	return(len);
}

113
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
114
115
116
{
	char*	tp;
	uint	i;
117
118
	uint	ugrp;
	uint	usub;
119
120
121
122
123
124
125
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

126
	if(!strcmp(sp,"VER"))
127
		return(VERSION);
128

129
	if(!strcmp(sp,"REV")) {
130
		safe_snprintf(str,maxlen,"%c",REVISION);
131
132
		return(str);
	}
133

134
	if(!strcmp(sp,"FULL_VER")) {
135
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
136
		truncsp(str);
137
#if defined(_DEBUG)
138
		strcat(str," Debug");
139
#endif
140
		return(str);
141
142
	}

143
	if(!strcmp(sp,"VER_NOTICE"))
144
		return(VERSION_NOTICE);
145

146
147
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
148
149

#ifdef JAVASCRIPT
150
151
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
152
153
#endif

154
155
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
156

157
158
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
159

160
	if(!strcmp(sp,"COMPILER")) {
161
		DESCRIBE_COMPILER(str);
162
		return(str);
163
164
	}

165
	if(!strcmp(sp,"UPTIME")) {
166
		extern volatile time_t uptime;
167
168
169
170
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
171
172
		char   days[64]="";
		if((up/(24*60*60))>=2) {
173
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
174
175
			up%=(24*60*60);
		}
176
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
177
	        ,days
178
179
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
180
			);
181
		return(str);
182
183
	}

184
	if(!strcmp(sp,"SERVED")) {
185
		extern volatile ulong served;
186
		safe_snprintf(str,maxlen,"%lu",served);
187
188
189
		return(str);
	}

190
	if(!strcmp(sp,"SOCKET_LIB"))
191
		return(socklib_version(str,SOCKLIB_DESC));
192

193
	if(!strcmp(sp,"MSG_LIB")) {
194
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
195
196
		return(str);
	}
197

198
199
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
200

201
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
202
		safe_snprintf(str,maxlen,"%lu",cur_rate);
203
204
		return(str);
	}
205

206
207
	if(!strcmp(sp,"CONN"))
		return(connection);
208

209
210
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
211

212
213
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
214

215
	if(!strcmp(sp,"NODE")) {
216
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
217
218
		return(str);
	}
219

220
	if(!strcmp(sp,"TNODE")) {
221
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
222
223
		return(str);
	}
224

225
226
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
227

228
229
230
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

231
	if(!strcmp(sp,"FIDOADDR")) {
232
		if(cfg.total_faddrs)
233
			return(smb_faddrtoa(&cfg.faddr[0],str));
234
		return(nulstr);
235
236
	}

237
	if(!strcmp(sp,"EMAILADDR"))
238
		return(usermailaddr(&cfg, str
239
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
240

241
242
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
243

244
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
245
		now=time(NULL);
246
		memset(&tm,0,sizeof(tm));
247
		localtime_r(&now,&tm);
248
		if(cfg.sys_misc&SM_MILITARY)
249
250
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
251
		else
252
			safe_snprintf(str,maxlen,"%02d:%02d %s"
253
254
255
				,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");
256
		return(str);
257
258
	}

rswindell's avatar
rswindell committed
259
260
261
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

262
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
263
		return(unixtodstr(&cfg,time32(NULL),str));
264
	}
265

rswindell's avatar
rswindell committed
266
267
268
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

269
	if(!strcmp(sp,"TMSG")) {
270
271
		l=0;
		for(i=0;i<cfg.total_subs;i++)
272
			l+=getposts(&cfg,i); 		/* l=total posts */
273
		safe_snprintf(str,maxlen,"%lu",l);
274
275
		return(str);
	}
276

277
	if(!strcmp(sp,"TUSER")) {
278
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
279
280
		return(str);
	}
281

282
	if(!strcmp(sp,"TFILE")) {
283
284
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
285
			l+=getfiles(&cfg,i);
286
		safe_snprintf(str,maxlen,"%lu",l);
287
288
		return(str);
	}
289

290
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
291
		getstats(&cfg,0,&stats);
292
		safe_snprintf(str,maxlen,"%lu",stats.logons);
293
294
		return(str);
	}
295

296
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
297
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
298
		return(lastuseron);
299

300
	if(!strcmp(sp,"CLS")) {
301
		CLS;
302
303
		return(nulstr);
	}
304

305
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
306
		pause();
307
308
		return(nulstr);
	}
309

310
	if(!strcmp(sp,"RESETPAUSE")) {
311
		lncntr=0;
312
313
		return(nulstr);
	}
314

315
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
316
		sys_status^=SS_PAUSEOFF;
317
318
		return(nulstr);
	}
319

320
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
321
		sys_status^=SS_PAUSEON;
322
323
		return(nulstr);
	}
324
325
326
327
328

	/* NOSTOP */

	/* STOP */

329
330
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
331

332
333
334
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
335
		return(timestr(event_time));
336
	}
337
338
339

	/* LASTCALL */

340
	if(!strncmp(sp,"NODE",4)) {
341
342
343
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
344
345
			printnodedat(i,&node);
		}
346
347
		return(nulstr);
	}
348

349
	if(!strcmp(sp,"WHO")) {
350
		whos_online(true);
351
352
		return(nulstr);
	}
353
354
355

	/* User Codes */

356
357
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
358

359
	if(!strcmp(sp,"FIRST")) {
360
		safe_snprintf(str,maxlen,"%s",useron.alias);
361
		tp=strchr(str,' ');
362
		if(tp) *tp=0;
363
		return(str);
364
	}
365

366
	if(!strcmp(sp,"USERNUM")) {
367
		safe_snprintf(str,maxlen,"%u",useron.number);
368
369
		return(str);
	}
370

371
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
372
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
373
		return(useron.phone);
374

375
376
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
377

378
379
	if(!strcmp(sp,"FROM"))
		return(useron.location);
380

381
	if(!strcmp(sp,"CITY")) {
382
		safe_snprintf(str,maxlen,"%s",useron.location);
383
		char* p=strchr(str,',');
384
385
		if(p) {
			*p=0;
386
387
			return(str);
		}
388
389
		return(nulstr);
	}
390

391
392
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
393
394
		if(p) {
			p++;
395
			if(*p==' ')
396
				p++;
397
398
			return(p);
		}
399
400
		return(nulstr);
	}
401

402
403
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
404

405
406
	if(!strcmp(sp,"HOST"))
		return(client_name);
407

408
409
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
410

411
	if(!strcmp(sp,"AGE")) {
412
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
413
414
		return(str);
	}
rswindell's avatar
rswindell committed
415

416
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
417
		safe_snprintf(str,maxlen,"%u",useron.logons);
418
419
		return(str);
	}
420

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

424
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
425
		safe_snprintf(str,maxlen,"%u",useron.level);
426
427
		return(str);
	}
428

429
430
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
431

432
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
433
		now=time(NULL);
434
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
435
436
		return(str);
	}
437

438
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
439
		now=time(NULL);
440
		return(sectostr((uint)(now-logontime),str)+1);
441
	}
442

443
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
444
		gettimeleft();
445
		return(sectostr(timeleft,str)+1);
446
	}
447

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

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

454
	if(!strcmp(sp,"TIMELIMIT")) {
455
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
456
457
		return(str);
	}
458

459
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
460
		gettimeleft();
461
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
462
463
		return(str);
	}
464

465
	if(!strcmp(sp,"LASTON"))
466
		return(timestr(useron.laston));
467

468
469
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
470

471
	if(!strcmp(sp,"LASTTIMEON")) {
472
		memset(&tm,0,sizeof(tm));
473
		localtime32(&useron.laston,&tm);
474
475
476
477
478
479
480
481
		if(cfg.sys_misc&SM_MILITARY)
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
				,tm.tm_hour, tm.tm_min, tm.tm_sec);
		else
			safe_snprintf(str,maxlen,"%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");
482
		return(str);
483
484
	}

485
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
486
		safe_snprintf(str,maxlen,"%u",useron.posts);
487
488
		return(str);
	}
489

490
	if(!strcmp(sp,"MSGREAD")) {
491
		safe_snprintf(str,maxlen,"%lu",posts_read);
492
493
		return(str);
	}
494

495
	if(!strcmp(sp,"FREESPACE")) {
496
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
497
498
499
500
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
501
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
502
503
		return(str);
	}
504

505
	if(!strcmp(sp,"UPBYTES")) {
506
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
507
508
		return(str);
	}
509

510
	if(!strcmp(sp,"UPK")) {
511
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
512
513
		return(str);
	}
514

515
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
516
		safe_snprintf(str,maxlen,"%u",useron.uls);
517
518
		return(str);
	}
519

520
	if(!strcmp(sp,"DLBYTES")) {
521
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
522
523
		return(str);
	}
524

525
	if(!strcmp(sp,"DOWNK")) {
526
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
527
528
		return(str);
	}
529

530
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
531
		safe_snprintf(str,maxlen,"%u",useron.dls);
532
533
		return(str);
	}
534

535
	if(!strcmp(sp,"LASTNEW"))
536
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
537

538
	if(!strcmp(sp,"NEWFILETIME"))
539
		return(timestr(ns_time));
540
541
542

	/* MAXDL */

543
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
544
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
545
546
		return(str);
	}
547

548
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
549
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
550
551
		return(str);
	}
552

553
	if(!strcmp(sp,"BYTELIMIT")) {
554
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]);
555
556
		return(str);
	}
557

558
	if(!strcmp(sp,"KBLEFT")) {
559
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
560
561
		return(str);
	}
562

563
	if(!strcmp(sp,"BYTESLEFT")) {
564
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
565
566
		return(str);
	}
567

568
	if(!strcmp(sp,"CONF")) {
569
		safe_snprintf(str,maxlen,"%s %s"
570
571
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
572
573
		return(str);
	}
574

575
	if(!strcmp(sp,"CONFNUM")) {
576
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
577
578
		return(str);
	}
579

580
	if(!strcmp(sp,"NUMDIR")) {
581
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
582
583
		return(str);
	}
584

585
586
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
587

588
	if(!strcmp(sp,"EXPDAYS")) {
589
		now=time(NULL);
590
		l=(long)(useron.expire-now);
591
592
		if(l<0)
			l=0;
593
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
594
595
		return(str);
	}
596

597
598
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
599

600
601
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
602

603
604
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
605

606
	if(!strcmp(sp,"HANGUP")) {
607
		hangup();
608
609
		return(nulstr);
	}
610
611
612

	/* Synchronet Specific */

613
	if(!strncmp(sp,"SETSTR:",7)) {
614
		strcpy(main_csi.str,sp+7);
615
616
		return(nulstr);
	}
617

618
	if(!strncmp(sp,"EXEC:",5)) {
619
		exec_bin(sp+5,&main_csi);
620
621
		return(nulstr);
	}
622

623
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
624
		for(i=0;i<cfg.total_xtrns;i++)
625
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
626
627
628
629
630
631
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

632
	if(!strncmp(sp,"MENU:",5)) {
633
		menu(sp+5);
634
635
		return(nulstr);
	}
636

637
638
639
640
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
641

642
	if(!strncmp(sp,"INCLUDE:",8)) {
643
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
644
645
646
		return(nulstr);
	}

647
648
	if(!strcmp(sp,"QUESTION"))
		return(question);
649

650
651
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
652

653
654
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
655

deuce's avatar
deuce committed
656
657
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
658

659
660
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
661

662
	if(!strcmp(sp,"PUSHXY")) {
663
		ansi_save();
664
665
		return(nulstr);
	}
666

667
	if(!strcmp(sp,"POPXY")) {
668
		ansi_restore();
669
670
		return(nulstr);
	}
671

rswindell's avatar
rswindell committed
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
	if(!strcmp(sp,"HOME")) {
		cursor_home();
		return(nulstr);
	}

	if(!strcmp(sp,"CLRLINE")) {
		clearline();
		return(nulstr);
	}

	if(!strcmp(sp,"CLR2EOL")) {
		cleartoeol();
		return(nulstr);
	}

	if(!strcmp(sp,"CLR2EOS")) {
		cleartoeos();
		return(nulstr);
	}

692
	if(!strncmp(sp,"UP:",3)) {
693
		cursor_up(atoi(sp+3));
694
695
		return(str);
	}
696

697
	if(!strncmp(sp,"DOWN:",5)) {
698
		cursor_down(atoi(sp+5));
699
700
		return(str);
	}
701

702
	if(!strncmp(sp,"LEFT:",5)) {
703
		cursor_left(atoi(sp+5));
704
705
		return(str);
	}
706

707
	if(!strncmp(sp,"RIGHT:",6)) {
708
		cursor_right(atoi(sp+6));
709
710
		return(str);
	}
711

712
	if(!strncmp(sp,"GOTOXY:",7)) {
713
714
715
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
716
			ansi_gotoxy(atoi(sp+7),atoi(tp));
717
		}
718
		return(nulstr);
719
720
	}

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

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

741
	if(!strcmp(sp,"GN")) {
742
743
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
744
		else
745
			ugrp=usrgrps ? curgrp+1 : 0;
746
		safe_snprintf(str,maxlen,"%u",ugrp);
747
748
		return(str);
	}
749

750
	if(!strcmp(sp,"GL")) {
751
752
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
753
		else
754
			ugrp=usrgrps ? curgrp+1 : 0;
755
		safe_snprintf(str,maxlen,"%-4u",ugrp);
756
757
		return(str);
	}
758

759
	if(!strcmp(sp,"GR")) {
760
761
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
762
		else
763
			ugrp=usrgrps ? curgrp+1 : 0;