コード例 #1
0
ファイル: commands.cpp プロジェクト: ddsun95/projects
void fn_rmr (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if(words.size() == 1){
      complain() << "rmr: Specify file name" << endl;
   } else if(words.size() > 2){
      complain() << "rmr: Too many arguments" << endl;
   } else if(words.at(1) == "." or words.at(1) == ".." or 
      (words.at(1).at(0) == '/' and words.at(1).length() == 1)){
      complain() << "rmr: Cannot remove directory" << endl;
   } else {
      path_name_set(words.at(1));
      const auto placeholder = state.get_cwd();
      if(words.at(1).at(0) == '/') state.setCwd(state.get_root());
      wordvec navpath = split(words[1], "/");
      string ffname = navpath.back();
      if(navpath.size() == 1){
         state.function_rmr(state.get_cwd(), ffname);
         return;
      }
      wordvec filepath(&navpath[0], &navpath[navpath.size() - 1]);
      state.function_final_rmr(ffname, filepath);
      state.setCwd(placeholder);
   }
}
コード例 #2
0
ファイル: commands.cpp プロジェクト: ddsun95/projects
void fn_cat (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if(words.size() < 2){
      complain() << "cat: Too few arguments" << endl;
   } else {
      const string firstword = words.at(1);
      path_name_set(firstword);
      if(firstword.at(0) == '/' and firstword.length() > 1){
         string navname = firstword.substr(1, firstword.length());
         cout << navname << endl;
         const auto placeholder = state.get_cwd();
         wordvec nav_path {};
         nav_path = split(navname, "/");
         state.setCwd(state.get_root());
         state.final_func_cat(nav_path);
         state.setCwd(placeholder);
         return;
      } else if(firstword.length() == 1 and firstword.at(0) == '/'){
          complain() << "cat: /: File is Directory" << endl;
          return;
      }
      wordvec nav_path = split(firstword, "/");
      state.final_func_cat(nav_path);
   }
}
コード例 #3
0
void fn_mkdir (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);

   inode_ptr cwd = state.get_cwd();
   const string filename = words[1];
   cwd->mkdirectory(filename, cwd);
}
コード例 #4
0
void fn_make (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
     
   inode_ptr cwd = state.get_cwd();
   wordvec w(words.begin() + 1, words.end()); 
   cwd->mkfile(cwd,w); 
   
}
コード例 #5
0
void fn_ls (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   
   for(unsigned int i = 0; i<state.directory_path_name.size(); i++)
      cout << state.directory_path_name[i];
      cout << ":\n";
   
   if(words.size() == 1){
      inode_ptr cwd = state.get_cwd();
      cwd->list_files(cwd);  

   //treat "ls /" the same as "ls "  
   } else if(words[1] == "/" and words.size() == 2){
      inode_ptr cwd = state.get_cwd();
      cwd->list_files(cwd);
   } 

}
コード例 #6
0
ファイル: commands.cpp プロジェクト: ddsun95/projects
void fn_lsr (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if(words.size() > 2){
      complain() << "lsr: Too many arguments" << endl;
      return;
   } else if(words.size() == 1){
      state.function_list_r(state.get_cwd());
   } else if(words.at(1).at(0) == '/'){
      if(words.at(1).length() == 1){
         state.function_list_r(state.get_root());
         return;
      }
      const auto placeholder = state.get_cwd();
      state.setCwd(state.get_root());
      wordvec nav_path = split(words.at(1), "/");
      state.function_list_r(state.get_working_ptr(nav_path));
      state.setCwd(placeholder);
   } else {
      wordvec nav_path = split(words[1], "/");
      state.function_list_r(state.get_working_ptr(nav_path));
   }
}
コード例 #7
0
ファイル: commands.cpp プロジェクト: ddsun95/projects
void fn_make (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if(words.size() < 2){
      complain() << "make: Specify pathname" << endl;
      return;
   }
   const auto placeholder = state.get_cwd();
   if(words.at(1).at(0) == '/'){
      state.setCwd(state.get_root());
   }
   wordvec nav_path  = split(words[1], "/");
   wordvec insertion(&words[2], &words[words.size()]);
   state.final_make_file(nav_path, insertion);
   state.setCwd(placeholder);
}
コード例 #8
0
void fn_cd (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);

   if(words.size() > 2)
      throw yshell_exn("Too many operands");

   inode_ptr cwd = state.get_cwd();
   state.set_cwd(cwd, words[1]);

   if(words[1] == "..") 
      {state.directory_path_name.pop_back();}

   else if (state.directory_path_name.size() > 1)
      {state.directory_path_name.push_back("/"+words[1]);}

   else if (state.directory_path_name.size() == 1)
      {state.directory_path_name.push_back(words[1]);} 
}
コード例 #9
0
ファイル: commands.cpp プロジェクト: ddsun95/projects
void fn_mkdir (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   //NEED TO CHECK IF THE DIR IS ALREADY IN THE DIR.
   if(words.size() < 2){
      complain() << "mkdir: Too few arguments" << endl;
   } else if(words.size() > 2) {
      complain() << "mkdir: Too many arguments" << endl;
   } else {
      path_name_set(words.at(1));
      const auto placeholder = state.get_cwd();
      if(words.at(1).at(0) == '/') {
         state.setCwd(state.get_root());
      }
      path_name_set(words.at(1));
      wordvec nav_path = split(words.at(1), "/");
      state.final_mkdir(nav_path);
      state.setCwd(placeholder);
   }
}
コード例 #10
0
void fn_cat (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   

   if (words.size() >= 2){
      inode_ptr cwd = state.get_cwd();
      
      for(unsigned int i = 1; i<words.size(); i++){
         string w(words.at(i));
         cwd->locate_plain_file(cwd, w);
         cout << '\n';  
      }
   } else if (words.size() == 1){
      throw yshell_exn("cat: No filename specified");
   } 
/*
    else if(words.size() > 2){
      throw yshell_exn("cat: Too many operands");
   }
*/
}