4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Executor non-inline non-template implementation */
26 #include "Executor.hh"
27 //#include "Executor.ih"
31 //#include "Executor.mpp"
33 ///////////////////////////////cc.p////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::console::Executor
38 prefix_ bool senf::console::Executor::operator()(ParseCommandInfo const & command,
39 std::ostream & output)
41 SENF_LOG(( "Executing: " << command ));
44 cwd_ = boost::static_pointer_cast<DirectoryNode>(
45 root().shared_from_this());
47 switch(command.builtin()) {
48 case ParseCommandInfo::NoBuiltin :
51 case ParseCommandInfo::BuiltinCD :
52 if ( command.arguments() &&
53 ! chdir(command.arguments().begin()[0]) )
54 output << "invalid directory\n";
57 case ParseCommandInfo::BuiltinLS :
58 for (DirectoryNode::child_iterator i (cwd().children().begin());
59 i != cwd().children().end(); ++i)
60 output << i->first << "\n";
63 case ParseCommandInfo::BuiltinPUSHD :
64 dirstack_.push_back(cwd_);
65 if ( command.arguments()
66 && ! chdir(command.arguments().begin()[0]) )
67 output << "invalid directory\n";
70 case ParseCommandInfo::BuiltinPOPD :
71 if (! dirstack_.empty()) {
72 cwd_ = dirstack_.back();
77 case ParseCommandInfo::BuiltinEXIT :
78 throw ExitException();
83 prefix_ bool senf::console::Executor::chdir(ParseCommandInfo::argument_value_type const & path)
86 DirectoryNode::ptr dir (cwd_.lock());
87 ParseCommandInfo::token_iterator i (path.begin());
88 ParseCommandInfo::token_iterator const i_end (path.end());
89 if (i != i_end && i->value().empty()) {
90 dir = boost::static_pointer_cast<DirectoryNode>(
91 root().shared_from_this());
94 for (; i != i_end; ++i) {
95 if (i->value() == "..") {
98 dir = boost::static_pointer_cast<DirectoryNode>(
99 root().shared_from_this());
101 else if (! i->value().empty() && i->value() != ".")
102 dir = boost::static_pointer_cast<DirectoryNode>(
103 (*dir)[i->value()].shared_from_this());
107 catch (std::bad_cast &) {
110 catch (UnknownNodeNameException &) {
116 ///////////////////////////////cc.e////////////////////////////////////////
118 //#include "Executor.mpp"
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"