Debian Codegraph @

packages/seacas/applications/nem_slice/elb_err.C

raw
1 /*
2 * Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8
9 #include "elb_err.h"
10 #include <cstddef> // for size_t
11 #include <cstdio>
12 #include <fmt/ostream.h>
13 #include <vector> // for vector
14
15 const int MAX_ERR_MSG = 1024;
16 int error_lev = 1;
17
18 namespace {
19 std::vector<error_message> error_info;
20 }
21
22 /*****************************************************************************/
23 /*****************************************************************************/
24 /*****************************************************************************/
25 /* This function adds the specified error message to the array of error
26 * structures.
27 *
28 * A level 0 error indicates a fatal error, otherwise it's a warning.
29 *****************************************************************************/
30 void error_add(int level, const std::string &message, const std::string &filename, int line_no)
31 {
32 if (error_info.size() < static_cast<size_t>(MAX_ERR_MSG)) {
33 error_info.emplace_back(level, message, line_no, filename);
34 }
35 }
36
37 /*****************************************************************************/
38 /*****************************************************************************/
39 /*****************************************************************************/
40 /* This function outputs the accumulated error messages to stderr
41 *****************************************************************************/
42 void error_report()
43 {
44
45 if (error_lev >= 1) {
46 int iflag = 0;
47 size_t error_cnt = error_info.size();
48 for (size_t i = 0; i < error_cnt; i++) {
49 if (error_info[i].level == 0 || error_info[i].level >= error_lev) {
50 if (iflag == 0) {
51 fmt::print(stderr, "================================");
52 fmt::print(stderr, "messages");
53 fmt::print(stderr, "================================\n");
54 iflag = 1;
55 }
56
57 fmt::print(stderr, "\t{}\n", error_info[i].err_mesg);
58 if (error_lev >= 2) {
59 fmt::print(stderr, "\t\tin file {}\n", error_info[i].filename);
60 }
61
62 if (error_lev >= 3) {
63 fmt::print(stderr, "\t\t\tat line {}\n", error_info[i].line_no);
64 }
65 }
66 }
67 }
68 }