FC

// fc.cpp : Defines the entry point for the console application.
//
#include <stdio.h>  




#include <iostream>
#include <vector>
#include <map>
#include <string>


#include <WINDOWS.H>


using namespace std;








int movefile(const char* source_multibyte, const char *destination_multibyte)
{
//char * source_multibyte = "D:\\chuax\\nist_encryption__2018.pdf";//源文件
//char * destination_multibyte = "D:\\chuax\\backup\\nist_encryption_FINAL.pdf";//目标文件


WCHAR source_widechar[1024];
memset(source_widechar, 0, sizeof(source_widechar));
MultiByteToWideChar(CP_ACP, 0, source_multibyte, strlen(source_multibyte) + 1, source_widechar, sizeof(source_widechar) / sizeof(source_widechar[0]));




WCHAR destination_widechar[1024];
memset(destination_widechar, 0, sizeof(destination_widechar));
MultiByteToWideChar(CP_ACP, 0, destination_multibyte, strlen(destination_multibyte) + 1, destination_widechar, sizeof(destination_widechar) / sizeof(destination_widechar[0]));


//char* szStr = "测试字符串";
//WCHAR wszClassName[256];
//memset(wszClassName, 0, sizeof(wszClassName));
//MultiByteToWideChar(CP_ACP, 0, szStr, strlen(szStr) + 1, wszClassName, sizeof(wszClassName) / sizeof(wszClassName[0]));




CopyFile(source_widechar, destination_widechar, FALSE);//false代表覆盖,true不覆盖
DeleteFile(source_widechar);
return 0;
}




class CMD
{
string function_name_;
map<string, string> parameter_;


public:
void parse_cmd(char* cmd);
void checking_cmd_integrity();
int exec_func();

};


void CMD::parse_cmd(char* cmd)
{
// remove '\n'
int end = strlen(cmd);
cmd[end-1] = ' ';


vector<string> str;


while (strlen(cmd) != 0)
{
bool begin_pos_found = false;
int begin_pos = 0;
int end_pos = 0;
int length = strlen(cmd);
for (int i = 0; i < length; i++)
{
if (!begin_pos_found && (' ' != cmd[i]))
{
begin_pos = i;
begin_pos_found = true;
}

if (begin_pos_found && (' ' == cmd[i]))
{
end_pos = i;
begin_pos_found = false;
int str_length = end_pos - begin_pos;
string str_element = ((string)cmd).substr(begin_pos, end_pos);


if (i != length - 1)
{
cmd += str_length + 1;
}
else
{
cmd += str_length;
}

str.push_back(str_element);
break;
}


if (!begin_pos_found && (i == length - 1))
{
cmd = "";
}


}
}


for (int i =0; i < str.size();)
{
if (i == 0)
{
function_name_ = str[0];
i++;
}
else
{
string key = str[i];
i++;
parameter_[key] = str[i];
i++;
}
}


cout << "done" << endl;
}




void CMD::checking_cmd_integrity()
{


}


int CMD::exec_func()
{
if (function_name_ == "mv")
{
auto it = parameter_.begin();


//some error code for map is empty, wait to sovle.
if (it == parameter_.end())
{
cout << "wrong input! Please check your input and retry!" << endl;
return 1;
}


string src = it->first;
string dst = it->second;
return movefile(src.c_str(), dst.c_str());


//auto it = parameter_.find("src");
//if (it == parameter_.end())
//{
// cout << "Miss source file! Please check your input and retry!" << endl;
// return 1;
//}
//string src = it->second;


//it = parameter_.find("dst");
//if (it == parameter_.end())
//{
// cout << "Miss dstination file! Please check your input and retry!" << endl;
// return 1;
//}
//string dst = it->second;


//return movefile(src.c_str(), dst.c_str());
}


}


int main()
{


while (true)
{
cout << "please input your working directory." << endl;


char parse_obj[1024];


CMD cmd;


if (nullptr != fgets(parse_obj, 1024, stdin))
{
cmd.parse_cmd(parse_obj);
int rt = cmd.exec_func();
if (rt != 0)
{
cout << "operation fail!"<< endl;
}
}
else
{
cout << "fail to get input!! Please report to the developer." << endl;
system("pause");
return 1;
}


}


    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值