bool Interpreter::SignalType::Get( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); const GenericSignal& signal = inInterpreter.StateMachine().ControlSignal(); string name = inInterpreter.GetToken(); if( !::stricmp( name.c_str(), "Channels" ) ) { inInterpreter.Out() << signal.Channels(); } else if( !::stricmp( name.c_str(), "Elements" ) ) { inInterpreter.Out() << signal.Elements(); } else { CommandInterpreter::ArgumentList args; inInterpreter.ParseArguments( name, args ); if( ::stricmp( name.c_str(), "Signal" ) ) throw bciexception( "Use 'Signal' to address the signal" ); if( args.size() != 1 || args[0].size() != 2 ) throw bciexception( "Expected two signal indices" ); int idx1 = ::atoi( args[0][0].c_str() ) - 1, idx2 = ::atoi( args[0][1].c_str() ) - 1; if( idx1 < 0 || idx2 < 0 || idx1 >= signal.Channels() || idx2 >= signal.Elements() ) throw bciexception( "Signal index out of range" ); inInterpreter.Out() << signal( idx1, idx2 ); } return true; }
bool FileType::Extract( CommandInterpreter& inInterpreter ) { string file = inInterpreter.GetToken(); if( !::stricmp( file.c_str(), "Base" ) ) inInterpreter.Out() << FileUtils::ExtractBase( inInterpreter.GetToken() ); else inInterpreter.Out() << FileUtils::ExtractFile( file ); return true; }
bool DirectoryType::Exists( CommandInterpreter& inInterpreter ) { bool result = FileUtils::IsDirectory( inInterpreter.GetToken() ); inInterpreter.Out() << ( result ? "true" : "false" ); return true; }
bool StateType::List( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); inInterpreter.Out() << GetState( inInterpreter ); return true; }
bool DirectoryType::Make( CommandInterpreter& inInterpreter ) { string dir = inInterpreter.GetToken(); if( !FileUtils::MakeDirectory( dir ) ) inInterpreter.Out() << "Could not make directory \"" << dir << "\""; return true; }
bool PathType::Exists( CommandInterpreter& inInterpreter ) { string path = inInterpreter.GetToken(); bool result = FileUtils::IsFile( path ) || FileUtils::IsDirectory( path ); inInterpreter.Out() << ( result ? "true" : "false" ); return true; }
bool StateType::Get( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); const State& state = GetState( inInterpreter ); // GetState() tests for existence of the state. inInterpreter.Out() << inInterpreter.StateMachine().GetStateValue( state.Name().c_str() ); return true; }
bool StateType::Exists( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); bool exists = inInterpreter.StateMachine().States().Exists( inInterpreter.GetToken() ); inInterpreter.Out() << ( exists ? "true" : "false" ); return true; }
bool LineType::Read( CommandInterpreter& inInterpreter ) { string line; if( !inInterpreter.ReadLine( line ) ) throw bciexception( "No input associated with command interpreter of type " << ClassName( typeid( inInterpreter ) ) ); inInterpreter.Out() << line; return true; }
bool StatesType::List( CommandInterpreter& inInterpreter ) { Lock lock( inInterpreter.StateMachine() ); string pattern = inInterpreter.GetRemainingTokens(); if( pattern.empty() ) pattern = "*"; const StateList& states = inInterpreter.StateMachine().States(); for( int i = 0; i < states.Size(); ++i ) if( WildcardMatch( pattern, states[i].Name(), false ) ) inInterpreter.Out() << states[i] << '\n'; return true; }
bool DirectoryType::ListSelection( CommandInterpreter& inInterpreter, const string& inDir, const string& inWildcard, bool (*inSelector)( const string& ) ) { string dir = inDir.empty() ? "." : inDir, wildcard = inWildcard.empty() ? "*" : inWildcard; dir = FileUtils::CanonicalPath( dir ); FileUtils::List list; if( !FileUtils::ListDirectory( dir, list ) ) throw bciexception( "Could not list directory \"" << dir << "\"" ); for( size_t i = 0; i < list.size(); ++i ) if( WildcardMatch( wildcard, list[i], false ) && inSelector( FileUtils::EnsureSeparator( dir ) + list[i] ) ) inInterpreter.Out() << list[i] << '\n'; return true; }
bool DirectoryType::List( CommandInterpreter& inInterpreter ) { string args; #if _WIN32 args = "/n "; #else args = "-l "; #endif string remainder = inInterpreter.GetRemainingTokens(); args += remainder; inInterpreter.Out() << ListDirectory( args ); return true; }
bool DirectoryType::Current( CommandInterpreter& inInterpreter ) { inInterpreter.Out() << FileUtils::WorkingDirectoryS(); return true; }
bool DirectoryType::Parent( CommandInterpreter& inInterpreter ) { inInterpreter.Out() << FileUtils::ParentDirectoryS( inInterpreter.GetToken() ); return true; }
bool PathType::Canonicalize( CommandInterpreter& inInterpreter ) { inInterpreter.Out() << FileUtils::CanonicalPath( inInterpreter.GetToken() ); return true; }