Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/message/handler_console.cc

Go to the documentation of this file.
00001 /*
00002  * lib/message/handler_console.cc
00003  * 
00004  * Message handling "system" for errors, warnings and verbose messages. 
00005  * This is the (UNIX default) console message handler. 
00006  * 
00007  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00008  * 
00009  * This file may be distributed and/or modified under the terms of the 
00010  * GNU General Public License version 2 as published by the Free Software 
00011  * Foundation. (See COPYING.GPL for details.)
00012  * 
00013  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00014  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00015  * 
00016  */
00017 
00018 #include "handler_console.h"
00019 
00020 #include <stdio.h>   /* OKAY here :) */
00021 
00022 
00023 void MessageHandler_Console::HandleMessage(const Message &m)
00024 {
00025     FILE *out;
00026     if(m.type() & Message::MTAllNonDebug)
00027     {  out=stderr;  }
00028     else
00029     {  out=stdout;  }
00030     
00031     if(use_color)
00032     {
00033         if(m.type() & (Message::MTError | Message::MTFatal))
00034         {  fprintf(out,"\33[1;31m");  }    // start error color
00035         else if(m.type() & Message::MTWarning)
00036         {  fprintf(out,"\33[0;31m");  }    // start warning color
00037     }
00038     
00039     const char *mtype="";
00040     if(m.type() & Message::MTFatal)  mtype="fatal: ";
00041     else if(m.type() & Message::MTError)  mtype="error: ";
00042     else if(m.type() & Message::MTWarning)  mtype="warning: ";
00043     
00044     // Dump message (with location (range) if present). 
00045     if(m.LocationRange().loc1)
00046     {
00047         fprintf(out,"%s: %s%s\n",
00048             m.LocationRange().RangeString().str(),
00049             mtype,
00050             m.msg().str());
00051     }
00052     else if(m.location())
00053     {
00054         fprintf(out,"%s: %s%s\n",
00055             m.location().LocString().str(),
00056             mtype,
00057             m.msg().str());
00058     }
00059     else
00060     {
00061         fprintf(out,"%s%s\n",mtype,m.msg().str());
00062     }
00063     
00064     if(use_color)
00065     {
00066         if(m.type() & (Message::MTError | Message::MTFatal))
00067         {  fprintf(out,"\33[00m");  }    // end error color
00068         else if(m.type() & Message::MTWarning)
00069         {  fprintf(out,"\33[00m");  }    // end warning color
00070     }
00071 }
00072 
00073 
00074 MessageHandler_Console::MessageHandler_Console(Message::Type mtmask,
00075     int _use_color) : 
00076     use_color(_use_color)
00077 {
00078     SelectMessageTypes(mtmask);
00079 }
00080 
00081 MessageHandler_Console::~MessageHandler_Console()
00082 {
00083     // It's better to select none before unregistering. 
00084     SelectMessageTypes(Message::MTNone);
00085 }

Generated on Sat Feb 19 22:33:45 2005 for Ray by doxygen 1.3.5