Add Special Mode and SingleMode Terminal
This commit is contained in:
parent
b9250a7ed1
commit
58f508cf1f
227
main.cpp
227
main.cpp
@ -12,6 +12,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include <cpplib/cpplib#time>
|
||||
#include <conio.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -118,13 +119,230 @@ void RemoteQuery(string PreCode,int ID)
|
||||
this_thread::sleep_for(chrono::seconds(rand()%3+1));
|
||||
}
|
||||
|
||||
#define HEAD_STR "15080801"
|
||||
#define NUM 5
|
||||
/*****************参数设置***************/
|
||||
char* _head_str = (char*)"15080801";
|
||||
const char* const HEAD_STR = _head_str;
|
||||
|
||||
int _num = 40;
|
||||
const int& NUM=_num;
|
||||
|
||||
int _beginnum=0;
|
||||
const int& BEGIN_NUM = _beginnum;
|
||||
bool _begin_after_singlemode = false;
|
||||
|
||||
|
||||
void _ClearKbhit()
|
||||
{
|
||||
while(kbhit()) getch();
|
||||
}
|
||||
|
||||
int ParseCommand(string Command)
|
||||
{
|
||||
istringstream istr(Command);
|
||||
string cmd;
|
||||
istr>>cmd;
|
||||
|
||||
if(cmd=="help")
|
||||
{
|
||||
printf("=====SingleMode 帮助列表=====\n");
|
||||
printf("===常规操作===\n");
|
||||
printf("help 显示本帮助列表\n");
|
||||
printf("query StudentID 查询某个ID对应的记录\n");
|
||||
printf("===高级操作===\n");
|
||||
printf("sethead HEAD_STR 修改HeadStr,当前值是%s(高级操作)\n",HEAD_STR);
|
||||
printf("setbegin BeginVal 修改ID起始点,当前值是%d(高级操作)\n",BEGIN_NUM);
|
||||
printf("setend EndVal 修改ID终点,当前值是%d(高级操作)\n",NUM);
|
||||
printf("updatecookie 重新获取cookie(高级操作)\n");
|
||||
printf("===退出操作===\n");
|
||||
printf("enterauto 进入自动模式(这个操作将退出当前模式)\n");
|
||||
printf("exit 退出特殊模式\n");
|
||||
return 0;
|
||||
}
|
||||
else if(cmd=="enterauto")
|
||||
{
|
||||
printf("将进入自动模式!请再次确认当前参数并键入enterautoyes\n");
|
||||
printf("当前参数: HEAD_STR=%s BeginVal=%d EndVal=%d\n",HEAD_STR,BEGIN_NUM,NUM);
|
||||
return 0;
|
||||
}
|
||||
else if(cmd=="updatecookie")
|
||||
{
|
||||
printf("重新获取Cookie中...\n");
|
||||
prepareCookie();
|
||||
printf("重新获取Cookie完成\n");
|
||||
return 0;
|
||||
}
|
||||
else if(cmd=="sethead")
|
||||
{
|
||||
printf("设置HEAD_STR\n");
|
||||
string headstr;
|
||||
if(istr>>headstr)
|
||||
{
|
||||
if(headstr.size()!=8)
|
||||
{
|
||||
printf("新HEAD_STR长度不正确\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("设置HEAD_STR中...\n");
|
||||
_head_str=new char[16];
|
||||
memset(_head_str,0,16);
|
||||
strcpy(_head_str,headstr.c_str());
|
||||
printf("设置完成.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("获取HEAD_STR失败.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(cmd=="setbegin")
|
||||
{
|
||||
printf("设置ID起始点\n");
|
||||
int val;
|
||||
if(istr>>val)
|
||||
{
|
||||
if(val<0)
|
||||
{
|
||||
printf("不能设置负数为ID起始点\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("设置ID起点...\n");
|
||||
_beginnum=val;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("读取ID起始点失败\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(cmd=="setend")
|
||||
{
|
||||
printf("设置ID终点(含).\n");
|
||||
int val;
|
||||
if(istr>>val)
|
||||
{
|
||||
if(val<0||val<=BEGIN_NUM)
|
||||
{
|
||||
printf("所设置的ID终点值不正确.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("设置ID终点...\n");
|
||||
_num=val;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("读取ID终点失败\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(cmd=="enterautoyes")
|
||||
{
|
||||
printf("设置常规启动标识...\n");
|
||||
_begin_after_singlemode=true;
|
||||
return -1;
|
||||
}
|
||||
else if(cmd=="exit")
|
||||
{
|
||||
printf("退出特殊模式.\n");
|
||||
return -1;
|
||||
}
|
||||
else if(cmd=="query")
|
||||
{
|
||||
printf("单点查询模式\n");
|
||||
string id;
|
||||
if(istr>>id)
|
||||
{
|
||||
printf("查询ID=%s的记录\n",id.c_str());
|
||||
if(id.size()!=10)
|
||||
{
|
||||
printf("不正确的ID长度.\n");
|
||||
return 0;
|
||||
}
|
||||
int val;
|
||||
sscanf(id.c_str()+8,"%d",&val);
|
||||
|
||||
printf("启动网络程序...\n");
|
||||
BeginNetwork();
|
||||
printf("执行查询前...\n");
|
||||
RemoteQuery(id.substr(0,8),val);
|
||||
printf("执行查询完毕.\n");
|
||||
|
||||
printf("调用解析前...\n");
|
||||
cashinfo info=LocalParse(val);
|
||||
printf("解析完成.\n");
|
||||
printf("[%s] 余额:%.2f 过渡余额:%.2f\n",info.status?"解析成功":"解析失败",info.current,info.transforming);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("读取ID失败.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cmd.size()) printf("未知的命令.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
void SingleModeMain()
|
||||
{
|
||||
printf("已进入特殊模式.\n");
|
||||
_ClearKbhit();
|
||||
printf("键入指令以实现功能\n");
|
||||
while(1)
|
||||
{
|
||||
printf("SingleMode> ");
|
||||
fflush(stdout);
|
||||
|
||||
string command;
|
||||
getline(cin,command);
|
||||
if(ParseCommand(command)<0) break;
|
||||
}
|
||||
printf("退出特殊模式...\n");
|
||||
}
|
||||
|
||||
bool EnterSingleMode()
|
||||
{
|
||||
printf("按下任何按键来中断常规启动. 3秒后将进入自动模式.\n");
|
||||
int interval=50;/// ms
|
||||
int looptime=3000/interval;
|
||||
|
||||
for(int i=0;i<looptime;i++)
|
||||
{
|
||||
if(kbhit())
|
||||
{
|
||||
SingleModeMain();
|
||||
return true;
|
||||
}
|
||||
this_thread::sleep_for(chrono::milliseconds(interval));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if(EnterSingleMode())
|
||||
{
|
||||
printf("已从特殊模式退出.\n");
|
||||
if(!_begin_after_singlemode) return 0;
|
||||
}
|
||||
|
||||
printf("已启动为自动模式.\n");
|
||||
printf("Target: Fetch %s01 to %s%02d...\n",HEAD_STR,HEAD_STR,NUM);
|
||||
|
||||
if(strlen(HEAD_STR)!=10-2)
|
||||
{
|
||||
printf("学号设置错误,不能进入自动模式.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("初始化随机数...\n");
|
||||
srand(time(NULL));
|
||||
printf("创建临时文件夹..\n");
|
||||
@ -136,7 +354,7 @@ int main()
|
||||
BeginNetwork();
|
||||
|
||||
printf("开始查询...\n");
|
||||
for(int i=0;i<NUM;i++)
|
||||
for(int i=BEGIN_NUM;i<NUM;i++)
|
||||
{
|
||||
RemoteQuery(HEAD_STR,i+1);
|
||||
}
|
||||
@ -196,6 +414,7 @@ int main()
|
||||
string fname;
|
||||
printf("请输入保存文件名称,时间将会自动追加到结尾,后缀名为txt\n");
|
||||
getline(cin,fname);
|
||||
fname=string("result/")+fname;
|
||||
s_time now=whattime();
|
||||
char gpbuff[1024];
|
||||
sprintf(gpbuff,"-%04d%02d%02d-%02d%02d%02d",now.year,now.mon,now.day,now.hour,now.min,now.sec);
|
||||
@ -207,7 +426,7 @@ int main()
|
||||
for(size_t i=0;i<vec.size();i++)
|
||||
{
|
||||
if(vec.at(i).status) ofs<<i+1<<" "<<vec.at(i).current<<" "<<vec.at(i).transforming<<endl;
|
||||
else ofs<<i+1<<" -1 -1"<<endl;
|
||||
else ofs<<i+1+BEGIN_NUM<<" -1 -1"<<endl;
|
||||
}
|
||||
ofs.flush();
|
||||
|
||||
|
Reference in New Issue
Block a user