home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Divers
/
lyx-0.13.2.tar.gz
/
lyx-0.13.2.tar
/
lyx-0.13.2
/
src
/
error.C
< prev
next >
Wrap
C/C++ Source or Header
|
1998-04-23
|
3KB
|
107 lines
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "error.h"
#include <stdio.h>
#include <stdlib.h>
#include <lstrings.h>
// $Id: error.C,v 1.1.1.1 1998/04/23 16:02:48 larsbj Exp $
#if !defined(lint) && !defined(WITH_WARNINGS)
static char vcid[] = "$Id: error.C,v 1.1.1.1 1998/04/23 16:02:48 larsbj Exp $";
#endif /* lint */
struct error_item {
Error::DEBUG_LEVELS level;
const char * name;
const char * desc;
};
static error_item errorTags[] = {
{ Error::INFO, "info", "General information"},
{ Error::INIT, "init", "Program initialisation"},
{ Error::KEY, "key", "Keyboard events handling"},
{ Error::TOOLBAR, "toolbar", "Toolbar handling"},
{ Error::PARSER, "parser", "Lyxlex grammer parser"},
{ Error::LYXRC, "lyxrc", "Configuration files reading"},
{ Error::KBMAP, "kbmap", "Custom keyboard definition"},
{ Error::LATEX, "latex", "LaTeX generation/execution"},
{ Error::MATHED, "mathed", "Math editor"},
{ Error::FONT, "font", "Font handling"},
{ Error::TCLASS, "tclass", "Textclass files reading"},
{ Error::LYXVC, "lyxvc", "Version control"},
{ Error::LYXSERVER, "lyxserver", "External control interface"},
{ Error::ANY, "any", "All debugging messages"}};
static const int numErrorTags = sizeof(errorTags)/sizeof(error_item);
Error::Error(int level) // should loglevel also be an argument?
{
debuglevel = level;
loglevel = 0;
}
void Error::setDebugLevel(char * lev)
{
LString levels = lev;
LString oneLevel;
int i;
levels.split(oneLevel,',');
while(!oneLevel.empty()) {
// Search for an explicit name
for (i = 0 ; i<numErrorTags ; i++)
if (compare_no_case(oneLevel,
errorTags[i].name) == 0) {
debuglevel |= errorTags[i].level;
break;
}
// No name found; is it a number?
if (i == numErrorTags) {
int num = atoi(oneLevel.c_str());
if (num)
debuglevel |= num;
else
print("Bad debug feature `"
+ oneLevel + '\'');
}
levels.split(oneLevel,',');
}
// Show what features are traced
for (i = 0 ; i < numErrorTags ; i++)
if (errorTags[i].level != Error::ANY
&& debuglevel & errorTags[i].level)
print(LString("Debugging ") + errorTags[i].name
+ " (" + errorTags[i].desc + ')');
}
void Error::showTags() {
for (int i = 0 ; i<numErrorTags ; i++)
fprintf(stdout, " %5d %-10s%-35s\n",
errorTags[i].level,
errorTags[i].name,
errorTags[i].desc);
}
void Error::debug(LString const & msg, int level)
{
if (debuglevel & level)
print(msg);
// should also print to the logfile
}
void Error::print(LString const & msg)
{
if (!msg.empty())
fprintf(stderr, "%s\n", msg.c_str());
}