⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 linux文件系统试验 一、实验目的 学习有关linux文件管理程序如何组织的知识
💻 CPP
字号:
/***************************************************************************                          main.cpp  -  description                             -------------------    begin                : 三  8月  6 21:37:02 EDT 2003    copyright            : (C) 2003 by Jeremy    email                : zhiming_z@hotmail.com ***************************************************************************/#include "para.h"#include "function.h"int main(int argc, char *argv[]){ 	 	char char_command[INP_LEN],char_name[INP_LEN],char_big[INP_LEN],char_all[INP_LEN*2],char_ext[INP_LEN];//used to handle the string that you input	char cur_path[INP_LEN],form_cur_path[INP_LEN];		 	int i=0,k=0;	//log=clu+31 	char str_empty[INP_LEN];str_empty[0]='\0'; 	for (i=0;i<INP_LEN*2;i++)		char_all[i]='\0'; 		for (i=0;i<INP_LEN;i++) 			{				char_command[i]='\0';		char_name[i]='\0';	char_ext[i]='\0'; 			} 	 	i=0; 	//strcpy(char_all,"ls");	log_num=19;	cout<<endl<<"Welcome!"<<endl<<endl<<"you can use 'ls' to show a file list	"<<endl<<"'cd' entry name' to get into a entry.'cd..' to the upper floor "<<"or"<<" 'cd/' back to the root "<<endl<<"'del filename' to delete a file"<<endl<<endl; 	strcpy(cur_path,"/floppy"); 	printf("%s>",cur_path); 	gets(char_all); 	/*fromn here start the loop of the command*/ 		while (strcmp(char_all,"exit\0")!=0)			 	{  		i=0;	  		while ((char_all[i]!='\0')&&(char_all[i]!=32))		//receive char_all and put the command in char_command and the file name in char_name 		{ 			char_command[i]=char_all[i]; 			i++;		} 		 	if (char_all[i]==32) //receive the file name 		{ 			i++; 			k=0; 			while ((char_all[i]!='\0')&&(char_all[i]!='.')) 			{ 					char_name[k]=char_all[i]; 	k++;	i++; 		   } 		   k=0; 		} 	 		if (char_all[i]=='.') 		{ 			i++; 			while (char_all[i]!='\0') 			{char_ext[k]=char_all[i];k++;i++;} 		} 	 			 	 		if (strcmp(char_command,"ls")==0)			//i think this part should rotate for certain times e.g. 16 			{ 				getdiskinfo(); 				 				read_index(log_num);							//caution when use void read_index() use a logic cluster number 				//show_buf(buffer); 				show_list(head); 			} 		 		if (strcmp(char_command,"cd")==0) 			{ 				read_index(log_num);								//caution when use void read_cluster() use a logic cluster number 				struct file_node *p3; 				p3=find_file(char_name,str_empty); 				if ((p3!=NULL)&&(p3->isdir==1))		//to be sure it is a folder 					{	 						form_clu_num=clu_num;clu_num=p3->start_cluster;		 					form_log_num=log_num;log_num=clu_num+31; 							strcpy(form_cur_path,cur_path); 							strcpy(cur_path,p3->file_name); 							//cur_head; 					}	 				else 					cout<<"\nwrong entry! No such folder! Please check name"<<endl; 			 			} 			 		else if (strcmp(char_command,"cd..")==0) 		{ 			clu_num=form_clu_num; 			log_num=form_log_num; 			strcpy(cur_path,form_cur_path); 		}		 		 		else if (strcmp(char_command,"cd/")==0) 		{ 			clu_num=0; 			log_num=19; 			strcpy(cur_path,"floppy"); 		}			 	 		else if (strcmp(char_command,"del")==0) 			{ 				read_index(log_num);								//caution when use void read_cluster() use a logic cluster number 				if (char_name[0]=='\0') 					cout<<"waring no file name to delete!"<<endl; 				else 					{ 						struct file_node *pf; 						pf=find_file(char_name,char_ext); 						del_file(pf->num_cluster,pf->num_index,pf->start_cluster); 		 		 						//part 2 					} 			 }		//else cout<<"wrong command"<<endl;		 		for (i=0;i<INP_LEN*2;i++)		char_all[i]='\0'; 		for (i=0;i<INP_LEN;i++) 			{ 				char_command[i]='\0';		char_name[i]='\0';	char_ext[i]='\0'; 			}  		 	  	  		//log_num=clu_num+31;  		printf("\n%s>",cur_path);  		gets(char_all);  	 }		// end loop while   		return EXIT_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -