// klog.h — engine logging, KexProof routing (1.3.0 engine swap)
//
// Every engine line goes ONLY to KPLogDirect — the synchronous, queue-free
// append to Documents/kexproof-live.log — which also feeds the transcript/UI
// for non-flood lines. 1.5.3: the old stderr leg is gone for good — the pipe
// capture could fill during the race flood and block the exploit thread in
// fputs/fflush right after a win (the post-guard hang that ate "returning 0").
//
// TweakLog (upstream's second sink) maps to the same routing. The one HUD
// hook the engine calls, tweak_exploit_set_cycle(), is a no-op: the app shell
// has no HUD.
#ifndef klog_h
#define klog_h

#include <stdio.h>
#include <string.h>

void KPLogDirect(const char *line);   // KPLog.m — synchronous panic-proof file write

#define KPRINTF(fmt, ...) do { \
    char _kpl[1024]; \
    snprintf(_kpl, sizeof(_kpl) - 1, fmt, ##__VA_ARGS__); \
    _kpl[sizeof(_kpl) - 1] = 0; \
    size_t _kplLen = strlen(_kpl); \
    while (_kplLen > 0 && _kpl[_kplLen - 1] == '\n') _kpl[--_kplLen] = 0; \
    KPLogDirect(_kpl); \
} while (0)

#define TweakLog KPRINTF

static inline void tweak_exploit_set_cycle(int c) { (void)c; }

#endif /* klog_h */
