資源簡介
os作業分享,可以在mac環境編譯運行,虛擬機沒調試過
代碼片段和文件信息
#include
#include
#include
#include
#include?
#include?
#include?
#define?LEN?sizeof(struct?commandHistory)
#define?LEN1?sizeof(struct?savePath)
struct?commandHistory
{
????int?iOrder;
????char?*strDisplay_name;
????char?*strDirectory;
????struct?commandHistory?*next;
};
struct?savePath
{
????char?*path_name;
????struct?savePath?*next;
};
/*?Function?prototypes?*/
char?*?extractRoute_cd(char?*?const?char?*?int);
char?*?extractRoute_path(char?*?const?char?*?int);
struct?commandHistory?*?create_commandHistroy(int?char?*?char?*);
void?display_History(struct?commandHistory?*);
int?clear_History(struct?commandHistory*);
struct?commandHistory?*??write_History(int??char?*?char?*?struct?commandHistory?*);
void?display_singleHistory(int?int?struct?commandHistory?*);
struct?savePath?*?create_path_head(char?*);
void?write_Path(int?char?*?struct?savePath?*);
struct?savePath?*?delete_path(char?*?struct?savePath?*);
void?display_path(struct?savePath?*);
int?execu_tion(char?*);
int?main(int?argc?const?char?*?argv[])?{
????char?*strCommand_name[6]?=?{?“exit““cd?““pwd““path““history“};?//add?a?“?“?to?each?command?so?that?the?program?can?know?if?the?format?is?wrong
????char?*strUser_command1;??????????//for?saving?user‘s?input
????char?strHistory_offset1[10]?=?“history?-c“;?????//for?“strcmp“?to?find?the?offset
????char?strUser_command[100];
????char?strNew_directory[100]?=?{0};?????????//for?saving?user‘s?file?route
????char?strOffset_empty[8]?=?{“????“};?????????//“pwd“?command?does?not?have?offset
????int?iDigit=0;??????????????????????????//to?record?the?command‘s?number?of?character
????int?irecordNumber?=?0;?????????????????//to?record?which?record?“history?-[num]“?wants?to?look?for
????int?iNumber?=?0;?????//?which?command?was?executed??0?means?“exit?“;1?means?“cd?“....
????int?iTotal_execution?=?0;?//to?record?how?many?commands?were?executed.
????struct?commandHistory?*?head?=?NULL;??//use?a?chain?to?record?command?history
????struct?savePath?*?head_path?=?NULL;
????char?*strCommand_extract_cd?=?NULL;
????char?*strCommand_extract_history?=?NULL;
????char?*strCommand_extract_path?=?NULL;
????
????char?*token=NULL;
????
????int?iNumber_path?=?0;
????char?buf[80];
????while?(1)
????{
????????char?str1[100]=“+?“;
????????char?str2[100]=“-?“;
????????char?*pathDirectory?=?NULL;
????????printf(“\n$“);
????????strUser_command1?=?(char?*)malloc(100?*sizeof(char));
????????fgets(strUser_command1100stdin);
????????strcpy(strUser_command?strUser_command1);
????????
????????iDigit?=?((int)strlen(strUser_command))-1;
????????//printf(“\n%d---digit“iDigit);
????????strUser_command[iDigit]=‘\0‘;
????????free(strUser_command1);
????????//if?(head_path!=NULL)
????????//{
????????
????????if(strUser_command[0]==‘/‘||(strUser_command[0]==‘.‘&&strUser_command[1]==‘/‘))?//if?the?input?is?a
????????{
????????????int?status;
????????????status?=?execu_tion(strUser_command);
?????
- 上一篇:Qt實現動態曲線圖+文本數據的實時顯示
- 下一篇:鍋爐課程設計計算用表.xlsm
評論
共有 條評論