/* report.c PUBLIC DOMAIN 2016 */ /* part of dqrs */ /* I, Tom Vajzovic, am the author of this software and its documentation. I permanently abandon all intellectual property rights in them, including copyright, trademarks, design rights, database right, patents, and the right to be identified as the author. I am fairly certain that the software does what the documentation says it does, but I do not guarantee that it does, or that it does what you think it should. I do not guarantee that it will not have undesirable side effects. You are free to use, modify and distribute this software as you please, but you do so at your own risk. If you do not pass on this warning then you may be responsible for any problems encountered by those who obtain the software through you. */ #include #include #include #include "output_buffer.h" #include "report.h" static char *name_buffer = NULL; static size_t name_buffer_size = 0; static size_t name_buffer_len = 0; static size_t round_up (size_t s) {{{ return ((s <= 2) ? s : ((ULLONG_MAX >> __builtin_clzll (s - 1)) + 1)); }}} static void allocate_name (size_t size) {{{ if (size > name_buffer_size) { name_buffer_size = size; name_buffer = realloc (name_buffer, size); } }}} size_t push_path (const char *basename) {{{ size_t dirname_len = name_buffer_len; size_t basename_len = strlen (basename); if ((dirname_len + basename_len + 1) >= name_buffer_size) { allocate_name (round_up (dirname_len + basename_len + 1000)); } memcpy (&name_buffer[dirname_len], basename, basename_len); name_buffer[dirname_len + basename_len] = '/'; name_buffer_len = (dirname_len + basename_len + 1); return dirname_len; }}} void pop_path (size_t path_length) {{{ name_buffer_len = path_length; }}} void report (const char *basename, unsigned char mode) {{{ size_t i; for (i = 0; i < name_buffer_len; i++) { if ((name_buffer[i] < 0x20) || (name_buffer[i] > 0x7E)) { output_mode (WHITE | ON_BLACK | INVERSE); char code[4] = "\\x"; code[2] = "0123456789ABCDEF"[(name_buffer[i] & 0xF0u) >> 4]; code[3] = "0123456789ABCDEF"[(name_buffer[i] & 0x0Fu) ]; output (code, 4); } else { if (name_buffer[i] == '/') { output_mode (BOLD | BLACK | ON_BLACK); } else { output_mode (WHITE | ON_BLACK); } output (&name_buffer[i], 1); } } for (i = 0; basename[i]; i++) { if ((basename[i] < 0x20) || (basename[i] > 0x7E)) { output_mode (BOLD | mode | INVERSE); char code[4] = "\\x"; code[2] = "0123456789ABCDEF"[(basename[i] & 0xF0u) >> 4]; code[3] = "0123456789ABCDEF"[(basename[i] & 0x0Fu) ]; output (code, 4); } else { if ((basename[i] == 0x20) && !basename[i + 1]) { output_mode (BOLD | mode | INVERSE); } else { output_mode (BOLD | mode); } output (&basename[i], 1); } } output_mode (WHITE | ON_BLACK); output ("\n", 1); }}}