Moved display logic to seperate TU (display.c), added options for display output types (TODO) and (TODO) flags.
Fortune for naka's current commit: Future small blessing − 末小吉master
parent
a5b3bc79b3
commit
9d0747a5f7
@ -0,0 +1,35 @@
|
||||
#ifndef _DISPLAY_H
|
||||
#define _DISPLAY_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "macros.h"
|
||||
#include "ints.h"
|
||||
#include "slice.h"
|
||||
|
||||
typedef enum display_kind {
|
||||
DISPK_NORMAL = 0,
|
||||
DISPK_CSV,
|
||||
DISPK_BINARY,
|
||||
DISPK_INI,
|
||||
} dispkind_t;
|
||||
|
||||
#define X(n) AS(1lu << (n), usize)
|
||||
typedef enum display_flags {
|
||||
DISPF_SHOW_NUMBER = X(0),
|
||||
DISPF_SHOW_LENGTH = X(1),
|
||||
DISPF_SHOW_SLICE = X(2),
|
||||
DISPF_SHOW_FAILURES = X(3),
|
||||
} dispflags_t;
|
||||
#define DISPLAY_FLAGS_DEFAULT (DISPF_SHOW_SLICE | DISPF_SHOW_NUMBER | DISPF_SHOW_FAILURES)
|
||||
#undef X
|
||||
|
||||
typedef struct {
|
||||
slice_t cslice;
|
||||
const void* base;
|
||||
usize index;
|
||||
} dispin_t;
|
||||
|
||||
void display_result(FILE* output, dispin_t input, dispkind_t how, dispflags_t flags);
|
||||
|
||||
#endif /* _DISPLAY_H */
|
@ -0,0 +1,50 @@
|
||||
//! Displaying match data
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <macros.h>
|
||||
#include <comp.h>
|
||||
#include <display.h>
|
||||
|
||||
static void _display_normal(FILE* output, dispin_t*pIN input, dispflags_t flags)
|
||||
{
|
||||
slice_t cslice = input->cslice;
|
||||
const void* base = input->base;
|
||||
usize i = input->index;
|
||||
|
||||
#ifdef _DEBUG_MANCALC_OFFSETS
|
||||
struct {
|
||||
usize start, end;
|
||||
} pos = {
|
||||
.start = AS(cslice.ptr - base, usize),
|
||||
};
|
||||
pos.end = pos.start + cslice.len;
|
||||
#else
|
||||
let pos = slice_sted((slice_t[]){ SLICE(AS(cslice.ptr - base, usize), cslice.len)});
|
||||
#endif
|
||||
INFO("Mapped region slice for %lu, pre-transform (at %p): " SLICE_FORMAT ", len: %lu", i+1, base, SLICE_FORMAT_ARGS(&cslice), cslice.len);
|
||||
|
||||
//TODO: Honour `flags`
|
||||
IGNORE(flags);
|
||||
fprintf(output, "match: %lu: %lu -> %lu\n", i+1, pos.start, pos.end);
|
||||
}
|
||||
|
||||
void display_result(FILE* output, dispin_t input, dispkind_t how, dispflags_t flags)
|
||||
{
|
||||
flags = flags ?: DISPLAY_FLAGS_DEFAULT;
|
||||
output = output ?: stdout;
|
||||
debug_assert(input);
|
||||
|
||||
TRACE("Outputting as %d to %p with flags 0x%08lx", (int)how, output, (usize)flags);
|
||||
switch(how)
|
||||
{
|
||||
case DISPK_NORMAL:
|
||||
_display_normal(output, &input, flags);
|
||||
break;
|
||||
case DISPK_CSV:
|
||||
case DISPK_BINARY:
|
||||
case DISPK_INI:
|
||||
default: COLD_EXPR(FATAL("unknown or unimplemented display kind: %d", (int)how));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue