1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: error.cc,v 1.1 1998/07/02 02:58:13 jgg Exp $
/* ######################################################################
Global Erorr Class - Global error mechanism
We use a simple STL vector to store each error record. A PendingFlag
is kept which indicates when the vector contains a Sever error.
This source is placed in the Public Domain, do with it what you will
It was originally written by Jason Gunthorpe.
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <pkglib/error.h>
/*}}}*/
GlobalError *_error = new GlobalError;
// GlobalError::GlobalError - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
GlobalError::GlobalError() : PendingFlag(false)
{
}
/*}}}*/
// GlobalError::Errno - Get part of the error string from errno /*{{{*/
// ---------------------------------------------------------------------
/* Function indicates the stdlib function that failed and Description is
a user string that leads the text. Form is:
Description - Function (errno: strerror)
Carefull of the buffer overrun, sprintf.
*/
bool GlobalError::Errno(const char *Function,const char *Description,...)
{
va_list args;
va_start(args,Description);
// sprintf the description
char S[400];
vsprintf(S,Description,args);
sprintf(S + strlen(S)," - %s (%i %s)",Function,errno,strerror(errno));
// Put it on the list
Item Itm;
Itm.Text = S;
Itm.Error = true;
List.push_back(Itm);
PendingFlag = true;
return false;
}
/*}}}*/
// GlobalError::Error - Add an error to the list /*{{{*/
// ---------------------------------------------------------------------
/* Just vsprintfs and pushes */
bool GlobalError::Error(const char *Description,...)
{
va_list args;
va_start(args,Description);
// sprintf the description
char S[400];
vsprintf(S,Description,args);
// Put it on the list
Item Itm;
Itm.Text = S;
Itm.Error = true;
List.push_back(Itm);
PendingFlag = true;
return false;
}
/*}}}*/
// GlobalError::Warning - Add a warning to the list /*{{{*/
// ---------------------------------------------------------------------
/* This doesn't set the pending error flag */
bool GlobalError::Warning(const char *Description,...)
{
va_list args;
va_start(args,Description);
// sprintf the description
char S[400];
vsprintf(S,Description,args);
// Put it on the list
Item Itm;
Itm.Text = S;
Itm.Error = false;
List.push_back(Itm);
return false;
}
/*}}}*/
// GlobalError::PopMessage - Pulls a single message out /*{{{*/
// ---------------------------------------------------------------------
/* This should be used in a loop checking empty() each cycle. It returns
true if the message is an error. */
bool GlobalError::PopMessage(string &Text)
{
bool Ret = List.front().Error;
Text = List.front().Text;
List.erase(List.begin());
// This really should check the list to see if only warnings are left..
if (empty())
PendingFlag = false;
return Ret;
}
/*}}}*/
// GlobalError::DumpErrors - Dump all of the errors/warns to cerr /*{{{*/
// ---------------------------------------------------------------------
/* */
void GlobalError::DumpErrors()
{
// Print any errors or warnings found
string Err;
while (empty() == false)
{
bool Type = PopMessage(Err);
if (Type == true)
cerr << "E: " << Err << endl;
else
cerr << "W: " << Err << endl;
}
}
/*}}}*/
|