vrq
glue.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 1997-2007, Mark Hummel
3  * This file is part of Vrq.
4  *
5  * Vrq is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * Vrq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301 USA
19  *****************************************************************************
20  */
21 
22 #ifndef GLUE_HPP
23 #define GLUE_HPP
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string>
28 #include <list>
29 #include <map>
30 #include <iostream>
31 #include <stdarg.h>
32 
33 using std::string;
34 using std::map;
35 using std::list;
36 
37 struct Coord_t;
38 class CBackend;
39 
43 typedef long INT32;
47 typedef unsigned long UINT32;
51 typedef signed long long INT64;
55 typedef unsigned long long UINT64;
56 
61 #ifndef TRUE
62 #define TRUE 1
63 #endif
64 #ifndef FALSE
65 #define FALSE 0
66 #endif
67 
68 #define PATH_SEPARATOR "/"
69 
70 extern int warningCount;
71 extern int errorCount;
72 extern FILE* logfile;
73 
77 void shell_assert( const char*, int );
78 void shell_xfree( void*, int );
79 void* shell_xmalloc( int );
89 class Message {
90 public:
94  enum Action_t {
99  };
100 private:
101  static map<string,Message*> *abbrev2Message;
102  static list<Message*> *messages;
103  CBackend* tool;
104  Action_t action;
105  int locked;
106  const string abbrev;
107  const string helpText;
108  const string format;
109 public:
119  static Message* RegisterWarning( CBackend* tool,
120  Action_t defaultAction,
121  const char* abbrev,
122  const char* format, ... );
131  static Message* RegisterError( CBackend* tool,
132  const char* abbrev,
133  const char* format, ... );
143  static Message* Find( const char* abbrev );
148  static list<Message*>& MessageList() {
149  if( !messages ) {
150  messages = new list<Message*>();
151  }
152  return *messages;
153  }
154  Message( CBackend* tool,
155  Action_t action,
156  int locked,
157  const char* abbrev,
158  const char* helpText,
159  const char* format );
160 
161  const char* Format() { return format.c_str(); }
162  const char* Abbreviation() { return abbrev.c_str(); }
163  const char* HelpText() { return helpText.c_str(); }
164  Action_t Action() { return action; }
165  void Action( Action_t a ) { if( !locked ) { action = a; } }
166  CBackend* Tool() { return tool; }
167  int Locked() { return locked; }
171 };
172 
180 void message( struct Coord_t* location, Message* message, ... );
187 void vlogprintf( const char* format, va_list args );
194 void logprintf( const char* format, ... );
195 
196 
201 void warning( struct Coord_t* location, const char* format, ... );
206 void error( struct Coord_t* location, const char* format, ... );
211 void info( struct Coord_t* location, const char* format, ... );
216 void fatal( struct Coord_t* location, const char* format, ... );
221 void trace( struct Coord_t* location, const char* format, ... );
222 
223 
229 #define MASSERT(c) if(!(c)) { shell_assert( __FILE__, __LINE__ ); abort(); }
230 
235 #define MTHROW_NIL(p) MASSERT(p!=NULL);
236 
237 #endif // GLUE_HPP
238 
static Message * RegisterWarning(CBackend *tool, Action_t defaultAction, const char *abbrev, const char *format,...)
Register a warning message.
void * shell_xmalloc(int s)
Definition: main.cc:363
unsigned long long UINT64
Short cut for unsigned 64 bit integer.
Definition: glue.h:55
void vlogprintf(const char *format, va_list args)
Print to logfile.
int errorCount
Definition: main.cc:287
Plugin's should need these.
Definition: glue.h:89
void fatal(struct Coord_t *location, const char *format,...)
This routine should not be used by plugins.
void shell_xfree(void *p, int s)
Definition: main.cc:359
long INT32
Short cut for signed 32 bit integer.
Definition: glue.h:38
ignore message, don't print or increment counts.
Definition: glue.h:95
signed long long INT64
Short cut for signed 64 bit integer.
Definition: glue.h:51
void message(struct Coord_t *location, Message *message,...)
Print message.
void warning(struct Coord_t *location, const char *format,...)
This routine should not be used by plugins.
Action_t
Message behaviors.
Definition: glue.h:94
void trace(struct Coord_t *location, const char *format,...)
This routine should not be used by plugins.
Structure to hold file coordinates.
Definition: cdecl.h:47
warning message, print and increment warning count
Definition: glue.h:97
void info(struct Coord_t *location, const char *format,...)
This routine should not be used by plugins.
error message, print and increment error count
Definition: glue.h:96
void error(struct Coord_t *location, const char *format,...)
This routine should not be used by plugins.
This is the abstract class to overload to create new backend tools.
Definition: cbackend.h:249
int warningCount
Definition: main.cc:288
unsigned long UINT32
Short cut for unsigned 32 bit integer.
Definition: glue.h:47
informative message, print only
Definition: glue.h:98
FILE * logfile
Definition: main.cc:232
static Message * RegisterError(CBackend *tool, const char *abbrev, const char *format,...)
Register an error message.
void logprintf(const char *format,...)
Print to logfile.
void shell_assert(const char *filename, int linenumber)
Definition: main.cc:356