From 5543cc647342a405f421fecd5dead2b1d3234989 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Thu, 30 Mar 2017 16:57:57 +0800 Subject: [PATCH] Add auto-toolchain mode. Auto-Toolchain: Passing 5 paraments, this program will switch to auto mode. In this mode, data will be fetched and saved to a file automatically. Fix Bug: Now if you don't press any key, the program will enter normal mode and start fetching data with default settings. --- main.cpp | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/main.cpp b/main.cpp index 108a811..03fcd4e 100644 --- a/main.cpp +++ b/main.cpp @@ -120,7 +120,7 @@ void RemoteQuery(string PreCode,int ID) } /*****************参数设置***************/ -char _head_str[16]; +char _head_str[16]{"15080801"}; const char* HEAD_STR = _head_str; int _num = 40; @@ -330,12 +330,28 @@ bool EnterSingleMode() return false; } -int main() +bool _out_file_targeted=false; +char _out_file_name[1024]; + +int main(int argc,char* argv[]) { - if(EnterSingleMode()) + /// 如果argc==5,则进入自动模式. + if(argc!=5) { - printf("已从特殊模式退出.\n"); - if(!_begin_after_singlemode) return 0; + if(EnterSingleMode()) + { + printf("已从特殊模式退出.\n"); + if(!_begin_after_singlemode) return 0; + } + } + + if(argc==4) + { + strncpy(_head_str,argv[1],8); + sscanf(argv[2],"%d",&_beginnum); + sscanf(argv[3],"%d",&_num); + _out_file_targeted=true; + strcpy(_out_file_name,argv[4]); } printf("已启动为自动模式.\n"); @@ -421,15 +437,23 @@ int main() printf("解析完成.\n"); - 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); string fname; - printf("请输入保存文件名称,时间将会自动追加到结尾,后缀名为txt\n"); - getline(cin,fname); - fname=string("result/")+fname; - fname.append(gpbuff); - fname.append(".txt"); + if(_out_file_targeted) + { + 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); + printf("请输入保存文件名称,时间将会自动追加到结尾,后缀名为txt\n"); + getline(cin,fname); + fname=string("result/")+fname; + fname.append(gpbuff); + fname.append(".txt"); + } + else + { + fname=string(_out_file_name); + } + printf("正在保存到 %s\n",fname.c_str()); ofstream ofs(fname);