• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ inode_state类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中inode_state的典型用法代码示例。如果您正苦于以下问题:C++ inode_state类的具体用法?C++ inode_state怎么用?C++ inode_state使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了inode_state类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: fn_make

void fn_make (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if (words.size() <= 0){
      cout << "mkdir: missing operand" << endl;
      return;
   }
   wordvec newData(words.begin()+2, words.end());

   wordvec pathvec = split (words[1], "/");
   string fullpath = "";
   string filename = *(pathvec.end()-1);
   for (auto it = pathvec.begin(); it != pathvec.end()-1; ++it)
      fullpath += (*it + "/");
   inode_ptr res = resolvePath(fullpath, state.getCwd()); //resulting path before filename
   if (res == nullptr) return;
   inode_ptr file = res->getContents()->getNode(filename); //search directory for filename if existing
   if (file != nullptr && res != nullptr) {
      if(file->isDirectory()) //getContents()->getNode(words[1])
         return;
      file->getContents()->writefile(newData);
      return;
   }
   res->getContents()->mkfile(filename);
   res->getContents()->getNode(filename)->getContents()->writefile(newData);

   inode_ptr ogcwd = state.getCwd();
   //inode_ptr newFile = state.getCwd()->getContents()->mkfile(words[1]);
   //wordvec newData(words.begin()+2, words.end());
   //newFile->getContents()->writefile(newData);
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:31,代码来源:commands.cpp


示例2: fn_cd

void fn_cd (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   /*
   if(words.size() > 1) {
      wordvec nav_path = split(words[1], "/");
      state.final_cd(nav_path);
   } else {
      wordvec root_dir{};
      state.final_cd(root_dir);
   }
   */
   if(words.size() > 2){
      complain() << "cd: Too many arguments" << endl;
      return;
   }
   if(words.size() > 1) path_name_set(words.at(1));
   if(words.size() == 1){
      state.setCwd(state.get_root());
      return;
   } else if(words.at(1).at(0) == '/'){
      state.setCwd(state.get_root());
   }
   wordvec nav_path = split(words.at(1), "/");
   state.final_cd(nav_path);
}
开发者ID:ddsun95,项目名称:projects,代码行数:26,代码来源:commands.cpp


示例3: print_dir

void print_dir(inode_state& state) {
   cout << pathname(state.get_contents().at("."),
            state.get_root()->get_inode_nr()) << ":" << endl;
   for(auto elem : state.get_contents()) {
      cout << "\t" << elem.second->get_inode_nr() << " "
      << elem.second->size() << " "
      << elem.first << " "
      << endl;
   }
   cout << endl;
}
开发者ID:oniemann,项目名称:CPP-Projects,代码行数:11,代码来源:commands.cpp


示例4: fn_cat

void fn_cat (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   string filename = *(words.end()-1);
   inode_ptr ogcwd = state.getCwd();
   inode_ptr res = resolvePath(words[1], state.getCwd());
   if (res == nullptr){
      throw command_error ("cat: " + filename + ": file does not exist");
      return; }
   if (res->isDirectory()) return; //error here
   cout << res->getContents()->readfile() << endl;
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:12,代码来源:commands.cpp


示例5: fn_ls

void fn_ls (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   inode_ptr ogcwd = state.getCwd();
   inode_ptr res = ogcwd;
   if(words.size() > 1)
      res = resolvePath(words[1], state.getCwd());
   if (res == nullptr) return;
   auto pathList = res->getContents()->getAllPaths();
   state.setCwd(res);
   fn_pwd(state, words);
   for (size_t i = 0; i < pathList.size(); i++){
      cout << pathList[i] << endl;
   }
   state.setCwd(ogcwd);
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:16,代码来源:commands.cpp


示例6: fn_rm

void fn_rm (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if (words.size() <= 0) return; //error here?
   wordvec pathvec = split(words[1],"/");
   string fullpath = "";
   string name = *(pathvec.end()-1);
   for (auto it = pathvec.begin(); it != pathvec.end()-1; ++it)
      fullpath += (*it + "/");
   inode_ptr res = resolvePath(fullpath,state.getCwd());
   if (res == nullptr) return; //error
   inode_ptr rmfile = res->getContents()->getNode(name);
   if (res != nullptr && rmfile != nullptr){
      if(rmfile->isDirectory()){
         if(rmfile->getContents()->getAllPaths().size() <= 2){
            res->getContents()->remove(name);
            return;
         } else { return; /* not empty */ }}
         res->getContents()->remove(name);
         return;
   }
   /*
   for (auto it = words.begin()+1; it != words.end(); ++it){
      state.getCwd()->getContents()->remove(*it);
   }
   */
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:27,代码来源:commands.cpp


示例7: fn_make

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);
}
开发者ID:ddsun95,项目名称:projects,代码行数:16,代码来源:commands.cpp


示例8: fn_mkdir

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);
}
开发者ID:jrzidow,项目名称:Advanced_Programming,代码行数:8,代码来源:commands.cpp


示例9: fn_prompt

void fn_prompt (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   string temp;
   for(unsigned int i =1; i < words.size(); i++) 
      temp += words[i] + " ";
   state.set_prompt(temp);
}
开发者ID:jrzidow,项目名称:Advanced_Programming,代码行数:8,代码来源:commands.cpp


示例10: fn_rmr

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);
   }
}
开发者ID:ddsun95,项目名称:projects,代码行数:25,代码来源:commands.cpp


示例11: fn_ls

