#include <iostream>
#include <vector>
#include <sstream>
#define pb push_back
using namespace std;
#include "HELP.h"
#include "_FILE.h"
#include "UFD.h"
#include "USER.h"
#include "MFD.h"
#include "LOGIN.h"
#include "CD.h"
#include "DIR.h"
#include "CREATE.h"
#include "DELETE.h"
#include "OPEN.h"
#include "CLOSE.h"
#include "READ.h"
#include "WRITE.h"
#include "CD.h"
#include "MKDIR.h"
#include "RMDIR.h"
int main()
{
//freopen("input.txt","r",stdin);
int user=-1;//当前用户指针
int cata=-1;//当前目录指针
MFD M;//创建一个主文件目录类
//界面命令输入前缀格式
cout<<"~";
if(user!=-1) cout<<"\\"<<M.Get_user_name(user);
if(cata!=-1) cout<<"\\"<<M.Get_cata_name(user,cata);
cout<<":>";
M.Add_user("root","123");//添加一个超级用户
help();//显示命令格式
while(1){
cout<<"~";
if(user!=-1) cout<<"\\"<<M.Get_user_name(user);
if(cata!=-1) cout<<"\\"<<M.Get_cata_name(user,cata);
cout<<":>";
//------处理命令,判断合法性和对应的操作
string s;
getline(cin,s);
stringstream ss(s);
string op[20];
op[0]=op[1]=op[2]="";
int cnt=0;
while(ss>>op[cnt]){
cnt++;
}
if(cnt>3) {
cout<<"Command format error!\n";
continue;
}
//------
//选择对应的操作,cnt==3则包含路径,cnt==2则不包含路劲
if(op[0] == "login")
{
if(cnt!=3) cout<<"Command format error!\n";
else
user = LOGIN(M,op[1],op[2]);
}
if(op[0]=="help"){
help();
}
if(user!=-1) {
if(op[0] == "add"){
if(cnt==3&&user==0)
M.Add_user(op[1],op[2]);
else cout<<"Command format error!\n";
}
else if(op[0] == "dir"){
if(cnt!=1) cout<<"Command format error!\n";
else
DIR(M,user,cata);
}
else if(op[0] == "create"){
if(cnt==2)
CREATE(M,user,cata,"",op[1]);
else if(cnt==3) CREATE(M,user,cata,op[1],op[2]);
else {
cout<<"Command format error!\n";
}
}
else if(op[0] == "delete"){
if(cnt==2)
DELETE(M,user,cata,"",op[1]);
else if(cnt==3) DELETE(M,user,cata,op[1],op[2]);
else {
cout<<"Command format error!\n";
}
}
else if(op[0] == "open"){
if(cnt==2)
OPEN(M,user,cata,"",op[1]);
else if(cnt==3) OPEN(M,user,cata,op[1],op[2]);
else {
cout<<"Command format error!\n";
}
}
else if(op[0] == "close"){
if(cnt==2)
CLOSE(M,user,cata,"",op[1]);
else if(cnt==3) CLOSE(M,user,cata,op[1],op[2]);
else {
cout<<"Command format error!\n";
}
}
else if(op[0] == "read"){
if(cnt==2)
READ(M,user,cata,"",op[1]);
else if(cnt==3) READ(M,user,cata,op[1],op[2]);
else {
cout<<"Command format error!\n";
}
}
else if(op[0] == "write"){
if(cnt==2)
WRITE(M,user,cata,"",op[1]);
else if(cnt==3) WRITE(M,user,cata,op[1],op[2]);
else {
cout<<"Command format error!\n";
}
}
else if(op[0] == "cd"){
if(cnt>2) {
cout<<"Command format error!\n";
continue;
}
CD(M,user,cata,op[1]);
}
else if