From: abv Date: Mon, 21 Aug 2017 13:48:23 +0000 (+0300) Subject: 0029024: DRAW - use common approach for reporting error message on wrong command... X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=6d61efef1e3a51ef616350ec715ada67816413ac;p=occt-copy.git 0029024: DRAW - use common approach for reporting error message on wrong command arguments Method Draw_Interpretor::ErrorOnWrongArgs() is added, providing user message for DRAW command called with incorrect arguments. --- diff --git a/src/Draw/Draw_Interpretor.cxx b/src/Draw/Draw_Interpretor.cxx index 025df3183f..c7398fc4b9 100644 --- a/src/Draw/Draw_Interpretor.cxx +++ b/src/Draw/Draw_Interpretor.cxx @@ -331,6 +331,34 @@ Standard_Boolean Draw_Interpretor::Remove(Standard_CString const n) return result == 0; } +//======================================================================= +//function : GetHelp +//purpose : +//======================================================================= + +Standard_CString Draw_Interpretor::GetHelp (Standard_CString theCommandName) const +{ + return Tcl_GetVar2 (myInterp, "Draw_Helps", theCommandName, TCL_GLOBAL_ONLY); +} + +//======================================================================= +//function : ErrorOnWrongArgs +//purpose : +//======================================================================= + +Standard_Integer Draw_Interpretor::ErrorOnWrongArgs (Standard_CString theCommandName) const +{ + std::cerr << "Error: wrong number of arguments" << std::endl; + + Standard_CString aHelp = GetHelp (theCommandName); + if (aHelp) + { + std::cerr << "Use: " << theCommandName << " " << aHelp << std::endl; + } + + return 1; +} + //======================================================================= //function : Result //purpose : diff --git a/src/Draw/Draw_Interpretor.hxx b/src/Draw/Draw_Interpretor.hxx index 9e113bc696..cf051a8366 100644 --- a/src/Draw/Draw_Interpretor.hxx +++ b/src/Draw/Draw_Interpretor.hxx @@ -164,6 +164,16 @@ public: //! Removes , returns true if success (the command existed). Standard_EXPORT Standard_Boolean Remove (const Standard_CString theCommandName); + //! Returns text of the help recorded for command theCommandName + //! (previously added by method Add() or by command "help" in Tcl interpretor). + //! Returns Null if no help string is defined for theCommandName. + Standard_EXPORT Standard_CString GetHelp (Standard_CString theCommandName) const; + + //! Prints (to std::cerr) standard error message for theCommandName called with + //! wrong number of arguments. The message includes help for this command. + //! Returns 1 indicating error status for Tcl command. + Standard_EXPORT Standard_Integer ErrorOnWrongArgs (Standard_CString theCommandName) const; + public: Standard_EXPORT Standard_CString Result() const;