#include #include using namespace Jenga::Common; CmdLines::CmdLines( const std::string &strCmdLine ) { char temporary[8192]; int i = 0; while( i<(int)strCmdLine.size() ) { while( strCmdLine[i] == ' ' ) { i ++; } if( strCmdLine[i] == '\0' ) { break; } if( strCmdLine[i] == '/' ) { i++; // コマンド文字列(オプション名)を抽出 for( int j = 0; ; j++, i++ ) { if( isalpha( strCmdLine[i] ) || isdigit( strCmdLine[i] ) || strCmdLine[i] == '_' ) { temporary[j] = strCmdLine[i]; } else { temporary[j] = 0; break; } } while( strCmdLine[i] == ' ' ) i++; std::string command = temporary; std::string parameter = ""; if( (int)strCmdLine.size() > i && strCmdLine[i] != '/' ) { if( strCmdLine[i] == ':' ) { // ':'はコマンドとパラメータの区切り文字として認識する i++; } // パラメータを抽出 if( strCmdLine[i] == '\"' ) { i++; //ダブルクォートの中身を取り出す for( int j=0; ; j++, i++ ) { if( strCmdLine[i] == '\"' || strCmdLine[i] == '\0' ) { temporary[j] = 0; if( strCmdLine[i] == '\"' ) i++; break; } temporary[j] = strCmdLine[i]; } } else { //空白またはヌル文字以前を取り出す for( int j=0; ; j++, i++ ) { if( strCmdLine[i] == ' ' || strCmdLine[i] == '\0' ) { temporary[j] = 0; break; } temporary[j] = strCmdLine[i]; } } parameter = temporary; } this->push_back( CmdLine( command, parameter ) ); } else if( strCmdLine[i] == '\"' ) { i++; //ダブルクォートの中身を取り出す for( int j=0; ; j++, i++ ) { if( strCmdLine[i] == '\"' || strCmdLine[i] == '\0' ) { temporary[j] = 0; if( strCmdLine[i] == '\"' ) i++; break; } temporary[j] = strCmdLine[i]; } this->push_back( CmdLine( "", temporary ) ); } else { //空白またはヌル文字以前を取り出す for( int j=0; ; j++, i++ ) { if( strCmdLine[i] == ' ' || strCmdLine[i] == '\0' ) { temporary[j] = 0; break; } temporary[j] = strCmdLine[i]; } this->push_back( CmdLine( "", temporary ) ); } } } bool CmdLines::IsExist( const std::string &commandString ) const { const CmdLines &cmdLines = *this; BOOST_FOREACH( const CmdLine &cmdLine, cmdLines ) { if( cmdLine.GetCommand() == commandString ) { return true; } } return false; }