Skip to content
Snippets Groups Projects
Commit c62a5a01 authored by rswindell's avatar rswindell
Browse files

Now strips ANSI, handle clear screens, carriage-returns, and bell chars.

parent f716d4d1
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,9 @@
#pragma hdrstop
#include "SpyFormUnit.h"
#include "sbbsdefs.h"
#define SPYBUF_LEN 10000
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
......@@ -13,6 +16,60 @@ __fastcall TSpyForm::TSpyForm(TComponent* Owner)
: TForm(Owner)
{
}
bool strip_ansi(char* str)
{
char* p=str;
char newstr[SPYBUF_LEN];
int newlen=0;
bool ff=false;
for(p=str;*p && newlen<(sizeof(newstr)-1);) {
switch(*p) {
case BEL: /* bell */
Beep();
break;
case BS: /* backspace */
if(newlen)
newlen--;
break;
case FF: /* form feed */
newlen=0;
ff=true;
break;
case ESC:
if(*(p+1)=='[') { /* ANSI */
p+=2;
if(!strncmp(p,"2J",2)) {
newlen=0;
ff=true;
}
while(*p && !isalpha(*p)) p++;
}
break;
case CR:
if(*(p+1)!=LF) {
while(newlen) {
newlen--;
if(newstr[newlen]==LF) {
newlen++;
break;
}
}
break;
} /* Fall through */
default:
newstr[newlen++]=*p;
break;
}
if(*p==0)
break;
p++;
}
newstr[newlen]=0;
strcpy(str,newstr);
return(ff);
}
//---------------------------------------------------------------------------
void __fastcall TSpyForm::SpyTimerTick(TObject *Sender)
{
......@@ -25,6 +82,10 @@ void __fastcall TSpyForm::SpyTimerTick(TObject *Sender)
rd=RingBufRead(*spybuf,buf,sizeof(buf)-1);
if(rd) {
buf[rd]=0;
if(strip_ansi(buf))
Log->Lines->Clear();
Log->SelLength=0;
Log->SelStart=Log->Lines->Text.Length();
Log->SelText=AnsiString(buf);
Timer->Interval=100;
} else
......@@ -47,8 +108,7 @@ void __fastcall TSpyForm::FormShow(TObject *Sender)
Log->Lines->Add("Malloc failure!");
return;
}
RingBufInit(*spybuf,10000);
Log->Lines->Add("Spying...");
RingBufInit(*spybuf,SPYBUF_LEN);
Timer->Enabled=true;
}
//---------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment