int main()
{
char a[100];
char code[14][10];
char name[12];
int i,flag;
startsys();
print();
show();
/*将命令全部保存在CODE数组中*/
strcpy(code[0],"halt");
strcpy(code[1],"create");
strcpy(code[2],"open");
strcpy(code[3],"close");
strcpy(code[4],"write");
strcpy(code[5],"read");
strcpy(code[6],"del");
strcpy(code[7],"mkdir");
strcpy(code[8],"rmdir");
strcpy(code[9],"dir");
strcpy(code[10],"cd");
strcpy(code[11],"back");
strcpy(code[12],"list");
strcpy(code[13],"root");
while(1)
{
scanf("%s",a);
for(i=0;i<14;i++)
{
if(!strcmp(code[i],a))
break;
}
switch(i)
{
case 0: //*--退出文件系统--//
my_exitsys();
return 0;
case 1: //*--创建文件--//
scanf("%s",name);
flag = my_create(name);
if(flag==-1)
{
printf("Error: \n The namelength is too long !\n");
}
else if(flag==-2)
{
printf("Error: \n The direct item is already full !\n");
}
else if(flag==-3)
{
printf("Error: \n The number of openfile is too much !\n");
}
else if(flag==-4)
{
printf("Error: \n The name is already in the direct !\n");
}
else
{
printf("Successfully create a file! \n");
}
show();
break;
case 2://--打开文件--//
scanf("%s",name);
fd = my_open(name);
if(fd == -1)
{
printf("Error: \n The open file not exit! \n");
}
else if(fd == -2)
{
printf("Error: \n The file have already opened! \n");
}
else if(fd == -3)
{
printf("Error: \n The number of open file is too much! \n");
}
else if(fd == -4)
{
printf("Error: \n It is a direct,can not open for read or write! \n");
}
else
{
printf("Successfully opened! \n");
}
show();
break;
case 3://--关闭文件--//
scanf("%s",name);
flag = my_close(name);
if(flag == -1)
{
printf("Error:\n The file is not opened ! \n");
}
else
{
printf("Successfully closed! \n");
}
show();
break;
case 4:/*--写文件--*/
if(openfilelist[fd].attribute == 0)
{
printf("Error:\n The file is not opened ! \n");
}
else
{
flag = my_write(fd);
if(flag == 1)
{
printf("Successfully write! \n");
}
else
{
printf("Error:\n The disk size is not enough! \n");
}
}
show();
break;
case 5:/*--读文件--*/
if(fd ==-1)
{
printf("Error:\n The file is not opened ! \n");
}
else
{
flag = my_read(fd);
}
show();
break;
case 6://*--删除文件--
scanf("%s",name);
flag = my_rm(name);
if(flag == -1)
{
printf("Error:\n The file not exit! \n");
}
else if(flag == -2)
{
printf("Error:\n The file is opened,please first close it ! \n");
}
else
{
printf("Successfully delete! \n");
}
show();
break;
case 7://*--创建子目录--/
scanf("%s",name);
flag = my_mkdir(name);
if(flag == -1)
{
printf("Error:\n The length of name is to long! \n");
}
else if(flag == -2)
{
printf("Error:\n The direct item is already full ! \n");
}
else if(flag == -3)
{
printf("Error:\n The name is already in the direct ! \n");
}
else if(flag == -4)
{
printf("Error:\n // can not in the name of a direct ! \n");
}
else if(flag == -5)
{
printf("Error: \n The disk space is full!\n");
}
else if(flag == -6)
{
printf("Error: \n '..' or '.' can not as the name of the direct!\n");
}
else if(flag == 1)
{
printf("Successfully make dircet! \n");
}
show();
break;
case 8://*--删除子目录--/
scanf("%s",name);
flag = my_rmdir(name);
if(flag == -1)
{
printf("Error:\n The direct is not exist! \n");
}
else if(flag == -2)
{
printf("Error:\nThe direct has son direct ,please first remove the son dircct!\n");
}
else if(flag == -3)
{
printf("Error:\n The remove is not direct ! \n");
}
else if(flag == 1)
{
printf("Successfully remove dircet! \n");
}
show();
break;
case 9://*--显示当前子目录--/
my_ls();
show();
break;
case 10:/*--更改当前目录--*/
scanf("%s",name);
flag = my_cd(name);
if(flag == -1)
{
printf("Error:\n The opened is not direct!\n");
}
else if(flag == -2)
{
printf("Error:\n! The opened is not direct\n");
}
else if(flag == -3)
{
printf("Error:\nThe '//' is too much !\n");
}
show();
break;
case 11:
flag = my_back();
if(flag == -1)
printf("Error:\n is root directory !\n");
else
printf("back Successfully!\n");
show();
break;
case 12:
list();
show();
break;
case 13:
rootprint();
show();
break;
default:
printf("\n Error!\n The command is wrong! \n");
show();
}
}
}