atcodes.cpp 29.9 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
	const char *cp;
58

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

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

83
84
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
85
86
87
		return(0);

	if(padded_left)
88
		bprintf("%-*.*s",disp_len,disp_len,cp);
89
	else if(padded_right)
90
		bprintf("%*.*s",disp_len,disp_len,cp);
91
	else if(centered) {
rswindell's avatar
rswindell committed
92
		int vlen = strlen(cp);
93
94
95
96
97
98
		if(vlen < disp_len) {
			int left = (disp_len - vlen) / 2;
			bprintf("%*s%-*s", left, "", disp_len - left, cp);
		} else
			bputs(cp);
	} else
99
		bputs(cp);
100
101
102
103

	return(len);
}

104
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
105
106
107
{
	char*	tp;
	uint	i;
108
109
	uint	ugrp;
	uint	usub;
110
111
112
113
114
115
116
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

117
	if(!strcmp(sp,"VER"))
118
		return(VERSION);
119

120
	if(!strcmp(sp,"REV")) {
121
		safe_snprintf(str,maxlen,"%c",REVISION);
122
123
		return(str);
	}
124

125
	if(!strcmp(sp,"FULL_VER")) {
126
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
127
		truncsp(str);
128
#if defined(_DEBUG)
129
		strcat(str," Debug");
130
#endif
131
		return(str);
132
133
	}

134
	if(!strcmp(sp,"VER_NOTICE"))
135
		return(VERSION_NOTICE);
136

137
138
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
139
140

#ifdef JAVASCRIPT
141
142
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
143
144
#endif

145
146
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
147

148
149
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
150

151
	if(!strcmp(sp,"COMPILER")) {
152
		DESCRIBE_COMPILER(str);
153
		return(str);
154
155
	}

156
	if(!strcmp(sp,"UPTIME")) {
157
		extern volatile time_t uptime;
158
159
160
161
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
162
163
		char   days[64]="";
		if((up/(24*60*60))>=2) {
164
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
165
166
			up%=(24*60*60);
		}
167
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
168
	        ,days
169
170
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
171
			);
172
		return(str);
173
174
	}

175
	if(!strcmp(sp,"SERVED")) {
176
		extern volatile ulong served;
177
		safe_snprintf(str,maxlen,"%lu",served);
178
179
180
		return(str);
	}

181
	if(!strcmp(sp,"SOCKET_LIB"))
182
		return(socklib_version(str,SOCKLIB_DESC));
183

184
	if(!strcmp(sp,"MSG_LIB")) {
185
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
186
187
		return(str);
	}
188

189
190
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
191

192
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
193
		safe_snprintf(str,maxlen,"%lu",cur_rate);
194
195
		return(str);
	}
196

197
198
	if(!strcmp(sp,"CONN"))
		return(connection);
199

200
201
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
202

203
204
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
205

206
	if(!strcmp(sp,"NODE")) {
207
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
208
209
		return(str);
	}
210

211
	if(!strcmp(sp,"TNODE")) {
212
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
213
214
		return(str);
	}
215

216
217
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
218

219
220
221
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

222
	if(!strcmp(sp,"FIDOADDR")) {
223
		if(cfg.total_faddrs)
224
			return(smb_faddrtoa(&cfg.faddr[0],str));
225
		return(nulstr);
226
227
	}

228
	if(!strcmp(sp,"EMAILADDR"))
229
		return(usermailaddr(&cfg, str
230
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
231

232
233
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
234

235
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
236
		now=time(NULL);
237
		memset(&tm,0,sizeof(tm));
238
		localtime_r(&now,&tm);
239
		if(cfg.sys_misc&SM_MILITARY)
240
241
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
242
		else
243
			safe_snprintf(str,maxlen,"%02d:%02d %s"
244
245
246
				,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");
247
		return(str);
248
249
	}

rswindell's avatar
rswindell committed
250
251
252
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

253
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
254
		return(unixtodstr(&cfg,time32(NULL),str));
255
	}
256

rswindell's avatar
rswindell committed
257
258
259
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

260
	if(!strcmp(sp,"TMSG")) {
261
262
		l=0;
		for(i=0;i<cfg.total_subs;i++)
263
			l+=getposts(&cfg,i); 		/* l=total posts */
264
		safe_snprintf(str,maxlen,"%lu",l);
265
266
		return(str);
	}
267

268
	if(!strcmp(sp,"TUSER")) {
269
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
270
271
		return(str);
	}
272

273
	if(!strcmp(sp,"TFILE")) {
274
275
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
276
			l+=getfiles(&cfg,i);
277
		safe_snprintf(str,maxlen,"%lu",l);
278
279
		return(str);
	}
280

281
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
282
		getstats(&cfg,0,&stats);
283
		safe_snprintf(str,maxlen,"%lu",stats.logons);
284
285
		return(str);
	}
