Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
opt_trace.cpp
Go to the documentation of this file.
1
29// expand _TEST_EXPORT macros
30#define _RWSTD_TEST_SRC
31
32#include "opt_trace.h"
33
34#include <stdio.h> // for fprintf()
35#include <stdlib.h> // for strtol()
36#include <string.h> // for strchar()
37
38
40// masked diagnostics (those that shouldn't be issued)
42
43// bitmap of diagnostics to ignore
45
46
47int
48_rw_setopt_trace_mask (int argc, char *argv[])
49{
50 if (1 == argc && argv && 0 == argv [0]) {
51 static const char helpstr[] = {
52 "Specifies the severity of diagnostic messages to be issued when\n"
53 "active. By default, diagnostics with severity of 3 and and above\n"
54 "are issued, all others are suppressed. The severity of an inactive"
55 "\ndiagnostic is always zero, regardless of what the severity would"
56 "\nbe if it were active.\n\n"
57 "The syntax of <arg> is as follows:\n"
58 "<arg> ::= <range> [ , <range> ]\n"
59 "<range> ::= [ - ] <digit> | <digit> - [ <digit> ]\n"
60 "<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n"
61 "\n"
62 "The default names of the diagnostic messages arranged in order\n"
63 "of increasing severity are as follows:\n"
64 "ITRACE, TRACE, DEBUG, INFO, NOTE, WARNING, ASSERTION, UNUSED,\n"
65 "ERROR, and FATAL.\n"
66 "The name of each inactive diagnostic is preceded by the name\n"
67 "of the severity-0 diagnostic (ITRACE_ by default). The severity\n"
68 "of an inactive diagnostic is always zero, regardless of what\n"
69 "the severity would be if it were active.\n"
70 };
71
72 argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
73
74 return 0;
75 }
76
77 char *parg = strchr (argv [0], '=');
78
79 if (0 == parg) {
80 _rw_diag_mask = 0;
81 return 0;
82 }
83
84 int diag_set = 0;
85
86 const char* const argbeg = ++parg;
87
88 // the lower bound of a range of severities to be enabled or disabled
89 // negative values are not valid and denote an implicit lower bound
90 // of 1 (such as in "-3" which is a shorthand for "1-3")
91 long first = -1;
92
93 for ( ; '\0' != *parg ; ) {
94
95 // skip any leading whitespace
96 for ( ; ' ' == *parg; ++parg);
97
98 if ('-' == *parg) {
99 if (first < 0) {
100 first = 0;
101 ++parg;
102 }
103 else {
104 fprintf (stderr,
105 "invalid character '%c' at position %d: \"%s\"\n",
106 *parg, int (parg - argbeg), argv [0]);
107 return 2;
108 }
109 }
110
111 // parse a numeric argument
112 char *end;
113 long severity = strtol (parg, &end, 0);
114
115 // skip any trailing whitespace
116 for ( ; ' ' == *end; ++end);
117
118 if (end == parg || ('-' != *end && ',' != *end && '\0' != *end)) {
119 fprintf (stderr,
120 "invalid character '%c' at position %d: \"%s\"\n",
121 *end, int (parg - argbeg), argv [0]);
122 return 2;
123 }
124
125 if (0 <= first) {
126 if (severity < 0 || N_DIAG_TYPES < severity) {
127 fprintf (stderr,
128 "invalid value %ld at position %d: \"%s\"\n",
129 severity, int (parg - argbeg), argv [0]);
130 return 2;
131 }
132
133 ++severity;
134
135 if ((',' == *end || '-' == *end) && end [1])
136 ++end;
137 }
138 else if (',' == *end) {
139 first = severity++;
140 if ('\0' == end [1]) {
141 fprintf (stderr,
142 "invalid character '%c' at position %d: \"%s\"\n",
143 *end, int (parg - argbeg), argv [0]);
144 return 2;
145 }
146
147 ++end;
148 }
149 else if ('-' == *end) {
150 first = severity;
151 while (' ' == *++end);
152 if ('\0' == *end) {
153 severity = N_DIAG_TYPES;
154 }
155 else if (',' == *end) {
156 severity = N_DIAG_TYPES;
157 ++end;
158 }
159 else
160 severity = -1;
161 }
162 else if ('\0' == *end) {
163 first = severity++;
164 }
165 else {
166 fprintf (stderr,
167 "invalid character '%c' at position %d: \"%s\"\n",
168 *end, int (parg - argbeg), argv [0]);
169 return 2;
170 }
171
172 parg = end;
173
174 if (0 <= first && first < severity) {
175 for (long i = first; i != severity; ++i)
176 diag_set |= 1 << i;
177 severity = -1;
178 }
179 }
180
181 _rw_diag_mask = ~diag_set;
182
183 return 0;
184}
185
186
188int
189_rw_setopt_trace (int argc, char *argv[])
190{
191 if (1 == argc && argv && 0 == argv [0]) {
192 static const char helpstr[] = {
193 "Specifies that diagnostic messages of all severities be issued\n"
194 "regardless of whether they are active or not. See the --severity\n"
195 "option for details.\n"
196 };
197
198 argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
199
200 return 0;
201 }
202
203 return _rw_setopt_trace_mask (argc, argv);
204}
#define i
Definition 17.names.cpp:126
const int end
#define stderr
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
@ N_DIAG_TYPES
Definition opt_diags.h:48
@ diag_trace
Definition opt_diags.h:37
int _rw_diag_mask
Definition opt_trace.cpp:41
int _rw_setopt_trace_mask(int argc, char *argv[])
Definition opt_trace.cpp:48
int _rw_setopt_trace(int argc, char *argv[])
int _rw_diag_ignore
Definition opt_trace.cpp:44