论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

一个抓msg的程序(for bbs)

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:37:26

作者: 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);
}
}
上一篇:{技巧}gcc批量建mysql库表 人气:4716
下一篇:{技巧}从程序员的角度看xwindows 人气:5089
视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058