Blame src/debug.cpp

Packit Service 50c9f2
/******************************************************************************
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * 
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Copyright (C) 1997-2015 by Dimitri van Heesch.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Permission to use, copy, modify, and distribute this software and its
Packit Service 50c9f2
 * documentation under the terms of the GNU General Public License is hereby 
Packit Service 50c9f2
 * granted. No representations are made about the suitability of this software 
Packit Service 50c9f2
 * for any purpose. It is provided "as is" without express or implied warranty.
Packit Service 50c9f2
 * See the GNU General Public License for more details.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Documents produced by Doxygen are derivative works derived from the
Packit Service 50c9f2
 * input used in their production; they are not affected by this license.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 */
Packit Service 50c9f2
Packit Service 50c9f2
#include <stdarg.h>
Packit Service 50c9f2
#include <stdio.h>
Packit Service 50c9f2
Packit Service 50c9f2
#include <qdict.h>
Packit Service 50c9f2
Packit Service 50c9f2
#include "debug.h"
Packit Service 50c9f2
#include "message.h"
Packit Service 50c9f2
Packit Service 50c9f2
//------------------------------------------------------------------------
Packit Service 50c9f2
Packit Service 50c9f2
/** Helper struct representing a mapping from debug label to a debug ID */
Packit Service 50c9f2
struct LabelMap
Packit Service 50c9f2
{
Packit Service 50c9f2
  const char *name;
Packit Service 50c9f2
  Debug::DebugMask event;
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
static LabelMap s_labels[] =
Packit Service 50c9f2
{
Packit Service 50c9f2
  { "findmembers",  Debug::FindMembers  },
Packit Service 50c9f2
  { "functions",    Debug::Functions    },
Packit Service 50c9f2
  { "variables",    Debug::Variables    },
Packit Service 50c9f2
  { "preprocessor", Debug::Preprocessor },
Packit Service 50c9f2
  { "classes",      Debug::Classes      },
Packit Service 50c9f2
  { "commentcnv",   Debug::CommentCnv   },
Packit Service 50c9f2
  { "commentscan",  Debug::CommentScan  },
Packit Service 50c9f2
  { "validate",     Debug::Validate     },
Packit Service 50c9f2
  { "printtree",    Debug::PrintTree    },
Packit Service 50c9f2
  { "time",         Debug::Time         },
Packit Service 50c9f2
  { "extcmd",       Debug::ExtCmd       },
Packit Service 50c9f2
  { "markdown",     Debug::Markdown     },
Packit Service 50c9f2
  { "filteroutput", Debug::FilterOutput },
Packit Service 50c9f2
  { "lex",          Debug::Lex },
Packit Service 50c9f2
  { 0,             (Debug::DebugMask)0  }
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
/** Class representing a mapping from debug labels to debug IDs. */
Packit Service 50c9f2
class LabelMapper
Packit Service 50c9f2
{
Packit Service 50c9f2
  public:
Packit Service 50c9f2
    LabelMapper() : m_map(17) 
Packit Service 50c9f2
    {
Packit Service 50c9f2
      m_map.setAutoDelete(TRUE);
Packit Service 50c9f2
      LabelMap *p = s_labels;
Packit Service 50c9f2
      while (p->name)
Packit Service 50c9f2
      {
Packit Service 50c9f2
        m_map.insert(p->name,new Debug::DebugMask(p->event));
Packit Service 50c9f2
        p++;
Packit Service 50c9f2
      }
Packit Service 50c9f2
    }
Packit Service 50c9f2
    Debug::DebugMask *find(const char *s) const 
Packit Service 50c9f2
    {
Packit Service 50c9f2
      if (s==0) return 0;
Packit Service 50c9f2
      return m_map.find(s);
Packit Service 50c9f2
    }
Packit Service 50c9f2
  private:
Packit Service 50c9f2
    QDict<Debug::DebugMask> m_map;
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
static LabelMapper g_labelMapper;
Packit Service 50c9f2
Packit Service 50c9f2
//------------------------------------------------------------------------
Packit Service 50c9f2
Packit Service 50c9f2
Debug::DebugMask Debug::curMask = Debug::Quiet;
Packit Service 50c9f2
int Debug::curPrio = 0;
Packit Service 50c9f2
Packit Service 50c9f2
void Debug::print(DebugMask mask,int prio,const char *fmt,...)
Packit Service 50c9f2
{
Packit Service 50c9f2
  if ((curMask&mask) && prio<=curPrio)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    va_list args;
Packit Service 50c9f2
    va_start(args,fmt);
Packit Service 50c9f2
    vfprintf(stdout, fmt, args);
Packit Service 50c9f2
    va_end(args);
Packit Service 50c9f2
  }
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static int labelToEnumValue(const char *l)
Packit Service 50c9f2
{
Packit Service 50c9f2
  QCString label=l;
Packit Service 50c9f2
  Debug::DebugMask *event = g_labelMapper.find(label.lower());
Packit Service 50c9f2
  if (event) return *event; else return 0;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
int Debug::setFlag(const char *lab)
Packit Service 50c9f2
{
Packit Service 50c9f2
  int retVal = labelToEnumValue(lab);
Packit Service 50c9f2
  curMask = (DebugMask)(curMask | labelToEnumValue(lab));   
Packit Service 50c9f2
  return retVal;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
void Debug::clearFlag(const char *lab)
Packit Service 50c9f2
{
Packit Service 50c9f2
  curMask = (DebugMask)(curMask & ~labelToEnumValue(lab));
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
void Debug::setPriority(int p)
Packit Service 50c9f2
{
Packit Service 50c9f2
  curPrio = p;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
bool Debug::isFlagSet(DebugMask mask)
Packit Service 50c9f2
{
Packit Service 50c9f2
  return (curMask & mask)!=0;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
void Debug::printFlags(void)
Packit Service 50c9f2
{
Packit Service 50c9f2
  int i;
Packit Service 50c9f2
  for (i = 0; i < (int)(sizeof(s_labels)/sizeof(*s_labels)); i++)
Packit Service 50c9f2
  {
Packit Service 50c9f2
     if (s_labels[i].name)
Packit Service 50c9f2
     {
Packit Service 50c9f2
        msg("\t%s\n",s_labels[i].name);
Packit Service 50c9f2
     }
Packit Service 50c9f2
  }
Packit Service 50c9f2
}