Exemple #1
0
/*-----------------------------------------------------------------------------
Name:        debugSetter

Description: Set the debug mode to on or off based on command line argument.

Algorithm:   Set debug off by default and use a while loop to determine if
             commands line argument exists to turn it on. Otherwise, it is
             automatically off.

Parameters:  arg1: default argument 1 from main

             arg2: default argument 2 from main

Output:      void

Result:      Debug is either enabled or disabled during execution.
-----------------------------------------------------------------------------*/
void debugSetter(int arg1, char * const * arg2)
{
    char option; /* determines debug mode */

    /* Set if off by default */
    debugOff();

    /* Loop executes when argument is present and will turn on debug mode */
    while((option = getopt(arg1, arg2, "x")) != EOF)
    {
        switch (option)
        {
        case 'x': /* Turn on if x is found in argument */
            debugOn();
            break;
        }
    }
}
Exemple #2
0
/** Function: debugOn
 *
 * Turn on debugging information at a specific level.
 *
 * Parameter: os Stream to report which debugging level has been turned on.
 */
void debugOn(std::ostream& os, const int& level)
{
	/* Setting the debug level to 0 is the same as turning it off. */
	if (0 == level)
	{
		debugOff(os);
		return;
	}

	/* These are defined in "Debug.h", and are used here to show the user what
	 * level of error details will be displayed.
	 */
	std::vector<std::string> warningLevels;
	warningLevels.push_back("CRITICAL_LEVEL");
	warningLevels.push_back("ERROR_LEVEL");
	warningLevels.push_back("WARNING_LEVEL");
	warningLevels.push_back("SUGGESTION_LEVEL");
	warningLevels.push_back("VERBOSE_LEVEL4");
	warningLevels.push_back("VERBOSE_LEVEL3");
	warningLevels.push_back("VERBOSE_LEVEL2");
	warningLevels.push_back("VERBOSE_LEVEL1");

	showDebug = level;

	if (showDebug >= warningLevels.size())
		showDebug = warningLevels.size() - 1;

	/* This is to prevent an out-of-range error if someone updates the enum
	 * in Debug.h without also updating this list.
	 */
	Monday_out(showDebug, os, "Setting debug ON to level %d (%s).\n",
	           showDebug, warningLevels[showDebug].c_str());

	/* And this warns the stupid person of the problem mentioned above. */
	if (warningLevels.size() < NUM_DEBUG_DEFINITIONS)
	{
		std::cerr << "*CRITICAL ERROR: The LevelDefinitions enum in Debug.h has "
		          << NUM_DEBUG_DEFINITIONS << " definitions, while the warningLevels vector in debugOn() only has "
		          << warningLevels.size() << " defined.  Update debugOn().\n";
		return;
	}
}