src/error.c

filter: Statementstmt 69.2% 36 / 52 Branchbran 20.8% 5 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 53.9% 41 / 76 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Text/BibTeX/Bib.pm ↑ Summary src/ast.c »
1 /* ------------------------------------------------------------------------
2 @NAME : error.c
3 @DESCRIPTION: Collecting errors and warnings. The library never prints
4 anything and never exits: every problem is appended to a
5 caller-supplied bt_errors list, and the caller (the Perl XS
6 layer) decides how to report it.
7 -------------------------------------------------------------------------- */
8  
9 #include <stdlib.h>
10 #include <string.h>
11 #include "bt_internal.h"
12  
13 static const char * errclass_names[BT_NUM_ERRCLASSES] =
14 {
15 NULL, /* BTERR_NOTIFY */
16 "warning", /* BTERR_CONTENT */
17 "warning", /* BTERR_LEXWARN */
18 "warning", /* BTERR_USAGEWARN */
19 "error", /* BTERR_LEXERR */
20 "syntax error", /* BTERR_SYNTAX */
21 "fatal error", /* BTERR_USAGEERR */
22 "internal error" /* BTERR_INTERNAL */
23 };
24  
25 const char *
26 0 bt_errclass_name (bt_errclass errclass)
27 {
28 0 ▶ if ((int) errclass < 0 || (int) errclass >= BT_NUM_ERRCLASSES)
Branch: 2 branches
BranchTrueFalseTotal
if ((int) errclass < 0 || (int) errclass >= BT_NUM_ERRCLASSES) 0 0 0
if ((int) errclass < 0 || (int) errclass >= BT_NUM_ERRCLASSES) 0 0 0
29 0 return NULL;
30 0 return errclass_names[errclass];
31 }
32  
33 void
34 749 bt_errors_init (bt_errors *errs)
35 {
36 749 memset (errs, 0, sizeof (*errs));
37 749 }
38  
39 void
40 60 bt_errors_clear (bt_errors *errs)
41 {
42 60 bt_error * e = errs->head;
43  
44 142 ▶ while (e)
Branch: 1 branch
BranchTrueFalseTotal
while (e) 82 60 142
45 {
46 82 bt_error * next = e->next;
47 82 free (e->filename);
48 82 free (e->item_desc);
49 82 free (e->message);
50 82 free (e);
51 82 e = next;
52 }
53 60 bt_errors_init (errs);
54 60 }
55  
56 void
57 82 bt_vreport (bt_errors *errs, bt_errclass errclass,
58 const char *filename, int line,
59 const char *item_desc, int item,
60 const char *fmt, va_list ap)
61 {
62 bt_error * e;
63 bt_sbuf msg;
64  
65 82 ▶ if (errs == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (errs == NULL) 0 82 82
66 0 return;
67  
68 82 bt_sbuf_init (&msg);
69 82 bt_sbuf_vprintf (&msg, fmt, ap);
70  
71 82 e = bt_xmalloc (sizeof (bt_error));
72 82 e->errclass = errclass;
73 82 e->filename = bt_xstrdup (filename);
74 82 e->line = line;
75 82 e->item_desc = bt_xstrdup (item_desc);
76 82 e->item = item;
77 82 e->message = bt_sbuf_steal (&msg);
78 82 e->next = NULL;
79  
80 82 ▶ if (errs->tail)
Branch: 1 branch
BranchTrueFalseTotal
if (errs->tail) 22 60 82
81 22 errs->tail->next = e;
82 else
83 60 errs->head = e;
84 82 errs->tail = e;
85 82 errs->counts[errclass]++;
86 }
87  
88 void
89 58 bt_report (bt_errors *errs, bt_errclass errclass,
90 const char *filename, int line,
91 const char *item_desc, int item,
92 const char *fmt, ...)
93 {
94 va_list ap;
95  
96 58 va_start (ap, fmt);
97 58 bt_vreport (errs, errclass, filename, line, item_desc, item, fmt, ap);
98 58 va_end (ap);
99 58 }
100  
101 int
102 0 bt_errors_count (const bt_errors *errs, bt_errclass errclass)
103 {
104 0 return errs->counts[errclass];
105 }
106  
107 /* A "serious" error is anything other than a notification, a content
108 * warning or a lexical warning -- the same rule btparse always used to
109 * decide whether an entry parsed OK. */
110 boolean
111 0 bt_errors_ok (const bt_errors *errs)
112 {
113 int i;
114  
115 0 ▶ for (i = 0; i < BT_NUM_ERRCLASSES; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < BT_NUM_ERRCLASSES; i++) 0 0 0
116 {
117 0 ▶ if (i == BTERR_NOTIFY || i == BTERR_CONTENT || i == BTERR_LEXWARN)
Branch: 3 branches
BranchTrueFalseTotal
if (i == BTERR_NOTIFY || i == BTERR_CONTENT || i == BTERR_LEXWARN) 0 0 0
if (i == BTERR_NOTIFY || i == BTERR_CONTENT || i == BTERR_LEXWARN) 0 0 0
if (i == BTERR_NOTIFY || i == BTERR_CONTENT || i == BTERR_LEXWARN) 0 0 0
118 0 continue;
119 0 ▶ if (errs->counts[i])
Branch: 1 branch
BranchTrueFalseTotal
if (errs->counts[i]) 0 0 0
120 0 return FALSE;
121 }
122 0 return TRUE;
123 }
124  
125 boolean
126 0 bt_errors_fatal (const bt_errors *errs)
127 {
128 0 ▶ return errs->counts[BTERR_USAGEERR] || errs->counts[BTERR_INTERNAL];
Branch: 2 branches
BranchTrueFalseTotal
return errs->counts[BTERR_USAGEERR] || errs->counts[BTERR_INTERNAL]; 0 0 0
return errs->counts[BTERR_USAGEERR] || errs->counts[BTERR_INTERNAL]; 0 0 0
129 }
« blib/lib/Text/BibTeX/Bib.pm ↑ Summary src/ast.c »