played a little with settings for headstyle - causes strange numbers - check!!
[cluster_expansion_thesis.git] / little_helpers / tikz / sketch-0.2.161 / error.c
blob4a53482ec30449044d13b321009efe49e54fb577
1 /* error.c
2 Copyright (C) 2005,2006,2007,2008 Eugene K. Ressler, Jr.
4 This file is part of Sketch, a small, simple system for making
5 3d drawings with LaTeX and the PSTricks or TikZ package.
7 Sketch is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 Sketch is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Sketch; see the file COPYING.txt. If not, see
19 http://www.gnu.org/copyleft */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include "error.h"
26 SRC_LINE no_line = { NULL, 0 };
28 typedef enum error_type_t
30 E_REMARK,
31 E_WARNING,
32 E_ERROR,
33 E_FATAL_ERROR,
34 E_N // keep last; this is the number of error types
36 ERROR_TYPE;
38 char *error_type_str[] = {
39 "remark",
40 "warning",
41 "error",
42 "fatal",
45 static int n_errors[E_N]; // assumes C initialization to zero
47 static void
48 print_error (ERROR_TYPE type, SRC_LINE line, char *fmt, va_list arg_list)
50 n_errors[type]++;
51 if (line.file_name)
52 fprintf (stderr, "%s", line.file_name);
53 if (line.number > 0)
54 fprintf (stderr, "(%u) : ", line.number);
55 fprintf (stderr, "%s, ", error_type_str[type]);
56 vfprintf (stderr, fmt, arg_list);
57 fprintf (stderr, "\n");
60 void
61 remark (SRC_LINE line, char *fmt, ...)
63 va_list arg_list;
65 va_start (arg_list, fmt);
66 print_error (E_REMARK, line, fmt, arg_list);
67 va_end (arg_list);
70 void
71 warn (SRC_LINE line, char *fmt, ...)
73 va_list arg_list;
75 va_start (arg_list, fmt);
76 print_error (E_WARNING, line, fmt, arg_list);
77 va_end (arg_list);
80 void
81 err (SRC_LINE line, char *fmt, ...)
83 va_list arg_list;
85 va_start (arg_list, fmt);
86 print_error (E_ERROR, line, fmt, arg_list);
87 va_end (arg_list);
90 void
91 die (SRC_LINE line, char *fmt, ...)
93 va_list arg_list;
95 va_start (arg_list, fmt);
96 print_error (E_FATAL_ERROR, line, fmt, arg_list);
97 va_end (arg_list);
98 report_errors ();
102 trouble_p (void)
104 return n_errors[E_ERROR] > 0 || n_errors[E_FATAL_ERROR] > 0;
107 void
108 report_errors (void)
110 int i, n_total = 0;
112 // start printing summary
113 fprintf (stderr, "summary: ");
114 for (i = 0; i < E_N; i++)
116 if (n_errors[i] > 0)
118 if (n_total > 0)
119 fprintf (stderr, ", ");
120 fprintf (stderr, "%d %s", n_errors[i], error_type_str[i]);
121 n_total++;
125 // see if we need to abort
126 if (trouble_p ())
128 fprintf (stderr, "\nquitting...\n");
129 exit (1);
131 // not aborting, so finish up the summary
132 if (n_total == 0)
134 fprintf (stderr, "no errors");
136 fprintf (stderr, "\n");
138 // zero the error counters
139 for (i = 0; i < E_N; i++)
140 n_errors[i] = 0;