Beispiel #1
0
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);
}
Beispiel #2
0
static void
listRecursive(const DirectoryPrx& dir, int depth = 0)
{
    string indent(++depth, '\t');

    NodeSeq contents = dir->list();

    for(NodeSeq::const_iterator i = contents.begin(); i != contents.end(); ++i)
    {
        DirectoryPrx dir = DirectoryPrx::checkedCast(*i);
        FilePrx file = FilePrx::uncheckedCast(*i);
        cout << indent << (*i)->name() << (dir ? " (directory):" : " (file):") << endl;
        if(dir)
        {
            listRecursive(dir, depth);
        }
        else
        {
            Lines text = file->read();
            for(Lines::const_iterator j = text.begin(); j != text.end(); ++j)
            {
                cout << indent << "\t" << *j << endl;
            }
        }
    }
}
Beispiel #3
0
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;
    }
}