//--------------------------------------------------------- bool CCMD_Module::Execute(CSG_String sLibName, int argc, char *argv[]) { int i; //----------------------------------------------------- if( !m_pModule ) { return( false ); } if( argc <= 1 ) { wxString sUsage = m_CMD.GetUsageString(); sUsage = wxString::Format(SG_T("Usage: saga_cmd %s %d %s"), sLibName.c_str(), m_pModule->Get_ID(), sUsage.AfterFirst(' ').AfterFirst(' ')); SG_PRINTF(sUsage); return( false ); } //----------------------------------------------------- // m_CMD.SetCmdLine(argc, argv); // // We can't do it this way (passing argv as char**) because then we use an // overload of the method which (re-)sets the locale from the current // enviromment; in order to prevent this, we use wxString overload wxString sCmdLine; for(i=1; i<argc; i++) { wxString sTmp = argv[i]; sCmdLine += wxString::Format(SG_T("\"%s\" "), sTmp.c_str()); } m_CMD.SetCmdLine(sCmdLine); //----------------------------------------------------- bool bResult = _Get_Parameters(m_pModule->Get_Parameters()); for(i=0; bResult && i<m_pModule->Get_Parameters_Count(); i++) { _Get_Parameters(m_pModule->Get_Parameters(i)); } if( !bResult ) { CMD_Print(""); wxString sUsage = m_CMD.GetUsageString(); sUsage = wxString::Format(SG_T("Usage: saga_cmd %s %d %s"), sLibName.c_str(), m_pModule->Get_ID(), sUsage.AfterFirst(' ').AfterFirst(' ')); SG_PRINTF(sUsage); } //----------------------------------------------------- CMD_Set_Module(this); if( bResult && m_pModule->On_Before_Execution() ) { bResult = m_pModule->Execute(); m_pModule->On_After_Execution(); } CMD_Set_Module(NULL); //----------------------------------------------------- if( bResult ) { _Save_Output(m_pModule->Get_Parameters()); for(i=0; i<m_pModule->Get_Parameters_Count(); i++) { _Save_Output(m_pModule->Get_Parameters(i)); } SG_Get_Data_Manager().Delete_Unsaved(); // remove temporary data to save memory resources } else { CMD_Print_Error(_TL("executing tool"), m_pModule->Get_Name()); } return( bResult ); }
//--------------------------------------------------------- bool CCMD_Module::Execute(int argc, char *argv[]) { //----------------------------------------------------- if( !m_pLibrary || !m_pModule ) { return( false ); } if( argc <= 1 ) { Usage(); return( false ); } //----------------------------------------------------- // m_CMD.SetCmdLine(argc, argv); // // We can't do it this way (passing argv as char**) because then we use an // overload of the method which (re-)sets the locale from the current // enviromment; in order to prevent this, we use wxString overload { wxString sCmdLine; for(int i=1; i<argc; i++) { sCmdLine += wxString(i == 1 ? "\"" : " \"") + argv[i] + "\""; } m_CMD.SetCmdLine(sCmdLine); } if( m_CMD.Parse(false) != 0 ) { Usage(); return( false ); } //----------------------------------------------------- int i; bool bResult = _Get_Parameters(m_pModule->Get_Parameters(), true); for(i=0; bResult && i<m_pModule->Get_Parameters_Count(); i++) { bResult = _Get_Parameters(m_pModule->Get_Parameters(i), true); } if( !bResult ) { Usage(); return( false ); } //----------------------------------------------------- CMD_Set_Module(this); if( m_pModule->On_Before_Execution() ) { bResult = m_pModule->Execute(); m_pModule->On_After_Execution(); } CMD_Set_Module(NULL); //----------------------------------------------------- if( bResult ) { _Save_Output(m_pModule->Get_Parameters()); for(i=0; i<m_pModule->Get_Parameters_Count(); i++) { _Save_Output(m_pModule->Get_Parameters(i)); } SG_Get_Data_Manager().Delete_Unsaved(); // remove temporary data to save memory resources } else { CMD_Print_Error(_TL("executing tool"), m_pModule->Get_Name()); } return( bResult ); }