2000-12-13 13:19:03 +00:00
|
|
|
/*
|
2000-12-13 15:37:35 +00:00
|
|
|
* $Source$
|
|
|
|
|
* $Revision$
|
|
|
|
|
* $Date$
|
2000-12-13 13:19:03 +00:00
|
|
|
*/
|
|
|
|
|
|
2000-12-13 15:37:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "argv.h"
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
/* This routine is a convenient way to enable or disable various
|
|
|
|
|
debugging modules according to the wishes of the user. It takes a
|
|
|
|
|
result array from argv_process(3), parses the contents and set the
|
|
|
|
|
debug level of the specified modules accordingly.
|
|
|
|
|
|
|
|
|
|
The provided array must contain zero or more options describing how
|
|
|
|
|
the debug level should be set. Each string must be of the form
|
|
|
|
|
'module,level', 'module/level' or 'module:level', for example:
|
|
|
|
|
'rfcparse,5'. argvSetDebugLevel() will then set the debug level of
|
|
|
|
|
the module 'rfcparse' to '5'.
|
|
|
|
|
|
|
|
|
|
In order to be able to map the name of a debug module to the
|
|
|
|
|
according internal module number, argvSetDebugLevel() expects an
|
|
|
|
|
array string pointers of the name 'ModuleTable', which lists all
|
|
|
|
|
available module names in the order in which they have been
|
|
|
|
|
assigned an id number. This array will typically be provided by the
|
|
|
|
|
main() routine of the caller.
|
|
|
|
|
|
|
|
|
|
RETURNS: In case of an error, -1 is returned. A return code of 0
|
|
|
|
|
indicates success.
|
|
|
|
|
|
|
|
|
|
REQUIRES: extern const char * const ModuleTable[]
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int
|
2000-12-13 15:37:35 +00:00
|
|
|
argvSetDebugLevel(argv_array_t debug)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
extern const char* const ModuleTable[];
|
|
|
|
|
void setDebugLevel(unsigned short, unsigned short);
|
|
|
|
|
|
2000-12-13 13:19:03 +00:00
|
|
|
char * ModuleName;
|
|
|
|
|
char * DebugLevel;
|
|
|
|
|
unsigned int count, i;
|
|
|
|
|
|
2000-12-13 15:37:35 +00:00
|
|
|
for (count = 0; count < debug.aa_entry_n; count++)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
ModuleName = strtok(ARGV_ARRAY_ENTRY(debug, char *, count), ",/:");
|
|
|
|
|
DebugLevel = strtok(NULL, ",/:");
|
2000-12-13 15:37:35 +00:00
|
|
|
if (ModuleName == NULL || DebugLevel == NULL || atoi(DebugLevel) < 0 || atoi(DebugLevel) > 9)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(stderr, "\"%s\" is not a valid debug-level specification.\n",
|
|
|
|
|
ARGV_ARRAY_ENTRY(debug, char *, count));
|
|
|
|
|
return -1;
|
2000-12-13 15:37:35 +00:00
|
|
|
}
|
|
|
|
|
for (i = 0; ModuleTable[i] != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!strcasecmp(ModuleName, ModuleTable[i]))
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
setDebugLevel(i, atoi(DebugLevel));
|
|
|
|
|
break;
|
2000-12-13 15:37:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ModuleTable[i] == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "\"%s\" is not a valid debug-module name.\n", ModuleName);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
#endif
|
2000-12-13 15:37:35 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|