File: message.h

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (155 lines) | stat: -rw-r--r-- 5,500 bytes parent folder | download | duplicates (4)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef INCLUDED_MESSAGE_H_
#define INCLUDED_MESSAGE_H_

#include "../root/root.h"

/*
    Enum MESSAGE_SEVERITY follows the syslog classification.  message() may
use the | operator to combine a message for several severity levels Also
message_setseverity() may use this, as well as MSG_NONE to suppress all
messages and MSG_ALL to show all messages (except for MSG_EMERG messages and
builtin WARNING() calls)

    MSG_DEBUG:  Probably too much info, like getting a (and which) character
                from the lexer's media stack.
    MSG_INFO:   Not as detailed as characters, but still very much info, like
                a media switch and return to a former media.
    MSG_NOTICE: All predefined function calls fall in this category
    MSG_WARNING:Something you should know about, but probably not affecting
                Yodl's proper functioning.
    MSG_ERR:    An error (like doubly defined symbols), parsing continues (up
                to a maximum number of errors) with fingers crossed,
                but no output is generated. With MSG_ERR functions may
                terminate without properly freeing allocated memory. The
                maximum error limit should be reached before memory
                exhaustion occurs. If not: too bad. The alternative is too
                cumbersome in C, lacking proper exception handling mechanisms.
    MSG_CRIT:   Below here yodl terminates. The message itself can be
                suppressed, but exiting can't. A critical condition is, e.g.,
                not an open parenthesis at a location where a parameter list
                is expected, or a non-existing file in an INCLUDEFILE
                specification (as thisfile should be parsed. A non-existing
                file with a NOEXPANDINCLUDE specification is a mere MSG_ERR)
    MSG_ALERT:  Yodl requests something of the system (like a get_cwd(),
                but the system fails.
    MSG_EMERG:  Shouldn't happen, like a failing regex_comp() with a fixed
                pattern: it used to work up to now, so it's unclear as to
                why it now fails. Also, an underflow of the lexer's media
                stack falls into this category. EMERG messages cannot be
                suppressed.
*/

typedef enum
{
    MSG_DEBUG   = 1 << 0,           /*  debug-level message                 */
    MSG_INFO    = 1 << 1,           /*  informational message               */
    MSG_NOTICE  = 1 << 2,           /*  normal, but significant, condition  */
    MSG_WARNING = 1 << 3,           /*  warning conditions                  */
    MSG_ERR     = 1 << 4,           /*  error conditions                    */
    MSG_CRIT    = 1 << 5,           /*  critical conditions                 */
    MSG_ALERT   = 1 << 6,           /*  action must be taken immediately    */
    MSG_EMERG   = 1 << 7,           /*  system is unusable                  */

    MSG_NONE    = 0,                /*  No messages                         */
    MSG_ALL     = ~0                /*  All messages                        */
}
MESSAGE_SEVERITY;

typedef struct
{
    size_t              d_max_errors;
    size_t              d_errors;
    char                *d_program_name;
    char                *d_filename;
    size_t              d_lineno;
    MESSAGE_SEVERITY    d_severity;
    MESSAGE_SEVERITY    d_last_show;
    bool                d_warn;

    char                *d_short_filename;          /* not allocated    */
}
Message;

extern int message_data;

void    message_construct(char const *argv0);

void    message(char const* format, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
void    message_error(char const *fmt,...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
void    message_optarg(char const *opt);
bool    message_show(MESSAGE_SEVERITY level);
void    message_setfilename(char const *newname);
void    message_setverbosity(int mode, char *arg);  /* arg may be modified  */
void    message_incseverity(void);
void    warning(char const* format, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
                                                    /* not suppressible     */

char const         *message_verbosity(void);       /* returns (hex) mask   */
char const         *message_version(void);

/* 
    Internal Message use only. Not used outside of this directory functions, needed here
    to allow proper compilation of the static inline functions below
*/

extern Message m_message;


/*  public interface continues from here */


static inline void message_setwarn(bool trueIsOn)
{
    m_message.d_warn = trueIsOn;
}

static inline void message_setseverity(MESSAGE_SEVERITY severity)
{
    m_message.d_severity = severity | MSG_EMERG;
}

static inline void message_setmaxerrors(size_t max)
{
    m_message.d_max_errors = max;
}

static inline void message_setlineno(size_t line)
{
    m_message.d_lineno = line;
}

static inline char const *message_filename()
{
    return m_message.d_filename;
}

static inline size_t message_lineno()
{
    return m_message.d_lineno;
}

static inline char const *message_programName(void)
{
    return m_message.d_program_name;
}

static inline MESSAGE_SEVERITY    message_mask()
{
    return m_message.d_severity;
}

static inline bool  message_errors()
{
    return m_message.d_errors != 0;
}

/*
    a decimal value: the corresponding MSG flags are set as the new
    verbosity level.
*/
static inline void message_setmask(size_t mask)
{
    m_message.d_severity = mask | MSG_ALERT;    /* new verbosity setting    */
}

#endif