]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/error.cc
59d2b8c8bdfe38a881845816061fd9693fe34ffe
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: error.cc,v 1.1 1998/07/02 02:58:13 jgg Exp $
4 /* ######################################################################
6 Global Erorr Class - Global error mechanism
8 We use a simple STL vector to store each error record. A PendingFlag
9 is kept which indicates when the vector contains a Sever error.
11 This source is placed in the Public Domain, do with it what you will
12 It was originally written by Jason Gunthorpe.
14 ##################################################################### */
16 // Include Files /*{{{*/
22 #include <pkglib/error.h>
25 GlobalError
*_error
= new GlobalError
;
27 // GlobalError::GlobalError - Constructor /*{{{*/
28 // ---------------------------------------------------------------------
30 GlobalError::GlobalError() : PendingFlag(false)
34 // GlobalError::Errno - Get part of the error string from errno /*{{{*/
35 // ---------------------------------------------------------------------
36 /* Function indicates the stdlib function that failed and Description is
37 a user string that leads the text. Form is:
38 Description - Function (errno: strerror)
39 Carefull of the buffer overrun, sprintf.
41 bool GlobalError::Errno(const char *Function
,const char *Description
,...)
44 va_start(args
,Description
);
46 // sprintf the description
48 vsprintf(S
,Description
,args
);
49 sprintf(S
+ strlen(S
)," - %s (%i %s)",Function
,errno
,strerror(errno
));
62 // GlobalError::Error - Add an error to the list /*{{{*/
63 // ---------------------------------------------------------------------
64 /* Just vsprintfs and pushes */
65 bool GlobalError::Error(const char *Description
,...)
68 va_start(args
,Description
);
70 // sprintf the description
72 vsprintf(S
,Description
,args
);
85 // GlobalError::Warning - Add a warning to the list /*{{{*/
86 // ---------------------------------------------------------------------
87 /* This doesn't set the pending error flag */
88 bool GlobalError::Warning(const char *Description
,...)
91 va_start(args
,Description
);
93 // sprintf the description
95 vsprintf(S
,Description
,args
);
106 // GlobalError::PopMessage - Pulls a single message out /*{{{*/
107 // ---------------------------------------------------------------------
108 /* This should be used in a loop checking empty() each cycle. It returns
109 true if the message is an error. */
110 bool GlobalError::PopMessage(string
&Text
)
112 bool Ret
= List
.front().Error
;
113 Text
= List
.front().Text
;
114 List
.erase(List
.begin());
116 // This really should check the list to see if only warnings are left..
123 // GlobalError::DumpErrors - Dump all of the errors/warns to cerr /*{{{*/
124 // ---------------------------------------------------------------------
126 void GlobalError::DumpErrors()
128 // Print any errors or warnings found
130 while (empty() == false)
132 bool Type
= PopMessage(Err
);
134 cerr
<< "E: " << Err
<< endl
;
136 cerr
<< "W: " << Err
<< endl
;