Missing changes from last commit
[senf.git] / Console / Executor.cc
index fdbb850..3a8c228 100644 (file)
@@ -52,11 +52,13 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
     SENF_LOG(( "Executing: " << command ));
 
     if (cwd_.expired() || ! cwd().active())
-        cwd_ = root().thisptr();
+        cwd_ = root_;
 
     try {
         switch(command.builtin()) {
         case ParseCommandInfo::NoBuiltin : {
+            if (skipping_)
+                break;
             GenericNode & node ( traverseCommand(command.commandPath()) );
             DirectoryNode * dir ( dynamic_cast<DirectoryNode*>(&node) );
             if ( dir ) {
@@ -72,23 +74,33 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
         }
 
         case ParseCommandInfo::BuiltinCD :
-            if ( command.arguments() ) {
-                if (command.arguments().begin()->size() == 1 
-                    && command.arguments().begin()->begin()->value() == "-") {
-                    if (oldCwd_.expired() || ! oldCwd_.lock()->active()) {
+            if (skipping_)
+                break;
+            try {
+                if ( command.arguments() ) {
+                    if (command.arguments().begin()->size() == 1 
+                        && command.arguments().begin()->begin()->value() == "-") {
+                        if (oldCwd_.expired() || ! oldCwd_.lock()->active()) {
+                            oldCwd_ = cwd_;
+                            cwd_ = root_;
+                        } else
+                            swap(cwd_, oldCwd_);
+                    }
+                    else {
                         oldCwd_ = cwd_;
-                        cwd_ = root().thisptr();
-                    } else
-                        swap(cwd_, oldCwd_);
-                }
-                else {
-                    oldCwd_ = cwd_;
                     cwd_ = traverseDirectory(*command.arguments().begin()).thisptr();
+                    }
                 }
             }
+            catch (IgnoreCommandException &) {
+                throw SyntaxErrorException(
+                    "'cd' cannot be skipped (don't use 'cd' in conf-files)");
+            }
             break;
             
         case ParseCommandInfo::BuiltinLS : {
+            if (skipping_)
+                break;
             DirectoryNode const & dir ( command.arguments()
                                         ? traverseDirectory(*command.arguments().begin())
                                         : cwd() );
@@ -103,22 +115,34 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
         }
 
         case ParseCommandInfo::BuiltinPUSHD :
-            dirstack_.push_back(cwd_);
-            if ( command.arguments() )
-                cwd_ = traverseDirectory(*command.arguments().begin()).thisptr();
+            dirstack_.push_back(DirEntry(cwd_, skipping_));
+            if ( ! skipping_ && command.arguments() ) {
+                try {
+                    cwd_ = traverseDirectory(*command.arguments().begin()).thisptr();
+                }
+                catch (IgnoreCommandException &) {
+                    cwd_.reset();
+                    skipping_ = true;
+                }
+            }
             break;
             
         case ParseCommandInfo::BuiltinPOPD :
             if (! dirstack_.empty()) {
-                cwd_ = dirstack_.back();
+                cwd_ = dirstack_.back().dir;
+                skipping_ = dirstack_.back().skip;
                 dirstack_.pop_back();
             }
             break;
             
         case ParseCommandInfo::BuiltinEXIT :
+            if (skipping_)
+                break;
             throw ExitException();
 
         case ParseCommandInfo::BuiltinHELP :
+            if (skipping_)
+                break;
             GenericNode const & node (command.arguments() 
                                       ? traverseNode(*command.arguments().begin())
                                       : cwd());
@@ -138,17 +162,18 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
     catch (InvalidCommandException &) {
         output << "invalid command" << std::endl;
     }
+    catch (IgnoreCommandException &) {}
 }
 
 prefix_ senf::console::GenericNode &
 senf::console::Executor::traverseNode(ParseCommandInfo::TokensRange const & path)
 {
     try {
-        return cwd().traverse(
+        return traverse(
+            cwd(),
             boost::make_iterator_range(
                 boost::make_transform_iterator(path.begin(), TraverseTokens()),
-                boost::make_transform_iterator(path.end(), TraverseTokens())),
-            autocomplete_);
+                boost::make_transform_iterator(path.end(), TraverseTokens())) );
     }
     catch (std::bad_cast &) {
         throw InvalidPathException();
@@ -162,7 +187,7 @@ prefix_ senf::console::GenericNode &
 senf::console::Executor::traverseCommand(ParseCommandInfo::CommandPathRange const & path)
 {
     try {
-        return cwd().traverse(path, autocomplete_);
+        return traverse(cwd(), path);
     }
     catch (std::bad_cast &) {
         throw InvalidPathException();