2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
2020-10-28 14:19:47 +00:00
|
|
|
* Copyright (C) 2007-2020 Cas Cremers
|
2007-06-11 13:01:04 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2004-05-15 15:22:44 +01:00
|
|
|
/**
|
|
|
|
*@file debug.c
|
|
|
|
*\brief Debugging code.
|
|
|
|
*
|
|
|
|
* It is hoped that this code will become redundant over time.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "debug.h"
|
2004-07-24 16:08:35 +01:00
|
|
|
#include "system.h"
|
2006-08-02 11:29:40 +01:00
|
|
|
#include "error.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
static int debuglevel;
|
|
|
|
|
2004-05-15 15:22:44 +01:00
|
|
|
//! Set the debuglevel from the main code.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
debugSet (int level)
|
|
|
|
{
|
|
|
|
debuglevel = level;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:22:44 +01:00
|
|
|
//! Test whether some debuglevel is meant to be printed.
|
|
|
|
/**
|
|
|
|
*@param level The debuglevel
|
|
|
|
*@return True iff level is smaller than, or equal to, the last set debuglevel.
|
|
|
|
*\sa debugSet()
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
int
|
|
|
|
debugCond (int level)
|
|
|
|
{
|
|
|
|
return (level <= debuglevel);
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:22:44 +01:00
|
|
|
//! Print some debug string for some level, if desired.
|
|
|
|
/**
|
|
|
|
*@param level The debuglevel
|
|
|
|
*@param string The string to be displayed for this level.
|
|
|
|
*@return If the debuglevel is higher than the level, the string is ignored.
|
|
|
|
* Otherwise it will be printed.
|
|
|
|
*\sa debugCond()
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
debug (int level, char *string)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debugCond (level))
|
|
|
|
{
|
|
|
|
indent ();
|
2006-08-02 11:29:40 +01:00
|
|
|
printfstderr ("DEBUG [%i]: %s\n", level, string);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|