void Parser::cat(const string& name) { DirectoryPrx dir = _dirs.front(); NodeDesc d; try { d = dir->find(name); } catch(const NoSuchName&) { cout << "`" << name << "': no such file" << endl; return; } if(d.type == DirType) { cout << "`" << name << "': not a file" << endl; return; } FilePrx f = FilePrx::uncheckedCast(d.proxy); Lines l = f->read(); for(Lines::const_iterator i = l.begin(); i != l.end(); ++i) { cout << *i << endl; } }
void Parser::write(std::list<string>& args) { DirectoryPrx dir = _dirs.front(); string name = args.front(); args.pop_front(); NodeDesc d; try { d = dir->find(name); } catch(const NoSuchName&) { cout << "`" << name << "': no such file" << endl; return; } if(d.type == DirType) { cout << "`" << name << "': not a file" << endl; return; } FilePrx f = FilePrx::uncheckedCast(d.proxy); Lines l; for(std::list<string>::const_iterator i = args.begin(); i != args.end(); ++i) { l.push_back(*i); } f->write(l); }
void Parser::destroy(const std::list<string>& names) { DirectoryPrx dir = _dirs.front(); for(std::list<string>::const_iterator i = names.begin(); i != names.end(); ++i) { if(*i == "*") { NodeDescSeq nodes = dir->list(); for(NodeDescSeq::iterator j = nodes.begin(); j != nodes.end(); ++j) { try { j->proxy->destroy(); } catch(const PermissionDenied& ex) { cout << "cannot remove `" << j->name << "': " << ex.reason << endl; } } return; } else { NodeDesc d; try { d = dir->find(*i); } catch(const NoSuchName&) { cout << "`" << *i << "': no such file or directory" << endl; return; } try { d.proxy->destroy(); } catch(const PermissionDenied& ex) { cout << "cannot remove `" << *i << "': " << ex.reason << endl; } } } }
void Parser::cd(const string& name) { if(name == "/") { while(_dirs.size() > 1) { _dirs.pop_front(); } return; } if(name == "..") { if(_dirs.size() > 1) { _dirs.pop_front(); } return; } DirectoryPrx dir = _dirs.front(); NodeDesc d; try { d = dir->find(name); } catch(const NoSuchName&) { cout << "`" << name << "': no such directory" << endl; return; } if(d.type == FileType) { cout << "`" << name << "': not a directory" << endl; return; } _dirs.push_front(DirectoryPrx::uncheckedCast(d.proxy)); }