/** Reduce any %xx escape sequences to the characters they represent. **/ void unescape_url(LString& url) { register int i,j; for(i=0,j=0; j<url.size(); ++i,++j) { if((url.at(i) = url[j]) == '%') { url.at(i) = x2c(url.at(j+1), url.at(j+2)); j+= 2 ; } } if (i < url.size()) url.at(i) = '\0' ; }
LStr::clStringsVector clConsole::GetAutocompleteCommand( const LString& CMDName ) const { LStr::clStringsVector Result; if ( CMDName.empty() ) { return Result; } LString CMD = LStr::GetUpper( CMDName ); size_t Len = CMD.length(); bool Lower = LStr::IsLower( CMDName[CMDName.size()-1] ); for ( clCommandsList::const_iterator i = FCommandsList.begin(); i != FCommandsList.end(); ++i ) { if ( LStr::StartsWith( i->first, CMD ) ) { LString Tail = LStr::CopyFromPosToEnd( i->first, Len ); Result.push_back( CMDName + ( Lower ? LStr::GetLower( Tail ) : Tail ) ); } } for ( clAliasesList::const_iterator i = FAliasesList.begin(); i != FAliasesList.end(); ++i ) { if ( LStr::StartsWith( i->first, CMD ) ) { LString Tail = LStr::CopyFromPosToEnd( i->first, Len ); Result.push_back( CMDName + ( Lower ? LStr::GetLower( Tail ) : Tail ) ); } } return Result; }
void clConsole::SendCommand( const LString& CMDName ) { guard( "%s", CMDName.c_str() ); FSendCommandResult.assign( "" ); if ( CMDName.size() == 0 ) { return; } bool IsScript = ( LStr::GetUpper( LStr::GetToken( CMDName, 1 ) ) == "RS" ); // split command size_t CommandsSeparator = FindCommandsSeparator( CMDName ); LString ThisCMDString = CMDName; LString RestCMDString( "" ); if ( !IsScript ) { if ( CommandsSeparator ) { ThisCMDString = CMDName.substr( 0, CommandsSeparator ); RestCMDString = CMDName.substr( CommandsSeparator, CMDName.length() - CommandsSeparator ); if ( RestCMDString.length() > 0 ) { LStr::pop_front( &RestCMDString ); } } } // extract command name and parameters LString ThisCMDName = LStr::GetToken( ThisCMDString, 1 ); LString ThisCMDParam = ThisCMDString.substr( ThisCMDName.length(), ThisCMDString.length() - ThisCMDName.length() ); if ( ThisCMDParam.length() > 0 ) { LStr::pop_front( &ThisCMDParam ); } LStr::ToUpper( &ThisCMDName ); if ( IsScript ) { // execute script and return ExecuteStatement( ThisCMDParam ); return; } if ( ThisCMDName.find( "WAIT" ) == 0 ) { // Leave the rest of the command until the next frame if ( CommandsSeparator ) { QueryCommand( RestCMDString ); } return; } else { clCommandsList::const_iterator i = FCommandsList.find( ThisCMDName ); if ( i != FCommandsList.end() ) { ( i->second ).Exec( clFileSystem::ReplaceEnvVars( ThisCMDParam ) ); } else { clAliasesList::const_iterator j = FAliasesList.find( ThisCMDName ); if ( j != FAliasesList.end() ) { QueryCommand( j->second ); } else { DisplayError( "Unknown command: " + ThisCMDName ); } } } if ( CommandsSeparator ) { SendCommand( RestCMDString ); } unguard(); }