作者: BloodDreamer (血梦)
用于抓收到的和回别人的msg, 花了一整天的时间总算写成乐,
贴出来于大家共享.
文件名:
catchmsg.cpp
编译:
g++ catchmsg.cpp -o catchmsg
用法是这样的:
telnet bbs.your.host |catchmsg savefile
祝:
广大的热爱Linux和Unix的GGDD们和JJMM们聊天快乐,
把更多美好回忆留在按ext2格式化的硬盘上和心中.
----蜀南血梦
//catchmsg.cpp
//抓取上bbs时和朋友对发的msg:)
//蜀南血梦.最后修改:1999.6.12 加入对msg镶套的支持.
//Email:blood_dreamer@126.com或BloodDreamer@263.net
//usage:
// telnet bbs.our.host |catchmsg outfile
//bugs: 未对重复的msg加以过滤;
// 抓到的msg按其出现的自然顺序组织;
// ^H和^[[?;?H尚未过滤.
#include<iostream.h>
#include<fstream.h>
#include<ctype.h>
#define MSG_INIT 0
#define MSG_BEGIN 1
#define MSG_PAUSE 2
#define MSG_STOP 3
#define MSG_RESUME 4
#define MSG_ESC 5
#define MSG_GET 6
#define MSG_ONE 7
#define MSG_TWO 8
struct CStateNode{
int nStart;
int nEnd;
char *pszSteps;
char *pszFullSteps;
}aStateNodes[100]={
{0,MSG_ESC,"x1b[",""},
{MSG_ESC,MSG_GET,"0;1;44;36m","x1b[0;1;44;36m"},
{0,MSG_BEGIN,"立即回讯息给","立即回讯息给"},
{0,MSG_BEGIN,"回讯息给","回讯息给"},
{MSG_ESC,MSG_ONE,"1",""},
{MSG_ONE,MSG_PAUSE,";*H",""},
{MSG_ESC,MSG_TWO,"2",""},
{MSG_TWO,MSG_RESUME,";","x1b[2;"},
{MSG_ESC,MSG_PAUSE,"3;*H",""},
{MSG_ESC,MSG_PAUSE,"4;*H",""},
{MSG_ESC,MSG_PAUSE,"5;*H",""},
{MSG_ESC,MSG_PAUSE,"6;*H",""},
{MSG_ESC,MSG_PAUSE,"7;*H",""},
{MSG_ESC,MSG_PAUSE,"8;*H",""},
{MSG_ESC,MSG_PAUSE,"9;*H",""},
{MSG_ONE,MSG_PAUSE,"0;*H",""},
{MSG_ONE,MSG_PAUSE,"1;*H",""},
{MSG_ONE,MSG_PAUSE,"2;*H",""},
{MSG_ONE,MSG_PAUSE,"3;*H",""},
{MSG_ONE,MSG_PAUSE,"4;*H",""},
{MSG_ONE,MSG_PAUSE,"5;*H",""},
{MSG_ONE,MSG_PAUSE,"6;*H",""},
{MSG_ONE,MSG_PAUSE,"7;*H",""},
{MSG_ONE,MSG_PAUSE,"8;*H",""},
{MSG_ONE,MSG_PAUSE,"9;*H",""},
{MSG_TWO,MSG_PAUSE,"0;*H",""},
{MSG_TWO,MSG_PAUSE,"1;*H",""},
{MSG_TWO,MSG_PAUSE,"2;*H",""},
{MSG_TWO,MSG_PAUSE,"3;*H",""},
{MSG_TWO,MSG_PAUSE,"4;*H",""},
{MSG_TWO,MSG_PAUSE,"5;*H",""},
{0,MSG_STOP,"r","rn"},
{0,0,NULL}};
int nState=0;
int nCurNode=0;
int nCurPos=0;
int StepOn(char c,const char **pp)
{
CStateNode *psn=aStateNodes+nCurNode;
if(psn->pszSteps[nCurPos]==''){
nCurPos=0;
CStateNode *p=aStateNodes;
nCurNode=0;
while(p->pszSteps!=NULL){
if(p->nStart==nState)
goto ok;
p++;
nCurNode++;
}
nState=nCurNode=0;
}
ok:
int nPass=0;
while(nPass<=1){
psn=aStateNodes+nCurNode;
while(psn->pszSteps!=NULL){
if(psn->nStart==nState){
if(c==psn->pszSteps[nCurPos]){
nCurPos++;
if(psn->pszSteps[nCurPos]==''){
*pp=psn->pszFullSteps;
nState=psn->nEnd;
}else
*pp=NULL;
return nState;
}else if(psn->pszSteps[nCurPos]=='*'){
if(c==psn->pszSteps[nCurPos+1]){
nCurPos+=2;
}else if(!isdigit(c)){
goto break_here;
}
if(psn->pszSteps[nCurPos]==''){
*pp=psn->pszFullSteps;
nState=psn->nEnd;
}else
*pp=NULL;
return nState;
}
}
break_here:
nCurPos=0;
nCurNode++;
psn++;
}
nState=nCurNode=nCurPos=0;
*pp=NULL;
nPass++;
}
return nState;
}
void main(int argc,char ** argv)
{
char c;
int stat=0;
int nPauseDepth=0;
const char *pszSteps;
ofstream out(argv[1]);
// ofstream stat_out("catchmsg.dat");
cin.get(c);
while(!cin.eof()){
cout.put(c);
int step=StepOn(c,&pszSteps);
if(//stat==MSG_PAUSE
nPauseDepth
&&step==MSG_RESUME
&& pszSteps){
stat=MSG_RESUME;
nPauseDepth--;
out.write(pszSteps,strlen(pszSteps));
out.flush();
}else if(stat==MSG_GET){
if(step==MSG_STOP && pszSteps){
stat=0;
out.put(c);
out.put('n');
out.flush();
}else{
out.put(c);
out.flush();
}
}else if(step==MSG_BEGIN&& pszSteps){
out.write(pszSteps,strlen(pszSteps));
out.flush();
stat=MSG_BEGIN;
}else if(step==MSG_GET&& pszSteps){
if(stat!=MSG_BEGIN)
out.write(pszSteps,strlen(pszSteps));
else
out.put(c);
out.flush();
stat=MSG_GET;
}else if(stat==MSG_BEGIN||stat==MSG_RESUME){
if(step==MSG_PAUSE
&& pszSteps){
stat=MSG_PAUSE;
nPauseDepth++;
out.put(c);
out.flush();
}else if(step==MSG_STOP
&& pszSteps){
stat=0;
out.put(c);
out.put('n');
out.flush();
}
if(stat&&stat!=MSG_PAUSE){
out.put(c);
out.flush();
}
}
// stat_out<<c<<'t'<<stat<<'t'<<'t'<<step<<'n';
cin.get(c);
}
}
视频教程列表
文章教程搜索
C语言程序设计推荐教程
C语言程序设计热门教程
|