Base::Console avoid magic numbers and enable external string size checks
This commit is contained in:
committed by
abdullahtahiriyo
parent
8b93107202
commit
2eb5c70147
@@ -1,5 +1,5 @@
|
||||
/***************************************************************************
|
||||
* (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
|
||||
* (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
@@ -10,12 +10,12 @@
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with FreeCAD; if not, write to the Free Software *
|
||||
* License along with FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
@@ -49,7 +49,7 @@ using namespace Base;
|
||||
//=========================================================================
|
||||
|
||||
namespace Base {
|
||||
|
||||
|
||||
class ConsoleEvent : public QEvent {
|
||||
public:
|
||||
ConsoleSingleton::FreeCAD_ConsoleMsgType msgtype;
|
||||
@@ -141,7 +141,7 @@ ConsoleSingleton::~ConsoleSingleton()
|
||||
//**************************************************************************
|
||||
// methods
|
||||
|
||||
/**
|
||||
/**
|
||||
* sets the console in a special mode
|
||||
*/
|
||||
void ConsoleSingleton::SetConsoleMode(ConsoleMode m)
|
||||
@@ -150,7 +150,7 @@ void ConsoleSingleton::SetConsoleMode(ConsoleMode m)
|
||||
_bVerbose = true;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* unsets the console from a special mode
|
||||
*/
|
||||
void ConsoleSingleton::UnsetConsoleMode(ConsoleMode m)
|
||||
@@ -165,7 +165,7 @@ void ConsoleSingleton::UnsetConsoleMode(ConsoleMode m)
|
||||
* The return value is an OR'ed value of all message types that have changed their state. For example
|
||||
* @code
|
||||
* // switch off warnings and error messages
|
||||
* ConsoleMsgFlags ret = Base::Console().SetEnabledMsgType("myObs",
|
||||
* ConsoleMsgFlags ret = Base::Console().SetEnabledMsgType("myObs",
|
||||
* ConsoleMsgType::MsgType_Wrn|ConsoleMsgType::MsgType_Err, false);
|
||||
* // do something without notifying observer myObs
|
||||
* ...
|
||||
@@ -236,10 +236,10 @@ void ConsoleSingleton::SetConnectionMode(ConnectionMode mode)
|
||||
}
|
||||
|
||||
/** Prints a Message
|
||||
* This method issues a Message.
|
||||
* This method issues a Message.
|
||||
* Messages are used to show some non vital information. That means when
|
||||
* FreeCAD is running in GUI mode a Message appears on the status bar.
|
||||
* In console mode a message is printed to the console.
|
||||
* FreeCAD is running in GUI mode a Message appears on the status bar.
|
||||
* In console mode a message is printed to the console.
|
||||
* \par
|
||||
* You can use a printf like interface like:
|
||||
* \code
|
||||
@@ -251,8 +251,8 @@ void ConsoleSingleton::SetConnectionMode(ConnectionMode mode)
|
||||
*/
|
||||
void ConsoleSingleton::Message( const char *pMsg, ... )
|
||||
{
|
||||
char format[4024];
|
||||
const unsigned int format_len = 4024;
|
||||
char format[BufferSize];
|
||||
const unsigned int format_len = BufferSize;
|
||||
|
||||
va_list namelessVars;
|
||||
va_start(namelessVars, pMsg); // Get the "..." vars
|
||||
@@ -266,7 +266,7 @@ void ConsoleSingleton::Message( const char *pMsg, ... )
|
||||
}
|
||||
|
||||
/** Prints a Message
|
||||
* This method issues a Warning.
|
||||
* This method issues a Warning.
|
||||
* Messages are used to get the users attention. That means when
|
||||
* FreeCAD is in GUI mode a Message Box pops up. In console
|
||||
* mode a colored message is returned to the console! Don't use this carelessly.
|
||||
@@ -282,8 +282,8 @@ void ConsoleSingleton::Message( const char *pMsg, ... )
|
||||
*/
|
||||
void ConsoleSingleton::Warning( const char *pMsg, ... )
|
||||
{
|
||||
char format[4024];
|
||||
const unsigned int format_len = 4024;
|
||||
char format[BufferSize];
|
||||
const unsigned int format_len = BufferSize;
|
||||
|
||||
va_list namelessVars;
|
||||
va_start(namelessVars, pMsg); // Get the "..." vars
|
||||
@@ -297,10 +297,10 @@ void ConsoleSingleton::Warning( const char *pMsg, ... )
|
||||
}
|
||||
|
||||
/** Prints a Message
|
||||
* This method issues an Error which makes some execution impossible.
|
||||
* Errors are used to get the users attention. That means when FreeCAD
|
||||
* This method issues an Error which makes some execution impossible.
|
||||
* Errors are used to get the users attention. That means when FreeCAD
|
||||
* is running in GUI mode an Error Message Box pops up. In console
|
||||
* mode a colored message is printed to the console! Don't use this carelessly.
|
||||
* mode a colored message is printed to the console! Don't use this carelessly.
|
||||
* For information purposes the 'Log' or 'Message' methods are more appropriate.
|
||||
* \par
|
||||
* You can use a printf like interface like:
|
||||
@@ -313,8 +313,8 @@ void ConsoleSingleton::Warning( const char *pMsg, ... )
|
||||
*/
|
||||
void ConsoleSingleton::Error( const char *pMsg, ... )
|
||||
{
|
||||
char format[4024];
|
||||
const unsigned int format_len = 4024;
|
||||
char format[BufferSize];
|
||||
const unsigned int format_len = BufferSize;
|
||||
|
||||
va_list namelessVars;
|
||||
va_start(namelessVars, pMsg); // Get the "..." vars
|
||||
@@ -331,7 +331,7 @@ void ConsoleSingleton::Error( const char *pMsg, ... )
|
||||
/** Prints a Message
|
||||
* This method is appropriate for development and tracking purposes.
|
||||
* It can be used to track execution of algorithms and functions.
|
||||
* The normal user doesn't need to see it, it's more for developers
|
||||
* The normal user doesn't need to see it, it's more for developers
|
||||
* and experienced users. So in normal user mode the logging is switched off.
|
||||
* \par
|
||||
* You can use a printf-like interface for example:
|
||||
@@ -346,8 +346,8 @@ void ConsoleSingleton::Error( const char *pMsg, ... )
|
||||
|
||||
void ConsoleSingleton::Log( const char *pMsg, ... )
|
||||
{
|
||||
char format[4024];
|
||||
const unsigned int format_len = 4024;
|
||||
char format[BufferSize];
|
||||
const unsigned int format_len = BufferSize;
|
||||
|
||||
if (_bVerbose)
|
||||
{
|
||||
@@ -373,8 +373,8 @@ const char* ConsoleSingleton::Time(void)
|
||||
{
|
||||
struct tm *newtime;
|
||||
time_t aclock;
|
||||
time( &aclock ); // Get time in seconds
|
||||
newtime = localtime( &aclock ); // Convert time to struct tm form
|
||||
time( &aclock ); // Get time in seconds
|
||||
newtime = localtime( &aclock ); // Convert time to struct tm form
|
||||
char* st = asctime( newtime );
|
||||
st[24] = 0;
|
||||
return st;
|
||||
@@ -386,7 +386,7 @@ const char* ConsoleSingleton::Time(void)
|
||||
// Observer stuff
|
||||
|
||||
/** Attaches an Observer to Console
|
||||
* Use this method to attach a ConsoleObserver derived class to
|
||||
* Use this method to attach a ConsoleObserver derived class to
|
||||
* the Console. After the observer is attached all messages will also
|
||||
* be forwarded to it.
|
||||
* @see ConsoleObserver
|
||||
@@ -703,8 +703,8 @@ PyObject *ConsoleSingleton::sPyGetStatus(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr1;
|
||||
char *pstr2;
|
||||
if (!PyArg_ParseTuple(args, "ss", &pstr1, &pstr2)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "ss", &pstr1, &pstr2)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
PY_TRY{
|
||||
bool b=false;
|
||||
@@ -723,7 +723,7 @@ PyObject *ConsoleSingleton::sPyGetStatus(PyObject * /*self*/, PyObject *args)
|
||||
b = pObs->bMsg;
|
||||
else if(strcmp(pstr2,"Err") == 0)
|
||||
b = pObs->bErr;
|
||||
|
||||
|
||||
return Py_BuildValue("i",b?1:0);
|
||||
}PY_CATCH;
|
||||
}
|
||||
@@ -733,8 +733,8 @@ PyObject *ConsoleSingleton::sPySetStatus(PyObject * /*self*/, PyObject *args)
|
||||
char *pstr1;
|
||||
char *pstr2;
|
||||
int Bool;
|
||||
if (!PyArg_ParseTuple(args, "ssi", &pstr1, &pstr2,&Bool)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "ssi", &pstr1, &pstr2,&Bool)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
PY_TRY{
|
||||
ConsoleObserver *pObs = Instance().Get(pstr1);
|
||||
@@ -754,7 +754,7 @@ PyObject *ConsoleSingleton::sPySetStatus(PyObject * /*self*/, PyObject *args)
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
} else {
|
||||
Py_Error(Base::BaseExceptionFreeCADError,"Unknown Console Type");
|
||||
Py_Error(Base::BaseExceptionFreeCADError,"Unknown Console Type");
|
||||
}
|
||||
|
||||
} PY_CATCH;
|
||||
@@ -887,7 +887,7 @@ void ConsoleObserverStd::Log (const char *sErr)
|
||||
}
|
||||
}
|
||||
|
||||
RedirectStdOutput::RedirectStdOutput()
|
||||
RedirectStdOutput::RedirectStdOutput()
|
||||
{
|
||||
buffer.reserve(80);
|
||||
}
|
||||
@@ -909,7 +909,7 @@ int RedirectStdOutput::sync()
|
||||
return 0;
|
||||
}
|
||||
|
||||
RedirectStdLog::RedirectStdLog()
|
||||
RedirectStdLog::RedirectStdLog()
|
||||
{
|
||||
buffer.reserve(80);
|
||||
}
|
||||
@@ -931,7 +931,7 @@ int RedirectStdLog::sync()
|
||||
return 0;
|
||||
}
|
||||
|
||||
RedirectStdError::RedirectStdError()
|
||||
RedirectStdError::RedirectStdError()
|
||||
{
|
||||
buffer.reserve(80);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user