//DONEDONEDONEDONEDONEDONEDONE///////////////////////////////////////
void fn_ls (inode_state& state, const wordvec& words){
   bool r = false;
   string orig = pathname(state.get_contents().at("."),
                  state.get_root()->get_inode_nr());
   if (words.size() > 1) {
      for(auto word = words.begin()+1; word != words.end(); word++) {
         if((*word)[0] == '/') r = true;
         state.set_cwd(split(*word,"/"), r);
         print_dir(state);
         state.set_cwd(split(orig,"/"),true);
      }
   }
   else
      print_dir(state);         

   DEBUGF ('c', state);
   DEBUGF ('c', words);
}
开发者ID:oniemann,项目名称:CPP-Projects,代码行数:19,代码来源:commands.cpp


示例12: fn_lsr

void fn_lsr (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);

   inode_ptr ogcwd = state.getCwd();
   inode_ptr newCwd = ogcwd;
   if (words.size() > 0){
      newCwd = resolvePath(words[1], state.getCwd());
      state.setCwd(newCwd);
   }
   auto pathList = newCwd->getContents()->getAllDirs();
   wordvec ls {"ls"};
   fn_ls(state, ls);
   for(int i = 0; i < pathList.size(); i++){
      DFS(pathList[i], state);
   }
   state.setCwd(ogcwd);
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:18,代码来源:commands.cpp


示例13: fn_pwd

void fn_pwd (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if(words.size() > 1) {
      complain() << "pwd: Too many arguments" << endl;
      return;
   }
   state.fn_pwd();
}
开发者ID:ddsun95,项目名称:projects,代码行数:9,代码来源:commands.cpp


示例14: fn_prompt

void fn_prompt (inode_state& state, const wordvec& words){
   string str {};
   for (auto iter = words.begin()+1; iter != words.end(); ++iter){
      str = str + *iter + " ";
   }
   state.set_prompt(str);
   DEBUGF ('c', state);
   DEBUGF ('c', words);
}
开发者ID:oniemann,项目名称:CPP-Projects,代码行数:9,代码来源:commands.cpp


示例15: fn_make

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); 
   
}
开发者ID:jrzidow,项目名称:Advanced_Programming,代码行数:9,代码来源:commands.cpp


示例16: fn_cd

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]);} 
}
开发者ID:jrzidow,项目名称:Advanced_Programming,代码行数:19,代码来源:commands.cpp


示例17: fn_mkdir

void fn_mkdir (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);

   if (words.size() <= 0){
      cout << "mkdir: missing operand" << endl;
      return;
   }
   //root case?
   if (words[1] == "/"){
      inode_ptr ogcwd = state.getCwd();
      auto root = state.getCwd()->getContents()->mkdir(words[1]);
      root->getContents()->setPath("..", ogcwd);
      root->getContents()->setPath(".", root);
      return;
   }

   wordvec pathvec = split(words[1], "/");
   string dirname = *(pathvec.end()-1);
   string fullpath = "";
   for (auto it = pathvec.begin(); it != pathvec.end()-1; ++it)
      fullpath += (*it + "/");
   inode_ptr res = resolvePath(fullpath,state.getCwd());
   if (res == nullptr) return;
   inode_ptr directory = res->getContents()->getNode(dirname);
   if (directory != nullptr && res != nullptr) //if filename exists and path exists
      //dont overwrite anything (ie file or directory)
      return;
   inode_ptr dir = res->getContents()->mkdir(dirname);
   dir->getContents()->setPath("..", res);
   dir->getContents()->setPath(".",res->getContents()->getNode(dirname));

   /*if (state.getCwd()->getContents()->getNode(filename) != nullptr)
      return; */
   /*
   inode_ptr ogcwd = state.getCwd();
   for (auto it = words.begin()+1; it != words.end(); ++it){
      auto newDir = state.getCwd()->getContents()->mkdir(*it);
      newDir->getContents()->setPath("..", ogcwd);
      newDir->getContents()->setPath(".", newDir);
   }
   */
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:43,代码来源:commands.cpp


示例18: fn_ls

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);
   } 

}
开发者ID:jrzidow,项目名称:Advanced_Programming,代码行数:19,代码来源:commands.cpp


示例19: DFS

void DFS(string s, inode_state& state){
   wordvec newLs {"ls", s};
   fn_ls(state, newLs);
   auto dirList = state.getCwd()->getContents()->getAllDirs();
   if (dirList.size() == 0)
      return;
   map<string, int> disc;
   for (int i = 0; i < dirList.size(); i++){
      disc[dirList[i]] = 0;
   }
   for (auto it = disc.begin(); it != disc.end(); ++it){
      if (it->second == 0){
     	disc[it->first] = 1;
     	inode_ptr ogcwd = state.getCwd();
     	state.setCwd(state.getCwd()->getContents()->getNode(it->first));
     	DFS(it->first, state);
     	state.setCwd(ogcwd);
      }
 	}
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:20,代码来源:commands.cpp


示例20: fn_pwd

void fn_pwd (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   string pwd = state.getCwd()->getContents()->getPwd();
   if (pwd.length() == 2){
      cout << "/" << endl;
   } else {
      pwd = pwd.substr(2, pwd.length()-2);
      cout << pwd << endl;
   }
}
开发者ID:coltonUCSC,项目名称:cs109,代码行数:11,代码来源:commands.cpp



注:本文中的inode_state类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ input类代码示例发布时间:2022-05-31
下一篇:
C++ initializer_list类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap