]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/error.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: error.cc,v 1.3 1998/07/12 23:58:46 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 /*{{{*/
18 #pragma implementation "apt-pkg/error.h"
26 #include <apt-pkg/error.h>
29 GlobalError
*_error
= new GlobalError
;
31 // GlobalError::GlobalError - Constructor /*{{{*/
32 // ---------------------------------------------------------------------
34 GlobalError::GlobalError() : List(0), PendingFlag(false)
38 // GlobalError::Errno - Get part of the error string from errno /*{{{*/
39 // ---------------------------------------------------------------------
40 /* Function indicates the stdlib function that failed and Description is
41 a user string that leads the text. Form is:
42 Description - Function (errno: strerror)
43 Carefull of the buffer overrun, sprintf.
45 bool GlobalError::Errno(const char *Function
,const char *Description
,...)
48 va_start(args
,Description
);
50 // sprintf the description
52 vsprintf(S
,Description
,args
);
53 sprintf(S
+ strlen(S
)," - %s (%i %s)",Function
,errno
,strerror(errno
));
66 // GlobalError::Error - Add an error to the list /*{{{*/
67 // ---------------------------------------------------------------------
68 /* Just vsprintfs and pushes */
69 bool GlobalError::Error(const char *Description
,...)
72 va_start(args
,Description
);
74 // sprintf the description
76 vsprintf(S
,Description
,args
);
89 // GlobalError::Warning - Add a warning to the list /*{{{*/
90 // ---------------------------------------------------------------------
91 /* This doesn't set the pending error flag */
92 bool GlobalError::Warning(const char *Description
,...)
95 va_start(args
,Description
);
97 // sprintf the description
99 vsprintf(S
,Description
,args
);
101 // Put it on the list
102 Item
*Itm
= new Item
;
110 // GlobalError::PopMessage - Pulls a single message out /*{{{*/
111 // ---------------------------------------------------------------------
112 /* This should be used in a loop checking empty() each cycle. It returns
113 true if the message is an error. */
114 bool GlobalError::PopMessage(string
&Text
)
119 bool Ret
= List
->Error
;
125 // This really should check the list to see if only warnings are left..
132 // GlobalError::DumpErrors - Dump all of the errors/warns to cerr /*{{{*/
133 // ---------------------------------------------------------------------
135 void GlobalError::DumpErrors()
137 // Print any errors or warnings found
139 while (empty() == false)
141 bool Type
= PopMessage(Err
);
143 cerr
<< "E: " << Err
<< endl
;
145 cerr
<< "W: " << Err
<< endl
;
149 // GlobalError::Discard - Discard /*{{{*/
150 // ---------------------------------------------------------------------
152 void GlobalError::Discard()
164 // GlobalError::Insert - Insert a new item at the end /*{{{*/
165 // ---------------------------------------------------------------------
167 void GlobalError::Insert(Item
*Itm
)
170 for (Item
*I
= List
; I
!= 0; I
= I
->Next
)