286

287
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
288
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
289
		return(lastuseron);
290

291
	if(!strcmp(sp,"CLS")) {
292
		CLS;
293
294
		return(nulstr);
	}
295

296
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
297
		pause();
298
299
		return(nulstr);
	}
300

301
	if(!strcmp(sp,"RESETPAUSE")) {
302
		lncntr=0;
303
304
		return(nulstr);
	}
305

306
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
307
		sys_status^=SS_PAUSEOFF;
308
309
		return(nulstr);
	}
310

311
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
312
		sys_status^=SS_PAUSEON;
313
314
		return(nulstr);
	}
315
316
317
318
319

	/* NOSTOP */

	/* STOP */

320
321
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
322

323
324
325
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
326
		return(timestr(event_time));
327
	}
328
329
330

	/* LASTCALL */

331
	if(!strncmp(sp,"NODE",4)) {
332
333
334
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
335
336
			printnodedat(i,&node);
		}
337
338
		return(nulstr);
	}
339

340
	if(!strcmp(sp,"WHO")) {
341
		whos_online(true);
342
343
		return(nulstr);
	}
344
345
346

	/* User Codes */

347
348
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
349

350
	if(!strcmp(sp,"FIRST")) {
351
		safe_snprintf(str,maxlen,"%s",useron.alias);
352
		tp=strchr(str,' ');
353
		if(tp) *tp=0;
354
		return(str);
355
	}
356

357
	if(!strcmp(sp,"USERNUM")) {
358
		safe_snprintf(str,maxlen,"%u",useron.number);
359
360
		return(str);
	}
361

362
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
363
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
364
		return(useron.phone);
365

366
367
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
368

369
370
	if(!strcmp(sp,"FROM"))
		return(useron.location);
371

372
	if(!strcmp(sp,"CITY")) {
373
		safe_snprintf(str,maxlen,"%s",useron.location);
374
		char* p=strchr(str,',');
375
376
		if(p) {
			*p=0;
377
378
			return(str);
		}
379
380
		return(nulstr);
	}
381

382
383
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
384
385
		if(p) {
			p++;
386
			if(*p==' ')
387
				p++;
388
389
			return(p);
		}
390
391
		return(nulstr);
	}
392

393
394
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
395

396
397
	if(!strcmp(sp,"HOST"))
		return(client_name);
398

399
400
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
401

402
	if(!strcmp(sp,"AGE")) {
403
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
404
405
		return(str);
	}
rswindell's avatar
rswindell committed
406

407
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
408
		safe_snprintf(str,maxlen,"%u",useron.logons);
409
410
		return(str);
	}
411

412
413
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
414

415
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
416
		safe_snprintf(str,maxlen,"%u",useron.level);
417
418
		return(str);
	}
419

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

423
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
424
		now=time(NULL);
425
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
426
427
		return(str);
	}
428

429
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
430
		now=time(NULL);
431
		return(sectostr((uint)(now-logontime),str)+1);
432
	}
433

434
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
435
		gettimeleft();
436
		return(sectostr(timeleft,str)+1);
437
	}
438

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

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

445
	if(!strcmp(sp,"TIMELIMIT")) {
446
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
447
448
		return(str);
	}
449

450
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
451
		gettimeleft();
452
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
453
454
		return(str);
	}
455

456
	if(!strcmp(sp,"LASTON"))
457
		return(timestr(useron.laston));
458

459
460
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
461

462
	if(!strcmp(sp,"LASTTIMEON")) {
463
		memset(&tm,0,sizeof(tm));
464
		localtime32(&useron.laston,&tm);
465
466
467
468
469
470
471
472
		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");
473
		return(str);
474
475
	}

476
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
477
		safe_snprintf(str,maxlen,"%u",useron.posts);
478
479
		return(str);
	}
480

481
	if(!strcmp(sp,"MSGREAD")) {
482
		safe_snprintf(str,maxlen,"%lu",posts_read);
483
484
		return(str);
	}
485

486
	if(!strcmp(sp,"FREESPACE")) {
487
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
488
489
490
491
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
492
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
493
494
		return(str);
	}
495

496
	if(!strcmp(sp,"UPBYTES")) {
497
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
498
499
		return(str);
	}
500

501
	if(!strcmp(sp,"UPK")) {
502
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
503
504
		return(str);
	}
