1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* misc/diag.h - Diagnostics
*
* Written 2016 by Werner Almesberger
* Copyright 2016 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef MISC_DIAG_H
#define MISC_DIAG_H
/*
* 0: no progress indications
* 1: reasonable progress indications
* 2: verbose output
* > 2: go wild !
*/
extern unsigned verbose;
/* ----- Internal errors --------------------------------------------------- */
#define STRINGIFY(s) #s
#define STRINGIFY_EXPAND(s) STRINGIFY(s)
#define BUG(...) \
fatal("BUG " __FILE__ ":" STRINGIFY_EXPAND(__LINE__) ": " __VA_ARGS__)
/* ----- Specialized diagnostic functions ---------------------------------- */
/* perror, based on "fatal" or "error" */
void __attribute__((noreturn)) diag_pfatal(const char *s);
void diag_perror(const char *s);
/* ----- General diagnostic functions -------------------------------------- */
/*
* Terminate immediately. Further execution makes no sense.
* E.g., out of memory.
*/
void __attribute__((noreturn)) fatal(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
/*
* Operation has failed, but the program as a whole may still be able to
* continue. E.g., a schematics component was not found.
*/
void error(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
/*
* A minor operation has failed or some other issue was detected. This may
* be (or lead to) a more serious problem, but does not immediately affect
* operation.
*/
void warning(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
/*
* Progress message, used mainly for debugging. "level" is the minimum
* verbosity level required.
*/
void progress(unsigned level, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
#endif /* !MISC_DIAG_H */
|