30#define _RWSTD_TEST_SRC
40#define ESC_END ESC "[30;30;0m"
41#define ESC_CODE(fg, bg, attr) ESC "[" fg bg attr "m", ESC_END
78 "inactive diagnostic trace"
93 "expected diagnostic inactive"
123 "fatal test error, abort imminent"
129_rw_vt100_colors[] = {
143_rw_vt100_attribs[] = {
156_rw_match_name (
const esc_text_t *text,
size_t nelems,
157 const char *first,
const char *
last)
163 const size_t len = size_t (
last - first);
168 for (
size_t i = 0;
i != nelems; ++
i) {
169 if ( 0 == strncmp (text [
i].code, first,
len)
170 &&
'\0' == text [
i].code [
len])
181 if (1 == argc && argv && 0 == argv [0]) {
182 static const char helpstr[] = {
183 "Sets the colors and names of the diagnostic messages issued by\n"
185 "There are 10 different types of diagnostic messages, each with\n"
186 "a unique severity level between 0 (the lowest) and 9. Each\n"
187 "diagnostic message can either be active or inactive. Each\n"
188 "message can have a name of up to 15 characters associated with\n"
189 "it, foreground color, background color, and a video attribute.\n"
190 "These parameters are controlled by the argument to this option.\n"
191 "\nThe syntax of <arg> is as follows:\n"
192 "<arg> ::= <color-list>\n"
193 "<color-list> ::= <color-txt> [ ,<color-list> ]\n"
194 "<color-txt> ::= <sev>:[<color>][:[<color>][:[<attr>][:[<text>]]]]"
195 "\n<sev> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n"
196 "<color> ::= black | red | green | yellow\n"
197 " | blue | magenta | cyan | white\n"
198 "<attr> ::= off | bold | dim | underscore\n"
199 " | blink | reverse | hidden\n"
200 "<text> ::= A-Z a-z 0-9 _\n\n"
201 "The first <color> component specifies the foreground color\n"
202 "while the second (optional) <color> component specifies\n"
203 "the background color for the diagnostic of the severity <sev>.\n"
204 "Empty arguments are permitted and denote the default system\n"
205 "color set for the terminal.\n"
213 char *parg = strchr (argv [0],
'=');
215 if (0 == parg ||
'\0' == parg [1]) {
216 fprintf (
stderr,
"%s:%d: missing argument in %s\n",
217 __FILE__, __LINE__, argv [0]);
247 if (
'0' <= *parg && *parg <=
'9') {
252 fprintf (
stderr,
"%s:%d: digit expected at position %d: %s\n",
253 __FILE__, __LINE__,
int (parg - argv [0]), argv [0]);
264 fprintf (
stderr,
"%s:%d: colon expected at position %d: %s\n",
265 __FILE__, __LINE__,
int (parg - argv [0]), argv [0]);
271 char *
end = strpbrk (parg,
":,");
273 end = parg + strlen (parg);
275 fgcol = _rw_match_name (_rw_vt100_colors, 8, parg,
end);
276 if (fgcol < 0 || 8 < fgcol) {
278 fprintf (
stderr,
"%s:%d: unknown color at position %d: %s\n",
279 __FILE__, __LINE__,
int (parg - argv [0]), argv [0]);
287 if (
':' == *
end ||
'\0' == *
end) {
289 end = strpbrk (parg,
":,");
291 end = parg + strlen (parg);
293 bgcol = _rw_match_name (_rw_vt100_colors, 8, parg,
end);
295 if (bgcol < 0 || 8 < bgcol) {
297 fprintf (
stderr,
"%s:%d: unknown color at position %d: %s\n",
298 __FILE__, __LINE__,
int (parg - argv [0]), argv [0]);
306 if (
':' == *
end ||
'\0' == *
end) {
307 parg =
end + (
'\0' != *
end);
308 end = strpbrk (parg,
":,");
310 end = parg + strlen (parg);
312 attr = _rw_match_name (_rw_vt100_attribs, 8, parg,
end);
313 if (attr < 0 || 8 < attr) {
316 "%s:%d: unknown attribute at position %d: %s\n",
317 __FILE__, __LINE__,
int (parg - argv [0]),
326 if (
':' == *
end ||
'\0' == *
end) {
328 end = strpbrk (parg,
":,");
330 end = parg + strlen (parg);
332 size_t len = size_t (
end - parg);
338 "%s:%d: name too long at position %d: %s\n",
339 __FILE__, __LINE__,
int (parg - argv [0]),
345 memcpy (diag_code, parg,
len);
346 diag_code [
len] =
'\0';
353 if (-1 < fgcol && fgcol < 8)
354 strcat (
diag_msgs [sev].esc_pfx, _rw_vt100_colors [fgcol].esc_pfx);
356 if (-1 < bgcol && bgcol < 8) {
357 strcat (
diag_msgs [sev].esc_pfx, _rw_vt100_colors [bgcol].esc_pfx);
359 const size_t bgdiginx = strlen (
diag_msgs [sev].esc_pfx) - 3;
365 if (-1 < attr && attr < 8)
366 strcat (
diag_msgs [sev].esc_pfx, _rw_vt100_attribs [attr].esc_pfx);
378 strcpy (
diag_msgs [sev].code, diag_code);
380 parg =
end + (
'\0' != *
end);
#define _RWSTD_CONST_CAST(T, x)
int _rw_setopt_diags(int argc, char *argv[])
#define ESC_CODE(fg, bg, attr)