505

506
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
507
		safe_snprintf(str,maxlen,"%u",useron.uls);
508
509
		return(str);
	}
510

511
	if(!strcmp(sp,"DLBYTES")) {
512
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
513
514
		return(str);
	}
515

516
	if(!strcmp(sp,"DOWNK")) {
517
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
518
519
		return(str);
	}
520

521
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
522
		safe_snprintf(str,maxlen,"%u",useron.dls);
523
524
		return(str);
	}
525

526
	if(!strcmp(sp,"LASTNEW"))
527
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
528

529
	if(!strcmp(sp,"NEWFILETIME"))
530
		return(timestr(ns_time));
531
532
533

	/* MAXDL */

534
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
535
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
536
537
		return(str);
	}
538

539
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
540
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
541
542
		return(str);
	}
543

544
	if(!strcmp(sp,"BYTELIMIT")) {
545
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]);
546
547
		return(str);
	}
548

549
	if(!strcmp(sp,"KBLEFT")) {
550
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
551
552
		return(str);
	}
553

554
	if(!strcmp(sp,"BYTESLEFT")) {
555
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
556
557
		return(str);
	}
558

559
	if(!strcmp(sp,"CONF")) {
560
		safe_snprintf(str,maxlen,"%s %s"
561
562
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
563
564
		return(str);
	}
565

566
	if(!strcmp(sp,"CONFNUM")) {
567
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
568
569
		return(str);
	}
570

571
	if(!strcmp(sp,"NUMDIR")) {
572
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
573
574
		return(str);
	}
575

576
577
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
578

579
	if(!strcmp(sp,"EXPDAYS")) {
580
		now=time(NULL);
581
		l=(long)(useron.expire-now);
582
583
		if(l<0)
			l=0;
584
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
585
586
		return(str);
	}
587

588
589
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
590

591
592
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
593

594
595
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
596

597
	if(!strcmp(sp,"HANGUP")) {
598
		hangup();
599
600
		return(nulstr);
	}
601
602
603

	/* Synchronet Specific */

604
	if(!strncmp(sp,"SETSTR:",7)) {
605
		strcpy(main_csi.str,sp+7);
606
607
		return(nulstr);
	}
608

609
	if(!strncmp(sp,"EXEC:",5)) {
610
		exec_bin(sp+5,&main_csi);
611
612
		return(nulstr);
	}
613

614
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
615
		for(i=0;i<cfg.total_xtrns;i++)
616
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
617
618
619
620
621
622
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

623
	if(!strncmp(sp,"MENU:",5)) {
624
		menu(sp+5);
625
626
		return(nulstr);
	}
627

628
629
630
631
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
632

633
	if(!strncmp(sp,"INCLUDE:",8)) {
634
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
635
636
637
		return(nulstr);
	}

638
639
	if(!strcmp(sp,"QUESTION"))
		return(question);
640

641
642
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
643

644
645
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
646

deuce's avatar
deuce committed
647
648
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
649

650
651
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
652

653
	if(!strcmp(sp,"PUSHXY")) {
654
		ansi_save();
655
656
		return(nulstr);
	}
657

658
	if(!strcmp(sp,"POPXY")) {
659
		ansi_restore();
660
661
		return(nulstr);
	}
662

rswindell's avatar
rswindell committed
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
	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);
	}

683
	if(!strncmp(sp,"UP:",3)) {
684
		cursor_up(atoi(sp+3));
685
686
		return(str);
	}
687

688
	if(!strncmp(sp,"DOWN:",5)) {
689
		cursor_down(atoi(sp+5));
690
691
		return(str);
	}
692

693
	if(!strncmp(sp,"LEFT:",5)) {
694
		cursor_left(atoi(sp+5));
695
696
		return(str);
	}
697

698
	if(!strncmp(sp,"RIGHT:",6)) {
699
		cursor_right(atoi(sp+6));
700
701
		return(str);
	}
702

703
	if(!strncmp(sp,"GOTOXY:",7)) {
704
705
706
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
707
			ansi_gotoxy(atoi(sp+7),atoi(tp));
708
		}
709
		return(nulstr);
710
711
	}

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

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

732
	if(!strcmp(sp,"GN")) {
733
734
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
735
		else
736
			ugrp=usrgrps ? curgrp+1 : 0;
737
		safe_snprintf(str,maxlen,"%u",ugrp);
738
739
		return(str);
	}
740

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

750
	if(!strcmp(sp,"GR")) {
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
760
761
762
763
764
765
	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);
		}
766
		return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
767
	}