| 1 |
/* 'checkit_tiff' is a conformance checker for baseline TIFFs |
| 2 |
* |
| 3 |
* author: Andreas Romeyke, 2015-2022 |
| 4 |
* licensed under conditions of libtiff |
| 5 |
* (see http://libtiff.maptools.org/misc.html) |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "check_renderer.h" |
| 10 |
#include "ctstring.h" |
| 11 |
#include <assert.h> |
| 12 |
|
| 13 |
/* color definitions, using ISO 6429 as listed in 'man (5) dir_colors' |
| 14 |
0 to restore default color |
| 15 |
1 for brighter colors |
| 16 |
4 for underlined text |
| 17 |
5 for flashing text |
| 18 |
30 for black foreground |
| 19 |
31 for red foreground |
| 20 |
32 for green foreground |
| 21 |
33 for yellow (or brown) foreground |
| 22 |
34 for blue foreground |
| 23 |
35 for purple foreground |
| 24 |
36 for cyan foreground |
| 25 |
37 for white (or gray) foreground |
| 26 |
40 for black background |
| 27 |
41 for red background |
| 28 |
42 for green background |
| 29 |
43 for yellow (or brown) background |
| 30 |
44 for blue background |
| 31 |
45 for purple background |
| 32 |
46 for cyan background |
| 33 |
47 for white (or gray) background |
| 34 |
*/ |
| 35 |
#define ANSI_NORMAL const_str("\033[0m") |
| 36 |
#define ANSI_BOLD const_str("\033[1m") |
| 37 |
#define ANSI_RED const_str("\033[00;31m") |
| 38 |
#define ANSI_RED_BOLD const_str("\033[01;31m") |
| 39 |
#define ANSI_RED_HIGH const_str("\033[00;91m") |
| 40 |
#define ANSI_GREEN const_str("\033[00;32m") |
| 41 |
#define ANSI_GREEN_BOLD const_str("\033[01;32m") |
| 42 |
#define ANSI_RESET const_str("\033[0m") |
| 43 |
#define ANSI_BLACK const_str("\033[00;30m") |
| 44 |
#define ANSI_BLACK_BOLD const_str("\033[01;30m") |
| 45 |
#define ANSI_BROWN const_str("\033[00;33m") |
| 46 |
#define ANSI_BLUE const_str("\033[00;34m") |
| 47 |
#define ANSI_BLUE_BOLD const_str("\033[01;34m") |
| 48 |
#define ANSI_PURPLE const_str("\033[00;35m") |
| 49 |
#define ANSI_CYAN const_str("\033[00;36m") |
| 50 |
#define ANSI_GREY const_str("\033[00;37m") |
| 51 |
#define ANSI_DARK_GREY const_str("\033[01;30m") |
| 52 |
#define ANSI_YELLOW const_str("\033[01;33m") |
| 53 |
#define ANSI_WHITE const_str("\033[01;37m") |
| 54 |
#define ANSI_INVERSE const_str("\033[7m") |
| 55 |
|
| 56 |
|
| 57 |
stringbuf_t renderer_ansi (const retmsg_t * ret) { |
| 58 |
assert (ret != NULL); |
| 59 |
stringbuf_t res = empty_stringbuf(); |
| 60 |
const retmsg_t * startp = ret; |
| 61 |
rc_tristate_t rc_is_valid = rc_undef; |
| 62 |
// print header |
| 63 |
res = secstrcat_cstr(res, "\n"); |
| 64 |
res = secstrcat_string(res, ANSI_BLACK_BOLD); |
| 65 |
res = secstrcat_cstr(res, "result IFD/tag \t--> rule description [; "); |
| 66 |
res = secstrcat_string(res, ANSI_BLUE); |
| 67 |
res = secstrcat_cstr(res, "expected specific values"); |
| 68 |
res = secstrcat_string( res, ANSI_BLACK_BOLD); |
| 69 |
res = secstrcat_cstr(res, "] ["); |
| 70 |
res = secstrcat_string(res, ANSI_RED); |
| 71 |
res = secstrcat_cstr(res, "error description"); |
| 72 |
res = secstrcat_string(res, ANSI_BLACK_BOLD); |
| 73 |
res = secstrcat_cstr(res, "] "); |
| 74 |
res = secstrcat_string(res, ANSI_GREY); |
| 75 |
res = secstrcat_cstr(res, "(lineno in config)"); |
| 76 |
res = secstrcat_string(res, ANSI_BLACK_BOLD); |
| 77 |
res = secstrcat_cstr(res, "\n"); |
| 78 |
res = secstrcat_cstr( res, "----------------------------------------------------------------------------\n"); |
| 79 |
while (NULL != startp) { |
| 80 |
if (startp->rm_type == rm_is_valid) {rc_is_valid = rc_valid;} |
| 81 |
else if (startp->rm_type == rm_error || startp->rm_type == rm_hard_error) {rc_is_valid = rc_invalid;} |
| 82 |
if ( check_if_quiet(startp, rc_is_valid) ) { /*do nothing */ } |
| 83 |
else { |
| 84 |
switch (startp->rm_type) { |
| 85 |
case rm_rule: |
| 86 |
res = secstrcat_string(res, ANSI_NORMAL); |
| 87 |
res = secstrcat_cstr(res, "\t--> "); |
| 88 |
res = secstrcat_string(res, startp->rm_msg); |
| 89 |
break; |
| 90 |
case rm_tag: |
| 91 |
case rm_mode: |
| 92 |
res = secstrcat_cstr(res, "\t"); |
| 93 |
res = secstrcat_string(res, ANSI_BOLD); |
| 94 |
res = secstrcat_string(res, startp->rm_msg); |
| 95 |
break; |
| 96 |
case rm_value: |
| 97 |
if (startp->rm_msg.len > 0) { |
| 98 |
res = secstrcat_string(res, ANSI_RED_HIGH); |
| 99 |
res = secstrcat_cstr(res, "; found: "); |
| 100 |
res = secstrcat_string(res, startp->rm_msg); |
| 101 |
} |
| 102 |
break; |
| 103 |
case rm_expected: |
| 104 |
if (startp->rm_msg.len > 0) { |
| 105 |
res = secstrcat_string(res, ANSI_BLUE); |
| 106 |
res = secstrcat_cstr(res, "; expected: "); |
| 107 |
res = secstrcat_string(res, startp->rm_msg); |
| 108 |
} |
| 109 |
break; |
| 110 |
case rm_hard_error: |
| 111 |
res = secstrcat_string(res, ANSI_RED_BOLD); |
| 112 |
res = secstrcat_cstr(res, "(HE)"); |
| 113 |
res = secstrcat_string(res, startp->rm_msg); |
| 114 |
rc_is_valid = rc_invalid; |
| 115 |
break; |
| 116 |
case rm_error: |
| 117 |
res = secstrcat_string(res, ANSI_RED); |
| 118 |
res = secstrcat_cstr(res, "(EE)"); |
| 119 |
res = secstrcat_string(res, startp->rm_msg); |
| 120 |
rc_is_valid = rc_invalid; |
| 121 |
break; |
| 122 |
case rm_error_description: |
| 123 |
res = secstrcat_string(res, ANSI_RED); |
| 124 |
res = secstrcat_cstr(res, " "); |
| 125 |
res = secstrcat_string(res, startp->rm_msg); |
| 126 |
break; |
| 127 |
case rm_warning: |
| 128 |
res = secstrcat_string(res, ANSI_GREY); |
| 129 |
res = secstrcat_cstr(res, "(WW)"); |
| 130 |
res = secstrcat_string(res, startp->rm_msg); |
| 131 |
rc_is_valid = rc_invalid; |
| 132 |
break; |
| 133 |
case rm_logicalor_error: |
| 134 |
res = secstrcat_string(res, ANSI_YELLOW); |
| 135 |
res = secstrcat_cstr(res, "(LE)"); |
| 136 |
res = secstrcat_string(res, startp->rm_msg); |
| 137 |
rc_is_valid = rc_invalid; |
| 138 |
break; |
| 139 |
case rm_file: |
| 140 |
res = secstrcat_cstr(res, "file: "); |
| 141 |
res = secstrcat_string(res, ANSI_BLUE_BOLD); |
| 142 |
res = secstrcat_string(res, startp->rm_msg); |
| 143 |
res = secstrcat_string(res, ANSI_NORMAL); |
| 144 |
res = secstrcat_cstr(res, "\n"); |
| 145 |
rc_is_valid = rc_undef; |
| 146 |
break; |
| 147 |
case rm_lineno: |
| 148 |
res = secstrcat_string(res, ANSI_GREY); |
| 149 |
res = secstrcat_cstr(res, " (lineno: "); |
| 150 |
res = secstrcat_string(res, startp->rm_msg); |
| 151 |
res = secstrcat_cstr(res, ")"); |
| 152 |
break; |
| 153 |
case rm_endrule: |
| 154 |
case rm_endtiff: |
| 155 |
res = secstrcat_string(res, ANSI_NORMAL); |
| 156 |
res = secstrcat_cstr(res, "\n"); |
| 157 |
rc_is_valid = rc_undef; |
| 158 |
break; |
| 159 |
case rm_is_valid: |
| 160 |
res = secstrcat_string(res, ANSI_GREEN); |
| 161 |
res = secstrcat_cstr(res, "(./)"); |
| 162 |
rc_is_valid = rc_valid; |
| 163 |
break; |
| 164 |
case rm_count_valid: |
| 165 |
res = secstrcat_string(res, ANSI_RESET); |
| 166 |
res = secstrcat_string(res, startp->rm_msg); |
| 167 |
res = secstrcat_cstr(res, "\n"); |
| 168 |
break; |
| 169 |
case rm_count_invalid: |
| 170 |
res = secstrcat_string(res, ANSI_RESET); |
| 171 |
res = secstrcat_string(res, startp->rm_msg); |
| 172 |
res = secstrcat_cstr(res, "\n"); |
| 173 |
break; |
| 174 |
case rm_summary_valid: |
| 175 |
res = secstrcat_string(res, ANSI_GREEN_BOLD); |
| 176 |
res = secstrcat_cstr(res, "\n(./) "); |
| 177 |
res = secstrcat_string(res, startp->rm_msg); |
| 178 |
rc_is_valid = rc_undef; |
| 179 |
break; |
| 180 |
case rm_summary_invalid: |
| 181 |
res = secstrcat_string(res, ANSI_RED_BOLD); |
| 182 |
res = secstrcat_cstr(res, "\n(EE)"); |
| 183 |
res = secstrcat_string(res, startp->rm_msg); |
| 184 |
rc_is_valid = rc_undef; |
| 185 |
break; |
| 186 |
default: |
| 187 |
res = secstrcat_string(res, ANSI_NORMAL); |
| 188 |
res = secstrcat_string(res, startp->rm_msg); |
| 189 |
|
| 190 |
} |
| 191 |
} |
| 192 |
startp = startp->next; |
| 193 |
} |
| 194 |
res=secstrcat_string( res, ANSI_NORMAL); |
| 195 |
res=secstrcat_cstr( res, "\n"); |
| 196 |
return res; |
| 197 |
} |
| 198 |
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/ |